Skip to content

Commit a136f85

Browse files
committed
- performance tweaking
- fixed crash on theme change - custom theme support
1 parent d73259c commit a136f85

File tree

3 files changed

+98
-37
lines changed

3 files changed

+98
-37
lines changed

SCXcodeMinimap.xcodeproj/project.pbxproj

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
188308091A7411830005DF40 /* DVTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTKit.framework; path = ../../../../../Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework; sourceTree = "<group>"; };
4848
1883080B1A7411930005DF40 /* IDESourceEditor.ideplugin */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = IDESourceEditor.ideplugin; path = ../../../../../Applications/Xcode.app/Contents/PlugIns/IDESourceEditor.ideplugin; sourceTree = "<group>"; };
4949
1883080F1A7411A70005DF40 /* IDESourceEditor */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = IDESourceEditor; path = ../../../../../Applications/Xcode.app/Contents/PlugIns/IDESourceEditor.ideplugin/Contents/MacOS/IDESourceEditor; sourceTree = "<group>"; };
50+
18B3CEE51A8AA52A00A0873D /* DVTPreferenceSetManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTPreferenceSetManager.h; sourceTree = "<group>"; };
5051
18C8F0331A7ECB1300C7A76F /* DVTFoldingLayoutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVTFoldingLayoutManager.h; sourceTree = "<group>"; };
5152
18C8F0341A7ECB1300C7A76F /* DVTLayoutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVTLayoutManager.h; sourceTree = "<group>"; };
5253
18FE09B21707639E00118FEB /* SCXcodeMinimap.xcplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SCXcodeMinimap.xcplugin; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -103,6 +104,7 @@
103104
184C117E1A740F8A002A7C65 /* IDESourceCodeEditor.h */,
104105
184C117F1A740F8A002A7C65 /* IDESourceCodeEditorContainerView.h */,
105106
184C11801A740F8A002A7C65 /* IDEViewController.h */,
107+
18B3CEE51A8AA52A00A0873D /* DVTPreferenceSetManager.h */,
106108
);
107109
path = "Xcode Headers";
108110
sourceTree = "<group>";
@@ -127,26 +129,18 @@
127129
18FE09B41707639E00118FEB /* Frameworks */ = {
128130
isa = PBXGroup;
129131
children = (
132+
18FE09B81707639E00118FEB /* AppKit.framework */,
130133
18FE09B51707639E00118FEB /* Cocoa.framework */,
134+
18FE09B91707639E00118FEB /* CoreData.framework */,
131135
184C118E1A741136002A7C65 /* DVTFoundation.framework */,
132136
188308091A7411830005DF40 /* DVTKit.framework */,
137+
18FE09BA1707639E00118FEB /* Foundation.framework */,
133138
1876135E1A77A74300974BE1 /* IDEKit.framework */,
134139
1883080F1A7411A70005DF40 /* IDESourceEditor */,
135140
1883080B1A7411930005DF40 /* IDESourceEditor.ideplugin */,
136-
18FE09B71707639E00118FEB /* Other Frameworks */,
137-
);
138-
name = Frameworks;
139-
sourceTree = "<group>";
140-
};
141-
18FE09B71707639E00118FEB /* Other Frameworks */ = {
142-
isa = PBXGroup;
143-
children = (
144141
8742532217307161001C947C /* QuartzCore.framework */,
145-
18FE09B81707639E00118FEB /* AppKit.framework */,
146-
18FE09B91707639E00118FEB /* CoreData.framework */,
147-
18FE09BA1707639E00118FEB /* Foundation.framework */,
148142
);
149-
name = "Other Frameworks";
143+
name = Frameworks;
150144
sourceTree = "<group>";
151145
};
152146
18FE09BB1707639E00118FEB /* SCXcodeMinimap */ = {
@@ -311,6 +305,7 @@
311305
"$(PROJECT_DIR)",
312306
"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/SharedFrameworks",
313307
"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Frameworks",
308+
"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/OtherFrameworks",
314309
);
315310
GCC_ENABLE_OBJC_GC = "";
316311
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -338,6 +333,7 @@
338333
"$(PROJECT_DIR)",
339334
"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/SharedFrameworks",
340335
"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Frameworks",
336+
"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/OtherFrameworks",
341337
);
342338
GCC_ENABLE_OBJC_GC = "";
343339
GCC_PRECOMPILE_PREFIX_HEADER = YES;

