-
Notifications
You must be signed in to change notification settings - Fork 172
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
Add example of toolbar button in text editor (+for particular file extension) #188
Comments
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗 |
Hey @ktaletsk thanks for proposing. This looks great. For information there is a simpler way coming in JLab 3.3 to add buttons from settings (see documentation). But for the case you are targeting with conditions on whether the button should be added or not. This looks good (note that the type of the widget should be updated as you are not receiving a Happy to review a PR on this. |
@fcollonval thanks for offering to review. Draft PR is now open. I added the new editor toolbar button alongside with the old notebook toolbar button in the I have to admit, I do not understand the machinery of widgets/panels/registries very well, so bear with me here. What should be the equivalent of |
🚀
For the file editor, you will receive a More in-depth, the reason TypeScript is not complaining is that function addWidgetExtension(
widgetName: string,
extension: DocumentRegistry.WidgetExtension
) There the type of |
Problem
There is an excellent example on how to add a button to the notebook toolbar, which boils down to
extension-examples/toolbar-button/src/index.ts
Line 67 in 9c35013
Now, I would like to do the same with other editors available in JupyterLab, in particular tailored for the specific file extension (think .py or .md or .tex). I played around with the example and reached the desired result. I thought the answer might be useful for someone else searching for the same functionality.
The first part (adding button to all text editors) is straightforward: change the name of the widget factory
widgetName
in theaddWidgetExtension
call from'Notebook'
to'Editor'
. The second part I achieved by checking the path ending:I am not sure this is the best (or even valid) way to do this, but it gave the desired result. The full example is available in my fork: https://github.com/ktaletsk/extension-examples/blob/toolbar-button-editor/toolbar-button/src/index.ts
To summarize, I would like to:
toolbar-button
example or posible a different example in this repo. I would be happy to create PR.Proposed Solution
Add example of the toolbar button enabled only for specific file extension
Additional context
Proposed example in action:
The text was updated successfully, but these errors were encountered: