Skip to content

Commit

Permalink
Add a 'Copy Path' option to filebrowser context menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
aisipos committed May 17, 2018
1 parent 18035d8 commit f6d7b5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/source/user/files.rst
Expand Up @@ -88,6 +88,12 @@ directory open.
:align: center
:class: jp-screenshot

.. _file-copy-path:

Right-click on a file or directory and select "Copy Path" to copy the
filesystem relative path. This can be used for passing arguments to open
files in functions called in various kernels.

Creating Files and Activities
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
19 changes: 19 additions & 0 deletions packages/filebrowser-extension/src/index.ts
Expand Up @@ -93,6 +93,10 @@ namespace CommandIDs {
export
const share = 'filebrowser:share-main';

// For main browser only.
export
const copyPath = 'filebrowser:copy-path';

// For main browser only.
export
const showBrowser = 'filebrowser:activate-main';
Expand Down Expand Up @@ -405,6 +409,20 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
label: 'Copy Shareable Link'
});

commands.addCommand(CommandIDs.copyPath, {
execute: () => {
const item = browser.selectedItems().next();
if (!item) {
return;
}

Clipboard.copyToSystem(item.path);
},
isVisible: () => toArray(browser.selectedItems()).length === 1,
iconClass: 'jp-MaterialIcon jp-FileIcon',
label: 'Copy Path'
});

commands.addCommand(CommandIDs.showBrowser, {
execute: () => { app.shell.activateById(browser.id); }
});
Expand Down Expand Up @@ -490,6 +508,7 @@ function createContextMenu(model: Contents.IModel | undefined, commands: Command
}

menu.addItem({ command: CommandIDs.share });
menu.addItem({ command: CommandIDs.copyPath });

return menu;
}
Expand Down

0 comments on commit f6d7b5d

Please sign in to comment.