SCXcodeMinimap/SCXcodeMinimapView.m

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#import "DVTPointerArray.h"
1919
#import "DVTSourceTextView.h"
2020
#import "DVTSourceNodeTypes.h"
21+
2122
#import "DVTFontAndColorTheme.h"
23+
#import "DVTPreferenceSetManager.h"
2224

2325
const CGFloat kBackgroundColorShadowLevel = 0.1f;
2426
const CGFloat kHighlightColorAlphaLevel = 0.3f;
@@ -48,6 +50,8 @@ @interface SCXcodeMinimapView () <NSLayoutManagerDelegate>
4850
@property (nonatomic, strong) NSColor *commentColor;
4951
@property (nonatomic, strong) NSColor *preprocessorColor;
5052

53+
@property (nonatomic, strong) DVTFontAndColorTheme *theme;
54+
5155
@end
5256

5357
@implementation SCXcodeMinimapView
@@ -79,7 +83,7 @@ - (instancetype)initWithFrame:(NSRect)frame editor:(IDESourceCodeEditor *)editor
7983
[self addSubview:self.scrollView];
8084

8185
self.textView = [[DVTSourceTextView alloc] initWithFrame:self.editorTextView.bounds];
82-
[self.editorTextView.textStorage addLayoutManager:self.textView.layoutManager];
86+
[self.textView setTextStorage:self.editorTextView.textStorage];
8387
[self.textView setEditable:NO];
8488
[self.textView setSelectable:NO];
8589

