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

Configure shortcut keys #4

Open
ghost opened this issue Oct 17, 2016 · 3 comments
Open

Configure shortcut keys #4

ghost opened this issue Oct 17, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 17, 2016

There's a lot of duplicated code inside createMenuBarAndToolBar() that can be refactored:

Messages.get

Can be:

import static Messages.get;
//...
get

The reference to MainWindow. should be abstracted. For example:

    Action fileNewAction = new Action(Messages.get("MainWindow.fileNewAction"), "Shortcut+N", FILE_ALT, e -> fileNew());

can become:

    Action fileNewAction = createAction("fileNewAction"), FILE_ALT, e -> fileNew());

Similarly:

    Action insertBlockquoteAction = createAction("insertBlockquoteAction", QUOTE_LEFT, e -> getActiveEditor().surroundSelection("\n\n> "), activeFileEditorIsNull);

Once these simplifications are made, the "createAction" method can use a configuration property value to look up the associated shortcut value. For example:

keyboard.modifier.separator=+
keyboard.shortcut=Shortcut${keyboard.modifier.separator}
keyboard.ctrl=Ctrl${keyboard.modifier.separator}
keyboard.action.fileNewAction=${keyboard.shortcut}n
keyboard.action.insertBlockquoteAction=${keyboard.ctrl}q

Note also that Ctrl+q should be distinguishable from Ctrl+Q, which could be a short-hand for Ctrl+Shift+q.

@ghost ghost changed the title Use import static ... Configure shortcut keys Oct 17, 2016
@JFormDesigner
Copy link
Owner

Sure, using static imports and additional helper function can make the code shorter. I'll have a look...

Moving the shortcut keys to messages.properties makes them only localizable, but not configurable (by the user) because this file is in the JAR and not changeable by the user.

@ghost
Copy link
Author

ghost commented Oct 19, 2016

Moving the shortcut keys to messages.properties makes them only localizable, but not configurable (by the user) because this file is in the JAR and not changeable by the user.

Right, of course. Perhaps they can move into the preferences?

@JFormDesigner
Copy link
Owner

Yes, a 'Shortcut Keys' tab in the Options dialog would be nice.

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

1 participant