Skip to content

Commit 02c4fee

Browse files
committed
Support choosing light, dark, or the system appearance (issue #714)
Some users want GitX to stay light or dark whatever the rest of the Mac is doing, which until now only System Settings could decide. - Store the choice as PBAppearance, defaulting to following the system - Apply it to NSApp.appearance before the first window opens, so no window shows the wrong appearance at launch - Offer it as a popup in Settings > General and as a View > Appearance submenu, both driving the same default - Leave every existing consumer of the appearance alone: overriding NSApp.appearance updates effectiveAppearance, which already drives them - Give the General pane the height the new row needs, and settle the Integration pane on the same margins while there, so all three panes stand 38 points clear at the top and 35 at the bottom
1 parent e8d7649 commit 02c4fee

6 files changed

Lines changed: 134 additions & 13 deletions

File tree

‎Classes/Controllers/ApplicationController.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121

2222
- (IBAction)openPreferencesWindow:(id)sender;
23+
- (IBAction)changeAppearance:(id)sender;
2324
- (IBAction)showAboutPanel:(id)sender;
2425

2526
- (IBAction)installCliTool:(id)sender;

‎Classes/Controllers/ApplicationController.m‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,56 @@ - (BOOL)applicationOpenUntitledFile:(NSApplication *)theApplication
115115
}
116116
}
117117

