Skip to content

Commit

Permalink
Dark mode support.
Browse files Browse the repository at this point in the history
[#468 state:fixed]
  • Loading branch information
Mento committed Oct 18, 2018
1 parent c69fb6d commit 4d259fe
Show file tree
Hide file tree
Showing 12 changed files with 1,774 additions and 1,786 deletions.
4 changes: 4 additions & 0 deletions GPGKeychain.xcodeproj/project.pbxproj
Expand Up @@ -52,6 +52,7 @@
3096C91B14D167FC00246400 /* Info.png in Resources */ = {isa = PBXBuildFile; fileRef = 3096C91A14D167FC00246400 /* Info.png */; };
309F5A3720E52B8E00D6FED4 /* GKPasswordStrengthIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 309F5A3620E52B8E00D6FED4 /* GKPasswordStrengthIndicator.m */; };
30AC56EC18BB71A30038F224 /* Redo.png in Resources */ = {isa = PBXBuildFile; fileRef = 30AC56EB18BB71A30038F224 /* Redo.png */; };
30ADF3F22178ABC9004A5945 /* Search_dark.png in Resources */ = {isa = PBXBuildFile; fileRef = 30ADF3F12178ABC8004A5945 /* Search_dark.png */; };
30B29BE6191156DE00FC453C /* gka.sdef in Resources */ = {isa = PBXBuildFile; fileRef = 30B29BE5191156DE00FC453C /* gka.sdef */; };
30B29BEE19116DF400FC453C /* GKScripting.m in Sources */ = {isa = PBXBuildFile; fileRef = 30B29BED19116DF400FC453C /* GKScripting.m */; };
30C2FB5420F4FEF20076FA73 /* GKSignaturesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 30C2FB5320F4FEF20076FA73 /* GKSignaturesController.m */; };
Expand Down Expand Up @@ -263,6 +264,7 @@
30AB9CE918E31EB800F2864A /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Localizable.strings; sourceTree = "<group>"; };
30AB9CF118E31F2000F2864A /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/MainMenu.strings; sourceTree = "<group>"; };
30AC56EB18BB71A30038F224 /* Redo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Redo.png; sourceTree = "<group>"; };
30ADF3F12178ABC8004A5945 /* Search_dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Search_dark.png; sourceTree = "<group>"; };
30B20F0814B1DAC300E8CCD8 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
30B20F1614B1DB3100E8CCD8 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/ModalSheets.strings; sourceTree = "<group>"; };
30B20F1714B1DB3100E8CCD8 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Preferences.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -451,6 +453,7 @@
3004A20A1CCF8948006D4E16 /* lock.icns */,
30AC56EB18BB71A30038F224 /* Redo.png */,
3075AFFE18B646C100BEAA71 /* Search.png */,
30ADF3F12178ABC8004A5945 /* Search_dark.png */,
3050FB771475B0FB00E589AA /* Undo.png */,
3052E2D2144B079F00D6716A /* Updates.png */,
);
Expand Down Expand Up @@ -623,6 +626,7 @@
30B29BE6191156DE00FC453C /* gka.sdef in Resources */,
3052E37D144B082B00D6716A /* gpgkey.icns in Resources */,
3052E37E144B082B00D6716A /* Icon.icns in Resources */,
30ADF3F22178ABC9004A5945 /* Search_dark.png in Resources */,
303CD5C620F4949E000F5892 /* Info.plist in Resources */,
3052E37F144B082B00D6716A /* Import.png in Resources */,
3004A20B1CCF8948006D4E16 /* lock.icns in Resources */,
Expand Down
3,336 changes: 1,672 additions & 1,664 deletions Resources/Base.lproj/MainMenu.xib

Large diffs are not rendered by default.

Binary file added Resources/Images/Search_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Resources/Info.plist
Expand Up @@ -87,5 +87,7 @@
<string>NSApplication</string>
<key>OSAScriptingDefinition</key>
<string>gka.sdef</string>
<key>NSRequiresAquaSystemAppearance</key>
<false/>
</dict>
</plist>
1 change: 1 addition & 0 deletions Resources/en.lproj/MainMenu.strings
Expand Up @@ -135,6 +135,7 @@
"ZyU-dv-qqW.headerCell.title" = "Algorithm";
"aIr-FD-0OQ.headerCell.title" = "Algo";
"bDr-uB-4z9.title" = "Revoke";
"c31-rN-XUI.title" = "Window";
"cEN-yv-emX.title" = "Algorithm:";
"cWK-eu-Lbv.title" = "Ultimate";
"cgi-y4-vYW.title" = "Validity:";
Expand Down
22 changes: 16 additions & 6 deletions Source/ActionController.m
Expand Up @@ -82,8 +82,17 @@ - (void)awakeFromNib {
signaturesTable.action = nil;
}

