Skip to content

Commit

Permalink
Duplicate notebook menu option (#7374)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
JasonWeill and github-actions[bot] authored May 21, 2024
1 parent 30587b8 commit 0a66f40
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/application-extension/schema/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"command": "application:rename",
"rank": 4.5
},
{
"command": "application:duplicate",
"rank": 4.8
},
{
"command": "notebook:trust",
"rank": 20
Expand Down
19 changes: 19 additions & 0 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0a66f40

Please sign in to comment.