118+
- (void)applicationWillFinishLaunching:(NSNotification *)notification
119+
{
120+
[self applyAppearancePreference];
121+
122+
[[NSNotificationCenter defaultCenter] addObserver:self
123+
selector:@selector(userDefaultsDidChange:)
124+
name:NSUserDefaultsDidChangeNotification
125+
object:nil];
126+
}
127+
128+
- (void)userDefaultsDidChange:(NSNotification *)notification
129+
{
130+
[self applyAppearancePreference];
131+
}
132+
133+
- (void)applyAppearancePreference
134+
{
135+
NSAppearance *appearance = nil;
136+
137+
switch ([PBGitDefaults appearance]) {
138+
case PBAppearanceLight:
139+
appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
140+
break;
141+
case PBAppearanceDark:
142+
appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
143+
break;
144+
case PBAppearanceSystem:
145+
break;
146+
}
147+
148+
if (NSApp.appearance == appearance || [NSApp.appearance.name isEqualToString:appearance.name])
149+
return;
150+
151+
NSLog(@"Applying appearance preference: %@", appearance.name ?: @"system");
152+
NSApp.appearance = appearance;
153+
}
154+
155+
- (IBAction)changeAppearance:(id)sender
156+
{
157+
[PBGitDefaults setAppearance:[sender tag]];
158+
}
159+
160+
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
161+
{
162+
if (menuItem.action == @selector(changeAppearance:))
163+
menuItem.state = (menuItem.tag == [PBGitDefaults appearance]) ? NSControlStateValueOn : NSControlStateValueOff;
164+
165+
return YES;
166+
}
167+
118168
- (void)applicationDidFinishLaunching:(NSNotification *)notification
119169
{
120170
#if !DEBUG

‎Classes/git/PBGitDefaults.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ typedef NS_ENUM(NSInteger, PBPruneOnFetchSetting) {
1414
PBPruneOnFetchNever = 2,
1515
};
1616

17+
typedef NS_ENUM(NSInteger, PBAppearanceSetting) {
18+
PBAppearanceSystem = 0,
19+
PBAppearanceLight = 1,
20+
PBAppearanceDark = 2,
21+
};
22+
1723
typedef NS_ENUM(NSInteger, PBCommitDateFormatSetting) {
1824
PBCommitDateFormatShort = 0,
1925
PBCommitDateFormatMedium = 1,
@@ -48,6 +54,8 @@ typedef NS_ENUM(NSInteger, PBCommitDateFormatSetting) {
4854
+ (void)setTerminalHandler:(NSString *)bundleIdentifier;
4955
+ (BOOL)terminalOpenAsTab;
5056
+ (void)setTerminalOpenAsTab:(BOOL)openAsTab;
57+
+ (PBAppearanceSetting)appearance;
58+
+ (void)setAppearance:(PBAppearanceSetting)appearance;
5159
+ (PBCommitDateFormatSetting)commitDateFormat;
5260
+ (NSString *)commitDateCustomFormat;
5361

‎Classes/git/PBGitDefaults.m‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define kPruneOnFetch @"PBPruneOnFetch"
3434
#define kTerminalHandler @"PBTerminalHandler"
3535
#define kTerminalOpenAsTab @"PBTerminalOpenAsTab"
36+
#define kAppearance @"PBAppearance"
3637
#define kCommitDateFormat @"PBCommitDateFormat"
3738
#define kCommitDateCustomFormat @"PBCommitDateCustomFormat"
3839
#define kDefaultCommitDateCustomFormat @"yyyy-MM-dd HH:mm"
@@ -76,6 +77,8 @@ + (void)initialize
7677
forKey:kTerminalHandler];
7778
[defaultValues setObject:[NSNumber numberWithBool:NO]
7879
forKey:kTerminalOpenAsTab];
80+
[defaultValues setObject:[NSNumber numberWithInteger:PBAppearanceSystem]
81+
forKey:kAppearance];
7982
[defaultValues setObject:[NSNumber numberWithInteger:PBCommitDateFormatLong]
8083
forKey:kCommitDateFormat];
8184
[defaultValues setObject:kDefaultCommitDateCustomFormat
@@ -266,6 +269,16 @@ + (void)setTerminalOpenAsTab:(BOOL)openAsTab
266269
[[NSUserDefaults standardUserDefaults] setBool:openAsTab forKey:kTerminalOpenAsTab];
267270
}
268271

272+
+ (PBAppearanceSetting)appearance
273+
{
274+
return [[NSUserDefaults standardUserDefaults] integerForKey:kAppearance];
275+
}
276+
277+
+ (void)setAppearance:(PBAppearanceSetting)appearance
278+
{
279+
[[NSUserDefaults standardUserDefaults] setInteger:appearance forKey:kAppearance];
280+
}
281+
269282
+ (PBCommitDateFormatSetting)commitDateFormat
270283
{
271284
return [[NSUserDefaults standardUserDefaults] integerForKey:kCommitDateFormat];

‎Resources/en.lproj/MainMenu.xib‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,28 @@ DQ
574574
<menuItem isSeparatorItem="YES" id="847">
575575
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
576576
</menuItem>
577+
<menuItem title="Appearance" id="Apr-mn-itm">
578+
<menu key="submenu" title="Appearance" id="Apr-mn-sub">
579+
<items>
580+
<menuItem title="System" tag="0" id="Apr-sy-itm">
581+
<connections>
582+
<action selector="changeAppearance:" target="-1" id="Apr-sy-act"/>
583+
</connections>
584+
</menuItem>
585+
<menuItem title="Light" tag="1" id="Apr-lt-itm">
586+
<connections>
587+
<action selector="changeAppearance:" target="-1" id="Apr-lt-act"/>
588+
</connections>
589+
</menuItem>
590+
<menuItem title="Dark" tag="2" id="Apr-dk-itm">
591+
<connections>
592+
<action selector="changeAppearance:" target="-1" id="Apr-dk-act"/>
593+
</connections>
594+
</menuItem>
595+
</items>
596+
</menu>
597+
</menuItem>
598+
<menuItem isSeparatorItem="YES" id="Apr-sp-itm"/>
577599
<menuItem title="History" keyEquivalent="1" id="927">
578600
<connections>
579601
<action selector="showHistoryView:" target="-1" id="930"/>

‎Resources/en.lproj/Preferences.xib‎

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,36 @@
2323
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
2424
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
2525
<customView id="1" userLabel="General">
26-
<rect key="frame" x="0.0" y="0.0" width="500" height="334"/>
26+
<rect key="frame" x="0.0" y="0.0" width="500" height="382"/>
2727
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
2828
<subviews>
29+
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Apr-lb-fld">
30+
<rect key="frame" x="91" y="323" width="110" height="17"/>
31+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
32+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Appearance:" id="Apr-lb-cel">
33+
<font key="font" metaFont="system"/>
34+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
35+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
36+
</textFieldCell>
37+
</textField>
38+
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Apr-pu-btn">
39+
<rect key="frame" x="205" y="319" width="215" height="25"/>
40+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
41+
<popUpButtonCell key="cell" type="push" title="System" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="Apr-pu-sys" id="Apr-pu-cel">
42+
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
43+
<font key="font" metaFont="menu"/>
44+
<menu key="menu" title="OtherViews" id="Apr-pu-mnu">
45+
<items>
46+
<menuItem title="System" state="on" tag="0" id="Apr-pu-sys"/>
47+
<menuItem title="Light" tag="1" id="Apr-pu-lgt"/>
48+
<menuItem title="Dark" tag="2" id="Apr-pu-drk"/>
49+
</items>
50+
</menu>
51+
</popUpButtonCell>
52+
<connections>
53+
<binding destination="28" name="selectedTag" keyPath="values.PBAppearance" id="Apr-pu-bnd"/>
54+
</connections>
55+
</popUpButton>
2956
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="164">
3057
<rect key="frame" x="91" y="154" width="110" height="17"/>
3158
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -347,11 +374,11 @@
347374
<customObject id="26" customClass="SUUpdater"/>
348375
<userDefaultsController representsSharedInstance="YES" id="28"/>
349376
<customView id="87" userLabel="Integration">
350-
<rect key="frame" x="0.0" y="0.0" width="500" height="306"/>
377+
<rect key="frame" x="0.0" y="0.0" width="500" height="324"/>
351378
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
352379
<subviews>
353380
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="43">
354-
<rect key="frame" x="91" y="247" width="99" height="17"/>
381+
<rect key="frame" x="91" y="265" width="99" height="17"/>
355382
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
356383
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Git Executable:" id="44">
357384
<font key="font" metaFont="system"/>
@@ -360,7 +387,7 @@
360387
</textFieldCell>
361388
</textField>
362389
<pathControl focusRingType="none" verticalHuggingPriority="750" fixedFrame="YES" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="45">
363-
<rect key="frame" x="205" y="243" width="195" height="25"/>
390+
<rect key="frame" x="205" y="261" width="195" height="25"/>
364391
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
365392
<pathCell key="cell" selectable="YES" editable="YES" focusRingType="none" alignment="left" pathStyle="popUp" id="46">
366393
<font key="font" metaFont="system"/>
@@ -381,7 +408,7 @@
381408
</connections>
382409
</pathControl>
383410
<button toolTip="Reset to 'No executable set'" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="77">
384-
<rect key="frame" x="404" y="247" width="16" height="16"/>
411+
<rect key="frame" x="404" y="265" width="16" height="16"/>
385412
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
386413
<buttonCell key="cell" type="bevel" bezelStyle="regularSquare" image="NSStopProgressFreestandingTemplate" imagePosition="left" alignment="left" alternateImage="NSStopProgressFreestandingTemplate" state="on" imageScaling="proportionallyDown" inset="2" id="78">
387414
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -397,7 +424,7 @@
397424
</connections>
398425
</button>
399426
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="47">
400-
<rect key="frame" x="112" y="208" width="270" height="28"/>
427+
<rect key="frame" x="112" y="226" width="270" height="28"/>
401428
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
402429
<textFieldCell key="cell" controlSize="small" sendsActionOnEndEditing="YES" id="48">
403430
<font key="font" metaFont="smallSystem"/>
@@ -408,7 +435,7 @@ or drag it from the Finder.</string>
408435
</textFieldCell>
409436
</textField>
410437
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="180">
411-
<rect key="frame" x="91" y="162" width="110" height="17"/>
438+
<rect key="frame" x="91" y="180" width="110" height="17"/>
412439
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
413440
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Open in Terminal:" id="181">
414441
<font key="font" metaFont="system"/>
@@ -417,7 +444,7 @@ or drag it from the Finder.</string>
417444
</textFieldCell>
418445
</textField>
419446
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="182">
420-
<rect key="frame" x="205" y="157" width="195" height="25"/>
447+
<rect key="frame" x="205" y="175" width="195" height="25"/>
421448
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
422449
<popUpButtonCell key="cell" type="push" title="Terminal" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="185" id="183">
423450
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
@@ -433,7 +460,7 @@ or drag it from the Finder.</string>
433460
</connections>
434461
</popUpButton>
435462
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="188">
436-
<rect key="frame" x="112" y="137" width="120" height="18"/>
463+
<rect key="frame" x="112" y="155" width="120" height="18"/>
437464
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
438465
<buttonCell key="cell" type="check" title="Open as tab" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="189">
439466
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -444,7 +471,7 @@ or drag it from the Finder.</string>
444471
</connections>
445472
</button>
446473
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="108">
447-
<rect key="frame" x="112" y="51" width="179" height="18"/>
474+
<rect key="frame" x="112" y="69" width="179" height="18"/>
448475
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
449476
<buttonCell key="cell" type="check" title="Make Gists public" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="109">
450477
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -456,7 +483,7 @@ or drag it from the Finder.</string>
456483
</connections>
457484
</button>
458485
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="97">
459-
<rect key="frame" x="112" y="73" width="181" height="18"/>
486+
<rect key="frame" x="112" y="91" width="181" height="18"/>
460487
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
461488
<buttonCell key="cell" type="check" title="Confirm creation of Gists" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="98">
462489
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -468,7 +495,7 @@ or drag it from the Finder.</string>
468495
</connections>
469496
</button>
470497
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="88">
471-
<rect key="frame" x="91" y="17" width="121" height="18"/>
498+
<rect key="frame" x="91" y="35" width="121" height="18"/>
472499
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
473500
<buttonCell key="cell" type="check" title="Enable Gravatar" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="91">
474501
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -479,7 +506,7 @@ or drag it from the Finder.</string>
479506
</connections>
480507
</button>
481508
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="89">
482-
<rect key="frame" x="91" y="95" width="169" height="18"/>
509+
<rect key="frame" x="91" y="113" width="169" height="18"/>
483510
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
484511
<buttonCell key="cell" type="check" title="Enable ‘Gist it’ button" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="90">
485512
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>

0 commit comments

Comments
 (0)