Duplicate notebook menu option (#7374)

* WIP: Create new application:duplicate command, add to menu

* WIP: Duplicate a file, then open the new file.

* Polish

* Removes null check for variable not typed to be null

* Removes unneeded import, type declaration

* Simplifies comments

* Update Playwright Snapshots

* Update Playwright Snapshots

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Jason Weill 2024-05-20 23:13:54 -07:00 committed by GitHub
parent 30587b826a
commit 0a66f40c46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 0 deletions

View File

@ -10,6 +10,10 @@
"command": "application:rename",
"rank": 4.5
},
{
"command": "application:duplicate",
"rank": 4.8
},
{
"command": "notebook:trust",
"rank": 20

View File

@ -83,6 +83,11 @@ const JUPYTERLAB_DOCMANAGER_PLUGIN_ID =
* The command IDs used by the application plugin.
*/
namespace CommandIDs {
/**
* Duplicate the current document and open the new document
*/
export const duplicate = 'application:duplicate';
/**
* Handle local links
*/
@ -615,6 +620,20 @@ const title: JupyterFrontEndPlugin<void> = {
return !!(currentWidget && docManager.contextForWidget(currentWidget));
};
commands.addCommand(CommandIDs.duplicate, {
label: () => trans.__('Duplicate'),
isEnabled,
execute: async () => {
if (!isEnabled()) {
return;
}
// Duplicate the file, and open the new file.
const result = await docManager.duplicate(current.context.path);
await commands.execute('docmanager:open', { path: result.path });
},
});
commands.addCommand(CommandIDs.rename, {
label: () => trans.__('Rename…'),
isEnabled,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB