88import * as nls from 'vs/nls' ;
99import * as paths from 'vs/base/common/paths' ;
1010import { TPromise } from 'vs/base/common/winjs.base' ;
11- import * as labels from 'vs/base/common/labels' ;
1211import URI from 'vs/base/common/uri' ;
1312import { toResource , IEditorCommandsContext } from 'vs/workbench/common/editor' ;
1413import { IWindowsService , IWindowService } from 'vs/platform/windows/common/windows' ;
@@ -31,7 +30,7 @@ import { IEditorViewState } from 'vs/editor/common/editorCommon';
3130import { getCodeEditor } from 'vs/editor/browser/editorBrowser' ;
3231import { KeybindingsRegistry , KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
3332import { KeyMod , KeyCode , KeyChord } from 'vs/base/common/keyCodes' ;
34- import { isWindows , isMacintosh , isLinux } from 'vs/base/common/platform' ;
33+ import { isWindows , isMacintosh } from 'vs/base/common/platform' ;
3534import { ITextModelService } from 'vs/editor/common/services/resolverService' ;
3635import { sequence } from 'vs/base/common/async' ;
3736import { getResourceForCommand , getMultiSelectedResources } from 'vs/workbench/parts/files/browser/files' ;
@@ -42,8 +41,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
4241import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
4342import { IEditorService , SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService' ;
4443import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService' ;
45- import { isEqual , basenameOrAuthority } from 'vs/base/common/resources' ;
46- import { ltrim } from 'vs/base/common/strings' ;
44+ import { IUriLabelService } from 'vs/platform/uriLabel/common/uriLabel' ;
4745
4846// Commands
4947
@@ -389,28 +387,12 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
389387 }
390388} ) ;
391389
392- function resourcesToClipboard ( resources : URI [ ] , clipboardService : IClipboardService , notificationService : INotificationService , contextService ?: IWorkspaceContextService ) : void {
390+ function resourcesToClipboard ( resources : URI [ ] , relative : boolean , clipboardService : IClipboardService , notificationService : INotificationService , uriLabelService : IUriLabelService ) : void {
393391 if ( resources . length ) {
394392 const lineDelimiter = isWindows ? '\r\n' : '\n' ;
395393
396- const text = resources . map ( resource => {
397- if ( contextService ) {
398- const workspaceFolder = contextService . getWorkspaceFolder ( resource ) ;
399- if ( workspaceFolder ) {
400- if ( isEqual ( workspaceFolder . uri , resource , ! isLinux ) ) {
401- return basenameOrAuthority ( workspaceFolder . uri ) ;
402- }
403-
404- return paths . normalize ( ltrim ( resource . path . substr ( workspaceFolder . uri . path . length ) , paths . sep ) , true ) ;
405- }
406- }
407-
408- if ( resource . scheme === Schemas . file ) {
409- return paths . normalize ( labels . normalizeDriveLetter ( resource . fsPath ) , true ) ;
410- }
411-
412- return resource . toString ( ) ;
413- } ) . join ( lineDelimiter ) ;
394+ const text = resources . map ( resource => uriLabelService . getLabel ( resource , relative , true ) )
395+ . join ( lineDelimiter ) ;
414396 clipboardService . writeText ( text ) ;
415397 } else {
416398 notificationService . info ( nls . localize ( 'openFileToCopy' , "Open a file first to copy its path" ) ) ;
@@ -427,7 +409,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
427409 id : COPY_PATH_COMMAND_ID ,
428410 handler : ( accessor , resource : URI | object ) => {
429411 const resources = getMultiSelectedResources ( resource , accessor . get ( IListService ) , accessor . get ( IEditorService ) ) ;
430- resourcesToClipboard ( resources , accessor . get ( IClipboardService ) , accessor . get ( INotificationService ) ) ;
412+ resourcesToClipboard ( resources , false , accessor . get ( IClipboardService ) , accessor . get ( INotificationService ) , accessor . get ( IUriLabelService ) ) ;
431413 }
432414} ) ;
433415
@@ -441,7 +423,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
441423 id : COPY_RELATIVE_PATH_COMMAND_ID ,
442424 handler : ( accessor , resource : URI | object ) => {
443425 const resources = getMultiSelectedResources ( resource , accessor . get ( IListService ) , accessor . get ( IEditorService ) ) ;
444- resourcesToClipboard ( resources , accessor . get ( IClipboardService ) , accessor . get ( INotificationService ) , accessor . get ( IWorkspaceContextService ) ) ;
426+ resourcesToClipboard ( resources , true , accessor . get ( IClipboardService ) , accessor . get ( INotificationService ) , accessor . get ( IUriLabelService ) ) ;
445427 }
446428} ) ;
447429
@@ -454,7 +436,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
454436 const editorService = accessor . get ( IEditorService ) ;
455437 const activeInput = editorService . activeEditor ;
456438 const resources = activeInput && activeInput . getResource ( ) ? [ activeInput . getResource ( ) ] : [ ] ;
457- resourcesToClipboard ( resources , accessor . get ( IClipboardService ) , accessor . get ( INotificationService ) ) ;
439+ resourcesToClipboard ( resources , false , accessor . get ( IClipboardService ) , accessor . get ( INotificationService ) , accessor . get ( IUriLabelService ) ) ;
458440 }
459441} ) ;
460442
0 commit comments