diff options
Diffstat (limited to 'Low Battery Yup')
| -rw-r--r-- | Low Battery Yup/AppDelegate.h | 9 | ||||
| -rw-r--r-- | Low Battery Yup/AppDelegate.m | 10 | ||||
| -rw-r--r-- | Low Battery Yup/Constants.h | 1 | ||||
| m--------- | Low Battery Yup/ShortcutRecorder | 0 | ||||
| -rw-r--r-- | Low Battery Yup/ShortcutView.h | 15 | ||||
| -rw-r--r-- | Low Battery Yup/ShortcutView.m | 26 | ||||
| -rw-r--r-- | Low Battery Yup/en.lproj/MainMenu.xib | 106 |
7 files changed, 93 insertions, 74 deletions
diff --git a/Low Battery Yup/AppDelegate.h b/Low Battery Yup/AppDelegate.h index ad3458f..3998e46 100644 --- a/Low Battery Yup/AppDelegate.h +++ b/Low Battery Yup/AppDelegate.h @@ -7,9 +7,12 @@ // #import <Cocoa/Cocoa.h> +#import <MASShortcut/MASShortcut.h> +#import "ShortcutView.h" -@interface AppDelegate : NSObject <NSApplicationDelegate> - -@property (assign) IBOutlet NSWindow *window; +@interface AppDelegate : NSObject <NSApplicationDelegate> { + IBOutlet NSWindow *window; + IBOutlet ShortcutView *_shortcut_view; +} @end diff --git a/Low Battery Yup/AppDelegate.m b/Low Battery Yup/AppDelegate.m index e5b9d90..83d03ae 100644 --- a/Low Battery Yup/AppDelegate.m +++ b/Low Battery Yup/AppDelegate.m @@ -7,6 +7,7 @@ // #import "AppDelegate.h" +#import "Constants.h" @implementation AppDelegate @@ -17,7 +18,14 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - // Insert code here to initialize your application + NSDictionary *saved_shortcut; + if ((saved_shortcut = [[NSUserDefaults standardUserDefaults] objectForKey:kPreferenceGlobalShortcut])) { + MASShortcut *shortcut = [MASShortcut + shortcutWithKeyCode:[[saved_shortcut objectForKey:@"keyCode"] unsignedIntegerValue] + modifierFlags:[[saved_shortcut objectForKey:@"modifierFlags"] unsignedIntegerValue]]; + + [_shortcut_view setShortcutValue:shortcut]; + } } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication diff --git a/Low Battery Yup/Constants.h b/Low Battery Yup/Constants.h new file mode 100644 index 0000000..8652225 --- /dev/null +++ b/Low Battery Yup/Constants.h @@ -0,0 +1 @@ +#define kPreferenceGlobalShortcut @"GlobalShortcut" diff --git a/Low Battery Yup/ShortcutRecorder b/Low Battery Yup/ShortcutRecorder new file mode 160000 +Subproject 3adf5909a503b6ebf769a1e2a24fc389a3556ed diff --git a/Low Battery Yup/ShortcutView.h b/Low Battery Yup/ShortcutView.h new file mode 100644 index 0000000..5eacb52 --- /dev/null +++ b/Low Battery Yup/ShortcutView.h @@ -0,0 +1,15 @@ +// +// ShortcutView.h +// Low Battery Yup.d +// +// Created by TW on 12/1/16. +// Copyright (c) 2016 TW. All rights reserved. +// + +#import <MASShortcut/MASShortcutView.h> + +@interface ShortcutView : MASShortcutView + +- (void)setShortcutValue:(MASShortcut *)shortcutValue; + +@end diff --git a/Low Battery Yup/ShortcutView.m b/Low Battery Yup/ShortcutView.m new file mode 100644 index 0000000..3dc2ff3 --- /dev/null +++ b/Low Battery Yup/ShortcutView.m @@ -0,0 +1,26 @@ +// +// ShortcutView.m +// Low Battery Yup.d +// +// Created by TW on 12/1/16. +// Copyright (c) 2016 TW. All rights reserved. +// + +#import "ShortcutView.h" +#import "Constants.h" + +@implementation ShortcutView + +- (void)setShortcutValue:(MASShortcut *)shortcutValue +{ + [super setShortcutValue:shortcutValue]; + + NSDictionary *shortcut = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithInteger:[shortcutValue keyCode]], @"keyCode", + [NSNumber numberWithInteger:[shortcutValue modifierFlags]], @"modifierFlags", + nil]; + + [[NSUserDefaults standardUserDefaults] setObject:shortcut forKey:kPreferenceGlobalShortcut]; +} + +@end diff --git a/Low Battery Yup/en.lproj/MainMenu.xib b/Low Battery Yup/en.lproj/MainMenu.xib index 1d99a3a..4b01316 100644 --- a/Low Battery Yup/en.lproj/MainMenu.xib +++ b/Low Battery Yup/en.lproj/MainMenu.xib @@ -12,10 +12,9 @@ </object> <array key="IBDocument.IntegratedClassDependencies"> <string>NSCustomObject</string> + <string>NSCustomView</string> <string>NSMenu</string> <string>NSMenuItem</string> - <string>NSTextField</string> - <string>NSTextFieldCell</string> <string>NSView</string> <string>NSWindowTemplate</string> </array> @@ -1294,65 +1293,36 @@ <object class="NSWindowTemplate" id="972006081"> <int key="NSWindowStyleMask">15</int> <int key="NSWindowBacking">2</int> - <string key="NSWindowRect">{{335, 390}, {480, 180}}</string> + <string key="NSWindowRect">{{335, 390}, {480, 185}}</string> <int key="NSWTFlags">1954021376</int> <string key="NSWindowTitle">Low Battery Yup</string> <string key="NSWindowClass">NSWindow</string> <nil key="NSViewClass"/> <nil key="NSUserInterfaceItemIdentifier"/> + <string key="NSWindowContentMaxSize">{480, 185}</string> + <string key="NSWindowContentMinSize">{480, 185}</string> <object class="NSView" key="NSWindowView" id="439893737"> <reference key="NSNextResponder"/> <int key="NSvFlags">256</int> <array class="NSMutableArray" key="NSSubviews"> - <object class="NSTextField" id="287633878"> + <object class="NSCustomView" id="489226571"> <reference key="NSNextResponder" ref="439893737"/> <int key="NSvFlags">268</int> - <string key="NSFrame">{{110, 79}, {261, 22}}</string> + <string key="NSFrame">{{84, 83}, {313, 19}}</string> <reference key="NSSuperview" ref="439893737"/> <reference key="NSWindow"/> <string key="NSReuseIdentifierKey">_NS:9</string> - <bool key="NSEnabled">YES</bool> - <object class="NSTextFieldCell" key="NSCell" id="414421354"> - <int key="NSCellFlags">-1804599231</int> - <int key="NSCellFlags2">272630784</int> - <string key="NSContents"/> - <object class="NSFont" key="NSSupport"> - <string key="NSName">LucidaGrande</string> - <double key="NSSize">13</double> - <int key="NSfFlags">1044</int> - </object> - <string key="NSCellIdentifier">_NS:9</string> - <reference key="NSControlView" ref="287633878"/> - <bool key="NSDrawsBackground">YES</bool> - <object class="NSColor" key="NSBackgroundColor"> - <int key="NSColorSpace">6</int> - <string key="NSCatalogName">System</string> - <string key="NSColorName">textBackgroundColor</string> - <object class="NSColor" key="NSColor"> - <int key="NSColorSpace">3</int> - <bytes key="NSWhite">MQA</bytes> - </object> - </object> - <object class="NSColor" key="NSTextColor"> - <int key="NSColorSpace">6</int> - <string key="NSCatalogName">System</string> - <string key="NSColorName">textColor</string> - <object class="NSColor" key="NSColor"> - <int key="NSColorSpace">3</int> - <bytes key="NSWhite">MAA</bytes> - </object> - </object> - </object> - <bool key="NSAllowsLogicalLayoutDirection">NO</bool> + <string key="NSClassName">ShortcutView</string> </object> </array> - <string key="NSFrameSize">{480, 180}</string> + <string key="NSFrameSize">{480, 185}</string> <reference key="NSSuperview"/> <reference key="NSWindow"/> - <reference key="NSNextKeyView" ref="287633878"/> + <reference key="NSNextKeyView" ref="489226571"/> </object> - <string key="NSScreenRect">{{0, 0}, {1440, 878}}</string> - <string key="NSMaxSize">{10000000000000, 10000000000000}</string> + <string key="NSScreenRect">{{0, 0}, {2560, 1578}}</string> + <string key="NSMinSize">{480, 207}</string> + <string key="NSMaxSize">{480, 207}</string> <bool key="NSWindowIsRestorable">YES</bool> </object> <object class="NSCustomObject" id="976324537"> @@ -2044,6 +2014,14 @@ </object> <int key="connectionID">532</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">_shortcut_view</string> + <reference key="source" ref="976324537"/> + <reference key="destination" ref="489226571"/> + </object> + <int key="connectionID">541</int> + </object> </array> <object class="IBMutableOrderedSet" key="objectRecords"> <array key="orderedObjects"> @@ -2569,7 +2547,7 @@ <int key="objectID">372</int> <reference key="object" ref="439893737"/> <array class="NSMutableArray" key="children"> - <reference ref="287633878"/> + <reference ref="489226571"/> </array> <reference key="parent" ref="972006081"/> </object> @@ -3048,17 +3026,9 @@ </object> <object class="IBObjectRecord"> <int key="objectID">536</int> - <reference key="object" ref="287633878"/> - <array class="NSMutableArray" key="children"> - <reference ref="414421354"/> - </array> + <reference key="object" ref="489226571"/> <reference key="parent" ref="439893737"/> </object> - <object class="IBObjectRecord"> - <int key="objectID">537</int> - <reference key="object" ref="414421354"/> - <reference key="parent" ref="287633878"/> - </object> </array> </object> <dictionary class="NSMutableDictionary" key="flattenedProperties"> @@ -3122,6 +3092,8 @@ <string key="350.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="351.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="354.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> + <boolean value="NO" key="371.IBNSWindowAutoPositionCentersHorizontal"/> + <boolean value="NO" key="371.IBNSWindowAutoPositionCentersVertical"/> <string key="371.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="371.IBWindowTemplateEditedContentRect">{{380, 496}, {480, 360}}</string> <integer value="1" key="371.NSWindowTemplate.visibleAtLaunch"/> @@ -3202,10 +3174,7 @@ <string key="516.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="517.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="534.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="536.CustomClassName">DDHotKeyTextField</string> <string key="536.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="537.CustomClassName">DDHotKeyTextFieldCell</string> - <string key="537.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="56.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="57.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="58.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -3225,7 +3194,7 @@ <nil key="activeLocalization"/> <dictionary class="NSMutableDictionary" key="localizations"/> <nil key="sourceID"/> - <int key="maxID">537</int> + <int key="maxID">541</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <array class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -3233,11 +3202,16 @@ <string key="className">AppDelegate</string> <string key="superclassName">NSObject</string> <dictionary class="NSMutableDictionary" key="outlets"> + <string key="_shortcut_view">ShortcutView</string> <string key="customShortcutView">MASShortcutView</string> <string key="feedbackTextField">NSTextField</string> <string key="window">NSWindow</string> </dictionary> <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName"> + <object class="IBToOneOutletInfo" key="_shortcut_view"> + <string key="name">_shortcut_view</string> + <string key="candidateClassName">ShortcutView</string> + </object> <object class="IBToOneOutletInfo" key="customShortcutView"> <string key="name">customShortcutView</string> <string key="candidateClassName">MASShortcutView</string> @@ -3257,27 +3231,19 @@ </object> </object> <object class="IBPartialClassDescription"> - <string key="className">DDHotKeyTextField</string> - <string key="superclassName">NSTextField</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> - <string key="minorKey">./Classes/DDHotKeyTextField.h</string> - </object> - </object> - <object class="IBPartialClassDescription"> - <string key="className">DDHotKeyTextFieldCell</string> - <string key="superclassName">NSTextFieldCell</string> + <string key="className">MASShortcutView</string> + <string key="superclassName">NSView</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> - <string key="minorKey">./Classes/DDHotKeyTextFieldCell.h</string> + <string key="minorKey">./Classes/MASShortcutView.h</string> </object> </object> <object class="IBPartialClassDescription"> - <string key="className">MASShortcutView</string> - <string key="superclassName">NSView</string> + <string key="className">ShortcutView</string> + <string key="superclassName">MASShortcutView</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> - <string key="minorKey">./Classes/MASShortcutView.h</string> + <string key="minorKey">./Classes/ShortcutView.h</string> </object> </object> </array> |
