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"
19
- #import " Sparkle/SUUpdater.h"
20
18
#import " PBCloneRepositoryPanel.h"
21
- #import " BMScript.h"
22
- #import " PBGitSidebarController.h"
19
+ #import " Sparkle/SUUpdater.h"
23
20
24
21
@implementation ApplicationController
25
- @synthesize cliProxy;
26
- @synthesize cliArgs;
27
- @synthesize launchedFromGitx;
28
- @synthesize deferredSelectSha;
29
-
30
- static ApplicationController * sharedApplicationControllerInstance = nil ;
31
-
32
- + (void ) initialize {
33
- if (sharedApplicationControllerInstance == nil )
34
- sharedApplicationControllerInstance = [[self alloc ] init ];
35
- }
36
-
37
- + (ApplicationController *) sharedApplicationController {
38
- // Already set by +initialize.
39
- return sharedApplicationControllerInstance;
40
- }
41
-
42
- + (id ) allocWithZone : (NSZone *) zone {
43
- // Usually already set by +initialize.
44
- if (sharedApplicationControllerInstance) {
45
- // The caller expects to receive a new object, so implicitly retain it
46
- // to balance out the eventual release message.
47
- return [sharedApplicationControllerInstance retain ];
48
- } else {
49
- // When not already set, +initialize is our caller.
50
- // It's creating the shared instance, let this go through.
51
- return [super allocWithZone: zone];
52
- }
53
- }
54
-
55
- - (id ) copyWithZone : (NSZone *) zone {
56
- return self;
57
- }
58
-
59
- - (NSUInteger ) retainCount {
60
- return UINT_MAX; // denotes an object that cannot be released
61
- }
62
22
63
- - (ApplicationController *) init
23
+ - (ApplicationController*) init
64
24
{
65
- // If sharedApplicationControllerInstance is nil, +initialize is our caller, so initialize the instance.
66
- // If it is not nil, simply return the instance without re-initializing it.
67
- if (sharedApplicationControllerInstance == nil ) {
68
25
#ifdef DEBUG_BUILD
69
- [NSApp activateIgnoringOtherApps: YES ];
26
+ [NSApp activateIgnoringOtherApps: YES ];
70
27
#endif
71
- if (self = [super init ]) {
72
- if (![[NSBundle bundleWithPath: @" /System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework" ] load ])
73
- if (![[NSBundle bundleWithPath: @" /System/Library/PrivateFrameworks/QuickLookUI.framework" ] load ])
74
- NSLog (@" Could not load QuickLook" );
75
-
76
- self.cliProxy = [PBCLIProxy new ];
77
- launchedFromGitx = NO ;
78
- cliArgs = nil ;
79
- deferredSelectSha = nil ;
80
- }
81
- /* Value Transformers */
82
- NSValueTransformer *transformer = [[PBNSURLPathUserDefaultsTransfomer alloc ] init ];
83
- [NSValueTransformer setValueTransformer: transformer forName: @" PBNSURLPathUserDefaultsTransfomer" ];
84
- // Make sure the PBGitDefaults is initialized, by calling a random method
85
- [PBGitDefaults class ];
86
- return self;
87
- }
88
- return self;
28
+
29
+ if (!(self = [super init ]))
30
+ return nil ;
31
+
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" );
35
+
36
+ /* Value Transformers */
37
+ NSValueTransformer *transformer = [[PBNSURLPathUserDefaultsTransfomer alloc ] init ];
38
+ [NSValueTransformer setValueTransformer: transformer forName: @" PBNSURLPathUserDefaultsTransfomer" ];
39
+
40
+ // Make sure the PBGitDefaults is initialized, by calling a random method
41
+ [PBGitDefaults class ];
42
+ return self;
89
43
}
90
44
91
45
- (void )registerServices
@@ -109,34 +63,16 @@ - (void)registerServices
109
63
110
64
- (void )applicationDidFinishLaunching : (NSNotification *)notification
111
65
{
66
+ [[SUUpdater sharedUpdater ] setSendsSystemProfile: YES ];
67
+
112
68
// Make sure Git's SSH password requests get forwarded to our little UI tool:
113
69
setenv ( " SSH_ASKPASS" , [[[NSBundle mainBundle ] pathForResource: @" gitx_askpasswd" ofType: @" " ] UTF8String ], 1 );
114
70
setenv ( " DISPLAY" , " localhost:0" , 1 );
115
71
116
- char * launchedfromgitx = getenv (" GITX_LAUNCHED_FROM_CLI" );
117
- char * cliargs = getenv (" GITX_CLI_ARGUMENTS" );
118
-
119
- self.launchedFromGitx = (launchedfromgitx ? YES : NO );
120
-
121
- if (cliargs) {
122
- self.cliArgs = [NSString stringWithUTF8String: (cliargs)];
123
- }
124
-
125
- // NSLog(@"[%@ %s] launchedFromGitx = %@", [self class], _cmd, (launchedFromGitx ? @"YES" : @"NO"));
126
- // NSLog(@"[%@ %s] cliArgs = %@", [self class], _cmd, cliArgs);
127
-
128
72
[self registerServices ];
129
73
130
- if ([cliArgs isEqualToString: @" --all" ]) {
131
- [PBGitDefaults setBranchFilter: kGitXAllBranchesFilter ];
132
- [[NSUserDefaults standardUserDefaults ] synchronize ];
133
- } else if ([cliArgs isEqualToString: @" --local" ]) {
134
- [PBGitDefaults setBranchFilter: kGitXLocalRemoteBranchesFilter ];
135
- [[NSUserDefaults standardUserDefaults ] synchronize ];
136
- }
137
-
138
74
BOOL hasOpenedDocuments = NO ;
139
- launchedDocuments = [[[PBRepositoryDocumentController sharedDocumentController ] documents ] copy ];
75
+ NSArray * launchedDocuments = [[[PBRepositoryDocumentController sharedDocumentController ] documents ] copy ];
140
76
141
77
// Only try to open a default document if there are no documents open already.
142
78
// For example, the application might have been launched by double-clicking a .git repository,
@@ -154,7 +90,7 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification
154
90
}
155
91
}
156
92
157
- // Try to find the current directory, to open that as a repository...
93
+ // Try to find the current directory, to open that as a repository
158
94
if ([PBGitDefaults openCurDirOnLaunch ] && !hasOpenedDocuments) {
159
95
NSString *curPath = [[[NSProcessInfo processInfo ] environment ] objectForKey: @" PWD" ];
160
96
NSURL *url = nil ;
@@ -166,47 +102,9 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification
166
102
hasOpenedDocuments = YES ;
167
103
}
168
104
169
- launchedDocuments = [[[PBRepositoryDocumentController sharedDocumentController ] documents ] copy ];
170
-
171
- // ...to bring the launched documents to the front
172
- for (PBGitRepository *document in launchedDocuments) {
173
-
174
- PBGitWindowController * wc = [(PBGitRepository *)document windowController ];
175
- PBGitHistoryController * historyViewController = wc.historyController ;
176
- NSArrayController * ccontroller = historyViewController.commitController ;
177
-
178
- // determine what to show right after start - stage or standard history view?
179
- if ([cliArgs isEqualToString: @" --commit" ] || [cliArgs isEqualToString: @" -c" ]) {
180
- [wc showCommitView: self ];
181
- launchedFromGitx = NO ;
182
- } else {
183
- [wc showHistoryView: self ];
184
- }
185
-
186
- if ([cliArgs hasPrefix: @" --author" ]) {
187
- NSArray * components = [cliArgs componentsSeparatedByString: @" =" ];
188
- NSString * author = [components objectAtIndex: 1 ];
189
- [ccontroller setFilterPredicate: [NSPredicate predicateWithFormat: @" author contains[c] %@" , author]];
190
- [historyViewController.commitList selectRowIndexes: [NSIndexSet indexSetWithIndex: 0 ] byExtendingSelection: NO ];
191
- } else if ([cliArgs hasPrefix: @" --subject" ]) {
192
- NSArray * components = [cliArgs componentsSeparatedByString: @" =" ];
193
- NSString * subject = [components objectAtIndex: 1 ];
194
- [ccontroller setFilterPredicate: [NSPredicate predicateWithFormat: @" subject contains[c] %@" , subject]];
195
- } else if ([cliArgs hasPrefix: @" --sha" ]) {
196
- NSArray * components = [cliArgs componentsSeparatedByString: @" =" ];
197
- NSString * sha = [components objectAtIndex: 1 ];
198
- [ccontroller setFilterPredicate: [NSPredicate predicateWithFormat: @" realSha contains[c] %@" , sha]];
199
- } else if ([cliArgs hasPrefix: @" -S" ]) {
200
- NSString * subject = [cliArgs substringFromIndex: 2 ];
201
- [ccontroller setFilterPredicate: [NSPredicate predicateWithFormat: @" subject contains[c] %@" , subject]];
202
- }
203
-
105
+ // to bring the launched documents to the front
106
+ for (PBGitRepository *document in launchedDocuments)
204
107
[document showWindows ];
205
- }
206
-
207
- if (launchedFromGitx) {
208
- [self performSelector: @selector (finalizeCLILaunch: ) withObject: self afterDelay: 0.5 ];
209
- }
210
108
211
109
if (![[NSApplication sharedApplication ] isActive ])
212
110
return ;
@@ -217,42 +115,14 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification
217
115
[[PBRepositoryDocumentController sharedDocumentController ] openDocument: self ];
218
116
}
219
117
220
- - (void ) finalizeCLILaunch : (id )object {
221
- for (PBGitRepository * document in launchedDocuments) {
222
- BOOL success = [[[(PBGitRepository *)document windowController ] historyController ] selectCommit: self .deferredSelectSha];
223
- // NSLog(@"[%@ %s] trying to select commit with sha %@ (success = %@)", [self class], _cmd, self.deferredSelectSha, BMStringFromBOOL(success));
224
- if (success) {
225
- PBGitWindowController * wc = [(PBGitRepository *)document windowController ];
226
- PBGitHistoryController * histController = wc.historyController ;
227
- PBCommitList * clist = histController.commitList ;
228
- // updating the selection with the selection seems redundant but it also updates the row select indicator
229
- [clist selectRowIndexes: [clist selectedRowIndexes ] byExtendingSelection: NO ];
230
- [histController scrollSelectionToTopOfViewFrom: 0 ];
231
- [histController updateKeys ];
232
- }
233
- }
234
- // Reset CLI indication status so KVO all over the controllers can go the intended ways again...
235
- self.deferredSelectSha = nil ;
236
- self.launchedFromGitx = NO ;
237
- }
238
-
239
-
240
- - (void ) windowWillClose : (id )sender
118
+ - (void ) windowWillClose : sender
241
119
{
242
- if ([[[sender object ] windowController ] isKindOfClass: [PBPrefsWindowController class ]] ) {
243
- for (PBGitRepository * doc in [[PBRepositoryDocumentController sharedDocumentController ] documents ]) {
244
- [[[doc windowForSheet ] contentView ] setNeedsDisplay: YES ];
245
- }
246
- } else {
247
- [firstResponder terminate: sender];
248
- }
120
+ [firstResponder terminate: sender];
249
121
}
250
122
251
123
- (IBAction )openPreferencesWindow : (id )sender
252
124
{
253
- DBPrefsWindowController * prefsWindowController = [PBPrefsWindowController sharedPrefsWindowController ];
254
- [[prefsWindowController window ] setDelegate: self ];
255
- [prefsWindowController showWindow: nil ];
125
+ [[PBPrefsWindowController sharedPrefsWindowController ] showWindow: nil ];
256
126
}
257
127
258
128
- (IBAction )showAboutPanel : (id )sender
@@ -376,7 +246,7 @@ - (NSPersistentStoreCoordinator *) persistentStoreCoordinator {
376
246
fileManager = [NSFileManager defaultManager ];
377
247
applicationSupportFolder = [self applicationSupportFolder ];
378
248
if ( ![fileManager fileExistsAtPath: applicationSupportFolder isDirectory: NULL ] ) {
379
- [fileManager createDirectoryAtPath: applicationSupportFolder withIntermediateDirectories: YES attributes: nil error :nil ];
249
+ [fileManager createDirectoryAtPath: applicationSupportFolder attributes: nil ];
380
250
}
381
251
382
252
url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @" GitTest.xml" ]];
0 commit comments