Is there a way to implement save action in mime extension?

Hi,

Basically, I have a mime renderer and I want to add a toolbar button that can implement the save action, just like saving from Jupyterlab interface either by shortcut or dropdown menu.

I notice the toolbar is minimized and I can easily add an item to that toolbar. However, I don’t know how to make the button to implement the save. Based on my finding, I think the save action can be call using app.commands.excecute('docmanager:save) but I’m having trouble getting it to work or even calling it.

Is there a way to implement the save action in a mime extension or could you point me to a beginner friendly documentation on it?

Thanks

If you grep the codebase for docmanager:save you can see how it’s done there:

[~/workspace/jupyterlab/jupyterlab/packages] (python3.8)
$ grep -RiP 'docmanager:save'
application-extension/src/index.tsx:              .execute('docmanager:save')
codemirror-extension/src/index.ts:    void app.commands.execute('docmanager:save');
docmanager-extension/schema/plugin.json:      "command": "docmanager:save",
docmanager-extension/schema/plugin.json:      "command": "docmanager:save-as",
docmanager-extension/src/index.ts:  export const save = 'docmanager:save';
docmanager-extension/src/index.ts:  export const saveAll = 'docmanager:save-all';
docmanager-extension/src/index.ts:  export const saveAs = 'docmanager:save-as';
extensionmanager/src/build-helper.tsx:            .execute('docmanager:save')
mainmenu-extension/src/index.ts:    'docmanager:save',
mainmenu-extension/src/index.ts:    'docmanager:save-as',
mainmenu-extension/src/index.ts:    'docmanager:save-all'
ode here

You can see that there is a file docmanager-extension/src/index.ts that contains instructions for how to save once you have a reference to a context.

Do you know how to find the context object?

I have not written a mime renderer, so perhaps this might not be applicable in that context.

I think you will need to convert your mime extension into a normal extension, which gives you access to the tools to save things, etc. In other words, you’ve gone beyond what the simple, lightweight mime extensions were designed for. Mime extensions are designed to be lightweight renderers of provided content, and are used in a variety of contexts, some of which involve documents and some of which may not involve documents.

Here are the docs and cookiecutters for each type of extension:

What happens when 2 or more mimerenderer extensions are registered for the same mime type; such as application/json and application/ld+json? Does such a user configuration situation prohibit normal extension development?

Thank you all for your responses. I’m learning a lot.

I think I do. But just for clarification, can you enlighten me how to find it? Thanks

Thank you. This was my backup plan so I’ll definitely try this. Could you point me toward some mime renderer example that use this? Thanks again

Yeah. I realized this after hours of researching and setbacks.

You may need to get a reference to a NotebookPanel using:Common Extension Points — JupyterLab 3.1.11 documentation

The NotebookPanel object will contain a context object, which contains relevant methods.

Thanks @adpatter. I’ll look into it.

Looking at the source, the last added renderer is the only one available.