12
12
13
13
#import " GitDiff.h"
14
14
#import < objc/runtime.h>
15
+ #import " GitDiffColorsWindowController.h"
15
16
16
17
extern " C" {
17
18
#import " DiffMatchPatch.h"
24
25
25
26
@interface GitDiff ()
26
27
27
- @property IBOutlet NSColorWell *modifiedColor, *addedColor, *deletedColor, *popoverColor, *changedColor;
28
-
29
28
@property NSMutableDictionary *diffsByFile;
30
29
@property Class sourceDocClass;
31
30
@property NSTextView *popover;
31
+ @property GitDiffColorsWindowController *colorsWindowController;
32
32
33
33
@end
34
34
@@ -38,19 +38,16 @@ + (void)pluginDidLoad:(NSBundle *)plugin
38
38
{
39
39
static dispatch_once_t onceToken;
40
40
dispatch_once (&onceToken, ^{
41
-
42
41
gitDiffPlugin = [[self alloc ] init ];
42
+ gitDiffPlugin.colorsWindowController = [[GitDiffColorsWindowController alloc ] initWithPluginBundle: plugin];
43
43
gitDiffPlugin.diffsByFile = [NSMutableDictionary new ];
44
-
45
- if ( ![NSBundle loadNibNamed: @" GitDiff" owner: gitDiffPlugin] )
46
- NSLog ( @" GitDiff Plugin: Could not load colors interface." );
47
-
44
+
45
+ [gitDiffPlugin insertMenuItems ];
46
+
48
47
gitDiffPlugin.popover = [[NSTextView alloc ] initWithFrame: NSZeroRect ];
49
48
gitDiffPlugin.popover .wantsLayer = YES ;
50
49
gitDiffPlugin.popover .layer .cornerRadius = 6.0 ;
51
50
52
- gitDiffPlugin.popover .backgroundColor = gitDiffPlugin.popoverColor .color ;
53
-
54
51
gitDiffPlugin.sourceDocClass = NSClassFromString (@" IDESourceCodeDocument" );
55
52
[self swizzleClass: [NSDocument class ]
56
53
exchange: @selector (_finishSavingToURL:ofType:forSaveOperation:changeCount: )
@@ -82,6 +79,26 @@ + (void)swizzleClass:(Class)aClass exchange:(SEL)origMethod with:(SEL)altMethod
82
79
class_getInstanceMethod (aClass, altMethod));
83
80
}
84
81
82
+ - (void )insertMenuItems
83
+ {
84
+ NSMenu *editorMenu = [[[NSApp mainMenu ] itemWithTitle: @" Edit" ] submenu ];
85
+
86
+ if ( editorMenu ) {
87
+ NSMenuItem *menuItem = [[NSMenuItem alloc ] initWithTitle: @" GitDiff Colors..."
88
+ action: @selector (gitDiffColorsMenuItemSelected: )
89
+ keyEquivalent: @" " ];
90
+ menuItem.target = self;
91
+
92
+ [editorMenu addItem: [NSMenuItem separatorItem ]];
93
+ [editorMenu addItem: menuItem];
94
+ }
95
+ }
96
+
97
+ - (void )gitDiffColorsMenuItemSelected : (id )sender
98
+ {
99
+ [gitDiffPlugin.colorsWindowController showWindow: self ];
100
+ }
101
+
85
102
@end
86
103
87
104
#import < map>
@@ -270,7 +287,7 @@ - (void)gitdiff_drawLineNumbersInSidebarRect:(CGRect)rect
270
287
for ( NSUInteger i=0 ; i<indexCount ; i++ ) {
271
288
NSUInteger line = indexes[i];
272
289
NSColor *highlight = !exists ( diffs->added , line ) ? nil :
273
- exists ( diffs->modified , line ) ? gitDiffPlugin.modifiedColor . color : gitDiffPlugin.addedColor . color ;
290
+ exists ( diffs->modified , line ) ? gitDiffPlugin.colorsWindowController . modifiedColor : gitDiffPlugin.colorsWindowController . addedColor ;
274
291
CGRect a0, a1;
275
292
276
293
if ( highlight ) {
@@ -281,7 +298,7 @@ - (void)gitdiff_drawLineNumbersInSidebarRect:(CGRect)rect
281
298
NSRectFill ( a0 );
282
299
}
283
300
else if ( exists ( diffs->deleted , line ) ) {
284
- [gitDiffPlugin.deletedColor.color setFill ];
301
+ [gitDiffPlugin.colorsWindowController.deletedColor setFill ];
285
302
[self getParagraphRect: &a0 firstLineRect: &a1 forLineNumber: line];
286
303
a0.size .height = 1 .;
287
304
NSRectFill ( a0 );
@@ -302,6 +319,7 @@ - (id)gitdiff_annotationAtSidebarPoint:(CGPoint)p0
302
319
{
303
320
id annotation = [self gitdiff_annotationAtSidebarPoint: p0];
304
321
NSTextView *popover = gitDiffPlugin.popover ;
322
+ popover.backgroundColor = gitDiffPlugin.colorsWindowController .popoverColor ;
305
323
306
324
if ( !annotation && p0.x < self.sidebarWidth ) {
307
325
GitFileDiffs *diffs = [self gitDiffs ];
@@ -320,7 +338,7 @@ - (id)gitdiff_annotationAtSidebarPoint:(CGPoint)p0
320
338
NSString *before = [NSString stringWithUTF8String: deleted.c_str ()];
321
339
322
340
if ( exists ( diffs->added , start ) ) {
323
- NSDictionary *attributes = @{NSForegroundColorAttributeName : gitDiffPlugin.changedColor . color };
341
+ NSDictionary *attributes = @{NSForegroundColorAttributeName : gitDiffPlugin.colorsWindowController . changedColor };
324
342
NSMutableAttributedString *attrstr = [[NSMutableAttributedString alloc ] init ];
325
343
326
344
std::string added = diffs->added [start];
@@ -389,7 +407,7 @@ - (void)gitdiff_drawKnobSlotInRect:(CGRect)a0 highlight:(char)a1
389
407
for ( const auto &added : diffs->added ) {
390
408
NSUInteger line = added.first ;
391
409
NSColor *highlight = exists ( diffs->modified , line ) ?
392
- gitDiffPlugin.modifiedColor . color : gitDiffPlugin.addedColor . color ;
410
+ gitDiffPlugin.colorsWindowController . modifiedColor : gitDiffPlugin.colorsWindowController . addedColor ;
393
411
394
412
[highlight setFill ];
395
413
NSRectFill ( NSMakeRect (0 , line*scale, 3 ., 1 .) );
@@ -398,7 +416,7 @@ - (void)gitdiff_drawKnobSlotInRect:(CGRect)a0 highlight:(char)a1
398
416
for ( const auto &deleted : diffs->deleted ) {
399
417
NSUInteger line = deleted.first ;
400
418
if ( !exists ( diffs->added , line ) ) {
401
- [gitDiffPlugin.deletedColor.color setFill ];
419
+ [gitDiffPlugin.colorsWindowController.deletedColor setFill ];
402
420
NSRectFill ( NSMakeRect (0 , line*scale, 3 ., 1 .) );
403
421
}
404
422
}
0 commit comments