diff --git a/MasterPassword/ObjC/Mac/MPMacApplication.h b/MasterPassword/ObjC/Mac/MPMacApplication.h new file mode 100644 index 00000000..61301fd0 --- /dev/null +++ b/MasterPassword/ObjC/Mac/MPMacApplication.h @@ -0,0 +1,9 @@ +// +// Created by Maarten Billemont on 2016-04-30. +// Copyright (c) 2016 Lyndir. All rights reserved. +// + +#import + +@interface MPMacApplication : NSApplication +@end diff --git a/MasterPassword/ObjC/Mac/MPMacApplication.m b/MasterPassword/ObjC/Mac/MPMacApplication.m new file mode 100644 index 00000000..9d345f22 --- /dev/null +++ b/MasterPassword/ObjC/Mac/MPMacApplication.m @@ -0,0 +1,54 @@ +// +// Created by Maarten Billemont on 2016-04-30. +// Copyright (c) 2016 Lyndir. All rights reserved. +// + +#import "MPMacApplication.h" + +@interface NSResponder (Editing) + +- (void)undo:(id)sender; +- (void)redo:(id)sender; + +@end + +@implementation MPMacApplication { +} + +- (void)sendEvent:(NSEvent *)event { + + if ([event type] == NSKeyDown) { + if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) { + if ([[event charactersIgnoringModifiers] isEqualToString:@"x"]) { + if ([self sendAction:@selector( cut: ) to:nil from:self]) + return; + } + else if ([[event charactersIgnoringModifiers] isEqualToString:@"c"]) { + if ([self sendAction:@selector( copy: ) to:nil from:self]) + return; + } + else if ([[event charactersIgnoringModifiers] isEqualToString:@"v"]) { + if ([self sendAction:@selector( paste: ) to:nil from:self]) + return; + } + else if ([[event charactersIgnoringModifiers] isEqualToString:@"z"]) { + if ([self sendAction:@selector( undo: ) to:nil from:self]) + return; + } + else if ([[event charactersIgnoringModifiers] isEqualToString:@"a"]) { + if ([self sendAction:@selector( selectAll: ) to:nil from:self]) + return; + } + } + else if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSShiftKeyMask)) { + if ([[event charactersIgnoringModifiers] isEqualToString:@"Z"]) { + if ([self sendAction:@selector( redo: ) to:nil from:self]) + return; + } + } + } + + [super sendEvent:event]; +} + +@end diff --git a/MasterPassword/ObjC/Mac/MasterPassword-Info.plist b/MasterPassword/ObjC/Mac/MasterPassword-Info.plist index f1fabe4e..9ba1fb3a 100644 --- a/MasterPassword/ObjC/Mac/MasterPassword-Info.plist +++ b/MasterPassword/ObjC/Mac/MasterPassword-Info.plist @@ -78,7 +78,7 @@ NSMainNibFile MainMenu NSPrincipalClass - NSApplication + MPMacApplication UTExportedTypeDeclarations diff --git a/MasterPassword/ObjC/Mac/MasterPassword-Mac.xcodeproj/project.pbxproj b/MasterPassword/ObjC/Mac/MasterPassword-Mac.xcodeproj/project.pbxproj index d7e74926..812cd321 100644 --- a/MasterPassword/ObjC/Mac/MasterPassword-Mac.xcodeproj/project.pbxproj +++ b/MasterPassword/ObjC/Mac/MasterPassword-Mac.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 93D390C676DF52DA7E459F19 /* MPPasswordWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39D9D0061FF1159998F06 /* MPPasswordWindow.m */; }; 93D391E61DC23E128DA4446C /* NSView+Traversing.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D393EE88DE554BCCBC1C2D /* NSView+Traversing.h */; }; 93D392EC39DA43C46C692C12 /* NSDictionary+Indexing.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D393B97158D7BE9332EA53 /* NSDictionary+Indexing.h */; }; + 93D393A1646430FAAC73E7FE /* MPMacApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39F83DD151985F2C7345A /* MPMacApplication.m */; }; 93D394C4254EEB45FB335AFB /* MPSitesTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39423D7BF4FD31FE6D27C /* MPSitesTableView.m */; }; 93D395E4830290EBB6E71F34 /* MPNoStateButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39538C4CEFF46DF379254 /* MPNoStateButton.m */; }; 93D395F08A087F8A24689347 /* NSArray+Indexing.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39067C0AFDC581794E2B8 /* NSArray+Indexing.m */; }; @@ -273,6 +274,7 @@ 93D39368EF3CBFEF2AFCA15A /* MPInitialWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPInitialWindowController.h; sourceTree = ""; }; 93D393B97158D7BE9332EA53 /* NSDictionary+Indexing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+Indexing.h"; sourceTree = ""; }; 93D393EE88DE554BCCBC1C2D /* NSView+Traversing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSView+Traversing.h"; sourceTree = ""; }; + 93D3942099C9AD0374B5777D /* MPMacApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPMacApplication.h; sourceTree = ""; }; 93D39423D7BF4FD31FE6D27C /* MPSitesTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSitesTableView.m; sourceTree = ""; }; 93D39538C4CEFF46DF379254 /* MPNoStateButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPNoStateButton.m; sourceTree = ""; }; 93D396D04E57792A54D437AC /* NSArray+Indexing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Indexing.h"; sourceTree = ""; }; @@ -283,6 +285,7 @@ 93D39D3CB30874147D9A9E1B /* MPInitialWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPInitialWindowController.m; sourceTree = ""; }; 93D39D9D0061FF1159998F06 /* MPPasswordWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPasswordWindow.m; sourceTree = ""; }; 93D39E73BF5CBF8E5B005CD3 /* MPSiteModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSiteModel.m; sourceTree = ""; }; + 93D39F83DD151985F2C7345A /* MPMacApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPMacApplication.m; sourceTree = ""; }; DA0933C91747A56A00DE1CEF /* MPInitialWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MPInitialWindow.xib; sourceTree = ""; }; DA0933CB1747AD2D00DE1CEF /* shot-laptop-leaning-iphone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "shot-laptop-leaning-iphone.png"; sourceTree = ""; }; DA0933CF1747B91B00DE1CEF /* appstore.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = appstore.png; sourceTree = ""; }; @@ -1140,6 +1143,8 @@ 93D39E73BF5CBF8E5B005CD3 /* MPSiteModel.m */, 93D39AC6360DDC16AEAA4119 /* MPSitesTableView.h */, 93D39423D7BF4FD31FE6D27C /* MPSitesTableView.m */, + 93D39F83DD151985F2C7345A /* MPMacApplication.m */, + 93D3942099C9AD0374B5777D /* MPMacApplication.h */, ); path = Mac; sourceTree = ""; @@ -2263,6 +2268,7 @@ 93D395E4830290EBB6E71F34 /* MPNoStateButton.m in Sources */, DA4DAE941A7D8117003E5423 /* MPAlgorithmV3.m in Sources */, DA4DAE951A7D8117003E5423 /* MPTypes.m in Sources */, + 93D393A1646430FAAC73E7FE /* MPMacApplication.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };