16
16
#import " PBPrefsWindowController.h"
17
17
#import " PBNSURLPathUserDefaultsTransfomer.h"
18
18
#import " PBGitDefaults.h"
19
+ #import " PBCloneRepositoryPanel.h"
19
20
20
21
@implementation ApplicationController
21
22
@synthesize cliProxy;
@@ -27,11 +28,10 @@ - (ApplicationController*)init
27
28
#endif
28
29
29
30
if (self = [super init ]) {
30
- /* Location of QuickLookUI.framework - it's public now */
31
- if (![[NSBundle bundleWithPath: @" /System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework" ] load ])
32
- {
33
- NSLog (@" Could not load QuickLook" );
34
- }
31
+ if (![[NSBundle bundleWithPath: @" /System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework" ] load ])
32
+ if (![[NSBundle bundleWithPath: @" /System/Library/PrivateFrameworks/QuickLookUI.framework" ] load ])
33
+ NSLog (@" Could not load QuickLook" );
34
+
35
35
self.cliProxy = [PBCLIProxy new ];
36
36
}
37
37
@@ -65,34 +65,53 @@ - (void)registerServices
65
65
66
66
- (void )applicationDidFinishLaunching : (NSNotification *)notification
67
67
{
68
+ // Make sure Git's SSH password requests get forwarded to our little UI tool:
69
+ setenv ( " SSH_ASKPASS" , [[[NSBundle mainBundle ] pathForResource: @" gitx_askpasswd" ofType: @" " ] UTF8String ], 1 );
70
+ setenv ( " DISPLAY" , " localhost:0" , 1 );
71
+
68
72
[self registerServices ];
69
73
74
+ BOOL hasOpenedDocuments = NO ;
75
+ NSArray *launchedDocuments = [[[PBRepositoryDocumentController sharedDocumentController ] documents ] copy ];
76
+
70
77
// Only try to open a default document if there are no documents open already.
71
78
// For example, the application might have been launched by double-clicking a .git repository,
72
79
// 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 ;
80
+ if ([launchedDocuments count ])
81
+ hasOpenedDocuments = YES ;
82
+
83
+ // open any documents that were open the last time the app quit
84
+ if ([PBGitDefaults openPreviousDocumentsOnLaunch ]) {
85
+ for (NSString *path in [PBGitDefaults previousDocumentPaths ]) {
86
+ NSURL *url = [NSURL fileURLWithPath: path isDirectory: YES ];
87
+ NSError *error = nil ;
88
+ if (url && [[PBRepositoryDocumentController sharedDocumentController ] openDocumentWithContentsOfURL: url display: YES error: &error])
89
+ hasOpenedDocuments = YES ;
90
+ }
91
+ }
80
92
81
93
// Try to find the current directory, to open that as a repository
82
- if ([PBGitDefaults openCurDirOnLaunch ]) {
94
+ if ([PBGitDefaults openCurDirOnLaunch ] && !hasOpenedDocuments ) {
83
95
NSString *curPath = [[[NSProcessInfo processInfo ] environment ] objectForKey: @" PWD" ];
96
+ NSURL *url = nil ;
84
97
if (curPath)
85
98
url = [NSURL fileURLWithPath: curPath];
99
+ // Try to open the found URL
100
+ NSError *error = nil ;
101
+ if (url && [[PBRepositoryDocumentController sharedDocumentController ] openDocumentWithContentsOfURL: url display: YES error: &error])
102
+ hasOpenedDocuments = YES ;
86
103
}
87
104
88
- // Try to open the found URL
89
- NSError *error = nil ;
90
- if (url && [[PBRepositoryDocumentController sharedDocumentController ] openDocumentWithContentsOfURL: url display: YES error: &error])
105
+ // to bring the launched documents to the front
106
+ for (PBGitRepository *document in launchedDocuments)
107
+ [document showWindows ];
108
+
109
+ if (![[NSApplication sharedApplication ] isActive ])
91
110
return ;
92
111
93
112
// The current directory was not enabled or could not be opened (most likely it’s not a git repository).
94
113
// show an open panel for the user to select a repository to view
95
- if ([PBGitDefaults showOpenPanelOnLaunch ])
114
+ if ([PBGitDefaults showOpenPanelOnLaunch ] && !hasOpenedDocuments )
96
115
[[PBRepositoryDocumentController sharedDocumentController ] openDocument: self ];
97
116
}
98
117
@@ -120,6 +139,14 @@ - (IBAction)showAboutPanel:(id)sender
120
139
[NSApp orderFrontStandardAboutPanelWithOptions: dict];
121
140
}
122
141
142
+ - (IBAction ) showCloneRepository : (id )sender
143
+ {
144
+ if (!cloneRepositoryPanel)
145
+ cloneRepositoryPanel = [PBCloneRepositoryPanel panel ];
146
+
147
+ [cloneRepositoryPanel showWindow: self ];
148
+ }
149
+
123
150
- (IBAction )installCliTool : (id )sender ;
124
151
{
125
152
BOOL success = NO ;
@@ -193,7 +220,7 @@ - (NSManagedObjectModel *)managedObjectModel {
193
220
return managedObjectModel;
194
221
}
195
222
196
- managedObjectModel = [NSManagedObjectModel mergedModelFromBundles: nil ];
223
+ managedObjectModel = [[ NSManagedObjectModel mergedModelFromBundles: nil ] retain ];
197
224
return managedObjectModel;
198
225
}
199
226
@@ -270,12 +297,14 @@ - (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window {
270
297
*/
271
298
272
299
- (IBAction ) saveAction : (id )sender {
300
+
273
301
NSError *error = nil ;
274
302
if (![[self managedObjectContext ] save: &error]) {
275
303
[[NSApplication sharedApplication ] presentError: error];
276
304
}
277
305
}
278
306
307
+
279
308
/* *
280
309
Implementation of the applicationShouldTerminate: method, used here to
281
310
handle the saving of changes in the application managed object context
@@ -324,24 +353,20 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
324
353
return reply;
325
354
}
326
355
327
- // QuickLook preview panel
328
-
329
- - (IBAction )togglePreviewPanel : (id )previewPanel
356
+ - (void )applicationWillTerminate : (NSNotification *)aNotification
330
357
{
331
- if ([QLPreviewPanel sharedPreviewPanelExists ] && [[QLPreviewPanel sharedPreviewPanel ] isVisible ]) {
332
- [[QLPreviewPanel sharedPreviewPanel ] orderOut: nil ];
333
- } else {
334
- [[QLPreviewPanel sharedPreviewPanel ] makeKeyAndOrderFront: nil ];
335
- }
336
- }
358
+ [PBGitDefaults removePreviousDocumentPaths ];
337
359
338
- - (BOOL ) validateMenuItem : (NSMenuItem *)item {
339
- if ([item action ] == @selector (saveAction: )) {
340
- // disable the Save menu item if there is no repository document open
341
- return ([[PBRepositoryDocumentController sharedDocumentController ] currentDocument ] != nil );
342
- } else {
343
- return [NSApp validateMenuItem: item];
344
- }
360
+ if ([PBGitDefaults openPreviousDocumentsOnLaunch ]) {
361
+ NSArray *documents = [[PBRepositoryDocumentController sharedDocumentController ] documents ];
362
+ if ([documents count ] > 0 ) {
363
+ NSMutableArray *paths = [NSMutableArray array ];
364
+ for (PBGitRepository *repository in documents)
365
+ [paths addObject: [repository workingDirectory ]];
366
+
367
+ [PBGitDefaults setPreviousDocumentPaths: paths];
368
+ }
369
+ }
345
370
}
346
371
347
372
/* *
0 commit comments