Skip to content

Commit ec81a92

Browse files
Windows Separation Remastered: Preferences Window (#618)
* kit: launch services locator has been added. * application: windows preferences window controller has been added. * application: project has been updated. * application: app delegate has been cleaned up. * application: windows xibs main menu preferences window has been removed. * application: common constants have been cleaned up. * application: project has been updated. * application: windows xibs preferences window constraints have been added. * application: preference text size has been fixed. * kit: launch services locator preferences keys have been renamed. Bugs have been fixed. * application: document has been fixed. * application: windows xibs preferences window layout has been updated. * application: windows preferences window controller small bugs have been fixed. * Fix bad merge from master Co-authored-by: Lucas Derraugh <[email protected]>
1 parent 3f5abaf commit ec81a92

15 files changed

+1139
-826
lines changed

GitUp/Application/AppDelegate.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
#import <AppKit/AppKit.h>
1717

1818
@interface AppDelegate : NSObject <NSApplicationDelegate>
19-
@property(nonatomic, strong) IBOutlet NSWindow* preferencesWindow;
20-
@property(nonatomic, weak) IBOutlet NSToolbar* preferencesToolbar;
21-
@property(nonatomic, weak) IBOutlet NSTabView* preferencesTabView;
22-
@property(nonatomic, weak) IBOutlet NSPopUpButton* channelPopUpButton;
23-
@property(nonatomic, weak) IBOutlet NSPopUpButton* themePopUpButton;
2419
+ (instancetype)sharedDelegate;
25-
2620
- (void)handleDocumentCountChanged;
2721
@end

GitUp/Application/AppDelegate.m

Lines changed: 28 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131

3232
#import "AboutWindowController.h"
3333
#import "CloneWindowController.h"
34+
#import "PreferencesWindowController.h"
3435
#import "WelcomeWindowController.h"
3536

3637
#define __ENABLE_SUDDEN_TERMINATION__ 1
3738

3839
#define kNotificationUserInfoKey_Action @"action" // NSString
3940

40-
#define kPreferencePaneIdentifier_General @"general"
41-
4241
#define kInstallerName @"install.sh"
4342
#define kToolName @"gitup"
4443
#define kToolInstallPath @"/usr/local/bin/" kToolName
4544

4645
@interface AppDelegate () <NSUserNotificationCenterDelegate, SUUpdaterDelegate>
4746
@property(nonatomic, strong) AboutWindowController *aboutWindowController;
4847
@property(nonatomic, strong) CloneWindowController *cloneWindowController;
48+
@property(nonatomic, strong) PreferencesWindowController *preferencesWindowController;
4949
@property(nonatomic, strong) WelcomeWindowController *welcomeWindowController;
5050
@end
5151

@@ -58,6 +58,7 @@ @implementation AppDelegate {
5858
}
5959

6060
#pragma mark - Properties
61+
6162
- (AboutWindowController *)aboutWindowController {
6263
if (!_aboutWindowController) {
6364
_aboutWindowController = [[AboutWindowController alloc] init];
@@ -72,6 +73,24 @@ - (CloneWindowController *)cloneWindowController {
7273
return _cloneWindowController;
7374
}
7475

76+
- (void)didChangeReleaseChannel:(BOOL)didChange {
77+
if (didChange) {
78+
_manualCheck = NO;
79+
[_updater checkForUpdatesInBackground];
80+
}
81+
}
82+
83+
- (PreferencesWindowController *)preferencesWindowController {
84+
if (!_preferencesWindowController) {
85+
_preferencesWindowController = [[PreferencesWindowController alloc] init];
86+
__weak typeof(self) weakSelf = self;
87+
_preferencesWindowController.didChangeReleaseChannel = ^(BOOL didChange) {
88+
[weakSelf didChangeReleaseChannel:didChange];
89+
};
90+
}
91+
return _preferencesWindowController;
92+
}
93+
7594
- (WelcomeWindowController *)welcomeWindowController {
7695
if (!_welcomeWindowController) {
7796
_welcomeWindowController = [[WelcomeWindowController alloc] init];
@@ -94,12 +113,12 @@ + (void)initialize {
94113
GICommitMessageViewUserDefaultKey_ShowMargins : @(YES),
95114
GICommitMessageViewUserDefaultKey_EnableSpellChecking : @(YES),
96115
GIUserDefaultKey_FontSize : @(GIDefaultFontSize),
97-
kUserDefaultsKey_ReleaseChannel : kReleaseChannel_Stable,
116+
kUserDefaultsKey_ReleaseChannel : PreferencesWindowController_ReleaseChannel_Stable,
98117
kUserDefaultsKey_CheckInterval : @(15 * 60),
99118
kUserDefaultsKey_FirstLaunch : @(YES),
100119
kUserDefaultsKey_DiffWhitespaceMode : @(kGCLiveRepositoryDiffWhitespaceMode_Normal),
101120
kUserDefaultsKey_ShowWelcomeWindow : @(YES),
102-
kUserDefaultsKey_Theme : kTheme_SystemPreference,
121+
kUserDefaultsKey_Theme : PreferencesWindowController_Theme_SystemPreference,
103122
};
104123
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
105124
}
@@ -138,52 +157,10 @@ - (void)_openDocumentAtURL:(NSURL *)url {
138157
[self _openRepositoryWithURL:url withCloneMode:kCloneMode_None windowModeID:NSNotFound];
139158
}
140159

141-
- (void)awakeFromNib {
142-
143-
_preferencesToolbar.selectedItemIdentifier = kPreferencePaneIdentifier_General;
144-
[self selectPreferencePane:nil];
145-
146-
[_channelPopUpButton.menu removeAllItems];
147-
for (NSString* string in @[ kReleaseChannel_Stable, kReleaseChannel_Continuous ]) {
148-
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(string, nil) action:NULL keyEquivalent:@""];
149-
item.representedObject = string;
150-
[_channelPopUpButton.menu addItem:item];
151-
}
152-
153-
NSString* theme = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_Theme];
154-
[self _applyTheme:theme];
155-
[_themePopUpButton.menu removeAllItems];
156-
for (NSString* string in [self _themePreferences]) {
157-
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(string, nil) action:NULL keyEquivalent:@""];
158-
item.representedObject = string;
159-
[_themePopUpButton.menu addItem:item];
160-
}
161-
}
162-
163160
- (void)handleDocumentCountChanged {
164161
[self.welcomeWindowController handleDocumentCountChanged];
165162
}
166163

167-
- (void)_updatePreferencePanel {
168-
NSString* channel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
169-
for (NSMenuItem* item in _channelPopUpButton.menu.itemArray) {
170-
if ([item.representedObject isEqualToString:channel]) {
171-
[_channelPopUpButton selectItem:item];
172-
break;
173-
}
174-
}
175-
}
176-
177-
- (void)_updateThemePopUpButton {
178-
NSString* theme = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_Theme];
179-
for (NSMenuItem* item in _themePopUpButton.menu.itemArray) {
180-
if ([item.representedObject isEqualToString:theme]) {
181-
[_themePopUpButton selectItem:item];
182-
break;
183-
}
184-
}
185-
}
186-
187164
- (void)_showNotificationWithTitle:(NSString*)title action:(SEL)action message:(NSString*)format, ... NS_FORMAT_FUNCTION(3, 4) {
188165
NSUserNotification* notification = [[NSUserNotification alloc] init];
189166
if (action) {
@@ -199,17 +176,6 @@ - (void)_showNotificationWithTitle:(NSString*)title action:(SEL)action message:(
199176
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
200177
}
201178

202-
#pragma mark - Loading Xibs
203-
- (id)_loadWindowFromBundleXibWithName:(NSString *)name expectedClass:(Class)class {
204-
NSBundle *mainBundle = [NSBundle mainBundle];
205-
NSArray *objects = @[];
206-
[mainBundle loadNibNamed:name owner:self topLevelObjects:&objects];
207-
NSArray *filteredObjects = [objects filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
208-
return [evaluatedObject isKindOfClass:class];
209-
}]];
210-
return filteredObjects.firstObject;
211-
}
212-
213179
#pragma mark - NSApplicationDelegate
214180

