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

Allow to use in XIB #14

Closed
p0deje opened this issue Jun 18, 2020 · 4 comments
Closed

Allow to use in XIB #14

p0deje opened this issue Jun 18, 2020 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@p0deje
Copy link

p0deje commented Jun 18, 2020

Hello, thank you for the great package!

I'm trying to figure out how to use recorded in Interface Builder? I'd normally add custom view and set its class to KeyboardShortcuts.RecorderCocoa but it doesn't work. I couldn't find any documentation about this too.

Is it possible to use KeyboardShortcuts.RecorderCocoa from XIB files?

p0deje added a commit to p0deje/Maccy that referenced this issue Jun 20, 2020
Replaces the global hotkey library from combination of KeyHolder,
Magnet and Sauce to KeyboardShortcuts.

The package has few benefits:

1. More native-like UI.
2. Better non-US keyboard support (fixes #108).
3. Built-in storage via UserDefaults.

The package has few limitations:

1. Storage key and type is hardcoded. This requires us to migrate from
   old "hotKey" string preference to "KeyboardShortcuts_popup" JSON
   preference.
2. There is no way to initialize KeyboardShortcuts.Key with character
   string. This is needed for migration. To workaround the limitation,
   Sauce package is left and is used to construct the key from string,
   retrieve key code from it and construct KeyboardShortcuts.Key with
   it.
3. There is no support for default shortcuts. This is addressed in
   sindresorhus/KeyboardShortcuts#13, which is why forked branch is used.
4. Recorder view cannot be previewed in Interface Builder:
   sindresorhus/KeyboardShortcuts#14.
5. It's impossible to register the same shortcut twice:
   sindresorhus/KeyboardShortcuts#15.

The package is great even with all these limitations. The most important
piece is of course better non-US keyboard support. DVORAK is supported
as well.
@sindresorhus
Copy link
Owner

That was not implemented as I had problems in the past where Interface Builder wouldn't display custom views from a package, and also, it's not something I needed personally. Happy to accept a PR to add it, but it's not something I plan to work on.

It's probably the easiest to just add a custom view in Interface Builder, get an outlet reference, and then programmatically add RecorderCocoa as a subview. I can document that in the readme.

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Jun 22, 2020
@p0deje
Copy link
Author

p0deje commented Jun 22, 2020

Fair enough - the package is great without it as well.

I managed to get it working but I don't know Cocoa programming well enough and it took me some time to figure it out. I was migrating from https://github.com/Clipy/KeyHolder which has this feature and it's nice to see what you get in XIB files (though there are additional workarounds I had to do make it work Clipy/KeyHolder#6).

I'm not experienced enough to send a PR to add this. Feel free to close the issue if you want.

@L1cardo
Copy link
Contributor

L1cardo commented Aug 28, 2020

This will be really nice if we can just drag a KeyboardShortcuts.RecorderCocoa to storyboard.
I don't know if this can be done now, but it seems that Swift5.3 allows to attach xib resources to Swift Packages.
Maybe I can do something on this, but no promises.

@sindresorhus
Copy link
Owner

I have decided to pass on this. SwiftUI is quickly maturing and I personally don't have any XIB/Storyboard usage left to warrant maintaining this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants