Support sudden and automatic termination.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 5 Mar 2013 00:45:48 +0000 (01:45 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 5 Mar 2013 00:45:48 +0000 (01:45 +0100)
English.lproj/MainMenu.xib
EnjoyableApplicationDelegate.h
EnjoyableApplicationDelegate.m
Info.plist
NJMappingsController.m

index 32c3a86..00740ba 100644 (file)
                                                                <int key="NSvFlags">268</int>
                                                                <string key="NSFrame">{{0, 14}, {140, 25}}</string>
                                                                <reference key="NSSuperview"/>
                                                                <int key="NSvFlags">268</int>
                                                                <string key="NSFrame">{{0, 14}, {140, 25}}</string>
                                                                <reference key="NSSuperview"/>
-                                                               <reference key="NSWindow"/>
                                                                <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                <bool key="NSEnabled">YES</bool>
                                                                <object class="NSButtonCell" key="NSCell" id="850080795">
                                                                <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                <bool key="NSEnabled">YES</bool>
                                                                <object class="NSButtonCell" key="NSCell" id="850080795">
                                                                <int key="NSvFlags">268</int>
                                                                <string key="NSFrame">{{19, 14}, {67, 25}}</string>
                                                                <reference key="NSSuperview"/>
                                                                <int key="NSvFlags">268</int>
                                                                <string key="NSFrame">{{19, 14}, {67, 25}}</string>
                                                                <reference key="NSSuperview"/>
-                                                               <reference key="NSWindow"/>
                                                                <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                <bool key="NSEnabled">YES</bool>
                                                                <object class="NSSegmentedCell" key="NSCell" id="594076765">
                                                                <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                <bool key="NSEnabled">YES</bool>
                                                                <object class="NSSegmentedCell" key="NSCell" id="594076765">
                                                <reference ref="981531896"/>
                                                <reference ref="658903347"/>
                                        </array>
                                                <reference ref="981531896"/>
                                                <reference ref="658903347"/>
                                        </array>
-                                       <array class="NSMutableArray" key="NSToolbarIBDefaultItems">
+                                       <array key="NSToolbarIBDefaultItems">
                                                <reference ref="496378711"/>
                                                <reference ref="658903347"/>
                                                <reference ref="981531896"/>
                                                <reference ref="496378711"/>
                                                <reference ref="658903347"/>
                                                <reference ref="981531896"/>
                                                                                                                        <string key="NSFrameSize">{200, 298}</string>
                                                                                                                        <reference key="NSSuperview" ref="698362889"/>
                                                                                                                        <reference key="NSWindow"/>
                                                                                                                        <string key="NSFrameSize">{200, 298}</string>
                                                                                                                        <reference key="NSSuperview" ref="698362889"/>
                                                                                                                        <reference key="NSWindow"/>
-                                                                                                                       <reference key="NSNextKeyView" ref="1036252745"/>
+                                                                                                                       <reference key="NSNextKeyView" ref="892486973"/>
                                                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                                                        <bool key="NSControlAllowsExpansionToolTips">YES</bool>
                                                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                                                        <bool key="NSControlAllowsExpansionToolTips">YES</bool>
                                                                                        <string key="NSFrameSize">{202, 300}</string>
                                                                                        <reference key="NSSuperview" ref="977242492"/>
                                                                                        <reference key="NSWindow"/>
                                                                                        <string key="NSFrameSize">{202, 300}</string>
                                                                                        <reference key="NSSuperview" ref="977242492"/>
                                                                                        <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView" ref="892486973"/>
+                                                                                       <reference key="NSNextKeyView" ref="698362889"/>
                                                                                        <int key="NSsFlags">150034</int>
                                                                                        <reference key="NSVScroller" ref="1036252745"/>
                                                                                        <reference key="NSHScroller" ref="892486973"/>
                                                                                        <int key="NSsFlags">150034</int>
                                                                                        <reference key="NSVScroller" ref="1036252745"/>
                                                                                        <reference key="NSHScroller" ref="892486973"/>
                                                                                        <string key="NSFrame">{{227, 55}, {180, 24}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
                                                                                        <string key="NSFrame">{{227, 55}, {180, 24}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView"/>
                                                                                        <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                        <object class="NSSegmentedCell" key="NSCell" id="301345285">
                                                                                        <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                        <object class="NSSegmentedCell" key="NSCell" id="301345285">
                                                                                <string key="NSFrameSize">{198, 198}</string>
                                                                                <reference key="NSSuperview" ref="947403733"/>
                                                                                <reference key="NSWindow"/>
                                                                                <string key="NSFrameSize">{198, 198}</string>
                                                                                <reference key="NSSuperview" ref="947403733"/>
                                                                                <reference key="NSWindow"/>
-                                                                               <reference key="NSNextKeyView" ref="968378655"/>
+                                                                               <reference key="NSNextKeyView" ref="553414014"/>
                                                                                <bool key="NSEnabled">YES</bool>
                                                                                <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                <bool key="NSControlAllowsExpansionToolTips">YES</bool>
                                                                                <bool key="NSEnabled">YES</bool>
                                                                                <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                <bool key="NSControlAllowsExpansionToolTips">YES</bool>
                                                <string key="NSFrame">{{0, 20}, {200, 200}}</string>
                                                <reference key="NSSuperview" ref="671181514"/>
                                                <reference key="NSWindow"/>
                                                <string key="NSFrame">{{0, 20}, {200, 200}}</string>
                                                <reference key="NSSuperview" ref="671181514"/>
                                                <reference key="NSWindow"/>
-                                               <reference key="NSNextKeyView" ref="553414014"/>
+                                               <reference key="NSNextKeyView" ref="947403733"/>
                                                <int key="NSsFlags">150034</int>
                                                <reference key="NSVScroller" ref="968378655"/>
                                                <reference key="NSHScroller" ref="553414014"/>
                                                <int key="NSsFlags">150034</int>
                                                <reference key="NSVScroller" ref="968378655"/>
                                                <reference key="NSHScroller" ref="553414014"/>
                                                <string key="NSFrame">{{66, -1}, {134, 23}}</string>
                                                <reference key="NSSuperview" ref="671181514"/>
                                                <reference key="NSWindow"/>
                                                <string key="NSFrame">{{66, -1}, {134, 23}}</string>
                                                <reference key="NSSuperview" ref="671181514"/>
                                                <reference key="NSWindow"/>
-                                               <reference key="NSNextKeyView"/>
                                                <string key="NSReuseIdentifierKey">_NS:22</string>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSButtonCell" key="NSCell" id="517346822">
                                                <string key="NSReuseIdentifierKey">_NS:22</string>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSButtonCell" key="NSCell" id="517346822">
                                        </object>
                                        <int key="connectionID">825</int>
                                </object>
                                        </object>
                                        <int key="connectionID">825</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">window</string>
+                                               <reference key="source" ref="207406104"/>
+                                               <reference key="destination" ref="808667431"/>
+                                       </object>
+                                       <int key="connectionID">865</int>
+                               </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBActionConnection" key="connection">
                                                <string key="label">removePressed:</string>
                                <object class="IBConnectionRecord">
                                        <object class="IBActionConnection" key="connection">
                                                <string key="label">removePressed:</string>
                        <nil key="activeLocalization"/>
                        <dictionary class="NSMutableDictionary" key="localizations"/>
                        <nil key="sourceID"/>
                        <nil key="activeLocalization"/>
                        <dictionary class="NSMutableDictionary" key="localizations"/>
                        <nil key="sourceID"/>
-                       <int key="maxID">864</int>
+                       <int key="maxID">865</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">
                                                <string key="inputController">NJDeviceController</string>
                                                <string key="mappingsController">NJMappingsController</string>
                                                <string key="outputController">NJOutputController</string>
                                                <string key="inputController">NJDeviceController</string>
                                                <string key="mappingsController">NJMappingsController</string>
                                                <string key="outputController">NJOutputController</string>
+                                               <string key="window">NSWindow</string>
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
                                                <object class="IBToOneOutletInfo" key="dockMenuBase">
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
                                                <object class="IBToOneOutletInfo" key="dockMenuBase">
                                                        <string key="name">outputController</string>
                                                        <string key="candidateClassName">NJOutputController</string>
                                                </object>
                                                        <string key="name">outputController</string>
                                                        <string key="candidateClassName">NJOutputController</string>
                                                </object>
+                                               <object class="IBToOneOutletInfo" key="window">
+                                                       <string key="name">window</string>
+                                                       <string key="candidateClassName">NSWindow</string>
+                                               </object>
                                        </dictionary>
                                        <object class="IBClassDescriptionSource" key="sourceIdentifier">
                                                <string key="majorKey">IBProjectSource</string>
                                        </dictionary>
                                        <object class="IBClassDescriptionSource" key="sourceIdentifier">
                                                <string key="majorKey">IBProjectSource</string>
index b77f799..6488135 100644 (file)
@@ -12,6 +12,7 @@
 
 @interface EnjoyableApplicationDelegate : NSObject <NSApplicationDelegate> {
     IBOutlet NSMenu *dockMenuBase;
 
 @interface EnjoyableApplicationDelegate : NSObject <NSApplicationDelegate> {
     IBOutlet NSMenu *dockMenuBase;
+    IBOutlet NSWindow *window;
 }
 
 @property (nonatomic, strong) IBOutlet NJDeviceController *inputController;
 }
 
 @property (nonatomic, strong) IBOutlet NJDeviceController *inputController;
index 388103b..313ba9a 100644 (file)
@@ -15,8 +15,8 @@
 
 @implementation EnjoyableApplicationDelegate
 
 
 @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];
 }
 
     [self.mappingsController activateMappingForProcess:currentApp.localizedName];
 }
 
     [self.mappingsController load];
 }
 
     [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 {
 }
 
 - (void)eventTranslationActivated:(NSNotification *)note {
+    [NSProcessInfo.processInfo disableAutomaticTermination:@"Input translation is active."];
     [NSWorkspace.sharedWorkspace.notificationCenter
         addObserver:self
         selector:@selector(didSwitchApplication:)
     [NSWorkspace.sharedWorkspace.notificationCenter
         addObserver:self
         selector:@selector(didSwitchApplication:)
@@ -61,6 +67,7 @@
 }
 
 - (void)eventTranslationDeactivated:(NSNotification *)note {
 }
 
 - (void)eventTranslationDeactivated:(NSNotification *)note {
+    [NSProcessInfo.processInfo enableAutomaticTermination:@"Input translation is active."];
     [NSWorkspace.sharedWorkspace.notificationCenter
         removeObserver:self
         name:NSWorkspaceDidActivateApplicationNotification
     [NSWorkspace.sharedWorkspace.notificationCenter
         removeObserver:self
         name:NSWorkspaceDidActivateApplicationNotification
     int added = 0;
     for (NJMapping *mapping in mappings) {
         NSString *keyEquiv = ++added < 10 ? @(added).stringValue : @"";
     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.representedObject = mapping;
+        item.state = mapping == self.mappingsController.currentMapping;
+        [dockMenuBase addItem:item];
     }
     [_outputController refreshMappings];
 }
     }
     [_outputController refreshMappings];
 }
index 8deb6f0..2940aaf 100644 (file)
@@ -2,6 +2,10 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
+       <key>NSSupportsAutomaticTermination</key>
+       <string>YES</string>
+       <key>NSSupportsSuddenTermination</key>
+       <true/>
        <key>CFBundleDevelopmentRegion</key>
        <string>English</string>
        <key>CFBundleExecutable</key>
        <key>CFBundleDevelopmentRegion</key>
        <string>English</string>
        <key>CFBundleExecutable</key>
index 26ef35f..43f6282 100644 (file)
                       if (result != NSFileHandlingPanelOKButton)
                           return;
                       [panel close];
                       if (result != NSFileHandlingPanelOKButton)
                           return;
                       [panel close];
+                      [NSProcessInfo.processInfo disableSuddenTermination];
                       NSError *error;
                       NSDictionary *serialization = [mapping serialize];
                       NSData *json = [NSJSONSerialization dataWithJSONObject:serialization
                       NSError *error;
                       NSDictionary *serialization = [mapping serialize];
                       NSData *json = [NSJSONSerialization dataWithJSONObject:serialization
                       if (!error)
                           [json writeToURL:panel.URL options:NSDataWritingAtomic error:&error];
                       
                       if (!error)
                           [json writeToURL:panel.URL options:NSDataWritingAtomic error:&error];
                       
+                      [NSProcessInfo.processInfo enableSuddenTermination];
                       if (error) {
                           [window presentError:error
                                 modalForWindow:window
                       if (error) {
                           [window presentError:error
                                 modalForWindow:window