Skip to content

Commit 0a66f40

Browse files
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>
1 parent 30587b8 commit 0a66f40

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

packages/application-extension/schema/menus.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"command": "application:rename",
1111
"rank": 4.5
1212
},
13+
{
14+
"command": "application:duplicate",
15+
"rank": 4.8
16+
},
1317
{
1418
"command": "notebook:trust",
1519
"rank": 20

packages/application-extension/src/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ const JUPYTERLAB_DOCMANAGER_PLUGIN_ID =
8383
* The command IDs used by the application plugin.
8484
*/
8585
namespace CommandIDs {
86+
/**
87+
* Duplicate the current document and open the new document
88+
*/
89+
export const duplicate = 'application:duplicate';
90+
8691
/**
8792
* Handle local links
8893
*/
@@ -615,6 +620,20 @@ const title: JupyterFrontEndPlugin<void> = {
615620
return !!(currentWidget && docManager.contextForWidget(currentWidget));
616621
};
617622

623+
commands.addCommand(CommandIDs.duplicate, {
624+
label: () => trans.__('Duplicate'),
625+
isEnabled,
626+
execute: async () => {
627+
if (!isEnabled()) {
628+
return;
629+
}
630+
631+
// Duplicate the file, and open the new file.
632+
const result = await docManager.duplicate(current.context.path);
633+
await commands.execute('docmanager:open', { path: result.path });
634+
},
635+
});
636+
618637
commands.addCommand(CommandIDs.rename, {
619638
label: () => trans.__('Rename…'),
620639
isEnabled,
325 Bytes
Loading
319 Bytes
Loading

0 commit comments

Comments
 (0)