A few plugin dev questions

The following post might be a bit long, but I thought I just used one topic instead of opening 5 separate ones. These are not theoretical questions, but limits/restrictions I came across when writing my plugin.

  1. Can I disable menu items, commands/shortcuts, and toolbar icons when using the WYSIWYG editor? Or better yet, not show them at all.
    When my plugin is active, it makes a mess when used with the WYSIWYG editor.

  2. Is there an unregister command (and something similar for menu item and toolbar icons)? e.g. let's say the plugin has a settings page that allows users to enable/disable these actions.
    It seems that Joplin has to be restarted (to check at startup the settings and either register or not), but it would be great if there was a way to allow a dynamic change.

  3. Toolbar icons are always added to the end of the toolbar. The same happens with menu items. Can we add a parameter to specify the position? e.g. I would like to position the icon for marking text next to the code icon:

  4. When I select text and click the Bold button, the resulting text is selected. However, in my plugin the text is just replaced (when clicking the mark button). I was wondering, if there was a way to acomplish the same thing as the bold button from core without having to use a content script.

  5. Is there a way to add CodeMirror shortuts (e.g. joinLines) in a plugin?

1 Like

In the "enabledCondition" field on the command you can put "markdownEditorVisible && !richTextEditorVisible" and that should work.

Is there an unregister command (and something similar for menu item and toolbar icons)?

Not currently.

Toolbar icons are always added to the end of the toolbar. The same happens with menu items. Can we add a parameter to specify the position?

Indeed a parameter like after: "codeblock" or before: "bold" would be useful.

When I select text and click the Bold button, the resulting text is selected. However, in my plugin the text is just replaced (when clicking the mark button). I was wondering, if there was a way to acomplish the same thing as the bold button from core without having to use a content script.

I'm not sure actually

Is there a way to add CodeMirror shortuts (e.g. joinLines) in a plugin?

Yes, I think there's an example in the content script doc.

Yes, it worked partly. The toolbar icons which always show a gear icon in the WYSIWYG editor are not disabled. Only the shortcuts and the menu items are disabled. I can still click that gear icon.

I would love the option to not show them at all, if the condition is false, but I know that this is a more complex change due to the Electron framework. Maybe even not possible.

I checked the API docs, but markdownEditorVisible and richTextEditorVisible are not listed in stateToWhenClauseContext.ts.
The section about enabledCondition seems out of date. e.g. when I use editorType == markdown, Joplin throws an error (Error: No such key: editorType) at startup.

So how did you come up with those 2 ...Visible checks? Can I use any state?

I think I might have to use a content script. I had hoped I could avoid it. But I think it makes sense to mirror the exact behavior of the ones in core.
Let's see when I get to it. :wink:

The API doc wasn't up to date. There are also when clauses in this file: joplin/stateToWhenClauseContext.ts at dev · laurent22/joplin · GitHub and that's where the desktop-specific clauses are.

The examples are just meant to show the possible syntaxes but some of the clauses in there don't exist. In particular since all of them are booleans at the moment, I had to use a non-existing ones to show the string comparison.

1 Like