Skip to content

Commit 5481745

Browse files
committed
Merge pull request #1 from stefanceriu/master
Merge from stefanceriu/SCXcodeMiniMap master
2 parents b6b8847 + 8e90e5d commit 5481745

File tree

3 files changed

+77
-23
lines changed

3 files changed

+77
-23
lines changed

SCXcodeMinimap/SCSelectionView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
@interface SCSelectionView : NSView
1212

13+
@property (nonatomic, assign) BOOL shouldInverseColors;
14+
1315
@end

SCXcodeMinimap/SCSelectionView.m

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,68 @@
88

99
#import "SCSelectionView.h"
1010

11+
@interface SCSelectionView ()
12+
13+
@property (nonatomic, retain) NSColor *selectionColor;
14+
15+
@end
16+
1117
@implementation SCSelectionView
1218

19+
- (void)dealloc
20+
{
21+
[self.selectionColor release];
22+
[super dealloc];
23+
}
24+
1325
- (void)drawRect:(NSRect)dirtyRect
1426
{
15-
[[NSColor colorWithDeviceRed:0.0f green:0.0f blue:0.0f alpha:0.3f] setFill];
27+
[[self selectionColor] setFill];
1628
NSRectFill(dirtyRect);
1729
}
1830

31+
- (NSColor *)selectionColor
32+
{
33+
if(_selectionColor == nil) {
34+
35+
_selectionColor = [NSColor colorWithDeviceRed:0.0f green:0.0f blue:0.0f alpha:0.3f];
36+
37+
Class DVTFontAndColorThemeClass = NSClassFromString(@"DVTFontAndColorTheme");
38+
39+
if([DVTFontAndColorThemeClass respondsToSelector:@selector(currentTheme)]) {
40+
NSObject *theme = [DVTFontAndColorThemeClass performSelector:@selector(currentTheme)];
41+
42+
if([theme respondsToSelector:@selector(sourceTextBackgroundColor)]) {
43+
NSColor *backgroundColor = [[theme performSelector:@selector(sourceTextBackgroundColor)] colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
44+
45+
if(self.shouldInverseColors) {
46+
47+
_selectionColor = [NSColor colorWithCalibratedRed:(1.0f - [backgroundColor redComponent])
48+
green:(1.0f - [backgroundColor greenComponent])
49+
blue:(1.0f - [backgroundColor blueComponent])
50+
alpha:0.3f];
51+
} else {
52+
53+
_selectionColor = [NSColor colorWithCalibratedHue:0.0f
54+
saturation:0.0f
55+
brightness:(1.0f - [backgroundColor brightnessComponent])
56+
alpha:0.3f];
57+
}
58+
}
59+
}
60+
}
61+
62+
return _selectionColor;
63+
}
64+
65+
- (void)setShouldInverseColors:(BOOL)shouldInverseColors
66+
{
67+
if(_shouldInverseColors == shouldInverseColors) {
68+
return;
69+
}
70+
71+
_shouldInverseColors = shouldInverseColors;
72+
_selectionColor = nil;
73+
}
1974

2075
@end

SCXcodeMinimap/SCXcodeMinimap.m

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,11 @@ - (void)updateMiniMapTextView:(NSTextView*)textView withAttributedString:(NSAttr
7878
[mutableAttributedString enumerateAttributesInRange:NSMakeRange(0, mutableAttributedString.length) options:NSAttributedStringEnumerationReverse usingBlock:
7979
^(NSDictionary *attributes, NSRange range, BOOL *stop) {
8080

81-
NSMutableParagraphStyle *newParagraphStyle = [[attributes objectForKey:NSParagraphStyleAttributeName] mutableCopy];
82-
newParagraphStyle.minimumLineHeight *= kDefaultZoomLevel;
83-
newParagraphStyle.maximumLineHeight *= kDefaultZoomLevel;
84-
newParagraphStyle.paragraphSpacing *= kDefaultZoomLevel;
85-
newParagraphStyle.paragraphSpacingBefore *= kDefaultZoomLevel;
86-
newParagraphStyle.firstLineHeadIndent *= kDefaultZoomLevel;
87-
newParagraphStyle.headIndent *= kDefaultZoomLevel;
88-
newParagraphStyle.tailIndent *= kDefaultZoomLevel;
89-
newParagraphStyle.tighteningFactorForTruncation *= kDefaultZoomLevel;
90-
9181
NSFont *font = [attributes objectForKey:NSFontAttributeName];
9282
NSFont *newFont = [NSFont fontWithName:font.familyName size:font.pointSize * kDefaultZoomLevel];
9383

94-
NSObject *DVTFontAndColorTheme = [NSClassFromString(@"DVTFontAndColorTheme") performSelector:@selector(currentTheme)];
95-
NSColor *textColor = [DVTFontAndColorTheme performSelector:@selector(sourcePlainTextColor)];
96-
9784
NSMutableDictionary *mutableAttributes = [NSMutableDictionary dictionaryWithDictionary:attributes];
98-
[mutableAttributes setObject:newParagraphStyle forKey:NSParagraphStyleAttributeName];
9985
[mutableAttributes setObject:newFont forKey:NSFontAttributeName];
100-
[mutableAttributes setObject:textColor forKey:NSForegroundColorAttributeName];
10186
[mutableAttributedString setAttributes:mutableAttributes range:range];
10287
}];
10388

@@ -167,7 +152,7 @@ - (void)onDidFinishSetup:(NSNotification*)sender
167152
CGFloat width = editorTextView.bounds.size.width * kDefaultZoomLevel;
168153

169154
NSRect frame = editorTextView.frame;
170-
frame.size.width -= (width + kRightSidePadding);
155+
frame.size.width -= width;
171156
[editorTextView setFrame:frame];
172157

173158
NSRect miniMapScrollViewFrame = NSMakeRect(editorContainerView.bounds.size.width - width - kRightSidePadding, 0, width, editorScrollView.bounds.size.height);
@@ -194,9 +179,18 @@ - (void)onDidFinishSetup:(NSNotification*)sender
194179
[miniMapScrollView setDocumentView:miniMapTextView];
195180
[miniMapTextView release];
196181

197-
NSObject *DVTFontAndColorTheme = [NSClassFromString(@"DVTFontAndColorTheme") performSelector:@selector(currentTheme)];
198-
NSColor *backgroundColor = [DVTFontAndColorTheme performSelector:@selector(sourceTextBackgroundColor)];
199-
[miniMapTextView setBackgroundColor:[backgroundColor shadowWithLevel:kDefaultShadowLevel]];
182+
NSColor *miniMapBackgroundColor = [NSColor clearColor];
183+
Class DVTFontAndColorThemeClass = NSClassFromString(@"DVTFontAndColorTheme");
184+
if([DVTFontAndColorThemeClass respondsToSelector:@selector(currentTheme)]) {
185+
NSObject *theme = [DVTFontAndColorThemeClass performSelector:@selector(currentTheme)];
186+
187+
if([theme respondsToSelector:@selector(sourceTextBackgroundColor)]) {
188+
miniMapBackgroundColor = [theme performSelector:@selector(sourceTextBackgroundColor)];
189+
190+
}
191+
}
192+
193+
[miniMapTextView setBackgroundColor:[miniMapBackgroundColor shadowWithLevel:kDefaultShadowLevel]];
200194

201195
objc_setAssociatedObject(editorDocument, &kKeyMiniMapTextView, miniMapTextView, OBJC_ASSOCIATION_ASSIGN);
202196
objc_setAssociatedObject(editorScrollView, &kKeyMiniMapTextView, miniMapTextView, OBJC_ASSOCIATION_ASSIGN);
@@ -206,6 +200,7 @@ - (void)onDidFinishSetup:(NSNotification*)sender
206200
NSRect miniMapSelectionViewFrame = NSMakeRect(0, 0, miniMapScrollView.bounds.size.width, editorScrollView.visibleRect.size.height * kDefaultZoomLevel);
207201
SCSelectionView *miniMapSelectionView = [[SCSelectionView alloc] initWithFrame:miniMapSelectionViewFrame];
208202
[miniMapSelectionView setAutoresizingMask: NSViewMinXMargin | NSViewMaxXMargin | NSViewWidthSizable | NSViewHeightSizable | NSViewMinYMargin | NSViewMaxYMargin];
203+
//[miniMapSelectionView setShouldInverseColors:YES];
209204
[miniMapScrollView.contentView addSubview:miniMapSelectionView];
210205
[miniMapSelectionView release];
211206

@@ -217,10 +212,12 @@ - (void)onDidFinishSetup:(NSNotification*)sender
217212

218213
#pragma mark - NSLayoutManagerDelegate
219214

220-
- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag
215+
- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinished
221216
{
222-
NSScrollView *editorScrollView = objc_getAssociatedObject(textContainer, &kKeyEditorScrollView);
223-
[self updateMiniMapForEditorScrollView:editorScrollView];
217+
if(layoutFinished) {
218+
NSScrollView *editorScrollView = objc_getAssociatedObject(textContainer, &kKeyEditorScrollView);
219+
[self updateMiniMapForEditorScrollView:editorScrollView];
220+
}
224221
}
225222

226223
- (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager shouldUseTemporaryAttributes:(NSDictionary *)attrs forDrawingToScreen:(BOOL)toScreen atCharacterIndex:(NSUInteger)charIndex effectiveRange:(NSRangePointer)effectiveCharRange

0 commit comments

Comments
 (0)