Permalink
Browse files

Merge branch 'master' of https://github.com/shell/textmate-missingdrawer



Conflicts:
	Classes/MDPreferenceController.h
	Classes/MDPreferenceController.m
	Classes/MDSettings.m
	Classes/NSWindowController+MDAdditions.m
	Classes/NSWindowController+Preferences.h
	Classes/NSWindowController+Preferences.m
	MissingDrawer.xcodeproj/project.pbxproj
	Resources/English.lproj/Preferences.xib
  • Loading branch information...
soffes committed May 28, 2011
2 parents 0904405 + a600def commit 3161f79113bacddb834b09855235129809da83e8
View
@@ -33,6 +33,7 @@ extern NSString *const kMD_SideView_bgColor;
extern NSString *const kMD_SideView_bgColorInactive;
extern NSString *const kMD_SideView_namedColors;
extern NSString *const kMD_TerminalLauncherAppName;
extern NSString *const kMD_OpenTerminalInTab;
@interface MDSettings : NSObject {
@@ -46,6 +47,7 @@ extern NSString *const kMD_TerminalLauncherAppName;
NSColor *_bgColorInactive;
NSDictionary *_namedColors;
NSString *_terminalLauncherAppName;
BOOL _openTerminalInTab;
}
@property (nonatomic, readonly) NSMenuItem *toggleSplitViewLayoutMenuItem;
@@ -57,6 +59,7 @@ extern NSString *const kMD_TerminalLauncherAppName;
@property (nonatomic, retain) NSColor *bgColorInactive;
@property (nonatomic, readonly) NSDictionary *namedColors;
@property (nonatomic, retain) NSString *terminalLauncherAppName;
@property BOOL openTerminalInTab;
+ (MDSettings *)defaultSettings;
View
@@ -35,6 +35,7 @@
NSString *const kMD_SideView_IsLeft = @"MDSideViewLeft";
NSString *const kMD_SideView_namedColors = @"MDSideViewNamedColors";
NSString *const kMD_TerminalLauncherAppName = @"TerminalLauncherAppName";
NSString *const kMD_OpenTerminalInTab = @"OpenTerminalInTab";
@implementation MDSettings
@@ -47,6 +48,7 @@ @implementation MDSettings
@synthesize bgColorInactive = _bgColorInactive;
@synthesize namedColors = _namedColors;
@synthesize terminalLauncherAppName = _terminalLauncherAppName;
@synthesize openTerminalInTab = _openTerminalInTab;
NSColor *NSColorFromRGBString(NSString *colorString) {
@@ -100,8 +102,10 @@ - (id)init {
self.mainViewLayout = NSRectFromString([defaults objectForKey:kMD_MainView_Frame]);
self.showSideViewOnLeft = [defaults boolForKey:kMD_SideView_IsLeft];
self.terminalLauncherAppName = [defaults objectForKey:kMD_TerminalLauncherAppName];
self.openTerminalInTab = [[defaults objectForKey:kMD_OpenTerminalInTab] boolValue];
// reset colors to bundledDefaults if something ain't right
[bundledDefaultSettings release];
NSString *menuTitle = self.showSideViewOnLeft ? @"Show on the Right" : @"Show on the Left";
@@ -41,5 +41,6 @@
// Actions
- (void)terminalButtonPressed:(id)sender;
- (void)gitButtonPressed:(id)sender;
@end
@@ -44,6 +44,11 @@ NSComparisonResult compareFrameOriginX(id viewA, id viewB, void *context) {
return NSOrderedSame;
}
@interface MDSidebarBorderView (PrivateMethods)
- (NSString *)_selectedFilePath;
@end
@implementation MDSidebarBorderView
#pragma mark Class Methods
@@ -72,7 +77,7 @@ - (void)drawRect:(NSRect)rect {
#pragma mark Drawing
- (void)addToSuperview:(NSView*)superview {
- (void)addToSuperview:(NSView *)superview {
NSScrollView *outlineView = nil;
int i, cnt;
BOOL showSidebarOnLeft = [[MDSettings defaultSettings] showSideViewOnLeft];
@@ -121,8 +126,9 @@ - (void)addToSuperview:(NSView*)superview {
}
[btns sortUsingFunction:(NSInteger (*)(id, id, void *))compareFrameOriginX context:nil];
// Terminal button
NSButton *lastButton = [btns lastObject];
NSRect terminalButtonFrame;
terminalButtonFrame.size.width = 23;
terminalButtonFrame.size.height = [lastButton frame].size.height;
@@ -143,7 +149,29 @@ - (void)addToSuperview:(NSView*)superview {
[terminalButton setBordered:NO];
[btns addObject:terminalButton];
[terminalButton release];
// Gitx button
NSRect gitButtonFrame;
gitButtonFrame.size.width = 23;
gitButtonFrame.size.height = [terminalButton frame].size.height;
gitButtonFrame.origin.x = [terminalButton frame].origin.x + gitButtonFrame.size.width;
gitButtonFrame.origin.y = [terminalButton frame].origin.y;
NSButton *gitButton = [[NSButton alloc] initWithFrame:gitButtonFrame];
NSImage *gitButtonImage = [MDSidebarBorderView bundledImageWithName:@"git"];
NSImage *gitButtonImagePressed = [MDSidebarBorderView bundledImageWithName:@"gitPressed"];
[gitButton setToolTip:@"Open git window here"];
[gitButton setImage:gitButtonImage];
[gitButton setAlternateImage:gitButtonImagePressed];
[gitButton setAction:@selector(gitButtonPressed:)];
[gitButton setTarget:self];
[gitButton setBordered:NO];
[btns addObject:gitButton];
[gitButton release];
// [btns sortUsingFunction:(NSInteger (*)(id, id, void *))compareFrameOriginX context:nil];
// Adjust outlineView frame
@@ -226,42 +254,76 @@ - (void)addToSuperview:(NSView*)superview {
#pragma mark Actions
- (void)terminalButtonPressed:(id)sender {
NSArray *selectedItems = nil;
if (_projectFileOutlineView &&
NSString *path = [self _selectedFilePath];
if (!path) {
return;
}
path = [path stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\\\\\""];
NSString *appName = [[MDSettings defaultSettings] terminalLauncherAppName];
// BOOL openTerminalInTab = [[MDSettings defaultSettings] openTerminalInTab];
NSString *appleScriptCommand = nil;
if ([appName caseInsensitiveCompare:@"iTerm"] == NSOrderedSame) {
appleScriptCommand = [NSString stringWithFormat:@"tell application \"iTerm\"\n\tactivate\n\ttell the first terminal\n\t\tlaunch session \"Default session\"\n\t\ttell the last session\n\t\t\twrite text \"cd \\\"%@\\\"\"\n\t\tend tell\n\tend tell\nend tell", path];
} else if ([appName caseInsensitiveCompare:@"Terminal"] == NSOrderedSame) {
appleScriptCommand = [NSString stringWithFormat:@"activate application \"Terminal\"\n\ttell application \"System Events\"\n\tkeystroke \"t\" using {command down}\n\tend tell\n\ttell application \"Terminal\"\n\trepeat with win in windows\n\ttry\n\tif get frontmost of win is true then\n\tdo script \"cd \\\"%@\\\"; clear\" in (selected tab of win)\n\tend if\n\tend try\n\tend repeat\n\tend tell", path];
} else {
return;
}
MDLog(@"script:\n%@", appleScriptCommand);
NSAppleScript *as = [[NSAppleScript alloc] initWithSource: appleScriptCommand];
[as executeAndReturnError:nil];
[as release];
return;
}
- (void)gitButtonPressed:(id)sender {
NSString *path = [self _selectedFilePath];
if (!path) {
return;
}
// Try to launch GitX
if (![[NSWorkspace sharedWorkspace] openFile:path withApplication:@"GitX"]) {
// Otherwise launch gitk
// TODO: Fix
// NSTask *task = [[NSTask alloc] init];
// [task setLaunchPath:@"/usr/local/bin/gitk"];
// [task setCurrentDirectoryPath:path];
// [task launch];
// [task waitUntilExit];
// [task release];
}
}
#pragma mark Private Methods
- (NSString *)_selectedFilePath {
NSArray *selectedItems = nil;
if (_projectFileOutlineView &&
[_projectFileOutlineView respondsToSelector:@selector(selectedItems)]) {
selectedItems = [_projectFileOutlineView performSelector:@selector(selectedItems)];
if (!selectedItems || ![selectedItems isKindOfClass:[NSArray class]] || [selectedItems count] == 0) {
selectedItems = [_projectFileOutlineView performSelector:@selector(selectedItems)];
if (!selectedItems || ![selectedItems isKindOfClass:[NSArray class]] || [selectedItems count] == 0) {
selectedItems = [NSArray arrayWithObject:[(NSOutlineView *)_projectFileOutlineView itemAtRow:0]];
}
}
}
}
for (NSDictionary *item in selectedItems) {
MDLog(@"[_projectFileOutlineView selectedItems]: %@", item);
NSString *path = [item objectForKey:@"sourceDirectory"];
if (!path) {
path = [[item objectForKey:@"filename"] stringByDeletingLastPathComponent];
}
for (NSDictionary *item in selectedItems) {
NSString *path = [item objectForKey:@"sourceDirectory"];
if (!path) {
path = [[item objectForKey:@"filename"] stringByDeletingLastPathComponent];
}
if (path) {
path = [path stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\\\\\""];
NSString *appName = [[MDSettings defaultSettings] terminalLauncherAppName];
NSString *appleScriptCommand;
if ([appName caseInsensitiveCompare:@"iTerm"] == NSOrderedSame) {
appleScriptCommand = [NSString stringWithFormat:@"tell application \"iTerm\"\n\tactivate\n\ttell the first terminal\n\t\tlaunch session \"Default session\"\n\t\ttell the last session\n\t\t\twrite text \"cd \\\"%@\\\"\"\n\t\tend tell\n\tend tell\nend tell", path];
} else if ([appName caseInsensitiveCompare:@"Terminal"] == NSOrderedSame) {
appleScriptCommand = [NSString stringWithFormat:@"tell application \"Terminal\"\n\tdo script \"cd \\\"%@\\\"\"\n\tactivate\nend tell", path];
} else {
return;
}
MDLog(@"script:\n%@", appleScriptCommand);
NSAppleScript *as = [[NSAppleScript alloc] initWithSource: appleScriptCommand];
[as executeAndReturnError:nil];
[as release];
return;
}
}
if (path) {
return path;
}
}
return nil;
}
@end
View
@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>currentDocument</key>
<string>Classes/MDSidebarBorderView.h</string>
<key>documents</key>
<array>
<dict>
@@ -20,10 +22,106 @@
<key>fileHierarchyDrawerWidth</key>
<integer>200</integer>
<key>metaData</key>
<dict/>
<dict>
<key>Classes/MDSettings.h</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>20</integer>
<key>line</key>
<integer>52</integer>
</dict>
<key>columnSelection</key>
<false/>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>4</integer>
<key>selectFrom</key>
<dict>
<key>column</key>
<integer>15</integer>
<key>line</key>
<integer>52</integer>
</dict>
<key>selectTo</key>
<dict>
<key>column</key>
<integer>33</integer>
<key>line</key>
<integer>52</integer>
</dict>
</dict>
<key>Classes/MDSettings.m</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>49</integer>
<key>line</key>
<integer>39</integer>
</dict>
<key>columnSelection</key>
<false/>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>14</integer>
<key>selectFrom</key>
<dict>
<key>column</key>
<integer>42</integer>
<key>line</key>
<integer>39</integer>
</dict>
<key>selectTo</key>
<dict>
<key>column</key>
<integer>59</integer>
<key>line</key>
<integer>39</integer>
</dict>
</dict>
<key>Classes/MDSidebarBorderView.h</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>27</integer>
<key>line</key>
<integer>24</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>0</integer>
</dict>
<key>Classes/MDSidebarBorderView.m</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
<integer>54</integer>
<key>line</key>
<integer>77</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
<integer>59</integer>
</dict>
</dict>
<key>openDocuments</key>
<array>
<string>Classes/MDSidebarBorderView.m</string>
<string>Classes/MDSidebarBorderView.h</string>
<string>Classes/MDSettings.h</string>
<string>Classes/MDSettings.m</string>
</array>
<key>showFileHierarchyDrawer</key>
<false/>
<key>windowFrame</key>
<string>{{210, 159}, {952, 621}}</string>
<string>{{49, 0}, {1231, 778}}</string>
</dict>
</plist>
Oops, something went wrong.

0 comments on commit 3161f79

Please sign in to comment.