Skip to content

Commit 7e5396a

Browse files
authored
Merge pull request #87 from DenisaCG/copyPath
Update `Copy Path` functionality
2 parents eb8dfff + 0a7b072 commit 7e5396a

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

schema/drives-file-browser.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@
8282
"command": "drives:rename",
8383
"selector": ".jp-DirListing-item[data-isdir]",
8484
"rank": 5
85+
},
86+
{
87+
"command": "filebrowser:copy-path",
88+
"selector": ".jp-DirListing-item[data-isdir]",
89+
"rank": 14,
90+
"disabled": true
91+
},
92+
{
93+
"command": "drives:copy-path",
94+
"selector": ".jp-DirListing-item[data-isdir]",
95+
"rank": 14
8596
}
8697
]
8798
},

src/plugins/driveBrowserPlugin.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { ITranslator } from '@jupyterlab/translation';
1414
import {
1515
createToolbarFactory,
16+
Clipboard,
1617
IToolbarWidgetRegistry,
1718
setToolbar,
1819
showDialog,
@@ -28,6 +29,7 @@ import {
2829
notebookIcon,
2930
editIcon
3031
} from '@jupyterlab/ui-components';
32+
import { PageConfig, PathExt } from '@jupyterlab/coreutils';
3133
import { CommandRegistry } from '@lumino/commands';
3234
import { Widget } from '@lumino/widgets';
3335

@@ -151,7 +153,7 @@ export const driveFileBrowser: JupyterFrontEndPlugin<void> = {
151153
);
152154

153155
// Add commands
154-
Private.addCommands(app, drive, driveBrowser);
156+
Private.addCommands(app, drive, driveBrowser, fileBrowserFactory);
155157

156158
const updateVisibility = () => {
157159
// Visibility of context menu and toolbar commands changed.
@@ -334,8 +336,11 @@ namespace Private {
334336
export function addCommands(
335337
app: JupyterFrontEnd,
336338
drive: Drive,
337-
browser: FileBrowser
339+
browser: FileBrowser,
340+
factory: IFileBrowserFactory
338341
): void {
342+
const { tracker } = factory;
343+
339344
app.commands.addCommand(CommandIDs.createNewDrive, {
340345
isEnabled: () => {
341346
return browser.model.path === 's3:';
@@ -425,5 +430,36 @@ namespace Private {
425430
icon: editIcon.bindprops({ stylesheet: 'menuItem' }),
426431
label: 'Rename'
427432
});
433+
434+
app.commands.addCommand(CommandIDs.copyPath, {
435+
execute: () => {
436+
const widget = tracker.currentWidget;
437+
if (!widget) {
438+
return;
439+
}
440+
const item = widget.selectedItems().next();
441+
if (item.done) {
442+
return;
443+
}
444+
445+
let path: string = item.value.path;
446+
if (PageConfig.getOption('copyAbsolutePath') === 'true') {
447+
path = PathExt.joinWithLeadingSlash(
448+
PageConfig.getOption('serverRoot') ?? '',
449+
item.value.path
450+
);
451+
}
452+
const parts = path.split(':');
453+
path = parts[0] + '://' + parts[1];
454+
Clipboard.copyToSystem(path);
455+
},
456+
isVisible: () =>
457+
// So long as this command only handles one file at time, don't show it
458+
// if multiple files are selected.
459+
!!tracker.currentWidget &&
460+
Array.from(tracker.currentWidget.selectedItems()).length === 1,
461+
icon: fileIcon.bindprops({ stylesheet: 'menuItem' }),
462+
label: 'Copy Path'
463+
});
428464
}
429465
}

src/token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export namespace CommandIDs {
1414
export const createNewFile = 'drives:create-new-file';
1515
export const createNewNotebook = 'drives:create-new-notebook';
1616
export const rename = 'drives:rename';
17+
export const copyPath = 'drives:copy-path';
1718
}
1819

1920
/**

0 commit comments

Comments
 (0)