forked from mz2/Fragaria
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathFragariaAppDelegate.m
204 lines (154 loc) · 4.71 KB
/
FragariaAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//
// FragariaAppDelegate.m
// Fragaria
//
// Created by Jonathan on 30/04/2010.
// Copyright 2010 mugginsoft.com. All rights reserved.
//
#import "FragariaAppDelegate.h"
#import <Fragaria/Fragaria.h>
#import "MGSSimpleBreakpointDelegate.h"
#import "ExampleCustomParser.h"
#import "ExampleCustomParserWithComposition.h"
@implementation FragariaAppDelegate {
IBOutlet MGSFragariaView *fragaria;
MGSSimpleBreakpointDelegate *breakptDelegate;
}
@synthesize window;
#pragma mark - NSApplicationDelegate
/*
* - applicationDidFinishLaunching:
*/
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
/* Register our custom parser factories.
* The custom parsers will appear in the list of languages, toghether with the
* other standard ones. */
[[MGSSyntaxController sharedInstance] registerParserFactory:[[ExampleCustomParser alloc] init]];
[[MGSSyntaxController sharedInstance] registerParserFactory:[[ExampleCustomParserWithComposition alloc] init]];
// define initial object configuration
//
// see Fragaria.h for details
//
fragaria.textViewDelegate = self;
// set our syntax definition
[self setSyntaxDefinition:@"Objective-C"];
// get initial text - in this case a test file from the bundle
NSString *path = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"txt"];
NSString *fileText = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
// set text
fragaria.string = fileText;
// define a syntax error
MGSSyntaxError *syntaxError = [MGSSyntaxError new];
syntaxError.errorDescription = @"Syntax errors can be defined.";
syntaxError.line = 1;
syntaxError.character = 1;
syntaxError.length = 10;
fragaria.syntaxErrors = @[syntaxError];
// specify a breakpoint delegate
breakptDelegate = [[MGSSimpleBreakpointDelegate alloc] init];
fragaria.breakpointDelegate = breakptDelegate;
// Use a color scheme with dynamic colors to support light/dark transition.
// When using FragariaDefaultsCoordinator, this is not required.
fragaria.colourScheme = [MGSColourScheme dynamicColorBuiltinColourScheme];
}
/*
* - applicationShouldTerminateAfterLastWindowClosed:
*/
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
#pragma unused(theApplication)
return YES;
}
#pragma mark - Actions
/*
* - reloadString:
*/
- (IBAction)reloadString:(id)sender
{
[fragaria setString:[fragaria string]];
}
#pragma mark - Pasteboard handling
/*
* - copyToPasteBoard:
*/
- (IBAction)copyToPasteBoard:(id)sender
{
NSAttributedString *attString = fragaria.textView.attributedString;
NSData *data = [attString RTFFromRange:NSMakeRange(0, [attString length])
documentAttributes:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}];
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
[pasteboard setData:data forType:NSRTFPboardType];
}
#pragma mark - Property Accessors
/*
* @property syntaxDefinition
*/
- (void)setSyntaxDefinition:(NSString *)name
{
fragaria.syntaxDefinitionName = name;
}
- (NSString *)syntaxDefinition
{
return fragaria.syntaxDefinitionName;
}
#pragma mark - NSTextDelegate
/*
* - textDidChange:
*/
- (void)textDidChange:(NSNotification *)notification
{
#pragma unused(notification)
[window setDocumentEdited:YES];
}
/*
* - textDidBeginEditing:
*/
- (void)textDidBeginEditing:(NSNotification *)aNotification
{
NSLog(@"notification : %@", [aNotification name]);
}
/*
* - textDidEndEditing:
*/
- (void)textDidEndEditing:(NSNotification *)aNotification
{
NSLog(@"notification : %@", [aNotification name]);
}
/*
* - textShouldBeginEditing:
*/
- (BOOL)textShouldBeginEditing:(NSText *)aTextObject
{
#pragma unused(aTextObject)
return YES;
}
/*
* - textShouldEndEditing:
*/
- (BOOL)textShouldEndEditing:(NSText *)aTextObject
{
#pragma unused(aTextObject)
return YES;
}
- (void)textViewDidChangeSelection:(NSNotification *)notification
{
NSUInteger i, r, c;
i = fragaria.textView.selectedRange.location;
[fragaria getRow:&r column:&c forCharacterIndex:i];
self.row = [NSString stringWithFormat:@"%lu", (unsigned long)r+1];
self.column = [NSString stringWithFormat:@"%lu", (unsigned long)c+1];
}
#pragma mark - MGSFragariaTextViewDelegate
/*
* - mgsTextDidPaste:
*/
- (void)mgsTextDidPaste:(NSNotification *)aNotification
{
// When this notification is received the paste will have been accepted.
// Use this method to query the pasteboard for additional pasteboard content
// that may be relevant to the application: eg: a plist that may contain custom data.
NSLog(@"notification : %@", [aNotification name]);
}
@end