- (NSResponder *)firstResponder {
NSWindow *inspectorWindow = appDelegate.inspectorWindow;
if (inspectorWindow == NSApp.keyWindow) {
return inspectorWindow.firstResponder;
} else {
return mainWindow.firstResponder;
}
}

- (IBAction)delete:(id)sender {
NSResponder *responder = mainWindow.firstResponder;
NSResponder *responder = self.firstResponder;

if (responder == appDelegate.userIDTable) {
[self removeUserID:nil];
Expand Down Expand Up @@ -526,7 +535,7 @@ - (void)importFromData:(NSData *)data {
- (IBAction)copy:(id)sender {
NSString *stringForPasteboard = nil;

NSResponder *responder = mainWindow.firstResponder;
NSResponder *responder = self.firstResponder;

if (responder == appDelegate.userIDTable) {
if (userIDsController.selectedObjects.count == 1) {
Expand Down Expand Up @@ -563,7 +572,7 @@ - (IBAction)copy:(id)sender {
}
- (IBAction)copyFingerprint:(id)sender {
NSString *stringForPasteboard = nil;
NSResponder *responder = mainWindow.firstResponder;
NSResponder *responder = self.firstResponder;

if (responder == appDelegate.userIDTable) {
if (userIDsController.selectedObjects.count == 1) {
Expand Down Expand Up @@ -1857,7 +1866,8 @@ - (IBAction)addSignature:(id)sender {
}

GPGUserID *userID = nil;
if ([sender tag] == 1 || ([sender tag] == -1 && (mainWindow.firstResponder == userIDsTable || mainWindow.firstResponder == signaturesTable))) {
NSResponder *firstResponder = self.firstResponder;
if ([sender tag] == 1 || ([sender tag] == -1 && (firstResponder == userIDsTable || firstResponder == signaturesTable))) {
NSArray *objects = [self selectedObjectsOf:userIDsTable];
if (objects.count == 1) {
// The user has selected a userID in the user ids tab.
Expand Down Expand Up @@ -2415,7 +2425,7 @@ - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item {


if (selector == @selector(delete:)) {
NSResponder *responder = mainWindow.firstResponder;
NSResponder *responder = self.firstResponder;

if (responder == appDelegate.userIDTable) {
selector = @selector(removeUserID:);
Expand All @@ -2431,7 +2441,7 @@ - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item {

if (selector == @selector(copy:) ||
selector == @selector(copyFingerprint:)) {
NSResponder *responder = mainWindow.firstResponder;
NSResponder *responder = self.firstResponder;

if (responder == appDelegate.userIDTable) {
if (userIDsController.selectedObjects.count == 1) {
Expand Down
11 changes: 5 additions & 6 deletions Source/AppDelegate.h
Expand Up @@ -19,16 +19,15 @@

#import "GKTableView.h"

@interface GPGKeychainAppDelegate : NSObject <NSWindowDelegate, NSApplicationDelegate, NSDrawerDelegate> {
@interface GPGKeychainAppDelegate : NSObject <NSWindowDelegate, NSApplicationDelegate> {
BOOL rowWasSelected;
BOOL _shouldTerminate;
}

@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSView *inspectorView;
@property (weak) IBOutlet GKTableView *keyTable;
@property (weak) IBOutlet NSTableView *userIDTable, *subkeyTable, *signatureTable;
@property (weak) IBOutlet NSDrawer *drawer;
@property (nonatomic, assign) IBOutlet NSWindow *window;
@property (nonatomic, weak) IBOutlet NSWindow *inspectorWindow;
@property (nonatomic, weak) IBOutlet GKTableView *keyTable;
@property (nonatomic, weak) IBOutlet NSTableView *userIDTable, *subkeyTable, *signatureTable;
@property (nonatomic) BOOL inspectorVisible;
@property (nonatomic, strong) NSTextView *fieldEditor;

Expand Down
116 changes: 22 additions & 94 deletions Source/AppDelegate.m
Expand Up @@ -26,7 +26,6 @@


@implementation GPGKeychainAppDelegate
@synthesize keyTable, userIDTable, subkeyTable, signatureTable, drawer, inspectorView;

- (NSWindow *)window {
return mainWindow;
Expand All @@ -36,95 +35,38 @@ - (void)setWindow:(NSWindow *)value {
}


- (NSSize)drawerWillResizeContents:(NSDrawer *)sender toSize:(NSSize)contentSize {

// Force the minimum drawer size. Contraints are not working, so do it manually.
CGFloat minWidth = inspectorView.fittingSize.width;
if (contentSize.width < minWidth) {
contentSize.width = minWidth;
NSSize minContentSize = drawer.minContentSize;
minContentSize.width = minWidth;
drawer.minContentSize = minContentSize;
}

// Save the current size.
[[GPGOptions sharedOptions] setValue:@(contentSize.width) forKey:@"drawerWidth"];


return contentSize;
}

- (BOOL)inspectorVisible {
return drawer.state;
return self.inspectorWindow.visible;
}
- (void)setInspectorVisible:(BOOL)inspectorVisible {
[self showInspector:inspectorVisible];
}

- (void)showInspector:(int)show {
BOOL isVisible = drawer.state;
static BOOL displayedAlready = NO;
BOOL isVisible = self.inspectorWindow.visible;

if (show == -1) {
show = !isVisible;
}

if (show) {
if (!isVisible) {
NSRect windowFrame = self.window.frame;
CGFloat drawerWidth = drawer.contentSize.width;
CGFloat spaceLeft = windowFrame.origin.x;
CGFloat screenWidth = self.window.screen.frame.size.width;
CGFloat spaceRight = screenWidth - windowFrame.origin.x - windowFrame.size.width;

BOOL right = spaceRight >= spaceLeft;

CGFloat maxSpace = MAX(spaceRight, spaceLeft) - 10;
if (drawerWidth > maxSpace) {
CGFloat minWidth = inspectorView.fittingSize.width;

if (minWidth <= maxSpace) {
// Left or right is enough space for the minimum sized drawer.
// Only need to shrink the drawer.
NSSize contentSize = drawer.contentSize;
contentSize.width = maxSpace;
drawer.contentSize = contentSize;
} else {
NSSize contentSize = drawer.contentSize;
contentSize.width = minWidth;
drawer.contentSize = contentSize;

if (spaceRight + spaceLeft - 10 >= minWidth) {
// Move the main window.
CGFloat diff = minWidth - maxSpace;
windowFrame.origin.x -= (right ? diff : -diff);
} else {
// Shrink the main window.
windowFrame.size.width = screenWidth - minWidth - 10;

if (right) {
windowFrame.origin.x = 0;
} else {
windowFrame.origin.x = minWidth + 10;
}
}

// Animate shrink and/or move.
NSDictionary *windowResize = @{NSViewAnimationTargetKey: self.window,
NSViewAnimationEndFrameKey: [NSValue valueWithRect:windowFrame]};

NSViewAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations:@[windowResize]];

[animation setAnimationBlockingMode: NSAnimationNonblocking];
[animation setAnimationCurve: NSAnimationEaseIn];
[animation setDuration:0.5];
[animation startAnimation];
}
if (!displayedAlready) {
displayedAlready = YES;
NSRect mainFrame = self.window.frame;
NSRect inspectorFrame = self.inspectorWindow.frame;
NSPoint origin;
origin.x = mainFrame.origin.x + mainFrame.size.width;
origin.y = mainFrame.origin.y + mainFrame.size.height - inspectorFrame.size.height;
[self.inspectorWindow setFrameOrigin:origin];
}
drawer.contentView.window.nextResponder = [ActionController sharedInstance];
[drawer open];

[self.window addChildWindow:self.inspectorWindow ordered:NSWindowAbove];
[self.inspectorWindow makeKeyAndOrderFront:nil];
}
} else {
[drawer close];
[self.inspectorWindow close];
}
}
- (IBAction)toggleInspector:(id)sender {
Expand All @@ -137,11 +79,11 @@ - (void)openInspector:(id)sender {


- (IBAction)singleClick:(NSTableView *)sender {
rowWasSelected = [keyTable clickedRowWasSelected];
rowWasSelected = [_keyTable clickedRowWasSelected];
}
- (IBAction)doubleClick:(NSTableView *)sender {
if (keyTable.clickedRow >= 0) {
if (keyTable.selectedRowIndexes.count > 1 ? [keyTable clickedRowWasSelected] : rowWasSelected) {
if (_keyTable.clickedRow >= 0) {
if (_keyTable.selectedRowIndexes.count > 1 ? [_keyTable clickedRowWasSelected] : rowWasSelected) {
[self showInspector:-1];
} else {
[self showInspector:1];
Expand All @@ -163,24 +105,10 @@ - (id)init {
- (void)awakeFromNib {
GPGDebugLog(@"GPGKeychainAppDelegate awakeFromNib");

#warning This code is required until jenkins is up to date.
keyTable.action = @selector(singleClick:);
keyTable.doubleAction = @selector(doubleClick:);
keyTable.target = self;


NSNumber *drawerWidth = [[GPGOptions sharedOptions] valueForKey:@"drawerWidth"];
if (drawerWidth) {
NSSize size = drawer.contentSize;
size.width = drawerWidth.floatValue;
drawer.contentSize = size;
}


[self generateContextMenuForTable:keyTable];
[self generateContextMenuForTable:subkeyTable];
[self generateContextMenuForTable:userIDTable];
[self generateContextMenuForTable:signatureTable];
[self generateContextMenuForTable:_keyTable];
[self generateContextMenuForTable:_subkeyTable];
[self generateContextMenuForTable:_userIDTable];
[self generateContextMenuForTable:_signatureTable];

NSArray *draggedTypes = [NSArray arrayWithObjects:NSFilenamesPboardType, NSStringPboardType, nil];
[mainWindow registerForDraggedTypes:draggedTypes];
Expand Down
5 changes: 1 addition & 4 deletions Source/GKPasswordStrengthIndicator.h
Expand Up @@ -10,10 +10,7 @@
@interface GKPasswordStrengthIndicator : NSProgressIndicator
@end
@interface GKPasswordStrengthIndicator () {
NSColor *borderColor;
NSColor *backgroundColor;
NSGradient *gradient;

NSGradient *gradient;
}
@end

16 changes: 7 additions & 9 deletions Source/GKPasswordStrengthIndicator.m
Expand Up @@ -15,19 +15,17 @@ - (instancetype)initWithCoder:(NSCoder *)decoder {
return nil;
}

borderColor = [NSColor colorWithCalibratedWhite:0.71 alpha:1];
backgroundColor = [NSColor colorWithCalibratedWhite:0.85 alpha:1];

NSColor* color1 = [NSColor colorWithCalibratedRed: 0.808 green: 0.241 blue: 0.241 alpha: 1];
NSColor* color2 = [NSColor colorWithCalibratedRed: 0.868 green: 0.83 blue: 0.213 alpha: 1];
NSColor* color3 = [NSColor colorWithCalibratedRed: 0.373 green: 0.848 blue: 0.19 alpha: 1];
NSColor *color1 = [NSColor colorWithCalibratedRed:0.808 green:0.241 blue:0.241 alpha:1];
NSColor *color2 = [NSColor colorWithCalibratedRed:0.868 green:0.83 blue:0.213 alpha:1];
NSColor *color3 = [NSColor colorWithCalibratedRed:0.373 green:0.848 blue:0.19 alpha:1];


gradient = [[NSGradient alloc] initWithColorsAndLocations:
color1, 0.23,
[color1 blendedColorWithFraction: 0.5 ofColor: color2], 0.27,
[color1 blendedColorWithFraction:0.5 ofColor:color2], 0.27,
color2, 0.36,
[color2 blendedColorWithFraction: 0.5 ofColor: color3], 0.43,
[color2 blendedColorWithFraction:0.5 ofColor:color3], 0.43,
color3, 0.50, nil];

return self;
Expand All @@ -54,8 +52,8 @@ - (void)drawRect:(NSRect)dirtyRect {


NSColor *barColor = [gradient interpolatedColorAtLocation:ratio];


NSColor *borderColor = [[NSColor tertiaryLabelColor] colorWithAlphaComponent:0.2];
NSColor *backgroundColor = [NSColor quaternaryLabelColor];


// Construct the BezierPath.
Expand Down
4 changes: 2 additions & 2 deletions Source/Globales.m
Expand Up @@ -110,13 +110,13 @@ - (id)transformedValue:(id)value {
}
}

return [NSColor blackColor];
return [NSColor labelColor];
}

@end

@implementation GKAValidityInidicatorTransformer
+ (Class)transformedValueClass { return [NSColor class]; }
+ (Class)transformedValueClass { return [NSNumber class]; }
+ (BOOL)allowsReverseTransformation { return NO; }
- (id)transformedValue:(id)value {

Expand Down

0 comments on commit 4d259fe

Please sign in to comment.