-
Notifications
You must be signed in to change notification settings - Fork 89
/
ViDocument.h
247 lines (213 loc) · 8.76 KB
/
ViDocument.h
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* Copyright (c) 2008-2012 Martin Hedenfalk <martin@vicoapp.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "ViWindowController.h"
#import "ViTextStorage.h"
#import "ViURLManager.h"
#import "ViScope.h"
#import "ViDocumentView.h"
#import "ViMarkManager.h"
@class ViTextView;
@class ExCommand;
@class ViFold;
/** A document.
*/
@interface ViDocument : NSDocument <NSTextViewDelegate, NSLayoutManagerDelegate, NSTextStorageDelegate, ViDeferredDelegate, ViViewDocument>
{
NSMutableSet *_views;
ViDocumentView *_hiddenView;
ViTextView *_scriptView;
NSMutableDictionary *_associatedViews;
ViBundle *_bundle;
ViLanguage *_language;
ViTheme *_theme;
NSInteger _tabSize; /* scope-specific */
BOOL _wrap; /* scope-specific */
/* Set when opening a new file from the ex command line. */
BOOL _isTemporary;
BOOL _hasUndoGroup;
BOOL _ignoreChangeCountNotification; // XXX: this is a hack
id<ViDeferred> _loader;
BOOL _busy;
BOOL _modified;
ViTextStorage *_textStorage;
NSDictionary *_typingAttributes;
ViWindowController *_windowController;
NSString *_readContent;
NSStringEncoding _encoding;
NSStringEncoding _forcedEncoding;
BOOL _retrySaveOperation;
// language parsing and highlighting
BOOL _ignoreEditing;
BOOL _closed;
ViSyntaxParser *_syntaxParser;
ViSyntaxContext *_nextContext;
// standard character marks
ViMarkStack *_localMarks;
NSMutableSet *_marks; // All marks associated with this document. XXX: don't retain!?
// symbol list
NSMutableArray *_symbols;
NSArray *_filteredSymbols;
NSDictionary *_symbolScopes;
NSDictionary *_symbolTransforms;
NSDictionary *_symbolIcons;
NSRange _matchingParenRange;
ViSnippet *_snippet;
id _didSaveDelegate;
SEL _didSaveSelector;
void *_didSaveContext;
/* Called when the document closes. code is 0 if document saved successfully. */
void (^_closeCallback)(int code);
}
@property(nonatomic,readwrite,strong) ViSnippet *snippet;
@property(nonatomic,readonly) NSSet *views;
@property(nonatomic,readwrite,strong) ViBundle *bundle;
@property(nonatomic,readwrite,strong) ViTheme *theme;
@property(nonatomic,readonly,strong) ViLanguage *language;
@property(nonatomic,readwrite,strong) NSArray *symbols;
@property(nonatomic,readwrite,strong) NSArray *filteredSymbols;
@property(nonatomic,readwrite,strong) NSDictionary *symbolScopes;
@property(nonatomic,readwrite,strong) NSDictionary *symbolTransforms;
@property(nonatomic,readonly) NSStringEncoding encoding;
@property(nonatomic,readwrite) BOOL isTemporary;
@property(nonatomic,readwrite) BOOL busy;
@property(nonatomic,readwrite,getter=isModified) BOOL modified;
@property(nonatomic,readwrite,copy) void (^closeCallback)(int);
@property(nonatomic,readwrite,strong) id<ViDeferred> loader;
@property(nonatomic,readwrite) BOOL ignoreChangeCountNotification;
@property(nonatomic,readwrite) NSRange matchingParenRange;
@property(nonatomic,readwrite,strong) ViDocumentView *hiddenView;
@property(nonatomic,readwrite,strong) ViSyntaxParser *syntaxParser;
@property(nonatomic,readonly) NSSet *marks;
@property(nonatomic,readonly) ViMarkStack *localMarks;
/** Return the ViTextStorage object. */
@property(nonatomic,readonly) ViTextStorage *textStorage;
- (void)message:(NSString *)fmt, ...;
- (NSDictionary *)typingAttributes;
/** Return a scriptable text view.
*
* The returned text view is not visible.
*
* @returns A scriptable text view.
*/
- (ViTextView *)text;
- (IBAction)toggleLineNumbers:(id)sender;
/** Get the language syntax.
* @returns The language syntax currently in use, or `nil` if no language configured.
*/
- (IBAction)setLanguageAction:(id)sender;
- (void)setLanguageAndRemember:(ViLanguage *)lang;
- (void)setLanguage:(ViLanguage *)lang;
- (void)configureForURL:(NSURL *)aURL;
- (void)configureSyntax;
- (void)changeTheme:(ViTheme *)aTheme;
- (void)updatePageGuide;
- (NSUInteger)filterSymbols:(ViRegexp *)rx;
- (void)dispatchSyntaxParserWithRange:(NSRange)aRange restarting:(BOOL)flag;
- (ViDocumentView *)makeViewWithParser:(ViParser *)aParser;
- (ViDocumentView *)makeView;
- (ViDocumentView *)cloneView:(ViDocumentView *)oldView;
- (void)removeView:(ViDocumentView *)aDocumentView;
- (void)addView:(ViDocumentView *)aDocumentView;
- (void)enableLineNumbers:(BOOL)flag relative:(BOOL)relative forScrollView:(NSScrollView *)aScrollView;
- (ViWindowController *)windowController;
- (void)closeWindowController:(ViWindowController *)aController;
- (NSString *)title;
- (void)setString:(NSString *)aString;
- (void)setData:(NSData *)data;
- (void)closeAndWindow:(BOOL)canCloseWindow;
- (BOOL)isEntireFileLoaded;
/** @name Working with scopes */
/** Return the scope at a given location.
* @param aLocation The location of the scope.
* @returns The scope at the given location, or nil of aLocation is not valid or no language syntax available.
*/
- (ViScope *)scopeAtLocation:(NSUInteger)aLocation;
/** Find the best matching scope selector.
* @param scopeSelectors Scope selectors to test.
* @param aLocation The location of the scope.
* @returns The scope selector with the highest matching rank at the given location.
*/
- (NSString *)bestMatchingScope:(NSArray *)scopeSelectors
atLocation:(NSUInteger)aLocation;
/** Find the range where a scope selector matches.
* @param scopeSelector Scope selectors to test.
* @param aLocation A location where the scope selector matches.
* @returns The whole range where the scope selector matches, possibly with different ranks.
*/
- (NSRange)rangeOfScopeSelector:(NSString *)scopeSelector
atLocation:(NSUInteger)aLocation;
- (NSRange)rangeOfScopeSelector:(NSString *)scopeSelector
forward:(BOOL)forward
fromLocation:(NSUInteger)aLocation;
- (void)endUndoGroup;
- (void)beginUndoGroup;
/** @name Setting marks */
/** Lookup a marked location.
* @param markName The name of the mark.
* @returns The named mark, or `nil` if not set.
*/
- (ViMark *)markNamed:(unichar)markName;
/** Set a mark.
* @param name The name of the mark.
* @param aLocation The location to mark.
*/
- (ViMark *)setMark:(unichar)name atLocation:(NSUInteger)aLocation;
- (ViMark *)setMark:(unichar)key toRange:(NSRange)range;
- (void)registerMark:(ViMark *)mark;
- (void)unregisterMark:(ViMark *)mark;
/** @name Dealing with manual folds */
- (void)createFoldForRange:(NSRange)range;
/** Closes the deepest fold at the given location, and recursively up +levels+ parent folds.
*
* @returns The range of the closed fold.
*/
- (NSRange)closeFoldAtLocation:(NSUInteger)aLocation levels:(NSUInteger)levels;
/** Opens the deepest fold at the given location, and recursively up +levels+ parent folds.
*
* @returns the range of the opened fold.
*/
- (NSRange)openFoldAtLocation:(NSUInteger)aLocation levels:(NSUInteger)levels;
/** Toggles the deepest fold at the given location, closing it if it is
* open and opening it if it is closed.
*/
- (void)toggleFoldAtLocation:(NSUInteger)aLocation;
/**
* Look up a fold by location in the text.
*
* Returns nil if there is no fold at that location.
*/
- (ViFold *)foldAtLocation:(NSUInteger)aLocation;
/**
* Look up a fold range by location in the text.
*
* If the location has a fold, returns a range whose location is the
* first character of the first line of the fold and whose length is
* through the first character of the last line of the fold.
* Returns NSRange(NSNotFound,-1) if there is no fold at that location.
*/
- (NSRange)foldRangeAtLocation:(NSUInteger)aLocation;
- (void)associateView:(ViViewController *)viewController forKey:(NSString *)key;
- (NSSet *)associatedViewsForKey:(NSString *)key;
@end