markdown-writer-fx icon indicating copy to clipboard operation
markdown-writer-fx copied to clipboard

Configure shortcut keys

Open ghost opened this issue 9 years ago • 3 comments

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 avatar Oct 17 '16 00:10 ghost

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.

JFormDesigner avatar Oct 18 '16 18:10 JFormDesigner

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?

ghost avatar Oct 19 '16 04:10 ghost

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

JFormDesigner avatar Oct 20 '16 16:10 JFormDesigner