@@ -37,7 +37,7 @@ import { Widget } from '@lumino/widgets';
3737
3838import { driveBrowserIcon , removeIcon } from '../icons' ;
3939import { Drive } from '../contents' ;
40- import { setListingLimit } from '../requests' ;
40+ import { getContents , setListingLimit } from '../requests' ;
4141import { CommandIDs } from '../token' ;
4242
4343/**
@@ -697,5 +697,81 @@ namespace Private {
697697 '#drive-file-browser.jp-SidePanel .jp-DirListing-content .jp-DirListing-item[data-isdir]' ,
698698 rank : 110
699699 } ) ;
700+
701+ app . commands . addCommand ( CommandIDs . copyToFilebrowser , {
702+ isVisible : ( ) => {
703+ // So long as this command only handles one file at time, don't show it
704+ // if multiple files are selected.
705+ return (
706+ ! ! tracker . currentWidget &&
707+ Array . from ( tracker . currentWidget . selectedItems ( ) ) . length === 1 &&
708+ browser . model . path !== 's3:'
709+ ) ;
710+ } ,
711+ isEnabled : ( ) => {
712+ return (
713+ ! ! tracker . currentWidget &&
714+ tracker . currentWidget ?. selectedItems ( ) . next ( ) ! . value &&
715+ tracker . currentWidget ?. selectedItems ( ) . next ( ) ! . value . type !==
716+ 'directory'
717+ ) ;
718+ } ,
719+ execute : async ( ) => {
720+ let currentPath : string = tracker . currentWidget ?. selectedItems ( ) . next ( )
721+ . value . path ;
722+ Clipboard . copyToSystem ( currentPath ) ;
723+ } ,
724+ label : 'Copy to Filebrowser' ,
725+ icon : driveBrowserIcon . bindprops ( { stylesheet : 'menuItem' } )
726+ } ) ;
727+
728+ app . contextMenu . addItem ( {
729+ command : CommandIDs . copyToFilebrowser ,
730+ selector : '#drive-file-browser.jp-SidePanel .jp-DirListing-content' ,
731+ rank : 105
732+ } ) ;
733+
734+ app . commands . addCommand ( CommandIDs . pasteToFilebrowser , {
735+ isVisible : ( ) => {
736+ return (
737+ ! ! factory . tracker . currentWidget &&
738+ factory . tracker . currentWidget ! . id === 'filebrowser'
739+ ) ;
740+ } ,
741+ execute : async ( args : any ) => {
742+ // Get path from clipboard.
743+ let currentPath = await navigator . clipboard . readText ( ) ;
744+ // Remove leading drive suffix.
745+ currentPath = currentPath . substring ( currentPath . indexOf ( ':' ) + 1 ) ;
746+ const driveName = currentPath . substring ( 0 , currentPath . indexOf ( '/' ) ) ;
747+ // Remove drive name.
748+ currentPath = currentPath . substring ( currentPath . indexOf ( '/' ) + 1 ) ;
749+ const fileName = PathExt . basename ( currentPath ) ;
750+
751+ const filebrowser = factory . tracker . find ( fb => fb . id === 'filebrowser' ) ;
752+
753+ // Save new file.
754+ const toDir = factory . tracker . currentWidget ! . model . path ;
755+ app . serviceManager . contents . save ( PathExt . join ( toDir , fileName ) , {
756+ type : 'file' ,
757+ format : 'text' ,
758+ content : (
759+ await getContents ( driveName , {
760+ path : currentPath ,
761+ registeredFileTypes : drive . registeredFileTypes
762+ } )
763+ ) . response . data . content
764+ } ) ;
765+ await filebrowser ?. model . refresh ( ) ;
766+ } ,
767+ label : 'Paste from Drive' ,
768+ icon : driveBrowserIcon . bindprops ( { stylesheet : 'menuItem' } )
769+ } ) ;
770+
771+ app . contextMenu . addItem ( {
772+ command : CommandIDs . pasteToFilebrowser ,
773+ selector : '.jp-FileBrowser-listing' ,
774+ rank : 105
775+ } ) ;
700776 }
701777}
0 commit comments