Created
June 16, 2011 23:57
-
-
Save alloy/1030607 to your computer and use it in GitHub Desktop.
MacVim file browser colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/MacVim/ImageAndTextCell.m b/src/MacVim/ImageAndTextCell.m | |
index 87d6597..f3278e8 100644 | |
--- a/src/MacVim/ImageAndTextCell.m | |
+++ b/src/MacVim/ImageAndTextCell.m | |
@@ -99,6 +99,11 @@ | |
return result; | |
} | |
+- (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { | |
+ // Returning nil circumvents the standard row highlighting. | |
+ return nil; | |
+} | |
+ | |
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent { | |
NSRect textFrame, imageFrame; | |
NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge); | |
diff --git a/src/MacVim/MMFileBrowserController.h b/src/MacVim/MMFileBrowserController.h | |
index 4231077..39effe2 100644 | |
--- a/src/MacVim/MMFileBrowserController.h | |
+++ b/src/MacVim/MMFileBrowserController.h | |
@@ -21,6 +21,7 @@ | |
- (void)makeFirstResponder; | |
- (void)selectInBrowser; | |
- (void)selectInBrowserByExpandingItems; | |
+- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore; | |
- (NSMenu *)menuForRow:(NSInteger)row; | |
diff --git a/src/MacVim/MMFileBrowserController.m b/src/MacVim/MMFileBrowserController.m | |
index 010c55d..403480f 100644 | |
--- a/src/MacVim/MMFileBrowserController.m | |
+++ b/src/MacVim/MMFileBrowserController.m | |
@@ -311,6 +311,7 @@ static NSString *LEFT_KEY_CHAR, *RIGHT_KEY_CHAR, *DOWN_KEY_CHAR, *UP_KEY_CHAR; | |
@interface MMFileBrowser : NSOutlineView { | |
BOOL canBecomeFirstResponder; | |
} | |
+@property (nonatomic, retain) NSColor *highlightColor; | |
- (void)makeFirstResponder; | |
- (NSMenu *)menuForEvent:(NSEvent *)event; | |
- (void)cancelOperation:(id)sender; | |
@@ -321,6 +322,8 @@ static NSString *LEFT_KEY_CHAR, *RIGHT_KEY_CHAR, *DOWN_KEY_CHAR, *UP_KEY_CHAR; | |
@implementation MMFileBrowser | |
+@synthesize highlightColor; | |
+ | |
- (id)initWithFrame:(NSRect)frame { | |
if ((self = [super initWithFrame:frame])) { | |
canBecomeFirstResponder = NO; | |
@@ -433,6 +436,27 @@ static NSString *LEFT_KEY_CHAR, *RIGHT_KEY_CHAR, *DOWN_KEY_CHAR, *UP_KEY_CHAR; | |
[self scrollRowToVisible:itemIndex]; | |
} | |
+- (void)highlightSelectionInClipRect:(NSRect)clipRect { | |
+ NSRange visibleIndexes = [self rowsInRect:clipRect]; | |
+ NSIndexSet *selectedIndexes = [self selectedRowIndexes]; | |
+ int row = visibleIndexes.location; | |
+ int max = row + visibleIndexes.length; | |
+ | |
+ NSColor *color; | |
+ // if (canBecomeFirstResponder) { | |
+ color = highlightColor; | |
+ //} else { | |
+ //color = [highlightColor colorWithAlphaComponent:0.5]; | |
+ //} | |
+ [color set]; | |
+ | |
+ for (; row < max; row++) { | |
+ if ([selectedIndexes containsIndex:row]) { | |
+ NSRectFill(NSInsetRect([self rectOfRow:row], 2, 1)); | |
+ } | |
+ } | |
+} | |
+ | |
@end | |
// **************************************************************************** | |
@@ -452,6 +476,7 @@ static NSString *LEFT_KEY_CHAR, *RIGHT_KEY_CHAR, *DOWN_KEY_CHAR, *UP_KEY_CHAR; | |
- (void)changeOccurredAtPath:(NSString *)path; | |
- (void)deleteBufferByPath:(NSString *)path; | |
- (void)selectInBrowserByExpandingItems:(BOOL)expand; | |
+- (void)assignPathControlTextColor; | |
@end | |
@@ -485,7 +510,7 @@ static NSString *LEFT_KEY_CHAR, *RIGHT_KEY_CHAR, *DOWN_KEY_CHAR, *UP_KEY_CHAR; | |
pathControl = [[NSPathControl alloc] initWithFrame:NSMakeRect(0, 0, 0, 20)]; | |
[pathControl setRefusesFirstResponder:YES]; | |
[pathControl setAutoresizingMask:NSViewWidthSizable]; | |
- [pathControl setBackgroundColor:[NSColor whiteColor]]; | |
+ //[pathControl setBackgroundColor:[NSColor whiteColor]]; | |
[pathControl setPathStyle:NSPathStylePopUp]; | |
[pathControl setFont:[NSFont fontWithName:[[pathControl font] fontName] size:12]]; | |
[pathControl setTarget:self]; | |
@@ -556,11 +581,35 @@ static NSString *LEFT_KEY_CHAR, *RIGHT_KEY_CHAR, *DOWN_KEY_CHAR, *UP_KEY_CHAR; | |
vim:[windowController vimController]]; | |
[fileBrowser reloadData]; | |
[fileBrowser expandItem:rootItem]; | |
+ | |
[pathControl setURL:[NSURL fileURLWithPath:root]]; | |
+ [self assignPathControlTextColor]; | |
[self watchRoot]; | |
} | |
+- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore { | |
+ [fileBrowser setBackgroundColor:back]; | |
+ [[[fileBrowser outlineTableColumn] dataCell] setTextColor:fore]; | |
+ NSColor *highlightColor = [NSColor colorWithDeviceRed:(back.redComponent + fore.redComponent) / 2.0 | |
+ green:(back.greenComponent + fore.greenComponent) / 2.0 | |
+ blue:(back.blueComponent + fore.blueComponent) / 2.0 | |
+ alpha:(back.alphaComponent + fore.alphaComponent) / 2.0]; | |
+ [fileBrowser setHighlightColor:highlightColor]; | |
+ | |
+ [pathControl setBackgroundColor:back]; | |
+ [self assignPathControlTextColor]; | |
+} | |
+ | |
+- (void)assignPathControlTextColor { | |
+ NSArray *cells = pathControl.pathComponentCells; | |
+ // HACK Lazy workaround | |
+ NSColor *color = [[[fileBrowser outlineTableColumn] dataCell] textColor]; | |
+ for (NSPathComponentCell *cell in cells) { | |
+ cell.textColor = color; | |
+ } | |
+} | |
+ | |
// Typing Tab (or Esc) in browser view sets keyboard focus to next view | |
- (void)setNextKeyView:(NSView *)nextKeyView { | |
[fileBrowser setNextKeyView:nextKeyView]; | |
diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m | |
index 3f36a40..ae6e6d9 100644 | |
--- a/src/MacVim/MMWindowController.m | |
+++ b/src/MacVim/MMWindowController.m | |
@@ -551,6 +551,7 @@ | |
[fullscreenWindow setOpaque:isOpaque]; | |
[vimView setDefaultColorsBackground:back foreground:fore]; | |
+ [fileBrowserController setDefaultColorsBackground:back foreground:fore]; | |
} | |
- (void)setFont:(NSFont *)font |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment