|
@@ -6,11 +6,11 @@ import {
|
|
|
} from '@jupyterlab/application';
|
|
|
|
|
|
import {
|
|
|
- InstanceTracker, ToolbarButton
|
|
|
+ Clipboard, InstanceTracker, ToolbarButton
|
|
|
} from '@jupyterlab/apputils';
|
|
|
|
|
|
import {
|
|
|
- IStateDB
|
|
|
+ IStateDB, PageConfig, PathExt, URLExt
|
|
|
} from '@jupyterlab/coreutils';
|
|
|
|
|
|
import {
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
} from '@jupyterlab/services';
|
|
|
|
|
|
import {
|
|
|
- each
|
|
|
+ map, toArray
|
|
|
} from '@phosphor/algorithm';
|
|
|
|
|
|
import {
|
|
@@ -53,6 +53,10 @@ namespace CommandIDs {
|
|
|
export
|
|
|
const copy = 'filebrowser:copy';
|
|
|
|
|
|
+ // For main browser only.
|
|
|
+ export
|
|
|
+ const createLauncher = 'filebrowser:create-main-launcher';
|
|
|
+
|
|
|
export
|
|
|
const cut = 'filebrowser:cut';
|
|
|
|
|
@@ -65,8 +69,13 @@ namespace CommandIDs {
|
|
|
export
|
|
|
const duplicate = 'filebrowser:duplicate';
|
|
|
|
|
|
+ // For main browser only.
|
|
|
+ export
|
|
|
+ const hideBrowser = 'filebrowser:hide-main';
|
|
|
+
|
|
|
+ // For main browser only.
|
|
|
export
|
|
|
- const hideBrowser = 'filebrowser:hide-main'; // For main browser only.
|
|
|
+ const navigate = 'filebrowser:navigate-main';
|
|
|
|
|
|
export
|
|
|
const open = 'filebrowser:open';
|
|
@@ -77,17 +86,20 @@ namespace CommandIDs {
|
|
|
export
|
|
|
const rename = 'filebrowser:rename';
|
|
|
|
|
|
+ // For main browser only.
|
|
|
export
|
|
|
- const showBrowser = 'filebrowser:activate-main'; // For main browser only.
|
|
|
+ const share = 'filebrowser:share-main';
|
|
|
|
|
|
+ // For main browser only.
|
|
|
export
|
|
|
- const shutdown = 'filebrowser:shutdown';
|
|
|
+ const showBrowser = 'filebrowser:activate-main';
|
|
|
|
|
|
export
|
|
|
- const toggleBrowser = 'filebrowser:toggle-main'; // For main browser only.
|
|
|
+ const shutdown = 'filebrowser:shutdown';
|
|
|
|
|
|
+ // For main browser only.
|
|
|
export
|
|
|
- const createLauncher = 'filebrowser:create-main-launcher'; // For main browser only.
|
|
|
+ const toggleBrowser = 'filebrowser:toggle-main';
|
|
|
}
|
|
|
|
|
|
|
|
@@ -227,11 +239,10 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
commands.addCommand(CommandIDs.del, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- return widget.delete();
|
|
|
+ if (widget) {
|
|
|
+ return widget.delete();
|
|
|
+ }
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-CloseIcon',
|
|
|
label: 'Delete',
|
|
@@ -241,11 +252,10 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
commands.addCommand(CommandIDs.copy, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- return widget.copy();
|
|
|
+ if (widget) {
|
|
|
+ return widget.copy();
|
|
|
+ }
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-CopyIcon',
|
|
|
label: 'Copy',
|
|
@@ -255,11 +265,10 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
commands.addCommand(CommandIDs.cut, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- return widget.cut();
|
|
|
+ if (widget) {
|
|
|
+ return widget.cut();
|
|
|
+ }
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-CutIcon',
|
|
|
label: 'Cut'
|
|
@@ -268,11 +277,10 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
commands.addCommand(CommandIDs.download, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- return widget.download();
|
|
|
+ if (widget) {
|
|
|
+ return widget.download();
|
|
|
+ }
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-DownloadIcon',
|
|
|
label: 'Download'
|
|
@@ -281,11 +289,10 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
commands.addCommand(CommandIDs.duplicate, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- return widget.duplicate();
|
|
|
+ if (widget) {
|
|
|
+ return widget.duplicate();
|
|
|
+ }
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-CopyIcon',
|
|
|
label: 'Duplicate'
|
|
@@ -299,34 +306,59 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ commands.addCommand(CommandIDs.navigate, {
|
|
|
+ execute: args => {
|
|
|
+ const path = args.path as string || '';
|
|
|
+ const services = app.serviceManager;
|
|
|
+ const open = 'docmanager:open';
|
|
|
+ const failure = (reason: any) => {
|
|
|
+ console.warn(`${CommandIDs.navigate} failed to open: ${path}`, reason);
|
|
|
+ };
|
|
|
+
|
|
|
+ return services.ready
|
|
|
+ .then(() => services.contents.get(path))
|
|
|
+ .then(value => {
|
|
|
+ const { model } = browser;
|
|
|
+ const { restored } = model;
|
|
|
+
|
|
|
+ if (value.type === 'directory') {
|
|
|
+ return restored.then(() => model.cd(`/${path}`));
|
|
|
+ }
|
|
|
+
|
|
|
+ return restored.then(() => model.cd(`/${PathExt.dirname(path)}`))
|
|
|
+ .then(() => commands.execute(open, { path }));
|
|
|
+ }).catch(failure);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
commands.addCommand(CommandIDs.open, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
+
|
|
|
if (!widget) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- each(widget.selectedItems(), item => {
|
|
|
+ return Promise.all(toArray(map(widget.selectedItems(), item => {
|
|
|
if (item.type === 'directory') {
|
|
|
- widget.model.cd(item.path);
|
|
|
- } else {
|
|
|
- commands.execute('docmanager:open', { path: item.path });
|
|
|
+ return widget.model.cd(item.path);
|
|
|
}
|
|
|
- });
|
|
|
+
|
|
|
+ return commands.execute('docmanager:open', { path: item.path });
|
|
|
+ })));
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-OpenFolderIcon',
|
|
|
label: 'Open',
|
|
|
- mnemonic: 0,
|
|
|
+ mnemonic: 0
|
|
|
});
|
|
|
|
|
|
commands.addCommand(CommandIDs.paste, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- return widget.paste();
|
|
|
+ if (widget) {
|
|
|
+ return widget.paste();
|
|
|
+ }
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-PasteIcon',
|
|
|
label: 'Paste',
|
|
@@ -336,16 +368,28 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
commands.addCommand(CommandIDs.rename, {
|
|
|
execute: (args) => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
+
|
|
|
+ if (widget) {
|
|
|
+ return widget.rename();
|
|
|
}
|
|
|
- return widget.rename();
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-EditIcon',
|
|
|
label: 'Rename',
|
|
|
mnemonic: 0
|
|
|
});
|
|
|
|
|
|
+ commands.addCommand(CommandIDs.share, {
|
|
|
+ execute: () => {
|
|
|
+ const path = browser.selectedItems().next().path;
|
|
|
+ const tree = PageConfig.getTreeUrl();
|
|
|
+
|
|
|
+ Clipboard.copyToSystem(URLExt.join(tree, (path as string)));
|
|
|
+ },
|
|
|
+ isVisible: () => toArray(browser.selectedItems()).length === 1,
|
|
|
+ iconClass: 'jp-MaterialIcon jp-LinkIcon',
|
|
|
+ label: 'Copy Shareable Link'
|
|
|
+ });
|
|
|
+
|
|
|
commands.addCommand(CommandIDs.showBrowser, {
|
|
|
execute: () => { app.shell.activateById(browser.id); }
|
|
|
});
|
|
@@ -353,11 +397,10 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
commands.addCommand(CommandIDs.shutdown, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- return widget.shutdownKernels();
|
|
|
+ if (widget) {
|
|
|
+ return widget.shutdownKernels();
|
|
|
+ }
|
|
|
},
|
|
|
iconClass: 'jp-MaterialIcon jp-StopIcon',
|
|
|
label: 'Shutdown Kernel'
|
|
@@ -367,9 +410,9 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
|
|
|
execute: () => {
|
|
|
if (browser.isHidden) {
|
|
|
return commands.execute(CommandIDs.showBrowser, void 0);
|
|
|
- } else {
|
|
|
- return commands.execute(CommandIDs.hideBrowser, void 0);
|
|
|
}
|
|
|
+
|
|
|
+ return commands.execute(CommandIDs.hideBrowser, void 0);
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -422,6 +465,8 @@ function createContextMenu(model: Contents.IModel, commands: CommandRegistry, re
|
|
|
menu.addItem({ command: CommandIDs.shutdown });
|
|
|
}
|
|
|
|
|
|
+ menu.addItem({ command: CommandIDs.share });
|
|
|
+
|
|
|
return menu;
|
|
|
}
|
|
|
|