Add Open in Terminal to the Repository menu.

Code came from B. Ohr at: http://groups.google.com/group/gitx/browse_thread/thread/a103df7ef7c1f037

Added quotes to workingDirectory path to support paths with spaces.
This commit is contained in:
Nathan Kinsinger
2010-02-03 18:40:01 -07:00
parent 9f048f6363
commit db0bb87340
5 changed files with 1357 additions and 148 deletions
+1180 -148
View File
File diff suppressed because it is too large Load Diff
+6
View File
@@ -46,6 +46,7 @@
D26DC6450E782C9000C777B2 /* gitx.icns in Resources */ = {isa = PBXBuildFile; fileRef = D26DC6440E782C9000C777B2 /* gitx.icns */; };
D854948610D5C01B0083B917 /* PBCreateBranchSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */; };
D85B939310E3D8B4007F3C28 /* PBCreateBranchSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = D85B939210E3D8B4007F3C28 /* PBCreateBranchSheet.xib */; };
D8E3B2B810DC9FB2001096A3 /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D8E3B2B710DC9FB2001096A3 /* ScriptingBridge.framework */; };
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */ = {isa = PBXBuildFile; fileRef = EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */; };
F50A411F0EBB874C00208746 /* mainSplitterBar.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */; };
F50A41200EBB874C00208746 /* mainSplitterDimple.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411E0EBB874C00208746 /* mainSplitterDimple.tiff */; };
@@ -210,10 +211,12 @@
93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitMessageView.m; sourceTree = "<group>"; };
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
D26DC6440E782C9000C777B2 /* gitx.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = gitx.icns; sourceTree = "<group>"; };
D823487410CB382C00944BDE /* Terminal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Terminal.h; sourceTree = "<group>"; };
D854948410D5C01B0083B917 /* PBCreateBranchSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCreateBranchSheet.h; sourceTree = "<group>"; };
D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCreateBranchSheet.m; sourceTree = "<group>"; };
D854949310D5C3E20083B917 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/PBCreateBranchSheet.xib; sourceTree = "<group>"; };
D85B93F610E51279007F3C28 /* PBGitRefish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRefish.h; sourceTree = "<group>"; };
D8E3B2B710DC9FB2001096A3 /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = /System/Library/Frameworks/ScriptingBridge.framework; sourceTree = "<absolute>"; };
EB2A73480FEE3F09006601CF /* PBCollapsibleSplitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCollapsibleSplitView.h; sourceTree = "<group>"; };
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCollapsibleSplitView.m; sourceTree = "<group>"; };
F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = mainSplitterBar.tiff; path = Images/mainSplitterBar.tiff; sourceTree = "<group>"; };
@@ -329,6 +332,7 @@
F580E6AE0E733276009E2D3F /* Sparkle.framework in Frameworks */,
F5E4DBFB0EAB58D90013FAFC /* SystemConfiguration.framework in Frameworks */,
F5C580E50EDA250900995434 /* libgit2.a in Frameworks */,
D8E3B2B810DC9FB2001096A3 /* ScriptingBridge.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -384,6 +388,7 @@
77C82804067257F0000B614F /* CoreData.framework */,
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
D8E3B2B710DC9FB2001096A3 /* ScriptingBridge.framework */,
);
name = "Other Frameworks";
sourceTree = "<group>";
@@ -586,6 +591,7 @@
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */,
F5FC41F20EBCBD4300191D80 /* PBGitXProtocol.h */,
F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */,
D823487410CB382C00944BDE /* Terminal.h */,
);
name = Aux;
sourceTree = "<group>";
+1
View File
@@ -35,4 +35,5 @@
- (IBAction) showCommitView:(id)sender;
- (IBAction) showHistoryView:(id)sender;
- (IBAction) openInTerminal:(id)sender;
@end
+11
View File
@@ -9,6 +9,7 @@
#import "PBGitWindowController.h"
#import "PBGitHistoryController.h"
#import "PBGitCommitController.h"
#import "Terminal.h"
@implementation PBGitWindowController
@@ -149,6 +150,16 @@
[self showErrorSheet:error];
}
- (IBAction) openInTerminal:(id)sender
{
TerminalApplication *term = [SBApplication applicationWithBundleIdentifier: @"com.apple.Terminal"];
NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"];
NSString *cmd = [NSString stringWithFormat: @"cd \"%@\"; clear; echo '# Opened by GitX:'; git status", workingDirectory];
[term doScript: cmd in: nil];
[NSThread sleepForTimeInterval: 0.1];
[term activate];
}
#pragma mark -
#pragma mark Toolbar Delegates
+159
View File
@@ -0,0 +1,159 @@
/*
* Terminal.h
*/
#import <AppKit/AppKit.h>
#import <ScriptingBridge/ScriptingBridge.h>
@class TerminalApplication, TerminalWindow, TerminalSettingsSet, TerminalTab;
typedef enum {
TerminalSaveOptionsYes = 'yes ' /* Save the file. */,
TerminalSaveOptionsNo = 'no ' /* Do not save the file. */,
TerminalSaveOptionsAsk = 'ask ' /* Ask the user whether or not to save the file. */
} TerminalSaveOptions;
typedef enum {
TerminalPrintingErrorHandlingStandard = 'lwst' /* Standard PostScript error handling */,
TerminalPrintingErrorHandlingDetailed = 'lwdt' /* print a detailed report of PostScript errors */
} TerminalPrintingErrorHandling;
/*
* Standard Suite
*/
// The applications top-level scripting object.
@interface TerminalApplication : SBApplication
- (SBElementArray *) windows;
@property (copy, readonly) NSString *name; // The name of the application.
@property (readonly) BOOL frontmost; // Is this the frontmost (active) application?
@property (copy, readonly) NSString *version; // The version of the application.
- (void) open:(NSArray *)x; // Open a document.
- (void) print:(id)x withProperties:(NSDictionary *)withProperties printDialog:(BOOL)printDialog; // Print a document.
- (void) quitSaving:(TerminalSaveOptions)saving; // Quit the application.
- (TerminalTab *) doScript:(NSString *)x in:(id)in_; // Runs a UNIX shell script or command.
@end
// A window.
@interface TerminalWindow : SBObject
- (SBElementArray *) tabs;
@property (copy, readonly) NSString *name; // The full title of the window.
- (NSInteger) id; // The unique identifier of the window.
@property NSInteger index; // The index of the window, ordered front to back.
@property NSRect bounds; // The bounding rectangle of the window.
@property (readonly) BOOL closeable; // Whether the window has a close box.
@property (readonly) BOOL miniaturizable; // Whether the window can be minimized.
@property BOOL miniaturized; // Whether the window is currently minimized.
@property (readonly) BOOL resizable; // Whether the window can be resized.
@property BOOL visible; // Whether the window is currently visible.
@property (readonly) BOOL zoomable; // Whether the window can be zoomed.
@property BOOL zoomed; // Whether the window is currently zoomed.
@property BOOL frontmost; // Whether the window is currently the frontmost Terminal window.
@property NSPoint position; // The position of the window, relative to the upper left corner of the screen.
@property NSPoint origin; // The position of the window, relative to the lower left corner of the screen.
@property NSPoint size; // The width and height of the window
@property NSRect frame; // The bounding rectangle, relative to the lower left corner of the screen.
- (void) closeSaving:(TerminalSaveOptions)saving savingIn:(NSURL *)savingIn; // Close a document.
- (void) saveIn:(NSURL *)in_; // Save a document.
- (void) printWithProperties:(NSDictionary *)withProperties printDialog:(BOOL)printDialog; // Print a document.
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location.
- (BOOL) exists; // Verify if an object exists.
- (void) moveTo:(SBObject *)to; // Move object(s) to a new location.
@end
/*
* Terminal Suite
*/
@interface TerminalApplication (TerminalSuite)
- (SBElementArray *) settingsSets;
@property (copy) TerminalSettingsSet *defaultSettings; // The settings set used for new windows.
@property (copy) TerminalSettingsSet *startupSettings; // The settings set used for the window created on application startup.
@end
// A set of settings.
@interface TerminalSettingsSet : SBObject
- (NSInteger) id; // The unique identifier of the settings set.
@property (copy) NSString *name; // The name of the settings set.
@property NSInteger numberOfRows; // The number of rows displayed in the tab.
@property NSInteger numberOfColumns; // The number of columns displayed in the tab.
@property (copy) NSColor *cursorColor; // The cursor color for the tab.
@property (copy) NSColor *backgroundColor; // The background color for the tab.
@property (copy) NSColor *normalTextColor; // The normal text color for the tab.
@property (copy) NSColor *boldTextColor; // The bold text color for the tab.
@property (copy) NSString *fontName; // The name of the font used to display the tabs contents.
@property NSInteger fontSize; // The size of the font used to display the tabs contents.
@property BOOL fontAntialiasing; // Whether the font used to display the tabs contents is antialiased.
@property (copy) NSArray *cleanCommands; // The processes which will be ignored when checking whether a tab can be closed without showing a prompt.
@property BOOL titleDisplaysDeviceName; // Whether the title contains the device name.
@property BOOL titleDisplaysShellPath; // Whether the title contains the shell path.
@property BOOL titleDisplaysWindowSize; // Whether the title contains the tabs size, in rows and columns.
@property BOOL titleDisplaysSettingsName; // Whether the title contains the settings name.
@property BOOL titleDisplaysCustomTitle; // Whether the title contains a custom title.
@property (copy) NSString *customTitle; // The tabs custom title.
- (void) closeSaving:(TerminalSaveOptions)saving savingIn:(NSURL *)savingIn; // Close a document.
- (void) saveIn:(NSURL *)in_; // Save a document.
- (void) printWithProperties:(NSDictionary *)withProperties printDialog:(BOOL)printDialog; // Print a document.
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location.
- (BOOL) exists; // Verify if an object exists.
- (void) moveTo:(SBObject *)to; // Move object(s) to a new location.
@end
// A tab.
@interface TerminalTab : SBObject
@property NSInteger numberOfRows; // The number of rows displayed in the tab.
@property NSInteger numberOfColumns; // The number of columns displayed in the tab.
@property (copy, readonly) NSString *contents; // The currently visible contents of the tab.
@property (copy, readonly) NSString *history; // The contents of the entire scrolling buffer of the tab.
@property (readonly) BOOL busy; // Whether the tab is busy running a process.
@property (copy, readonly) NSArray *processes; // The processes currently running in the tab.
@property BOOL selected; // Whether the tab is selected.
@property BOOL titleDisplaysCustomTitle; // Whether the title contains a custom title.
@property (copy) NSString *customTitle; // The tabs custom title.
@property (copy, readonly) NSString *tty; // The tabs TTY device.
@property (copy) TerminalSettingsSet *currentSettings; // The set of settings which control the tabs behavior and appearance.
@property (copy) NSColor *cursorColor; // The cursor color for the tab.
@property (copy) NSColor *backgroundColor; // The background color for the tab.
@property (copy) NSColor *normalTextColor; // The normal text color for the tab.
@property (copy) NSColor *boldTextColor; // The bold text color for the tab.
@property (copy) NSArray *cleanCommands; // The processes which will be ignored when checking whether a tab can be closed without showing a prompt.
@property BOOL titleDisplaysDeviceName; // Whether the title contains the device name.
@property BOOL titleDisplaysShellPath; // Whether the title contains the shell path.
@property BOOL titleDisplaysWindowSize; // Whether the title contains the tabs size, in rows and columns.
@property BOOL titleDisplaysFileName; // Whether the title contains the file name.
@property (copy) NSString *fontName; // The name of the font used to display the tabs contents.
@property NSInteger fontSize; // The size of the font used to display the tabs contents.
@property BOOL fontAntialiasing; // Whether the font used to display the tabs contents is antialiased.
- (void) closeSaving:(TerminalSaveOptions)saving savingIn:(NSURL *)savingIn; // Close a document.
- (void) saveIn:(NSURL *)in_; // Save a document.
- (void) printWithProperties:(NSDictionary *)withProperties printDialog:(BOOL)printDialog; // Print a document.
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location.
- (BOOL) exists; // Verify if an object exists.
- (void) moveTo:(SBObject *)to; // Move object(s) to a new location.
@end