215181
- (void)applicationWillFinishLaunching:(NSNotification*)notification {
@@ -248,6 +214,9 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
248214
}
249215
#endif
250216

217+
// Locate installed apps.
218+
[GILaunchServicesLocator setup];
219+
251220
// Initialize user notification center
252221
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
253222

@@ -303,8 +272,7 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
303272
}
304273

305274
// Load theme preference
306-
NSString* theme = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_Theme];
307-
[self _applyTheme:theme];
275+
[PreferencesThemeService applySelectedTheme];
308276

309277
#if __ENABLE_SUDDEN_TERMINATION__
310278
// Enable sudden termination
@@ -413,44 +381,6 @@ - (IBAction)openDocument:(id)sender {
413381
[[NSDocumentController sharedDocumentController] openDocument:sender];
414382
}
415383

416-
- (IBAction)changeReleaseChannel:(id)sender {
417-
NSString* oldChannel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
418-
NSString* newChannel = _channelPopUpButton.selectedItem.representedObject;
419-
if (![newChannel isEqualToString:oldChannel]) {
420-
[[NSUserDefaults standardUserDefaults] setObject:newChannel forKey:kUserDefaultsKey_ReleaseChannel];
421-
422-
_manualCheck = NO;
423-
[_updater checkForUpdatesInBackground];
424-
}
425-
}
426-
427-
- (NSArray*)_themePreferences {
428-
return @[ kTheme_SystemPreference, kTheme_Dark, kTheme_Light ];
429-
}
430-
431-
- (void)_applyTheme:(NSString*)theme {
432-
if (@available(macOS 10.14, *)) {
433-
NSInteger index = [[self _themePreferences] indexOfObject:theme];
434-
switch (index) {
435-
case 0:
436-
NSApp.appearance = nil;
437-
break;
438-
case 1:
439-
NSApp.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
440-
break;
441-
case 2:
442-
NSApp.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
443-
break;
444-
}
445-
}
446-
[[NSUserDefaults standardUserDefaults] setObject:theme forKey:kUserDefaultsKey_Theme];
447-
}
448-
449-
- (IBAction)changeTheme:(id)sender {
450-
NSString* theme = _themePopUpButton.selectedItem.representedObject;
451-
[self _applyTheme:theme];
452-
}
453-
454384
- (IBAction)viewWiki:(id)sender {
455385
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:kURL_Wiki]];
456386
}
@@ -469,24 +399,7 @@ - (IBAction)showAboutPanel:(id)sender {
469399
}
470400

471401
- (IBAction)showPreferences:(id)sender {
472-
[self _updatePreferencePanel];
473-
[self _updateThemePopUpButton];
474-
[_preferencesWindow makeKeyAndOrderFront:nil];
475-
}
476-
477-
- (IBAction)selectPreferencePane:(id)sender {
478-
[_preferencesTabView selectTabViewItemWithIdentifier:_preferencesToolbar.selectedItemIdentifier];
479-
NSSize size = NSSizeFromString(_preferencesTabView.selectedTabViewItem.label);
480-
NSRect rect = [_preferencesWindow contentRectForFrameRect:_preferencesWindow.frame];
481-
if (sender) {
482-
rect.origin.y += rect.size.height;
483-
}
484-
rect.size.width = size.width;
485-
rect.size.height = size.height;
486-
if (sender) {
487-
rect.origin.y -= rect.size.height;
488-
}
489-
[_preferencesWindow setFrame:[_preferencesWindow frameRectForContentRect:rect] display:YES animate:(sender ? YES : NO)];
402+
[self.preferencesWindowController showWindow:nil];
490403
}
491404

492405
- (IBAction)resetPreferences:(id)sender {

0 commit comments

Comments
 (0)