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 32c3a8641edd368c3350758ffc7e83c29c11a6e4..00740ba8f728e5ca2acffa93767e472e18aa25b9 100644 (file)
                                                                <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">
                                                                <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">
                                                <reference ref="981531896"/>
                                                <reference ref="658903347"/>
                                        </array>
-                                       <array class="NSMutableArray" key="NSToolbarIBDefaultItems">
+                                       <array key="NSToolbarIBDefaultItems">
                                                <reference ref="496378711"/>
                                                <reference ref="658903347"/>
                                                <reference ref="981531896"/>
                                                                                                                        <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>
                                                                                        <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"/>
                                                                                        <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="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>
                                                <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"/>
                                                <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">
                                        </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>
                        <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">
                                                <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">
                                                        <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>
index b77f799e6879220960689d4ce1739ae100ac424c..648813585e08d38763e1c81489e1a4a4bc4d4d1b 100644 (file)
@@ -12,6 +12,7 @@
 
 @interface EnjoyableApplicationDelegate : NSObject <NSApplicationDelegate> {
     IBOutlet NSMenu *dockMenuBase;
+    IBOutlet NSWindow *window;
 }
 
 @property (nonatomic, strong) IBOutlet NJDeviceController *inputController;
index 388103b38e2a8b867a9640a629bbbe1608960d27..313ba9a2fbf65df4a82e89369a7ceade015b0204 100644 (file)
@@ -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];
 }
 
     [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
     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];
 }
index 8deb6f020e1111a88869bacd5cbb77ddf40cc586..2940aaf7ebaee21e72ec4e46f96aef91f283c422 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>
+       <key>NSSupportsAutomaticTermination</key>
+       <string>YES</string>
+       <key>NSSupportsSuddenTermination</key>
+       <true/>
        <key>CFBundleDevelopmentRegion</key>
        <string>English</string>
        <key>CFBundleExecutable</key>
index 26ef35f7754f4550ef6d02706515d932512bc3a2..43f6282a4fc6876814fd4c2e439a34becffa43da 100644 (file)
                       if (result != NSFileHandlingPanelOKButton)
                           return;
                       [panel close];
+                      [NSProcessInfo.processInfo disableSuddenTermination];
                       NSError *error;
                       NSDictionary *serialization = [mapping serialize];
                       NSData *json = [NSJSONSerialization dataWithJSONObject:serialization
                       if (!error)
                           [json writeToURL:panel.URL options:NSDataWritingAtomic error:&error];
                       
+                      [NSProcessInfo.processInfo enableSuddenTermination];
                       if (error) {
                           [window presentError:error
                                 modalForWindow:window