@@ -154,40 +158,47 @@ - (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager
154158

155159
// Prevent full range invalidation for performance reasons.
156160
if(!self.shouldAllowFullSyntaxHighlight) {
161+
162+
// Attempt a full range invalidation after all temporary attributes are set
163+
__weak typeof(self) weakSelf = self;
164+
void(^invalidationBlock)() = ^{
165+
weakSelf.shouldAllowFullSyntaxHighlight = YES;
166+
NSRange visibleMinimapRange = [weakSelf.textView visibleCharacterRange];
167+
[weakSelf.textView.layoutManager invalidateDisplayForCharacterRange:visibleMinimapRange];
168+
};
169+
157170
NSRange visibleEditorRange = [self.editorTextView visibleCharacterRange];
158171
if(charIndex > visibleEditorRange.location + visibleEditorRange.length ) {
159172
*effectiveCharRange = NSMakeRange(visibleEditorRange.location + visibleEditorRange.length,
160173
layoutManager.textStorage.length - visibleEditorRange.location - visibleEditorRange.length);
174+
175+
[self performBlock:invalidationBlock afterDelay:0.5f cancelPreviousRequest:YES];
161176

162-
return @{NSForegroundColorAttributeName : [[DVTFontAndColorTheme currentTheme] sourcePlainTextColor]};
177+
return @{NSForegroundColorAttributeName : [self.theme sourcePlainTextColor]};
163178
}
164179

165180
if(charIndex < visibleEditorRange.location) {
166181
*effectiveCharRange = NSMakeRange(0, visibleEditorRange.location);
167-
return @{NSForegroundColorAttributeName : [[DVTFontAndColorTheme currentTheme] sourcePlainTextColor]};
182+
183+
[self performBlock:invalidationBlock afterDelay:0.5f cancelPreviousRequest:YES];
184+
185+
return @{NSForegroundColorAttributeName : [self.theme sourcePlainTextColor]};
168186
}
169187
}
170188

171-
// Attempt a full range invalidation after all temporary attributes are set
172-
__weak typeof(self) weakSelf = self;
173-
[self performBlock:^{
174-
weakSelf.shouldAllowFullSyntaxHighlight = YES;
175-
NSRange visibleMinimapRange = [weakSelf.textView visibleCharacterRange];
176-
[weakSelf.textView.layoutManager invalidateDisplayForCharacterRange:visibleMinimapRange];
177-
} afterDelay:0.5f cancelPreviousRequest:YES];
178-
179189
// Rely on the colorAtCharacterIndex: method to update the effective range
180190
DVTTextStorage *storage = [self.editorTextView textStorage];
181191
NSColor *color = [storage colorAtCharacterIndex:charIndex effectiveRange:effectiveCharRange context:nil];
182192

183-
// Background color for comments and preprocessor directives
184-
short currentNodeId = [storage nodeTypeAtCharacterIndex:charIndex effectiveRange:NULL context:nil];
185-
if(currentNodeId == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentNodeName] ||
186-
currentNodeId == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentDocNodeName] ||
187-
currentNodeId == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentDocKeywordNodeName]) {
188-
return @{NSForegroundColorAttributeName : [[DVTFontAndColorTheme currentTheme] sourceTextBackgroundColor], NSBackgroundColorAttributeName : self.commentColor};
189-
} else if(currentNodeId == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxPreprocessorNodeName]) {
190-
return @{NSForegroundColorAttributeName : [[DVTFontAndColorTheme currentTheme] sourceTextBackgroundColor], NSBackgroundColorAttributeName : self.preprocessorColor};
193+
// Background color for comments and preprocessor directives. Could query for nodeTypeAtCharacterIndex: but it's too slow.
194+
DVTPointerArray *colors = [[DVTFontAndColorTheme currentTheme] syntaxColorsByNodeType];
195+
if([color isEqual:[colors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentNodeName]]] ||
196+
[color isEqual:[colors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentDocNodeName]]] ||
197+
[color isEqual:[colors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentDocKeywordNodeName]]])
198+
{
199+
return @{NSForegroundColorAttributeName : [self.theme sourceTextBackgroundColor], NSBackgroundColorAttributeName : self.commentColor};
200+
} else if([color isEqual:[colors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxPreprocessorNodeName]]]) {
201+
return @{NSForegroundColorAttributeName : [self.theme sourceTextBackgroundColor], NSBackgroundColorAttributeName : self.preprocessorColor};
191202
}
192203

193204
return @{NSForegroundColorAttributeName : color};
@@ -260,8 +271,12 @@ - (void)handleMouseEvent:(NSEvent *)theEvent
260271

261272
- (void)updateTheme
262273
{
263-
DVTFontAndColorTheme *theme = [DVTFontAndColorTheme currentTheme];
264-
NSColor *backgroundColor = [theme.sourceTextBackgroundColor shadowWithLevel:kBackgroundColorShadowLevel];
274+
//DVTPreferenceSetManager *preferenceSetManager = [DVTFontAndColorTheme preferenceSetsManager];
275+
//NSArray *preferenceSet = [preferenceSetManager availablePreferenceSets];
276+
//self.theme = [preferenceSet lastObject];
277+
self.theme = [DVTFontAndColorTheme currentTheme];
278+
279+
NSColor *backgroundColor = [self.theme.sourceTextBackgroundColor shadowWithLevel:kBackgroundColorShadowLevel];
265280

266281
[self.scrollView setBackgroundColor:backgroundColor];
267282
[self.textView setBackgroundColor:backgroundColor];
@@ -271,7 +286,7 @@ - (void)updateTheme
271286
blue:(1.0f - [backgroundColor blueComponent])
272287
alpha:kHighlightColorAlphaLevel];
273288

