Skip to content

Commit

Permalink
Refactor the gitx CLI to use apple events and the scripting bridge
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brotherbard committed Sep 13, 2010
1 parent beaa591 commit e60bb32
Show file tree
Hide file tree
Showing 13 changed files with 610 additions and 97 deletions.
3 changes: 0 additions & 3 deletions ApplicationController.h
Expand Up @@ -9,7 +9,6 @@
#import <Cocoa/Cocoa.h>
#import "PBGitRepository.h"

@class PBCLIProxy;
@class PBCloneRepositoryPanel;

@interface ApplicationController : NSObject
Expand All @@ -20,10 +19,8 @@
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;

PBCLIProxy *cliProxy;
PBCloneRepositoryPanel *cloneRepositoryPanel;
}
@property (retain) PBCLIProxy* cliProxy;

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator;
- (NSManagedObjectModel *)managedObjectModel;
Expand Down
13 changes: 5 additions & 8 deletions ApplicationController.m
Expand Up @@ -10,7 +10,6 @@
#import "PBGitRevisionCell.h"
#import "PBGitWindowController.h"
#import "PBRepositoryDocumentController.h"
#import "PBCLIProxy.h"
#import "PBServicesController.h"
#import "PBGitXProtocol.h"
#import "PBPrefsWindowController.h"
Expand All @@ -20,21 +19,19 @@
#import "Sparkle/SUUpdater.h"

@implementation ApplicationController
@synthesize cliProxy;

