From a984e2dd951bcbfe5e3e6374213eb9a5fd5423cf Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 1 Dec 2016 06:58:56 -0500 Subject: Able to get a shortcut from the MASShortcutView Fuck damn it finally freaking works! Damn, just had to take a 1.5 hour nap after that. We're finally able to extract a shortcut out of the MASShortcutView. After trying a whole bunch of different things, I ultimately tried opening the debugger and figured out that for whatever reason the bindings weren't getting created and because of that my shortcut wasn't getting saved in the user defaults. Couldn't figure out how to get the binding to work even after includes and whatnot. Finally decided screw it I'm going to subclass the view and get the shortcut and store it in `NSUserDefaults` myself. So that's what we're going to do and this is the first step to getting that working. Hoo boy. Definitely need to vaccum the code after this. --- Low Battery Yup.d.xcodeproj/project.pbxproj | 6 ++ Low Battery Yup/AppDelegate.h | 6 +- Low Battery Yup/AppDelegate.m | 33 +++++++++- Low Battery Yup/ShortcutRecorder | 1 + Low Battery Yup/ShortcutView.h | 13 ++++ Low Battery Yup/ShortcutView.m | 19 ++++++ Low Battery Yup/en.lproj/MainMenu.xib | 98 +++++++++++++++++++++++++---- 7 files changed, 162 insertions(+), 14 deletions(-) create mode 160000 Low Battery Yup/ShortcutRecorder create mode 100644 Low Battery Yup/ShortcutView.h create mode 100644 Low Battery Yup/ShortcutView.m diff --git a/Low Battery Yup.d.xcodeproj/project.pbxproj b/Low Battery Yup.d.xcodeproj/project.pbxproj index 89d2710..157918d 100644 --- a/Low Battery Yup.d.xcodeproj/project.pbxproj +++ b/Low Battery Yup.d.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 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 */; }; @@ -48,6 +49,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + D15D90B51DF0465E001700CD /* ShortcutView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShortcutView.h; sourceTree = ""; }; + D15D90B61DF0465E001700CD /* ShortcutView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShortcutView.m; sourceTree = ""; }; 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; }; @@ -172,6 +175,8 @@ D195AE4F1DDC774200A53A18 /* MASShortcut.xcodeproj */, D1F809EE1DDC6AA0001671E9 /* AppDelegate.h */, D1F809EF1DDC6AA0001671E9 /* AppDelegate.m */, + D15D90B51DF0465E001700CD /* ShortcutView.h */, + D15D90B61DF0465E001700CD /* ShortcutView.m */, D1F809F11DDC6AA0001671E9 /* MainMenu.xib */, D1F809E31DDC6AA0001671E9 /* Supporting Files */, ); @@ -330,6 +335,7 @@ files = ( D1F809E91DDC6AA0001671E9 /* main.m in Sources */, D1F809F01DDC6AA0001671E9 /* AppDelegate.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 21e15f0..9621fd4 100644 --- a/Low Battery Yup/AppDelegate.h +++ b/Low Battery Yup/AppDelegate.h @@ -8,10 +8,14 @@ #import #import +#import +#import @interface AppDelegate : NSObject { IBOutlet NSWindow *window; - IBOutlet MASShortcutView *shortcut_view; + IBOutlet MASShortcutView *_shortcut_view; } +- (IBAction)logDefaults:(id)sender; + @end diff --git a/Low Battery Yup/AppDelegate.m b/Low Battery Yup/AppDelegate.m index 0c9bbdc..8a9005f 100644 --- a/Low Battery Yup/AppDelegate.m +++ b/Low Battery Yup/AppDelegate.m @@ -8,6 +8,9 @@ #import "AppDelegate.h" +static NSString *const kPreferenceGlobalShortcut = @"GlobalShortcut"; +static void *AppObservingContext = &AppObservingContext; + @implementation AppDelegate - (void)dealloc @@ -17,7 +20,35 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - // Insert code here to initialize your application + [_shortcut_view setAssociatedUserDefaultsKey:kPreferenceGlobalShortcut]; + +// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; +// [_shortcut_view bind:@"shortcutValue" toObject:defaults withKeyPath:@"thisisatest" options:nil]; + +// [defaults addObserver:self forKeyPath:@"thisisatest" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:AppObservingContext]; + +// [[MASShortcutBinder sharedBinder] +// bindShortcutWithDefaultsKey:kPreferenceGlobalShortcut +// toAction:^{NSLog(@"dudebro");}]; + +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + NSLog(@"OBSERVED"); + NSLog(@"%@", change); +} + +- (IBAction)logDefaults:(id)sender +{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSLog(@"%@", [defaults objectForKey:[@"values." stringByAppendingString:kPreferenceGlobalShortcut]]); +// NSLog(@"%@", [defaults objectForKey:kPreferenceGlobalShortcut]); +// NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]); + +// NSLog(@"%@", [_shortcut_view shortcutValue]); +// NSLog(@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"thisisatest"]); +// [[NSUserDefaults standardUserDefaults] setObject:@"dude come on" forKey:@"thisisatest"]; } @end diff --git a/Low Battery Yup/ShortcutRecorder b/Low Battery Yup/ShortcutRecorder new file mode 160000 index 0000000..3adf590 --- /dev/null +++ b/Low Battery Yup/ShortcutRecorder @@ -0,0 +1 @@ +Subproject commit 3adf5909a503b6ebf769a1e2a24fc389a3556ed3 diff --git a/Low Battery Yup/ShortcutView.h b/Low Battery Yup/ShortcutView.h new file mode 100644 index 0000000..c30b08a --- /dev/null +++ b/Low Battery Yup/ShortcutView.h @@ -0,0 +1,13 @@ +// +// ShortcutView.h +// Low Battery Yup.d +// +// Created by TW on 12/1/16. +// Copyright (c) 2016 TW. All rights reserved. +// + +#import + +@interface ShortcutView : MASShortcutView + +@end diff --git a/Low Battery Yup/ShortcutView.m b/Low Battery Yup/ShortcutView.m new file mode 100644 index 0000000..5604834 --- /dev/null +++ b/Low Battery Yup/ShortcutView.m @@ -0,0 +1,19 @@ +// +// ShortcutView.m +// Low Battery Yup.d +// +// Created by TW on 12/1/16. +// Copyright (c) 2016 TW. All rights reserved. +// + +#import "ShortcutView.h" + +@implementation ShortcutView + +- (void)setShortcutValue:(MASShortcut *)shortcutValue +{ + [super setShortcutValue:shortcutValue]; + NSLog(@"%@", shortcutValue); +} + +@end diff --git a/Low Battery Yup/en.lproj/MainMenu.xib b/Low Battery Yup/en.lproj/MainMenu.xib index 44ef13e..989bd27 100644 --- a/Low Battery Yup/en.lproj/MainMenu.xib +++ b/Low Battery Yup/en.lproj/MainMenu.xib @@ -11,6 +11,8 @@ 2844 + NSButton + NSButtonCell NSCustomObject NSCustomView NSMenu @@ -1305,21 +1307,50 @@ 256 - + 268 {{84, 83}, {313, 19}} + + _NS:9 + ShortcutView + + + + 268 + {{211, 18}, {192, 32}} + + _NS:9 - MASShortcutView + YES + + 67108864 + 134217728 + Defaults? + + LucidaGrande + 13 + 1044 + + _NS:9 + + -2038284288 + 129 + + + 200 + 25 + + NO {480, 185} - + {{0, 0}, {1440, 878}} {480, 207} @@ -2019,10 +2050,18 @@ shortcut_view - + 537 + + + logDefaults: + + + + 540 + @@ -2548,7 +2587,8 @@ 372 - + + @@ -3027,9 +3067,22 @@ 536 - + + + + + 538 + + + + + + 539 + + + @@ -3176,6 +3229,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3195,20 +3250,35 @@ - 537 + 540 AppDelegate NSObject + + logDefaults: + id + + + logDefaults: + + logDefaults: + id + + + MASShortcutView MASShortcutView NSTextField - MASShortcutView NSWindow + + _shortcut_view + MASShortcutView + customShortcutView MASShortcutView @@ -3217,10 +3287,6 @@ feedbackTextField NSTextField - - shortcut_view - MASShortcutView - window NSWindow @@ -3239,6 +3305,14 @@ ./Classes/MASShortcutView.h + + ShortcutView + MASShortcutView + + IBProjectSource + ./Classes/ShortcutView.h + + 0 -- cgit v1.2.3