274-
DVTPointerArray *colors = [[DVTFontAndColorTheme currentTheme] syntaxColorsByNodeType];
289+
DVTPointerArray *colors = [self.theme syntaxColorsByNodeType];
275290
self.commentColor = [colors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentNodeName]];
276291
self.commentColor = [NSColor colorWithCalibratedRed:self.commentColor.redComponent
277292
green:self.commentColor.greenComponent
@@ -280,9 +295,9 @@ - (void)updateTheme
280295

281296

282297
self.preprocessorColor = [colors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxPreprocessorNodeName]];
283-
self.preprocessorColor = [NSColor colorWithCalibratedRed:self.commentColor.redComponent
284-
green:self.commentColor.greenComponent
285-
blue:self.commentColor.blueComponent
298+
self.preprocessorColor = [NSColor colorWithCalibratedRed:self.preprocessorColor.redComponent
299+
green:self.preprocessorColor.greenComponent
300+
blue:self.preprocessorColor.blueComponent
286301
alpha:kHighlightColorAlphaLevel];
287302

288303
[self.selectionView setSelectionColor:selectionColor];
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Generated by class-dump 3.3.4 (64 bit).
3+
*
4+
* class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2011 by Steve Nygard.
5+
*/
6+
7+
8+
@class DVTDelayedInvocation, DVTMapTable, NSArray, NSMutableArray, NSMutableSet;
9+
10+
@interface DVTPreferenceSetManager : NSObject
11+
{
12+
Class _preferenceSetClass;
13+
NSArray *_builtInPreferenceSets;
14+
NSMutableSet *_specifierNamesInDataStore;
15+
NSMutableArray *_userPreferenceSets;
16+
NSMutableArray *_availablePreferenceSets;
17+
id <DVTPreferenceSet> _currentPreferenceSet;
18+
DVTMapTable *_preferenceSetObserverTokens;
19+
DVTDelayedInvocation *_autosavePreferenceSetsInvocation;
20+
}
21+
22+
+ (void)initialize;
23+
@property(readonly) Class preferenceSetClass; // @synthesize preferenceSetClass=_preferenceSetClass;
24+
- (id)description;
25+
- (void)_writePreferenceSetsIfNeeded;
26+
- (void)_applicationWillTerminate:(id)arg1;
27+
- (void)_scheduleAutoSavePreferenceSets;
28+
- (void)_removeObserversForPreferenceSet:(id)arg1;
29+
- (void)_addObserversForPreferenceSet:(id)arg1;
30+
- (void)deletePreferenceSet:(id)arg1 completionQueue:(id)arg2 completionBlock:(id)arg3;
31+
- (id)duplicatePreferenceSet:(id)arg1 error:(id *)arg2;
32+
- (void)renamePreferenceSet:(id)arg1 toName:(id)arg2 completionQueue:(id)arg3 completionBlock:(id)arg4;
33+
- (id)editableUserPreferenceSetForPreferenceSet:(id)arg1;
34+
- (id)_createUserPreferenceSetWithBaseName:(id)arg1 basedOn:(id)arg2;
35+
- (id)_nameForDuplicateOfPreferenceSet:(id)arg1;
36+
- (id)_availablePreferenceSetWithLocalizedName:(id)arg1;
37+
- (id)preferenceSetForName:(id)arg1;
38+
@property(readonly) NSArray *builtInPreferenceSets;
39+
@property(retain) id <DVTPreferenceSet> currentPreferenceSet;
40+
- (void)_rebuildAvailableandUserSetsList;
41+
- (void)dealloc;
42+
- (id)initWithPreferenceSetClass:(Class)arg1;
43+
44+
// Remaining properties
45+
@property(copy) NSArray *availablePreferenceSets; // @dynamic availablePreferenceSets;
46+
@property(readonly) NSMutableArray *mutableAvailablePreferenceSets; // @dynamic mutableAvailablePreferenceSets;
47+
@property(readonly) NSMutableArray *mutableUserPreferenceSets; // @dynamic mutableUserPreferenceSets;
48+
@property(copy) NSArray *userPreferenceSets; // @dynamic userPreferenceSets;
49+
50+
@end

0 commit comments

Comments
 (0)