Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set hotkey combo programatically #69

Closed
c-alpha opened this issue Apr 10, 2017 · 2 comments
Closed

Set hotkey combo programatically #69

c-alpha opened this issue Apr 10, 2017 · 2 comments

Comments

@c-alpha
Copy link

c-alpha commented Apr 10, 2017

Hi @Kentzo, many thanks for your modernisation efforts!

I am currently converting a project which used @ChrisForsythe's initial ShortcutRecorder to now use your new incarnation. It's a plugin for Apple's Mail.app, and I am hence handling the prefs file manually to make sure I don't "pollute" Apple's prefs file but store stuff in a separate file. Hence, I'm not binding to a NSUserDefaultsController, but need to set and get the hotkey and modifier flags between my SRRecorderControl and NSUserDefaults instances manually.

I can infer any new shortcut that was entered in the -shortcutRecorderDidEndRecording: delegate method by inspecting the objectValue just fine.

What I am lacking is a way of setting the hotkey and modifier when Mail.app is started and the plugin gets loaded, so that when the UI is opened for the first time, it shows the values that were read from the prefs file. With the old SRRecorderControl, I would do something like this:

KeyCombo    hotkeyCombo;
hotkeyCombo.flags = [m_settings getHotKeyModifierFlags];
hotkeyCombo.code  = [m_settings getHotKey];
[hotkeyController setKeyCombo:hotkeyCombo];

But with your new code I don't seem to be able to achieve something similar?

The SRRecorderControl is created by code generated by Interface Builder, so in case you should eye adding a new method for this, it cannot be any sort of init method, but should be a dedicated one. Off the top of my head, - (void) setCodeAndFlags:(NSDictionary*)hotkey could e.g. spring to mind.

@c-alpha
Copy link
Author

c-alpha commented Apr 10, 2017

[...]
The SRRecorderControl is created by code generated by Interface Builder, so in case you should eye adding a new method for this, it cannot be any sort of init method, but should be a dedicated one. Off the top of my head, - (void) setCodeAndFlags:(NSDictionary*)hotkey could e.g. spring to mind.

Actually, rethinking it, it would seem that something along the lines of - (void) setCode:(NSInteger)newCode andFlags:(NSUInteger)newFlags could make more sense; wouldn't require me to furnish stuff that's palatable to ShortcutRecorder 2's internal workings.

@Kentzo
Copy link
Owner

Kentzo commented Apr 11, 2017

@c-alpha The control supports Cocoa bindings so you should use setObjectValue: where objectValue is a dict created with SRShortcutWithCocoaModifierFlagsAndKeyCode or manually populated.

@Kentzo Kentzo closed this as completed Apr 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants