10
10
#import " PBGitRevisionCell.h"
11
11
#import " PBGitWindowController.h"
12
12
#import " PBRepositoryDocumentController.h"
13
- #import " PBCLIProxy.h"
14
13
#import " PBServicesController.h"
15
14
#import " PBGitXProtocol.h"
16
15
#import " PBPrefsWindowController.h"
17
16
#import " PBNSURLPathUserDefaultsTransfomer.h"
18
17
#import " PBGitDefaults.h"
18
+ #import " PBCloneRepositoryPanel.h"
19
19
#import " Sparkle/SUUpdater.h"
20
20
21
21
@implementation ApplicationController
22
- @synthesize cliProxy;
23
22
24
23
- (ApplicationController*)init
25
24
{
26
25
#ifdef DEBUG_BUILD
27
26
[NSApp activateIgnoringOtherApps: YES ];
28
27
#endif
29
28
30
- if (self = [super init ]) {
29
+ if (!(self = [super init ]))
30
+ return nil ;
31
+
32
+ if (![[NSBundle bundleWithPath: @" /System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework" ] load ])
31
33
if (![[NSBundle bundleWithPath: @" /System/Library/PrivateFrameworks/QuickLookUI.framework" ] load ])
32
34
NSLog (@" Could not load QuickLook" );
33
35
34
- self.cliProxy = [PBCLIProxy new ];
35
- }
36
-
37
36
/* Value Transformers */
38
37
NSValueTransformer *transformer = [[PBNSURLPathUserDefaultsTransfomer alloc ] init ];
39
38
[NSValueTransformer setValueTransformer: transformer forName: @" PBNSURLPathUserDefaultsTransfomer" ];
@@ -65,34 +64,55 @@ - (void)registerServices
65
64
- (void )applicationDidFinishLaunching : (NSNotification *)notification
66
65
{
67
66
[[SUUpdater sharedUpdater ] setSendsSystemProfile: YES ];
67
+ [[SUUpdater sharedUpdater ] setDelegate: self ];
68
+
69
+ // Make sure Git's SSH password requests get forwarded to our little UI tool:
70
+ setenv ( " SSH_ASKPASS" , [[[NSBundle mainBundle ] pathForResource: @" gitx_askpasswd" ofType: @" " ] UTF8String ], 1 );
71
+ setenv ( " DISPLAY" , " localhost:0" , 1 );
72
+
68
73
[self registerServices ];
69
74
75
+ BOOL hasOpenedDocuments = NO ;
76
+ NSArray *launchedDocuments = [[[PBRepositoryDocumentController sharedDocumentController ] documents ] copy ];
77
+
70
78
// Only try to open a default document if there are no documents open already.
71
79
// For example, the application might have been launched by double-clicking a .git repository,
72
80
// or by dragging a folder to the app icon
73
- if ([[[PBRepositoryDocumentController sharedDocumentController ] documents ] count ])
74
- return ;
75
-
76
- if (![[NSApplication sharedApplication ] isActive ])
77
- return ;
78
-
79
- NSURL *url = nil ;
81
+ if ([launchedDocuments count ])
82
+ hasOpenedDocuments = YES ;
83
+
84
+ // open any documents that were open the last time the app quit
85
+ if ([PBGitDefaults openPreviousDocumentsOnLaunch ]) {
86
+ for (NSString *path in [PBGitDefaults previousDocumentPaths ]) {
87
+ NSURL *url = [NSURL fileURLWithPath: path isDirectory: YES ];
88
+ NSError *error = nil ;
89
+ if (url && [[PBRepositoryDocumentController sharedDocumentController ] openDocumentWithContentsOfURL: url display: YES error: &error])
90
+ hasOpenedDocuments = YES ;
91
+ }
92
+ }
80
93
81
94
// Try to find the current directory, to open that as a repository
82
- if ([PBGitDefaults openCurDirOnLaunch ]) {
95
+ if ([PBGitDefaults openCurDirOnLaunch ] && !hasOpenedDocuments ) {
83
96
NSString *curPath = [[[NSProcessInfo processInfo ] environment ] objectForKey: @" PWD" ];
97
+ NSURL *url = nil ;
84
98
if (curPath)
85
99
url = [NSURL fileURLWithPath: curPath];
100
+ // Try to open the found URL
101
+ NSError *error = nil ;
102
+ if (url && [[PBRepositoryDocumentController sharedDocumentController ] openDocumentWithContentsOfURL: url display: YES error: &error])
103
+ hasOpenedDocuments = YES ;
86
104
}
87
105
88
- // Try to open the found URL
89
- NSError *error = nil ;
90
- if (url && [[PBRepositoryDocumentController sharedDocumentController ] openDocumentWithContentsOfURL: url display: YES error: &error])
106
+ // to bring the launched documents to the front
107
+ for (PBGitRepository *document in launchedDocuments)
108
+ [document showWindows ];
109
+
110
+ if (![[NSApplication sharedApplication ] isActive ])
91
111
return ;
92
112
93
113
// The current directory was not enabled or could not be opened (most likely it’s not a git repository).
94
114
// show an open panel for the user to select a repository to view
95
- if ([PBGitDefaults showOpenPanelOnLaunch ])
115
+ if ([PBGitDefaults showOpenPanelOnLaunch ] && !hasOpenedDocuments )
96
116
[[PBRepositoryDocumentController sharedDocumentController ] openDocument: self ];
97
117
}
98
118
@@ -120,6 +140,14 @@ - (IBAction)showAboutPanel:(id)sender
120
140
[NSApp orderFrontStandardAboutPanelWithOptions: dict];
121
141
}
122
142
143
+ - (IBAction ) showCloneRepository : (id )sender
144
+ {
145
+ if (!cloneRepositoryPanel)
146
+ cloneRepositoryPanel = [PBCloneRepositoryPanel panel ];
147
+
148
+ [cloneRepositoryPanel showWindow: self ];
149
+ }
150
+
123
151
- (IBAction )installCliTool : (id )sender ;
124
152
{
125
153
BOOL success = NO ;
@@ -169,11 +197,6 @@ - (IBAction)installCliTool:(id)sender;
169
197
former cannot be found), the system's temporary directory.
170
198
*/
171
199
172
- - (IBAction ) showHelp : (id ) sender
173
- {
174
- [[NSWorkspace sharedWorkspace ] openURL: [NSURL URLWithString: @" http://gitx.frim.nl/user_manual.html" ]];
175
- }
176
-
177
200
- (NSString *)applicationSupportFolder {
178
201
179
202
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSApplicationSupportDirectory, NSUserDomainMask, YES );
@@ -326,6 +349,21 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
326
349
return reply;
327
350
}
328
351
352
+ - (void )applicationWillTerminate : (NSNotification *)aNotification
353
+ {
354
+ [PBGitDefaults removePreviousDocumentPaths ];
355
+
356
+ if ([PBGitDefaults openPreviousDocumentsOnLaunch ]) {
357
+ NSArray *documents = [[PBRepositoryDocumentController sharedDocumentController ] documents ];
358
+ if ([documents count ] > 0 ) {
359
+ NSMutableArray *paths = [NSMutableArray array ];
360
+ for (PBGitRepository *repository in documents)
361
+ [paths addObject: [repository workingDirectory ]];
362
+
363
+ [PBGitDefaults setPreviousDocumentPaths: paths];
364
+ }
365
+ }
366
+ }
329
367
330
368
/* *
331
369
Implementation of dealloc, to release the retained variables.
@@ -338,4 +376,44 @@ - (void) dealloc {
338
376
[managedObjectModel release ], managedObjectModel = nil ;
339
377
[super dealloc ];
340
378
}
379
+
380
+
381
+ #pragma mark Sparkle delegate methods
382
+
383
+ - (NSArray *)feedParametersForUpdater : (SUUpdater *)updater sendingSystemProfile : (BOOL )sendingProfile
384
+ {
385
+ NSArray *keys = [NSArray arrayWithObjects: @" key" , @" displayKey" , @" value" , @" displayValue" , nil ];
386
+ NSMutableArray *feedParameters = [NSMutableArray array ];
387
+
388
+ // only add parameters if the profile is being sent this time
389
+ if (sendingProfile) {
390
+ NSString *CFBundleGitVersion = [[[NSBundle mainBundle ] infoDictionary ] valueForKey: @" CFBundleGitVersion" ];
391
+ if (CFBundleGitVersion)
392
+ [feedParameters addObject: [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: @" CFBundleGitVersion" , @" Full Version" , CFBundleGitVersion, CFBundleGitVersion, nil ]
393
+ forKeys: keys]];
394
+
395
+ NSString *gitVersion = [PBGitBinary version ];
396
+ if (gitVersion)
397
+ [feedParameters addObject: [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: @" gitVersion" , @" git Version" , gitVersion, gitVersion, nil ]
398
+ forKeys: keys]];
399
+ }
400
+
401
+ return feedParameters;
402
+ }
403
+
404
+
405
+ #pragma mark Help menu
406
+
407
+ - (IBAction )showHelp : (id )sender
408
+ {
409
+ [[NSWorkspace sharedWorkspace ] openURL: [NSURL URLWithString: @" http://gitx.frim.nl/user_manual.html" ]];
410
+ }
411
+
412
+ - (IBAction )reportAProblem : (id )sender
413
+ {
414
+ [[NSWorkspace sharedWorkspace ] openURL: [NSURL URLWithString: @" http://gitx.lighthouseapp.com/tickets" ]];
415
+ }
416
+
417
+
418
+
341
419
@end
0 commit comments