- (ApplicationController*)init
{
#ifdef DEBUG_BUILD
[NSApp activateIgnoringOtherApps:YES];
#endif

if(self = [super init]) {
if(![[NSBundle bundleWithPath:@"/System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework"] load])
if(![[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load])
NSLog(@"Could not load QuickLook");
if(!(self = [super init]))
return nil;

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

/* Value Transformers */
NSValueTransformer *transformer = [[PBNSURLPathUserDefaultsTransfomer alloc] init];
Expand Down
69 changes: 69 additions & 0 deletions GitX.h
@@ -0,0 +1,69 @@
/*
* GitX.h
*/

#import <AppKit/AppKit.h>
#import <ScriptingBridge/ScriptingBridge.h>


@class GitXApplication, GitXDocument, GitXWindow;



/*
* Standard Suite
*/

// The application's top-level scripting object.
@interface GitXApplication : SBApplication

- (SBElementArray *) documents;
- (SBElementArray *) windows;

@property (copy, readonly) NSString *name; // The name of the application.
@property (readonly) BOOL frontmost; // Is this the active application?
@property (copy, readonly) NSString *version; // The version number of the application.

- (void) open:(NSArray *)x; // Open a document.
- (void) quit; // Quit the application.
- (BOOL) exists:(id)x; // Verify that an object exists.
- (void) showDiff:(NSString *)x; // Show the supplied diff output in a GitX window.

@end

// A document.
@interface GitXDocument : SBObject

@property (copy, readonly) NSString *name; // Its name.
@property (copy, readonly) NSURL *file; // Its location on disk, if it has one.

- (void) close; // Close a document.
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
- (void) moveTo:(SBObject *)to; // Move an object to a new location.

@end

// A window.
@interface GitXWindow : SBObject

@property (copy, readonly) NSString *name; // The 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; // Does the window have a close button?
@property (readonly) BOOL miniaturizable; // Does the window have a minimize button?
@property BOOL miniaturized; // Is the window minimized right now?
@property (readonly) BOOL resizable; // Can the window be resized?
@property BOOL visible; // Is the window visible right now?
@property (readonly) BOOL zoomable; // Does the window have a zoom button?
@property BOOL zoomed; // Is the window zoomed right now?
@property (copy, readonly) GitXDocument *document; // The document whose contents are displayed in the window.

- (void) close; // Close a document.
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
- (void) moveTo:(SBObject *)to; // Move an object to a new location.

@end

166 changes: 166 additions & 0 deletions GitX.sdef
@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">

<dictionary title="GitX Terminology">

<suite name="Standard Suite" code="????" description="Common classes and commands for all applications.">

<command name="open" code="aevtodoc" description="Open a document.">
<direct-parameter description="The file(s) to be opened.">
<type type="file" list="yes"/>
</direct-parameter>
</command>

<command name="close" code="coreclos" description="Close a document.">
<cocoa class="NSCloseCommand"/>
<direct-parameter type="specifier" description="the document(s) or window(s) to close."/>
</command>

<command name="quit" code="aevtquit" description="Quit the application.">
<cocoa class="NSQuitCommand"/>
</command>

<command name="count" code="corecnte" description="Return the number of elements of a particular class within an object.">
<cocoa class="NSCountCommand"/>
<direct-parameter type="specifier" description="The objects to be counted."/>
<parameter name="each" code="kocl" type="type" optional="yes" description="The class of objects to be counted." hidden="yes">
<cocoa key="ObjectClass"/>
</parameter>
<result type="integer" description="The count."/>
</command>

<command name="delete" code="coredelo" description="Delete an object.">
<cocoa class="NSDeleteCommand"/>
<direct-parameter type="specifier" description="The object(s) to delete."/>
</command>

<command name="duplicate" code="coreclon" description="Copy an object.">
<cocoa class="NSCloneCommand"/>
<direct-parameter type="specifier" description="The object(s) to copy."/>
<parameter name="to" code="insh" type="location specifier" description="The location for the new copy or copies." optional="yes">
<cocoa key="ToLocation"/>
</parameter>
<parameter name="with properties" code="prdt" type="record" description="Properties to set in the new copy or copies right away." optional="yes">
<cocoa key="WithProperties"/>
</parameter>
</command>

<command name="exists" code="coredoex" description="Verify that an object exists.">
<cocoa class="NSExistsCommand"/>
<direct-parameter type="any" description="The object(s) to check."/>
<result type="boolean" description="Did the object(s) exist?"/>
</command>

<command name="make" code="corecrel" description="Create a new object.">
<cocoa class="NSCreateCommand"/>
<parameter name="new" code="kocl" type="type" description="The class of the new object.">
<cocoa key="ObjectClass"/>
</parameter>
<parameter name="at" code="insh" type="location specifier" optional="yes" description="The location at which to insert the object.">
<cocoa key="Location"/>
</parameter>
<parameter name="with data" code="data" type="any" optional="yes" description="The initial contents of the object.">
<cocoa key="ObjectData"/>
</parameter>
<parameter name="with properties" code="prdt" type="record" optional="yes" description="The initial values for properties of the object.">
<cocoa key="KeyDictionary"/>
</parameter>
<result type="specifier" description="The new object."/>
</command>

<command name="move" code="coremove" description="Move an object to a new location.">
<cocoa class="NSMoveCommand"/>
<direct-parameter type="specifier" description="The object(s) to move."/>
<parameter name="to" code="insh" type="location specifier" description="The new location for the object(s).">
<cocoa key="ToLocation"/>
</parameter>
</command>

<class name="application" code="capp" description="The application's top-level scripting object.">
<cocoa class="NSApplication"/>
<property name="name" code="pnam" type="text" access="r" description="The name of the application."/>
<property name="frontmost" code="pisf" type="boolean" access="r" description="Is this the active application?">
<cocoa key="isActive"/>
</property>
<property name="version" code="vers" type="text" access="r" description="The version number of the application."/>
<element type="document">
<cocoa key="orderedDocuments"/>
</element>
<element type="window" access="r">
<cocoa key="orderedWindows"/>
</element>
<responds-to name="open">
<cocoa method="handleOpenScriptCommand:"/>
</responds-to>
<responds-to name="quit">
<cocoa method="handleQuitScriptCommand:"/>
</responds-to>
</class>

<class name="document" code="docu" description="A document.">
<cocoa class="NSDocument"/>
<property name="name" code="pnam" type="text" access="r" description="Its name.">
<cocoa key="displayName"/>
</property>
<property name="file" code="file" type="file" access="r" description="Its location on disk, if it has one.">
<cocoa key="fileURL"/>
</property>
<responds-to command="close">
<cocoa method="handleCloseScriptCommand:"/>
</responds-to>
</class>

<class name="window" code="cwin" description="A window.">
<cocoa class="NSWindow"/>
<property name="name" code="pnam" type="text" access="r" description="The title of the window.">
<cocoa key="title"/>
</property>
<property name="id" code="ID " type="integer" access="r" description="The unique identifier of the window.">
<cocoa key="uniqueID"/>
</property>
<property name="index" code="pidx" type="integer" description="The index of the window, ordered front to back.">
<cocoa key="orderedIndex"/>
</property>
<property name="bounds" code="pbnd" type="rectangle" description="The bounding rectangle of the window.">
<cocoa key="boundsAsQDRect"/>
</property>
<property name="closeable" code="hclb" type="boolean" access="r" description="Does the window have a close button?">
<cocoa key="hasCloseBox"/>
</property>
<property name="miniaturizable" code="ismn" type="boolean" access="r" description="Does the window have a minimize button?">
<cocoa key="isMiniaturizable"/>
</property>
<property name="miniaturized" code="pmnd" type="boolean" description="Is the window minimized right now?">
<cocoa key="isMiniaturized"/>
</property>
<property name="resizable" code="prsz" type="boolean" access="r" description="Can the window be resized?">
<cocoa key="isResizable"/>
</property>
<property name="visible" code="pvis" type="boolean" description="Is the window visible right now?">
<cocoa key="isVisible"/>
</property>
<property name="zoomable" code="iszm" type="boolean" access="r" description="Does the window have a zoom button?">
<cocoa key="isZoomable"/>
</property>
<property name="zoomed" code="pzum" type="boolean" description="Is the window zoomed right now?">
<cocoa key="isZoomed"/>
</property>

<property name="document" code="docu" type="document" access="r" description="The document whose contents are displayed in the window."/>

<responds-to name="close">
<cocoa method="handleCloseScriptCommand:"/>
</responds-to>
</class>

</suite>

<suite name="GitX Suite" code="GitX" description="Classes for GitX.">

<command name="show diff" code="GitXShDf" description="Show the supplied diff output in a GitX window.">
<direct-parameter type="text" description="The textual output from a diff tool."/>
</command>

</suite>

</dictionary>

0 comments on commit e60bb32

Please sign in to comment.