mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Add preferences for opening things at launch.
Heavily-Edited-By: Pieter de Bie <pdebie@ai.rug.nl>
This commit is contained in:
committed by
Pieter de Bie
parent
ed4bb78706
commit
85322728fa
+23
-11
@@ -68,18 +68,30 @@
|
||||
// Only try to open a default document if there are no documents open already.
|
||||
// For example, the application might have been launched by double-clicking a .git repository,
|
||||
// or by dragging a folder to the app icon
|
||||
if ([[[PBRepositoryDocumentController sharedDocumentController] documents] count] == 0 && [[NSApplication sharedApplication] isActive]) {
|
||||
// Try to open the current directory as a git repository
|
||||
NSURL *url = nil;
|
||||
if([[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"])
|
||||
url = [NSURL fileURLWithPath:[[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"]];
|
||||
NSError *error = nil;
|
||||
if (!url || [[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url display:YES error:&error] == NO) {
|
||||
// The current directory could not be opened (most likely it’s not a git repository)
|
||||
// so show an open panel for the user to select a repository to view
|
||||
[[PBRepositoryDocumentController sharedDocumentController] openDocument:self];
|
||||
}
|
||||
if ([[[PBRepositoryDocumentController sharedDocumentController] documents] count])
|
||||
return;
|
||||
|
||||
if (![[NSApplication sharedApplication] isActive])
|
||||
return;
|
||||
|
||||
NSURL *url = nil;
|
||||
|
||||
// Try to find the current directory, to open that as a repository
|
||||
if ([PBGitDefaults openCurDirOnLaunch]) {
|
||||
NSString *curPath = [[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"];
|
||||
if (curPath)
|
||||
url = [NSURL fileURLWithPath:curPath];
|
||||
}
|
||||
|
||||
// Try to open the found URL
|
||||
NSError *error = nil;
|
||||
if (url && [[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url display:YES error:&error])
|
||||
return;
|
||||
|
||||
// The current directory was not enabled or could not be opened (most likely it’s not a git repository).
|
||||
// show an open panel for the user to select a repository to view
|
||||
if ([PBGitDefaults showOpenPanelOnLaunch])
|
||||
[[PBRepositoryDocumentController sharedDocumentController] openDocument:self];
|
||||
}
|
||||
|
||||
- (void) windowWillClose: sender
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<object class="NSTextField" id="441589300">
|
||||
<reference key="NSNextResponder" ref="1005"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<string key="NSFrame">{{17, 74}, {99, 17}}</string>
|
||||
<string key="NSFrame">{{17, 54}, {99, 17}}</string>
|
||||
<reference key="NSSuperview" ref="1005"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSTextFieldCell" key="NSCell" id="31526941">
|
||||
@@ -90,7 +90,7 @@
|
||||
<string>NSFilenamesPboardType</string>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrame">{{121, 70}, {179, 22}}</string>
|
||||
<string key="NSFrame">{{121, 50}, {179, 22}}</string>
|
||||
<reference key="NSSuperview" ref="1005"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSPathCell" key="NSCell" id="331807888">
|
||||
@@ -112,7 +112,7 @@
|
||||
<object class="NSTextField" id="617839596">
|
||||
<reference key="NSNextResponder" ref="1005"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<string key="NSFrame">{{118, 20}, {192, 42}}</string>
|
||||
<string key="NSFrame">{{118, 0}, {192, 42}}</string>
|
||||
<reference key="NSSuperview" ref="1005"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSTextFieldCell" key="NSCell" id="453728129">
|
||||
@@ -128,7 +128,7 @@
|
||||
<object class="NSButton" id="1032928366">
|
||||
<reference key="NSNextResponder" ref="1005"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<string key="NSFrame">{{306, 74}, {54, 14}}</string>
|
||||
<string key="NSFrame">{{306, 54}, {54, 14}}</string>
|
||||
<reference key="NSSuperview" ref="1005"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSButtonCell" key="NSCell" id="806993456">
|
||||
@@ -177,6 +177,28 @@
|
||||
<int key="NSPeriodicInterval">25</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSButton" id="68472633">
|
||||
<reference key="NSNextResponder" ref="1005"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<string key="NSFrame">{{18, 78}, {207, 18}}</string>
|
||||
<reference key="NSSuperview" ref="1005"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSButtonCell" key="NSCell" id="456188813">
|
||||
<int key="NSCellFlags">-2080244224</int>
|
||||
<int key="NSCellFlags2">0</int>
|
||||
<string type="base64-UTF8" key="NSContents">U2hvdyAiT3BlbiIgcGFuZWwgb24gbGF1bmNoA</string>
|
||||
<reference key="NSSupport" ref="734450335"/>
|
||||
<reference key="NSControlView" ref="68472633"/>
|
||||
<int key="NSButtonFlags">1211912703</int>
|
||||
<int key="NSButtonFlags2">2</int>
|
||||
<reference key="NSNormalImage" ref="495198475"/>
|
||||
<reference key="NSAlternateImage" ref="690089052"/>
|
||||
<string key="NSAlternateContents"/>
|
||||
<string key="NSKeyEquivalent"/>
|
||||
<int key="NSPeriodicDelay">200</int>
|
||||
<int key="NSPeriodicInterval">25</int>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{400, 139}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
@@ -428,7 +450,7 @@
|
||||
<object class="NSUserDefaultsController" id="557723770">
|
||||
<object class="NSMutableArray" key="NSDeclaredKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>PBShowWhitespaceDifferences</string>
|
||||
<string>PBShowOpenPanelOnLaunch</string>
|
||||
</object>
|
||||
<bool key="NSSharedInstance">YES</bool>
|
||||
</object>
|
||||
@@ -865,6 +887,22 @@
|
||||
</object>
|
||||
<int key="connectionID">117</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: values.PBShowOpenPanelOnLaunch</string>
|
||||
<reference key="source" ref="68472633"/>
|
||||
<reference key="destination" ref="557723770"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="68472633"/>
|
||||
<reference key="NSDestination" ref="557723770"/>
|
||||
<string key="NSLabel">value: values.PBShowOpenPanelOnLaunch</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">values.PBShowOpenPanelOnLaunch</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">121</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
@@ -900,11 +938,12 @@
|
||||
<reference key="object" ref="1005"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="910887184"/>
|
||||
<reference ref="441589300"/>
|
||||
<reference ref="525163949"/>
|
||||
<reference ref="617839596"/>
|
||||
<reference ref="1032928366"/>
|
||||
<reference ref="910887184"/>
|
||||
<reference ref="68472633"/>
|
||||
</object>
|
||||
<reference key="parent" ref="1002"/>
|
||||
<string key="objectName">General</string>
|
||||
@@ -1226,6 +1265,20 @@
|
||||
<reference key="object" ref="709654045"/>
|
||||
<reference key="parent" ref="910887184"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">118</int>
|
||||
<reference key="object" ref="68472633"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="456188813"/>
|
||||
</object>
|
||||
<reference key="parent" ref="1005"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">119</int>
|
||||
<reference key="object" ref="456188813"/>
|
||||
<reference key="parent" ref="68472633"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
@@ -1246,6 +1299,8 @@
|
||||
<string>11.IBPluginDependency</string>
|
||||
<string>114.IBPluginDependency</string>
|
||||
<string>115.IBPluginDependency</string>
|
||||
<string>118.IBPluginDependency</string>
|
||||
<string>119.IBPluginDependency</string>
|
||||
<string>12.IBPluginDependency</string>
|
||||
<string>13.IBPluginDependency</string>
|
||||
<string>14.IBPluginDependency</string>
|
||||
@@ -1314,6 +1369,8 @@
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{514, 459}, {106, 71}}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
@@ -1327,7 +1384,7 @@
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{297, 436}, {400, 139}}</string>
|
||||
<string>{{324, 683}, {400, 139}}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<object class="NSMutableArray">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -1381,7 +1438,7 @@
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">117</int>
|
||||
<int key="maxID">121</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
|
||||
@@ -17,5 +17,7 @@
|
||||
+ (BOOL) confirmPublicGists;
|
||||
+ (BOOL) isGistPublic;
|
||||
+ (BOOL)showWhitespaceDifferences;
|
||||
+ (BOOL)openCurDirOnLaunch;
|
||||
+ (BOOL)showOpenPanelOnLaunch;
|
||||
|
||||
@end
|
||||
|
||||
+17
-1
@@ -15,6 +15,8 @@
|
||||
#define kConfirmPublicGists @"PBConfirmPublicGists"
|
||||
#define kPublicGist @"PBGistPublic"
|
||||
#define kShowWhitespaceDifferences @"PBShowWhitespaceDifferences"
|
||||
#define kOpenCurDirOnLaunch @"PBOpenCurDirOnLaunch"
|
||||
#define kShowOpenPanelOnLaunch @"PBShowOpenPanelOnLaunch"
|
||||
|
||||
@implementation PBGitDefaults
|
||||
|
||||
@@ -33,6 +35,10 @@
|
||||
forKey:kPublicGist];
|
||||
[defaultValues setObject:[NSNumber numberWithBool:YES]
|
||||
forKey:kShowWhitespaceDifferences];
|
||||
[defaultValues setObject:[NSNumber numberWithBool:YES]
|
||||
forKey:kOpenCurDirOnLaunch];
|
||||
[defaultValues setObject:[NSNumber numberWithBool:YES]
|
||||
forKey:kShowOpenPanelOnLaunch];
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
|
||||
}
|
||||
|
||||
@@ -61,9 +67,19 @@
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:kPublicGist];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)showWhitespaceDifferences
|
||||
{
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:kShowWhitespaceDifferences];
|
||||
}
|
||||
|
||||
+ (BOOL)openCurDirOnLaunch
|
||||
{
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:kOpenCurDirOnLaunch];
|
||||
}
|
||||
|
||||
+ (BOOL)showOpenPanelOnLaunch
|
||||
{
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:kShowOpenPanelOnLaunch];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user