Skip to content

Commit

Permalink
getPathLabel clients pass contextService when possible unles you expl…
Browse files Browse the repository at this point in the history
…icitly want an absolute path
  • Loading branch information
isidorn committed Jun 13, 2018
1 parent 04e893c commit 6683ba1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/vs/code/electron-main/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { KeybindingsResolver } from 'vs/code/electron-main/keyboard';
import { IWindowsMainService, IWindowsCountChangedEvent } from 'vs/platform/windows/electron-main/windows';
import { IHistoryMainService } from 'vs/platform/history/common/history';
import { IWorkspaceIdentifier, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';

interface IMenuItemClickHandler {
inDevTools: (contents: Electron.WebContents) => void;
Expand Down Expand Up @@ -65,7 +66,8 @@ export class CodeMenu {
@IWindowsService private windowsService: IWindowsService,
@IEnvironmentService private environmentService: IEnvironmentService,
@ITelemetryService private telemetryService: ITelemetryService,
@IHistoryMainService private historyMainService: IHistoryMainService
@IHistoryMainService private historyMainService: IHistoryMainService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
this.nativeTabMenuItems = [];

Expand Down Expand Up @@ -490,7 +492,7 @@ export class CodeMenu {
let label: string;
let path: string;
if (isSingleFolderWorkspaceIdentifier(workspace) || typeof workspace === 'string') {
label = unmnemonicLabel(getPathLabel(workspace, this.environmentService));
label = unmnemonicLabel(getPathLabel(workspace, this.environmentService, this.contextService));
path = workspace;
} else {
label = getWorkspaceLabel(workspace, this.environmentService, { verbose: true });
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/referenceSearch/referencesWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ export class ReferenceWidget extends PeekViewWidget {

// Update widget header
if (reference.uri.scheme !== Schemas.inMemory) {
this.setTitle(reference.name, getPathLabel(reference.directory, this._environmentService, this._contextService, ));
this.setTitle(reference.name, getPathLabel(reference.directory, this._environmentService, this._contextService));
} else {
this.setTitle(nls.localize('peekView.alternateTitle', "References"));
}
Expand Down
4 changes: 3 additions & 1 deletion src/vs/platform/history/electron-main/historyMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { IHistoryMainService, IRecentlyOpened } from 'vs/platform/history/common
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { isEqual } from 'vs/base/common/paths';
import { RunOnceScheduler } from 'vs/base/common/async';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';

export class HistoryMainService implements IHistoryMainService {

Expand All @@ -41,6 +42,7 @@ export class HistoryMainService implements IHistoryMainService {
@ILogService private logService: ILogService,
@IWorkspacesMainService private workspacesMainService: IWorkspacesMainService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
this.macOSRecentDocumentsUpdater = new RunOnceScheduler(() => this.updateMacOSRecentDocuments(), 800);

Expand Down Expand Up @@ -254,7 +256,7 @@ export class HistoryMainService implements IHistoryMainService {
name: nls.localize('recentFolders', "Recent Workspaces"),
items: this.getRecentlyOpened().workspaces.slice(0, 7 /* limit number of entries here */).map(workspace => {
const title = isSingleFolderWorkspaceIdentifier(workspace) ? getBaseLabel(workspace) : getWorkspaceLabel(workspace, this.environmentService);
const description = isSingleFolderWorkspaceIdentifier(workspace) ? nls.localize('folderDesc', "{0} {1}", getBaseLabel(workspace), getPathLabel(path.dirname(workspace), this.environmentService)) : nls.localize('codeWorkspace', "Code Workspace");
const description = isSingleFolderWorkspaceIdentifier(workspace) ? nls.localize('folderDesc', "{0} {1}", getBaseLabel(workspace), getPathLabel(path.dirname(workspace), this.environmentService, this.contextService)) : nls.localize('codeWorkspace', "Code Workspace");

return <Electron.JumpListItem>{
type: 'task',
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/actions/workspaceCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
const folderPicks = folders.map(folder => {
return {
label: folder.name,
description: getPathLabel(resources.dirname(folder.uri), environmentService),
description: getPathLabel(resources.dirname(folder.uri), environmentService, contextService),
folder,
resource: folder.uri,
fileKind: FileKind.ROOT_FOLDER
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/dnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import { WORKSPACE_EXTENSION, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
import { extname, basename } from 'vs/base/common/paths';
import { extname, basename, normalize } from 'vs/base/common/paths';
import { IFileService } from 'vs/platform/files/common/files';
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import URI from 'vs/base/common/uri';
Expand All @@ -22,7 +22,7 @@ import { IEditorViewState } from 'vs/editor/common/editorCommon';
import { DataTransfers } from 'vs/base/browser/dnd';
import { DefaultDragAndDrop } from 'vs/base/parts/tree/browser/treeDefaults';
import { DragMouseEvent } from 'vs/base/browser/mouseEvent';
import { getPathLabel } from 'vs/base/common/labels';
import { normalizeDriveLetter } from 'vs/base/common/labels';
import { MIME_BINARY } from 'vs/base/common/mime';
import { ITree, IDragAndDropData } from 'vs/base/parts/tree/browser/tree';
import { isWindows } from 'vs/base/common/platform';
Expand Down Expand Up @@ -370,7 +370,7 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:

// Text: allows to paste into text-capable areas
const lineDelimiter = isWindows ? '\r\n' : '\n';
event.dataTransfer.setData(DataTransfers.TEXT, sources.map(source => source.resource.scheme === Schemas.file ? getPathLabel(source.resource, undefined) : source.resource.toString()).join(lineDelimiter));
event.dataTransfer.setData(DataTransfers.TEXT, sources.map(source => source.resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(source.resource.fsPath), true) : source.resource.toString()).join(lineDelimiter));

// Download URL: enables support to drag a tab as file to desktop (only single file supported)
if (firstSource.resource.scheme === Schemas.file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
function resourcesToClipboard(resources: URI[], clipboardService: IClipboardService, notificationService: INotificationService): void {
if (resources.length) {
const lineDelimiter = isWindows ? '\r\n' : '\n';
const text = resources.map(r => r.scheme === Schemas.file ? paths.normalize(labels.normalizeDriveLetter(r.fsPath)) : r.toString()).join(lineDelimiter);
const text = resources.map(r => r.scheme === Schemas.file ? paths.normalize(labels.normalizeDriveLetter(r.fsPath), true) : r.toString()).join(lineDelimiter);
clipboardService.writeText(text);
} else {
notificationService.info(nls.localize('openFileToCopy', "Open a file first to copy its path"));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/search/browser/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
}

function uriToClipboardString(resource: URI): string {
return resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(resource.fsPath)) : resource.toString();
return resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(resource.fsPath), true) : resource.toString();
}

export const copyPathCommand: ICommandHandler = (accessor, fileMatch: FileMatch | FolderMatch) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IProgress, IProgressRunner, emptyProgressRunner } from 'vs/platform/progress/common/progress';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';

abstract class Recording {

Expand Down Expand Up @@ -268,7 +269,8 @@ export class BulkEdit {
progress: IProgressRunner,
@ITextModelService private readonly _textModelService: ITextModelService,
@IFileService private readonly _fileService: IFileService,
@IEnvironmentService private readonly _environmentService: IEnvironmentService
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
@IWorkspaceContextService private readonly _contextService: IWorkspaceContextService
) {
this._editor = editor;
this._progress = progress || emptyProgressRunner;
Expand Down Expand Up @@ -361,7 +363,7 @@ export class BulkEdit {

const conflicts = edits
.filter(edit => recording.hasChanged(edit.resource))
.map(edit => getPathLabel(edit.resource, this._environmentService));
.map(edit => getPathLabel(edit.resource, this._environmentService, this._contextService));

recording.stop();

Expand All @@ -385,7 +387,8 @@ export class BulkEditService implements IBulkEditService {
@IEditorService private readonly _editorService: IEditorService,
@ITextModelService private readonly _textModelService: ITextModelService,
@IFileService private readonly _fileService: IFileService,
@IEnvironmentService private readonly _environmentService: IEnvironmentService
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
@IWorkspaceContextService private readonly _contextService: IWorkspaceContextService
) {

}
Expand Down Expand Up @@ -416,7 +419,7 @@ export class BulkEditService implements IBulkEditService {
}
}

const bulkEdit = new BulkEdit(options.editor, options.progress, this._textModelService, this._fileService, this._environmentService);
const bulkEdit = new BulkEdit(options.editor, options.progress, this._textModelService, this._fileService, this._environmentService, this._contextService);
bulkEdit.add(edits);
return bulkEdit.perform().then(selection => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { TestFileService, TestEditorService, TestEditorGroupsService, TestEnvironmentService } from 'vs/workbench/test/workbenchTestServices';
import { TestFileService, TestEditorService, TestEditorGroupsService, TestEnvironmentService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { TPromise } from 'vs/base/common/winjs.base';
import { IFileStat } from 'vs/platform/files/common/files';
import { ResourceTextEdit } from 'vs/editor/common/modes';
Expand Down Expand Up @@ -73,7 +73,7 @@ suite('MainThreadEditors', () => {
const workbenchEditorService = new TestEditorService();
const editorGroupService = new TestEditorGroupsService();

const bulkEditService = new BulkEditService(modelService, new TestEditorService(), null, fileService, TestEnvironmentService);
const bulkEditService = new BulkEditService(modelService, new TestEditorService(), null, fileService, TestEnvironmentService, new TestContextService());

const rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(ExtHostContext.ExtHostDocuments, new class extends mock<ExtHostDocumentsShape>() {
Expand Down

0 comments on commit 6683ba1

Please sign in to comment.