@@ -13,6 +13,7 @@ import {
1313import { ITranslator } from '@jupyterlab/translation' ;
1414import {
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' ;
3133import { CommandRegistry } from '@lumino/commands' ;
3234import { 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}
0 commit comments