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

How to apply the KeyBinding Manager to invoke an external program configured for the OpenWith... command? #1083

Closed
jbridgy opened this issue Mar 10, 2024 · 8 comments

Comments

@jbridgy
Copy link

jbridgy commented Mar 10, 2024

I am glad to see that mm's KeyBinding Manager has been improved recently, especially because I hope that it would fulfill also the last part of feature request #947. However, I could not figure out how to extend MarkdownMonster-KeyBindings.json properly.

I also asked ChatGPT 4 which responded:

In Markdown Monster version 3.2, you can bind any of MM's internal commands, including custom commands like invoking an external program, to a keyboard shortcut.
...
However, the exact details on how to specify this binding for an external program invocation are not directly provided in the release notes.

Please give me an example which may also be added to the fine Markdown Monster Documentation.

@RickStrahl
Copy link
Owner

It's not currently supported since the external programs are not bound to known commands.

However, after giving this some thought I think what I can do is add an option to provide a "KeyboardShortcut" to the entry in ExternalPrograms and then attempt to add that shortcut to the keybindings.

The main issue with a short cut is that there will be no context. So this would have to be generically tied to the editor surface. It won't work in the folder browser.

image

@jbridgy
Copy link
Author

jbridgy commented Mar 10, 2024

Applying the "KeyboardShortcut" option for "ExternalPrograms" always to the current document (if one exists)
would be a pragmatic solution for me. However, for the sake of safety the current context could be taken into account as follows:

  • If no specific file can reasonably be associated with the current context then mm could ignore the shortcut (or invoke the external program without "Args"). Example: The Table Editor is closely related to the current document. Nevertheless it seems not reasonable to edit the current document with an external editor while the Table Editor is open. Furthermore the option "SaveBeforeActivation" would probably be hard to handle in the context of the Table Editor.

  • Otherwise the external program is invoked. If the line number ({1}) and column number ({2}) are not available in the current context then use the default value 1.

@RickStrahl
Copy link
Owner

The keyboard bindings are not global - they are tied to the editor anyway so they won't work outside of that context regardless. There are bindings in the UI that forward to other tasks, but those are implementation specific and is not something that you would be linking to. External programs thus are tied to the editor surface only. So it won't work in the table editor.

The External program shortcuts are added to context menus in various contexts so they may apply to files in the folder browser, the editor and a few other places, but that's explicitly made so by the application. There's no way to make this more generic. As it is it'll be hard enough to find key combos that can actually be used and not interfere with existing behavior.

I've renamed the key to EditorKeyboardShortcut to make it more explicit - the editor opens the file and if line and row are available they are applied (depends you your command line format ie. "{0}:{1}:{2}" -g for example for VS code).

@jbridgy
Copy link
Author

jbridgy commented Mar 11, 2024

I tested the new option of ExternalPrograms with mm v3.2.5 and found the following issue:

Pressing the keyboard shortcut configured with the new option EditorKeyboardShortcut and clicking the corresponding context menu item such as Open...>Edit With MyFavoriteEditor do not behave identically if the current document has been modified and the external program is configured with "SaveBeforeActivation": false.
The former shows the following dialog as expected:
image

The latter opens the modified document with the external program immediately, without confirmation. This is risky when you switch often between mm and a source code editor, as I do.

@RickStrahl
Copy link
Owner

Ah that's a good point. I have to move the original code into the command and then use the command in both places. Currently the shortcut menu option is inline.

Will take a look.

@RickStrahl
Copy link
Owner

RickStrahl commented Mar 12, 2024

Updated in 3.2.6

It ended up not being quite so easy because of the different use cases where the execution can be run from. I ended up with a helper that manages the saving of the file if unsaved consistently that is called from the calling context.

FWIW, the two contexts are a file in the Folder Browser, or from within the editor and the current file.

@jbridgy
Copy link
Author

jbridgy commented Mar 12, 2024

It works like a charm. Thank you so much! I can use this little time saver very often when writing documentation.

@RickStrahl
Copy link
Owner

Thanks for the feedback! Aloha.

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