Skip to content

Commit 0eb04c6

Browse files
lolgearlucasderraugh
authored andcommitted
Windows Separation Remastered: Welcome Window Controller (#604)
* application: main menu welcome window has been extracted into separate xib. * application: windows welcome window has been incapsulated. * application: app delegate loading from xibs has been added. welcome window has been introduced. * application: project has been updated. * application: app delegate loading xibs from bundle has been added. * application: main menu about panel has been extracted into separate xib. * application: windows about panel has been incapsulated. * application: app delegate about panel has been introduced. * application: project has been updated. * application: window loading category has been added. * application: windows about panel xib has been renamed. * application: about panel has become independent. * application: app delegate about panel has been instantiated on demand. * application: project has been updated. * Revert "application: project has been updated." 5b41d79 * application: windows xibs about panel has been renamed. * application: about panel window controller has been introduced. * application: windows xibs about panel window controller has been added. * application: app delegate about panel window controller has been added. * application: about panel cleanup. * application: app delegate about panel property has been removed. * application: about panel unnecessary loadWindow invocation has been removed. * application: about panel custom subclass has been removed. * application: app delegate about panel new api has been adopted. * application: about panel window controller has been renamed. * application: app delegate about window controller lazy property has been added. * application: about panel has been eliminated. * application: window loading category has been removed. * application: project has been updated. * application: about window controller xib has been introduced. * application: welcome window controller has been introduced. * application: windows welcome window xib welcome window controller has become owner. * application: app delegate welcome window controller has been added. * application: windows welcome window controller model not activated state has been added. * application: app delegate welcome window controller model state not activated yet has been added. * application: welcome window controller reign of blocks has been suppressed. * application: app delegate welcome window controller blocks have been removed. * application: welcome window controller explicit window manipulation has been removed. * application: welcome window controller has been cleaned up. * application: welcome window forums button has been involved into first responder chain. * application: app delegate welcome window forums button has been involved into first responder chain. * application: welcome window controller twitter url has been sewn into controller. * application: welcome window controller model has been removed. * application: welcome window has been renamed to welcome window controller. * application: app delegate open document at url has been added. * application: welcome window controller unnecessary block has been removed. * application: welcome window controller xib destination view has been set. * application: welcome window controller destination view app delegate has been removed.
1 parent 097e278 commit 0eb04c6

File tree

7 files changed

+208
-167
lines changed

7 files changed

+208
-167
lines changed

GitUp/Application/AppDelegate.m

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#import "GARawTracker.h"
3131

3232
#import "AboutWindowController.h"
33-
#import "WelcomeWindow.h"
33+
#import "WelcomeWindowController.h"
3434

3535
#define __ENABLE_SUDDEN_TERMINATION__ 1
3636

@@ -44,14 +44,13 @@
4444

4545
@interface AppDelegate () <NSUserNotificationCenterDelegate, SUUpdaterDelegate>
4646
@property(nonatomic, strong) AboutWindowController *aboutWindowController;
47-
@property(nonatomic, strong) WelcomeWindow* welcomeWindow;
47+
@property(nonatomic, strong) WelcomeWindowController *welcomeWindowController;
4848
@end
4949

5050
@implementation AppDelegate {
5151
SUUpdater* _updater;
5252
BOOL _updatePending;
5353
BOOL _manualCheck;
54-
NSInteger _allowWelcome;
5554

5655
BOOL _authenticationUseKeychain;
5756
NSURL* _authenticationURL;
@@ -69,6 +68,21 @@ - (AboutWindowController *)aboutWindowController {
6968
return _aboutWindowController;
7069
}
7170

71+
- (WelcomeWindowController *)welcomeWindowController {
72+
if (!_welcomeWindowController) {
73+
_welcomeWindowController = [[WelcomeWindowController alloc] init];
74+
75+
_welcomeWindowController.keyShouldShowWindow = kUserDefaultsKey_ShowWelcomeWindow;
76+
77+
__weak typeof(self) weakSelf = self;
78+
_welcomeWindowController.openDocumentAtURL = ^(NSURL * _Nonnull url) {
79+
[weakSelf _openDocumentAtURL:url];
80+
};
81+
82+
}
83+
return _welcomeWindowController;
84+
}
85+
7286
#pragma mark - Initialize
7387
+ (void)initialize {
7488
NSDictionary* defaults = @{
@@ -198,14 +212,12 @@ - (void)_openRepositoryWithURL:(NSURL*)url withCloneMode:(CloneMode)cloneMode wi
198212
}];
199213
}
200214

201-
- (void)_openDocument:(NSMenuItem*)sender {
202-
[self _openRepositoryWithURL:sender.representedObject withCloneMode:kCloneMode_None windowModeID:NSNotFound];
215+
- (void)_openDocumentAtURL:(NSURL *)url {
216+
[self _openRepositoryWithURL:url withCloneMode:kCloneMode_None windowModeID:NSNotFound];
203217
}
204218

205219
- (void)awakeFromNib {
206220

207-
_allowWelcome = -1;
208-
209221
_preferencesToolbar.selectedItemIdentifier = kPreferencePaneIdentifier_General;
210222
[self selectPreferencePane:nil];
211223

@@ -226,6 +238,10 @@ - (void)awakeFromNib {
226238
}
227239
}
228240

241+
- (void)handleDocumentCountChanged {
242+
[self.welcomeWindowController handleDocumentCountChanged];
243+
}
244+
229245
- (void)_updatePreferencePanel {
230246
NSString* channel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
231247
for (NSMenuItem* item in _channelPopUpButton.menu.itemArray) {
@@ -261,19 +277,6 @@ - (void)_showNotificationWithTitle:(NSString*)title action:(SEL)action message:(
261277
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
262278
}
263279

264-
- (void)handleDocumentCountChanged {
265-
BOOL showWelcomeWindow = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsKey_ShowWelcomeWindow];
266-
if (showWelcomeWindow && (_allowWelcome > 0) && ![[[NSDocumentController sharedDocumentController] documents] count]) {
267-
if (!_welcomeWindow.visible) {
268-
[_welcomeWindow makeKeyAndOrderFront:nil];
269-
}
270-
} else {
271-
if (_welcomeWindow.visible) {
272-
[_welcomeWindow orderOut:nil];
273-
}
274-
}
275-
}
276-
277280
#pragma mark - Loading Xibs
278281
- (id)_loadWindowFromBundleXibWithName:(NSString *)name expectedClass:(Class)class {
279282
NSBundle *mainBundle = [NSBundle mainBundle];
@@ -285,25 +288,6 @@ - (id)_loadWindowFromBundleXibWithName:(NSString *)name expectedClass:(Class)cla
285288
return filteredObjects.firstObject;
286289
}
287290

288-
- (void)_loadWindowsFromBundle {
289-
self.welcomeWindow = [self _loadWindowFromBundleXibWithName:@"Welcome" expectedClass:NSWindow.class];
290-
[self _windowsPostSetup];
291-
}
292-
293-
- (void)_windowsPostSetup {
294-
_allowWelcome = -1;
295-
296-
__weak NSDocumentController *documentController = NSDocumentController.sharedDocumentController;
297-
self.welcomeWindow.getRecentDocuments = ^NSArray<NSURL *> * _Nonnull{
298-
return documentController.recentDocumentURLs;
299-
};
300-
__weak typeof(self) weakSelf = self;
301-
self.welcomeWindow.configureItem = ^(NSMenuItem * _Nonnull item) {
302-
item.target = weakSelf;
303-
item.action = @selector(_openDocument:);
304-
};
305-
}
306-
307291
#pragma mark - NSApplicationDelegate
308292

309293
- (void)applicationWillFinishLaunching:(NSNotification*)notification {
@@ -400,9 +384,6 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
400384
NSString* theme = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_Theme];
401385
[self _applyTheme:theme];
402386

403-
// Load xibs
404-
[self _loadWindowsFromBundle];
405-
406387
#if __ENABLE_SUDDEN_TERMINATION__
407388
// Enable sudden termination
408389
[[NSProcessInfo processInfo] enableSuddenTermination];
@@ -425,18 +406,18 @@ - (BOOL)applicationShouldOpenUntitledFile:(NSApplication*)sender {
425406

426407
- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows {
427408
if (!hasVisibleWindows) {
428-
_allowWelcome = 1; // Always show welcome when clicking on dock icon
409+
// Always show welcome when clicking on dock icon
410+
[self.welcomeWindowController setShouldShow];
429411
[self handleDocumentCountChanged];
430412
}
431413
return YES;
432414
}
433415

434416
- (void)applicationDidBecomeActive:(NSNotification*)notification {
435-
if (_allowWelcome < 0) {
436-
_allowWelcome = 1;
417+
if (self.welcomeWindowController.notActivedYet) {
418+
[self.welcomeWindowController setShouldShow];
437419
}
438420
[self handleDocumentCountChanged];
439-
440421
#if !DEBUG
441422
[[GARawTracker sharedTracker] sendEventWithCategory:@"application"
442423
action:@"activate"
@@ -664,15 +645,6 @@ - (IBAction)checkForUpdates:(id)sender {
664645
[_updater checkForUpdatesInBackground];
665646
}
666647

667-
- (IBAction)closeWelcomeWindow:(id)sender {
668-
[_welcomeWindow orderOut:nil];
669-
_allowWelcome = 0;
670-
}
671-
672-
- (IBAction)openTwitter:(id)sender {
673-
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:kURL_Twitter]];
674-
}
675-
676648
- (IBAction)installTool:(id)sender {
677649
AuthorizationRef authorization;
678650
OSStatus status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorization);

GitUp/Application/Base.lproj/Welcome.xib renamed to GitUp/Application/Base.lproj/WelcomeWindowController.xib

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<objects>
9-
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"/>
9+
<customObject id="-2" userLabel="File's Owner" customClass="WelcomeWindowController">
10+
<connections>
11+
<outlet property="closeButton" destination="Fwx-IU-wXQ" id="oxX-AV-ffo"/>
12+
<outlet property="destinationView" destination="UVs-2r-EAT" id="br0-1Q-MbA"/>
13+
<outlet property="forumsButton" destination="ozw-os-Nc4" id="xgP-Uj-SKc"/>
14+
<outlet property="recentPopUpButton" destination="rck-lm-gsz" id="SFe-iy-HxX"/>
15+
<outlet property="twitterButton" destination="5ht-7L-7AO" id="2AV-yQ-MVQ"/>
16+
<outlet property="window" destination="mjY-As-hbN" id="6Bt-UR-GyN"/>
17+
</connections>
18+
</customObject>
1019
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
1120
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
12-
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
1321
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="mjY-As-hbN" userLabel="Welcome" customClass="WelcomeWindow">
1422
<rect key="contentRect" x="131" y="158" width="280" height="349"/>
1523
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
@@ -32,9 +40,6 @@
3240
<font key="font" metaFont="system"/>
3341
</buttonCell>
3442
<accessibility description="Close window"/>
35-
<connections>
36-
<action selector="closeWelcomeWindow:" target="Voe-Tx-rLC" id="xWF-ok-YMZ"/>
37-
</connections>
3843
</button>
3944
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Apd-kA-Fr2">
4045
<rect key="frame" x="76" y="180" width="128" height="128"/>
@@ -132,9 +137,6 @@
132137
<color key="value" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
133138
</userDefinedRuntimeAttribute>
134139
</userDefinedRuntimeAttributes>
135-
<connections>
136-
<action selector="openTwitter:" target="Voe-Tx-rLC" id="CcB-Tp-tMx"/>
137-
</connections>
138140
</customView>
139141
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3gN-gU-6Rk">
140142
<rect key="frame" x="154" y="20" width="12" height="12"/>
@@ -155,7 +157,7 @@
155157
</userDefinedRuntimeAttribute>
156158
</userDefinedRuntimeAttributes>
157159
<connections>
158-
<action selector="viewIssues:" target="Voe-Tx-rLC" id="C7T-gw-NmH"/>
160+
<action selector="viewIssues:" target="-1" id="aqi-az-ote"/>
159161
</connections>
160162
</customView>
161163
</subviews>
@@ -167,12 +169,6 @@
167169
</box>
168170
</subviews>
169171
</view>
170-
<connections>
171-
<outlet property="destinationView" destination="UVs-2r-EAT" id="AvQ-6L-KSz"/>
172-
<outlet property="forumsButton" destination="ozw-os-Nc4" id="419-9M-VYK"/>
173-
<outlet property="recentPopUpButton" destination="rck-lm-gsz" id="DNt-71-Rfh"/>
174-
<outlet property="twitterButton" destination="5ht-7L-7AO" id="uy0-ug-BuC"/>
175-
</connections>
176172
<point key="canvasLocation" x="-185" y="548"/>
177173
</window>
178174
</objects>

GitUp/Application/Common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@
4242
#define kURL_Wiki @"https://github.com/git-up/GitUp/wiki"
4343
#define kURL_ReleaseNotes @"https://github.com/git-up/GitUp/releases"
4444

45-
#define kURL_Twitter @"https://twitter.com/GitUpApp"

GitUp/Application/WelcomeWindow.h

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// WelcomeWindowController.h
3+
// Application
4+
//
5+
// Created by Dmitry Lobanov on 10/09/2019.
6+
//
7+
8+
#import <Cocoa/Cocoa.h>
9+
#import <GitUpKit/GitUpKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface WelcomeWindowController : NSWindowController
14+
15+
// Hide and Show
16+
@property (assign, nonatomic, readonly) BOOL shouldShow;
17+
@property (assign, nonatomic, readonly) BOOL notActivedYet;
18+
- (void)setShouldShow;
19+
- (void)setShouldHide;
20+
21+
// Recent items configuration
22+
@property(nonatomic, copy) void(^openDocumentAtURL)(NSURL *url);
23+
24+
// UserDefaultsKeys
25+
@property(nonatomic, copy) NSString *keyShouldShowWindow;
26+
27+
// Actions
28+
- (void)handleDocumentCountChanged;
29+
@end
30+
31+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)