Skip to content

Commit e60bb32

Browse files
committed
Refactor the gitx CLI to use apple events and the scripting bridge
Sending the arguments with the openURL:... message allows the repository document to modify it's UI without the UI flashing between states as it opens. Covers all the existing functionality of the CLI, but modifies: - "--all" "--local" "--branch" change the branch filter - cleaned up the usage (help) text and added info on missing commands - looks up the full ref name of refs so the name of a branch or tag can be entered (the user can enter "master" instead of "refs/heads/master") Modified the History Controller to watch for and react to branch filter changes. The GitX.h file is generated by the 'sdp' tool in a run script build phase called 'Generate Scripting Bridge Header' based on the content of GitX.sdef. It is used by the Scripting Bridge so that other apps (in this case the gitx CLI) can call Applescript commands on GitX in objective-c.
1 parent beaa591 commit e60bb32

13 files changed

+610
-97
lines changed

ApplicationController.h

-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import <Cocoa/Cocoa.h>
1010
#import "PBGitRepository.h"
1111

12-
@class PBCLIProxy;
1312
@class PBCloneRepositoryPanel;
1413

1514
@interface ApplicationController : NSObject
@@ -20,10 +19,8 @@
2019
NSManagedObjectModel *managedObjectModel;
2120
NSManagedObjectContext *managedObjectContext;
2221

23-
PBCLIProxy *cliProxy;
2422
PBCloneRepositoryPanel *cloneRepositoryPanel;
2523
}
26-
@property (retain) PBCLIProxy* cliProxy;
2724

2825
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator;
2926
- (NSManagedObjectModel *)managedObjectModel;

ApplicationController.m

+5-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#import "PBGitRevisionCell.h"
1111
#import "PBGitWindowController.h"
1212
#import "PBRepositoryDocumentController.h"
13-
#import "PBCLIProxy.h"
1413
#import "PBServicesController.h"
1514
#import "PBGitXProtocol.h"
1615
#import "PBPrefsWindowController.h"
@@ -20,21 +19,19 @@
2019
#import "Sparkle/SUUpdater.h"
2120

2221
@implementation ApplicationController
23-
@synthesize cliProxy;
2422

