diff options
| -rw-r--r-- | Low Battery Yup.d.xcodeproj/project.pbxproj | 8 | ||||
| -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 |
8 files changed, 101 insertions, 74 deletions
diff --git a/Low Battery Yup.d.xcodeproj/project.pbxproj b/Low Battery Yup.d.xcodeproj/project.pbxproj index ac058e8..2402b65 100644 --- a/Low Battery Yup.d.xcodeproj/project.pbxproj +++ b/Low Battery Yup.d.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ D1871D081DE094C200B8030D /* DDHotKeyUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = D1A37AF01DE001770022434D /* DDHotKeyUtilities.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; D1871D091DE0955E00B8030D /* DDHotKeyCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = D123F5A71DDF9D2400A27B7A /* DDHotKeyCenter.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; D1871D0A1DE0957C00B8030D /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A37AED1DE0012C0022434D /* Carbon.framework */; }; + D15D90B71DF0465E001700CD /* ShortcutView.m in Sources */ = {isa = PBXBuildFile; fileRef = D15D90B61DF0465E001700CD /* ShortcutView.m */; }; D18C94A31DDC33CF00E03F87 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D18C94A21DDC33CF00E03F87 /* Cocoa.framework */; }; D18C94AD1DDC33CF00E03F87 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D18C94AB1DDC33CF00E03F87 /* InfoPlist.strings */; }; D18C94AF1DDC33CF00E03F87 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D18C94AE1DDC33CF00E03F87 /* main.m */; }; @@ -59,6 +60,8 @@ D123F5A71DDF9D2400A27B7A /* DDHotKeyCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DDHotKeyCenter.m; path = DDHotKey/DDHotKeyCenter.m; sourceTree = "<group>"; }; D1871D051DE094AB00B8030D /* DDHotKeyTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DDHotKeyTextField.h; path = DDHotKey/DDHotKeyTextField.h; sourceTree = "<group>"; }; D1871D061DE094AB00B8030D /* DDHotKeyTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DDHotKeyTextField.m; path = DDHotKey/DDHotKeyTextField.m; sourceTree = "<group>"; }; + D15D90B51DF0465E001700CD /* ShortcutView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShortcutView.h; sourceTree = "<group>"; }; + D15D90B61DF0465E001700CD /* ShortcutView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShortcutView.m; sourceTree = "<group>"; }; D18C949E1DDC33CF00E03F87 /* Low Battery Yup.d.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Low Battery Yup.d.app"; sourceTree = BUILT_PRODUCTS_DIR; }; D18C94A21DDC33CF00E03F87 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; D18C94A51DDC33CF00E03F87 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; @@ -77,6 +80,7 @@ D1A37AED1DE0012C0022434D /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; }; D1A37AEF1DE001770022434D /* DDHotKeyUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DDHotKeyUtilities.h; path = DDHotKey/DDHotKeyUtilities.h; sourceTree = "<group>"; }; D1A37AF01DE001770022434D /* DDHotKeyUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DDHotKeyUtilities.m; path = DDHotKey/DDHotKeyUtilities.m; sourceTree = "<group>"; }; + D19DF1F41DF09CF30094C50F /* Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = "<group>"; }; D1F809DF1DDC6AA0001671E9 /* Low Battery Yup.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Low Battery Yup.app"; sourceTree = BUILT_PRODUCTS_DIR; }; D1F809E41DDC6AA0001671E9 /* Low Battery Yup-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Low Battery Yup-Info.plist"; sourceTree = "<group>"; }; D1F809E61DDC6AA0001671E9 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; @@ -203,6 +207,9 @@ D195AE4F1DDC774200A53A18 /* MASShortcut.xcodeproj */, D1F809EE1DDC6AA0001671E9 /* AppDelegate.h */, D1F809EF1DDC6AA0001671E9 /* AppDelegate.m */, + D19DF1F41DF09CF30094C50F /* Constants.h */, + D15D90B51DF0465E001700CD /* ShortcutView.h */, + D15D90B61DF0465E001700CD /* ShortcutView.m */, D1F809F11DDC6AA0001671E9 /* MainMenu.xib */, D1F809E31DDC6AA0001671E9 /* Supporting Files */, ); @@ -366,6 +373,7 @@ D1871D071DE094AB00B8030D /* DDHotKeyTextField.m in Sources */, D1871D081DE094C200B8030D /* DDHotKeyUtilities.m in Sources */, D1871D091DE0955E00B8030D /* DDHotKeyCenter.m in Sources */, + D15D90B71DF0465E001700CD /* ShortcutView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 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> |
