From 6044e47a97de33531c47cd209b30d4405aa0530a Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Tue, 5 Mar 2013 01:45:48 +0100 Subject: [PATCH] Support sudden and automatic termination. --- English.lproj/MainMenu.xib | 29 +++++++++++++++++++---------- EnjoyableApplicationDelegate.h | 1 + EnjoyableApplicationDelegate.m | 25 +++++++++++++++++-------- Info.plist | 4 ++++ NJMappingsController.m | 2 ++ 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 32c3a86..00740ba 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -333,7 +333,6 @@ 268 {{0, 14}, {140, 25}} - _NS:9 YES @@ -383,7 +382,6 @@ 268 {{19, 14}, {67, 25}} - _NS:9 YES @@ -462,7 +460,7 @@ - + @@ -497,7 +495,7 @@ {200, 298} - + YES NO YES @@ -627,7 +625,7 @@ {202, 300} - + 150034 @@ -691,7 +689,6 @@ {{227, 55}, {180, 24}} - _NS:9 YES @@ -1036,7 +1033,7 @@ {198, 198} - + YES NO YES @@ -1128,7 +1125,7 @@ {{0, 20}, {200, 200}} - + 150034 @@ -1144,7 +1141,6 @@ {{66, -1}, {134, 23}} - _NS:22 YES @@ -1420,6 +1416,14 @@ 825 + + + window + + + + 865 + removePressed: @@ -2398,7 +2402,7 @@ - 864 + 865 @@ -2410,6 +2414,7 @@ NJDeviceController NJMappingsController NJOutputController + NSWindow @@ -2428,6 +2433,10 @@ outputController NJOutputController + + window + NSWindow + IBProjectSource diff --git a/EnjoyableApplicationDelegate.h b/EnjoyableApplicationDelegate.h index b77f799..6488135 100644 --- a/EnjoyableApplicationDelegate.h +++ b/EnjoyableApplicationDelegate.h @@ -12,6 +12,7 @@ @interface EnjoyableApplicationDelegate : NSObject { IBOutlet NSMenu *dockMenuBase; + IBOutlet NSWindow *window; } @property (nonatomic, strong) IBOutlet NJDeviceController *inputController; diff --git a/EnjoyableApplicationDelegate.m b/EnjoyableApplicationDelegate.m index 388103b..313ba9a 100644 --- a/EnjoyableApplicationDelegate.m +++ b/EnjoyableApplicationDelegate.m @@ -15,8 +15,8 @@ @implementation EnjoyableApplicationDelegate -- (void)didSwitchApplication:(NSNotification *)notification { - NSRunningApplication *currentApp = notification.userInfo[NSWorkspaceApplicationKey]; +- (void)didSwitchApplication:(NSNotification *)note { + NSRunningApplication *currentApp = note.userInfo[NSWorkspaceApplicationKey]; [self.mappingsController activateMappingForProcess:currentApp.localizedName]; } @@ -46,12 +46,18 @@ [self.mappingsController load]; } -- (void)applicationWillTerminate:(NSNotification *)aNotification { - [NSUserDefaults.standardUserDefaults synchronize]; - [NSNotificationCenter.defaultCenter removeObserver:self]; +- (void)applicationDidBecomeActive:(NSNotification *)notification { + [window makeKeyAndOrderFront:nil]; +} + +- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication + hasVisibleWindows:(BOOL)flag { + [window makeKeyAndOrderFront:nil]; + return NO; } - (void)eventTranslationActivated:(NSNotification *)note { + [NSProcessInfo.processInfo disableAutomaticTermination:@"Input translation is active."]; [NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(didSwitchApplication:) @@ -61,6 +67,7 @@ } - (void)eventTranslationDeactivated:(NSNotification *)note { + [NSProcessInfo.processInfo enableAutomaticTermination:@"Input translation is active."]; [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:NSWorkspaceDidActivateApplicationNotification @@ -75,10 +82,12 @@ int added = 0; for (NJMapping *mapping in mappings) { NSString *keyEquiv = ++added < 10 ? @(added).stringValue : @""; - NSMenuItem *item = [dockMenuBase addItemWithTitle:mapping.name - action:@selector(chooseMapping:) - keyEquivalent:keyEquiv]; + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name + action:@selector(chooseMapping:) + keyEquivalent:keyEquiv]; item.representedObject = mapping; + item.state = mapping == self.mappingsController.currentMapping; + [dockMenuBase addItem:item]; } [_outputController refreshMappings]; } diff --git a/Info.plist b/Info.plist index 8deb6f0..2940aaf 100644 --- a/Info.plist +++ b/Info.plist @@ -2,6 +2,10 @@ + NSSupportsAutomaticTermination + YES + NSSupportsSuddenTermination + CFBundleDevelopmentRegion English CFBundleExecutable diff --git a/NJMappingsController.m b/NJMappingsController.m index 26ef35f..43f6282 100644 --- a/NJMappingsController.m +++ b/NJMappingsController.m @@ -281,6 +281,7 @@ if (result != NSFileHandlingPanelOKButton) return; [panel close]; + [NSProcessInfo.processInfo disableSuddenTermination]; NSError *error; NSDictionary *serialization = [mapping serialize]; NSData *json = [NSJSONSerialization dataWithJSONObject:serialization @@ -289,6 +290,7 @@ if (!error) [json writeToURL:panel.URL options:NSDataWritingAtomic error:&error]; + [NSProcessInfo.processInfo enableSuddenTermination]; if (error) { [window presentError:error modalForWindow:window -- 2.30.2