2523
- (ApplicationController*)init
2624
{
2725
#ifdef DEBUG_BUILD
2826
[NSApp activateIgnoringOtherApps:YES];
2927
#endif
3028

31-
if(self = [super init]) {
32-
if(![[NSBundle bundleWithPath:@"/System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework"] load])
33-
if(![[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load])
34-
NSLog(@"Could not load QuickLook");
29+
if(!(self = [super init]))
30+
return nil;
3531

36-
self.cliProxy = [PBCLIProxy new];
37-
}
32+
if(![[NSBundle bundleWithPath:@"/System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework"] load])
33+
if(![[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load])
34+
NSLog(@"Could not load QuickLook");
3835

3936
/* Value Transformers */
4037
NSValueTransformer *transformer = [[PBNSURLPathUserDefaultsTransfomer alloc] init];

GitX.h

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* GitX.h
3+
*/
4+
5+
#import <AppKit/AppKit.h>
6+
#import <ScriptingBridge/ScriptingBridge.h>
7+
8+
9+
@class GitXApplication, GitXDocument, GitXWindow;
10+
11+
12+
13+
/*
14+
* Standard Suite
15+
*/
16+
17+
// The application's top-level scripting object.
18+
@interface GitXApplication : SBApplication
19+
20+
- (SBElementArray *) documents;
21+
- (SBElementArray *) windows;
22+
23+
@property (copy, readonly) NSString *name; // The name of the application.
24+
@property (readonly) BOOL frontmost; // Is this the active application?
25+
@property (copy, readonly) NSString *version; // The version number of the application.
26+
27+
- (void) open:(NSArray *)x; // Open a document.
28+
- (void) quit; // Quit the application.
29+
- (BOOL) exists:(id)x; // Verify that an object exists.
30+
- (void) showDiff:(NSString *)x; // Show the supplied diff output in a GitX window.
31+
32+
@end
33+
34+
// A document.
35+
@interface GitXDocument : SBObject
36+
37+
@property (copy, readonly) NSString *name; // Its name.
38+
@property (copy, readonly) NSURL *file; // Its location on disk, if it has one.
39+
40+
- (void) close; // Close a document.
41+
- (void) delete; // Delete an object.
42+
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
43+
- (void) moveTo:(SBObject *)to; // Move an object to a new location.
44+
45+
@end
46+
47+
// A window.
48+
@interface GitXWindow : SBObject
49+
50+
@property (copy, readonly) NSString *name; // The title of the window.
51+
- (NSInteger) id; // The unique identifier of the window.
52+
@property NSInteger index; // The index of the window, ordered front to back.
53+
@property NSRect bounds; // The bounding rectangle of the window.
54+
@property (readonly) BOOL closeable; // Does the window have a close button?
55+
@property (readonly) BOOL miniaturizable; // Does the window have a minimize button?
56+
@property BOOL miniaturized; // Is the window minimized right now?
57+
@property (readonly) BOOL resizable; // Can the window be resized?
58+
@property BOOL visible; // Is the window visible right now?
59+
@property (readonly) BOOL zoomable; // Does the window have a zoom button?
60+
@property BOOL zoomed; // Is the window zoomed right now?
61+
@property (copy, readonly) GitXDocument *document; // The document whose contents are displayed in the window.
62+
63+
- (void) close; // Close a document.
64+
- (void) delete; // Delete an object.
65+
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
66+
- (void) moveTo:(SBObject *)to; // Move an object to a new location.
67+
68+
@end
69+

GitX.sdef

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
3+
4+
<dictionary title="GitX Terminology">
5+
6+
<suite name="Standard Suite" code="????" description="Common classes and commands for all applications.">
7+
8+
<command name="open" code="aevtodoc" description="Open a document.">
9+
<direct-parameter description="The file(s) to be opened.">
10+
<type type="file" list="yes"/>
11+
</direct-parameter>
12+
</command>
13+
14+
<command name="close" code="coreclos" description="Close a document.">
15+
<cocoa class="NSCloseCommand"/>
16+
<direct-parameter type="specifier" description="the document(s) or window(s) to close."/>
17+
</command>
18+
19+
<command name="quit" code="aevtquit" description="Quit the application.">
20+
<cocoa class="NSQuitCommand"/>
21+
</command>
22+
23+
<command name="count" code="corecnte" description="Return the number of elements of a particular class within an object.">
24+
<cocoa class="NSCountCommand"/>
25+
<direct-parameter type="specifier" description="The objects to be counted."/>
26+
<parameter name="each" code="kocl" type="type" optional="yes" description="The class of objects to be counted." hidden="yes">
27+
<cocoa key="ObjectClass"/>
28+
</parameter>
29+
<result type="integer" description="The count."/>
30+
</command>
31+
32+
<command name="delete" code="coredelo" description="Delete an object.">
33+
<cocoa class="NSDeleteCommand"/>
34+
<direct-parameter type="specifier" description="The object(s) to delete."/>
35+
</command>
36+
37+
<command name="duplicate" code="coreclon" description="Copy an object.">
38+
<cocoa class="NSCloneCommand"/>
39+
<direct-parameter type="specifier" description="The object(s) to copy."/>
40+
<parameter name="to" code="insh" type="location specifier" description="The location for the new copy or copies." optional="yes">
41+
<cocoa key="ToLocation"/>
42+
</parameter>
43+
<parameter name="with properties" code="prdt" type="record" description="Properties to set in the new copy or copies right away." optional="yes">
44+
<cocoa key="WithProperties"/>
45+
</parameter>
46+
</command>
47+
48+
<command name="exists" code="coredoex" description="Verify that an object exists.">
49+
<cocoa class="NSExistsCommand"/>
50+
<direct-parameter type="any" description="The object(s) to check."/>
51+
<result type="boolean" description="Did the object(s) exist?"/>
52+
</command>
53+
54+
<command name="make" code="corecrel" description="Create a new object.">
55+
<cocoa class="NSCreateCommand"/>
56+
<parameter name="new" code="kocl" type="type" description="The class of the new object.">
57+
<cocoa key="ObjectClass"/>
58+
</parameter>
59+
<parameter name="at" code="insh" type="location specifier" optional="yes" description="The location at which to insert the object.">
60+
<cocoa key="Location"/>
61+
</parameter>
62+
<parameter name="with data" code="data" type="any" optional="yes" description="The initial contents of the object.">
63+
<cocoa key="ObjectData"/>
64+
</parameter>
65+
<parameter name="with properties" code="prdt" type="record" optional="yes" description="The initial values for properties of the object.">
66+
<cocoa key="KeyDictionary"/>
67+
</parameter>
68+
<result type="specifier" description="The new object."/>
69+
</command>
70+
71+
<command name="move" code="coremove" description="Move an object to a new location.">
72+
<cocoa class="NSMoveCommand"/>
73+
<direct-parameter type="specifier" description="The object(s) to move."/>
74+
<parameter name="to" code="insh" type="location specifier" description="The new location for the object(s).">
75+
<cocoa key="ToLocation"/>
76+
</parameter>
77+
</command>
78+
79+
<class name="application" code="capp" description="The application's top-level scripting object.">
80+
<cocoa class="NSApplication"/>
81+
<property name="name" code="pnam" type="text" access="r" description="The name of the application."/>
82+
<property name="frontmost" code="pisf" type="boolean" access="r" description="Is this the active application?">
83+
<cocoa key="isActive"/>
84+
</property>
85+
<property name="version" code="vers" type="text" access="r" description="The version number of the application."/>
86+
<element type="document">
87+
<cocoa key="orderedDocuments"/>
88+
</element>
89+
<element type="window" access="r">
90+
<cocoa key="orderedWindows"/>
91+
</element>
92+
<responds-to name="open">
93+
<cocoa method="handleOpenScriptCommand:"/>
94+
</responds-to>
95+
<responds-to name="quit">
96+
<cocoa method="handleQuitScriptCommand:"/>
97+
</responds-to>
98+
</class>
99+
100+
<class name="document" code="docu" description="A document.">
101+
<cocoa class="NSDocument"/>
102+
<property name="name" code="pnam" type="text" access="r" description="Its name.">
103+
<cocoa key="displayName"/>
104+
</property>
105+
<property name="file" code="file" type="file" access="r" description="Its location on disk, if it has one.">
106+
<cocoa key="fileURL"/>
107+
</property>
108+
<responds-to command="close">
109+
<cocoa method="handleCloseScriptCommand:"/>
110+
</responds-to>
111+
</class>
112+
113+
<class name="window" code="cwin" description="A window.">
114+
<cocoa class="NSWindow"/>
115+
<property name="name" code="pnam" type="text" access="r" description="The title of the window.">
116+
<cocoa key="title"/>
117+
</property>
118+
<property name="id" code="ID " type="integer" access="r" description="The unique identifier of the window.">
119+
<cocoa key="uniqueID"/>
120+
</property>
121+
<property name="index" code="pidx" type="integer" description="The index of the window, ordered front to back.">
122+
<cocoa key="orderedIndex"/>
123+
</property>
124+
<property name="bounds" code="pbnd" type="rectangle" description="The bounding rectangle of the window.">
125+
<cocoa key="boundsAsQDRect"/>
126+
</property>
127+
<property name="closeable" code="hclb" type="boolean" access="r" description="Does the window have a close button?">
128+
<cocoa key="hasCloseBox"/>
129+
</property>
130+
<property name="miniaturizable" code="ismn" type="boolean" access="r" description="Does the window have a minimize button?">
131+
<cocoa key="isMiniaturizable"/>
132+
</property>
133+
<property name="miniaturized" code="pmnd" type="boolean" description="Is the window minimized right now?">
134+
<cocoa key="isMiniaturized"/>
135+
</property>
136+
<property name="resizable" code="prsz" type="boolean" access="r" description="Can the window be resized?">
137+
<cocoa key="isResizable"/>
138+
</property>
139+
<property name="visible" code="pvis" type="boolean" description="Is the window visible right now?">
140+
<cocoa key="isVisible"/>
141+
</property>
142+
<property name="zoomable" code="iszm" type="boolean" access="r" description="Does the window have a zoom button?">
143+
<cocoa key="isZoomable"/>
144+
</property>
145+
<property name="zoomed" code="pzum" type="boolean" description="Is the window zoomed right now?">
146+
<cocoa key="isZoomed"/>
147+
</property>
148+
149+
<property name="document" code="docu" type="document" access="r" description="The document whose contents are displayed in the window."/>
150+
151+
<responds-to name="close">
152+
<cocoa method="handleCloseScriptCommand:"/>
153+
</responds-to>
154+
</class>
155+
156+
</suite>
157+
158+
<suite name="GitX Suite" code="GitX" description="Classes for GitX.">
159+
160+
<command name="show diff" code="GitXShDf" description="Show the supplied diff output in a GitX window.">
161+
<direct-parameter type="text" description="The textual output from a diff tool."/>
162+
</command>
163+
164+
</suite>
165+
166+
</dictionary>

0 commit comments

Comments
 (0)