Skip to content

Commit c2a1178

Browse files
committed
workbench: more adoption of uriDisplayService
1 parent d33df69 commit c2a1178

10 files changed

Lines changed: 64 additions & 45 deletions

File tree

src/vs/base/common/labels.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ export interface IUserHomeProvider {
2323
}
2424

2525
/**
26-
* @param resource for which to compute the path label
27-
* @param userHomeProvider if a resource has a file schema userHomeProvider is used for tildifiying the label
28-
* @param rootProvider only passed in if the label should be relative to the workspace root
26+
* @deprecated use UriLabelService instead
2927
*/
3028
export function getPathLabel(resource: URI | string, userHomeProvider: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string {
3129
if (!resource) {

src/vs/code/electron-main/menubar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,10 @@ export class Menubar {
524524
let label: string;
525525
let uri: URI;
526526
if (isSingleFolderWorkspaceIdentifier(workspace)) {
527-
label = unmnemonicLabel(getWorkspaceLabel(workspace, this.environmentService, { verbose: true }));
527+
label = unmnemonicLabel(getWorkspaceLabel(workspace, this.environmentService, this.uriDisplayService, { verbose: true }));
528528
uri = workspace;
529529
} else if (isWorkspaceIdentifier(workspace)) {
530-
label = getWorkspaceLabel(workspace, this.environmentService, { verbose: true });
530+
label = getWorkspaceLabel(workspace, this.environmentService, this.uriDisplayService, { verbose: true });
531531
uri = URI.file(workspace.configPath);
532532
} else {
533533
uri = URI.file(workspace);

src/vs/platform/history/electron-main/historyMainService.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
'use strict';
77

8-
import * as path from 'path';
98
import * as nls from 'vs/nls';
109
import * as arrays from 'vs/base/common/arrays';
1110
import { trim } from 'vs/base/common/strings';
1211
import { IStateService } from 'vs/platform/state/common/state';
1312
import { app } from 'electron';
1413
import { ILogService } from 'vs/platform/log/common/log';
15-
import { getPathLabel, getBaseLabel } from 'vs/base/common/labels';
14+
import { getBaseLabel } from 'vs/base/common/labels';
1615
import { IPath } from 'vs/platform/windows/common/windows';
1716
import { Event as CommonEvent, Emitter } from 'vs/base/common/event';
1817
import { isWindows, isMacintosh, isLinux } from 'vs/base/common/platform';
@@ -21,9 +20,10 @@ import { IHistoryMainService, IRecentlyOpened } from 'vs/platform/history/common
2120
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
2221
import { isEqual } from 'vs/base/common/paths';
2322
import { RunOnceScheduler } from 'vs/base/common/async';
24-
import { getComparisonKey, isEqual as areResourcesEqual, hasToIgnoreCase } from 'vs/base/common/resources';
23+
import { getComparisonKey, isEqual as areResourcesEqual, hasToIgnoreCase, dirname } from 'vs/base/common/resources';
2524
import URI, { UriComponents } from 'vs/base/common/uri';
2625
import { Schemas } from 'vs/base/common/network';
26+
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
2727

2828
interface ISerializedRecentlyOpened {
2929
workspaces: (IWorkspaceIdentifier | string | UriComponents)[];
@@ -48,7 +48,8 @@ export class HistoryMainService implements IHistoryMainService {
4848
@IStateService private stateService: IStateService,
4949
@ILogService private logService: ILogService,
5050
@IWorkspacesMainService private workspacesMainService: IWorkspacesMainService,
51-
@IEnvironmentService private environmentService: IEnvironmentService
51+
@IEnvironmentService private environmentService: IEnvironmentService,
52+
@IUriDisplayService private uriDisplayService: IUriDisplayService
5253
) {
5354
this.macOSRecentDocumentsUpdater = new RunOnceScheduler(() => this.updateMacOSRecentDocuments(), 800);
5455

@@ -308,8 +309,8 @@ export class HistoryMainService implements IHistoryMainService {
308309
type: 'custom',
309310
name: nls.localize('recentFolders', "Recent Workspaces"),
310311
items: this.getRecentlyOpened().workspaces.slice(0, 7 /* limit number of entries here */).map(workspace => {
311-
const title = getWorkspaceLabel(workspace, this.environmentService);
312-
const description = isSingleFolderWorkspaceIdentifier(workspace) ? nls.localize('folderDesc', "{0} {1}", getBaseLabel(workspace), getPathLabel(path.dirname(workspace.path), this.environmentService)) : nls.localize('codeWorkspace', "Code Workspace");
312+
const title = getWorkspaceLabel(workspace, this.environmentService, this.uriDisplayService);
313+
const description = isSingleFolderWorkspaceIdentifier(workspace) ? nls.localize('folderDesc', "{0} {1}", getBaseLabel(workspace), this.uriDisplayService.getLabel(dirname(workspace))) : nls.localize('codeWorkspace', "Code Workspace");
313314
let args;
314315
// use quotes to support paths with whitespaces
315316
if (isSingleFolderWorkspaceIdentifier(workspace)) {

src/vs/platform/workspaces/common/workspaces.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import { basename, dirname, join } from 'vs/base/common/paths';
1313
import { isLinux } from 'vs/base/common/platform';
1414
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1515
import { Event } from 'vs/base/common/event';
16-
import { getPathLabel, getBaseLabel } from 'vs/base/common/labels';
16+
import { getBaseLabel } from 'vs/base/common/labels';
1717
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
1818
import URI from 'vs/base/common/uri';
1919
import { Schemas } from 'vs/base/common/network';
20+
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
2021

2122
export const IWorkspacesMainService = createDecorator<IWorkspacesMainService>('workspacesMainService');
2223
export const IWorkspacesService = createDecorator<IWorkspacesService>('workspacesService');
@@ -112,17 +113,17 @@ export interface IWorkspacesService {
112113
createWorkspace(folders?: IWorkspaceFolderCreationData[]): TPromise<IWorkspaceIdentifier>;
113114
}
114115

115-
export function getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier), environmentService: IEnvironmentService, options?: { verbose: boolean }): string {
116+
export function getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier), environmentService: IEnvironmentService, uriDisplayService: IUriDisplayService, options?: { verbose: boolean }): string {
116117

117118
// Workspace: Single Folder
118119
if (isSingleFolderWorkspaceIdentifier(workspace)) {
119120
// Folder on disk
120121
if (workspace.scheme === Schemas.file) {
121-
return options && options.verbose ? getPathLabel(workspace, environmentService) : getBaseLabel(workspace);
122+
return options && options.verbose ? uriDisplayService.getLabel(workspace) : getBaseLabel(workspace);
122123
}
123124

124125
// Remote folder
125-
return options && options.verbose ? getPathLabel(workspace, environmentService) : `${getBaseLabel(workspace)} (${workspace.scheme})`;
126+
return options && options.verbose ? uriDisplayService.getLabel(workspace) : `${getBaseLabel(workspace)} (${workspace.scheme})`;
126127
}
127128

128129
// Workspace: Untitled
@@ -134,7 +135,7 @@ export function getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFold
134135
const filename = basename(workspace.configPath);
135136
const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
136137
if (options && options.verbose) {
137-
return localize('workspaceNameVerbose', "{0} (Workspace)", getPathLabel(join(dirname(workspace.configPath), workspaceName), environmentService));
138+
return localize('workspaceNameVerbose', "{0} (Workspace)", uriDisplayService.getLabel(URI.file(join(dirname(workspace.configPath), workspaceName))));
138139
}
139140

140141
return localize('workspaceName', "{0} (Workspace)", workspaceName);

src/vs/workbench/browser/parts/menubar/menubarPart.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
3535
import { RunOnceScheduler } from 'vs/base/common/async';
3636
import { MENUBAR_SELECTION_FOREGROUND, MENUBAR_SELECTION_BACKGROUND, MENUBAR_SELECTION_BORDER, TITLE_BAR_ACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_FOREGROUND, MENU_BACKGROUND, MENU_FOREGROUND, MENU_SELECTION_BACKGROUND, MENU_SELECTION_FOREGROUND, MENU_SELECTION_BORDER } from 'vs/workbench/common/theme';
3737
import URI from 'vs/base/common/uri';
38+
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
3839

3940
interface CustomMenu {
4041
title: string;
@@ -128,7 +129,8 @@ export class MenubarPart extends Part {
128129
@IContextKeyService private contextKeyService: IContextKeyService,
129130
@IKeybindingService private keybindingService: IKeybindingService,
130131
@IConfigurationService private configurationService: IConfigurationService,
131-
@IEnvironmentService private environmentService: IEnvironmentService
132+
@IEnvironmentService private environmentService: IEnvironmentService,
133+
@IUriDisplayService private uriDisplayService: IUriDisplayService
132134
) {
133135
super(id, { hasTitle: false }, themeService);
134136

@@ -496,10 +498,10 @@ export class MenubarPart extends Part {
496498
let uri: URI;
497499

498500
if (isSingleFolderWorkspaceIdentifier(workspace)) {
499-
label = getWorkspaceLabel(workspace, this.environmentService, { verbose: true });
501+
label = getWorkspaceLabel(workspace, this.environmentService, this.uriDisplayService, { verbose: true });
500502
uri = workspace;
501503
} else if (isWorkspaceIdentifier(workspace)) {
502-
label = getWorkspaceLabel(workspace, this.environmentService, { verbose: true });
504+
label = getWorkspaceLabel(workspace, this.environmentService, this.uriDisplayService, { verbose: true });
503505
uri = URI.file(workspace.configPath);
504506
} else {
505507
label = getPathLabel(workspace, this.environmentService);
@@ -1211,4 +1213,4 @@ class ModifierKeyEmitter extends Emitter<IModifierKeyStatus> {
12111213
super.dispose();
12121214
this._subscriptions = dispose(this._subscriptions);
12131215
}
1214-
}
1216+
}

src/vs/workbench/electron-browser/actions.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
3333
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
3434
import * as os from 'os';
3535
import { webFrame, shell } from 'electron';
36-
import { getPathLabel, getBaseLabel } from 'vs/base/common/labels';
36+
import { getBaseLabel } from 'vs/base/common/labels';
3737
import { IViewlet } from 'vs/workbench/common/viewlet';
3838
import { IPanel } from 'vs/workbench/common/panel';
3939
import { IWorkspaceIdentifier, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
@@ -50,6 +50,8 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
5050
import { Context } from 'vs/platform/contextkey/browser/contextKeyService';
5151
import { IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue';
5252
import { INotificationService } from 'vs/platform/notification/common/notification';
53+
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
54+
import { dirname } from 'vs/base/common/resources';
5355

5456
// --- actions
5557

@@ -705,6 +707,7 @@ export abstract class BaseOpenRecentAction extends Action {
705707
private quickOpenService: IQuickOpenService,
706708
private contextService: IWorkspaceContextService,
707709
private environmentService: IEnvironmentService,
710+
private uriDisplayService: IUriDisplayService,
708711
private keybindingService: IKeybindingService,
709712
private instantiationService: IInstantiationService
710713
) {
@@ -720,22 +723,22 @@ export abstract class BaseOpenRecentAction extends Action {
720723

721724
private openRecent(recentWorkspaces: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[], recentFiles: string[]): void {
722725

723-
function toPick(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | string, separator: ISeparator, fileKind: FileKind, environmentService: IEnvironmentService, action: IAction): IFilePickOpenEntry {
726+
function toPick(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | string, separator: ISeparator, fileKind: FileKind, environmentService: IEnvironmentService, uriDisplayService: IUriDisplayService, action: IAction): IFilePickOpenEntry {
724727
let resource: URI;
725728
let label: string;
726729
let description: string;
727730
if (isSingleFolderWorkspaceIdentifier(workspace)) {
728731
resource = workspace;
729-
label = getWorkspaceLabel(workspace, environmentService);
730-
description = getPathLabel(resource.with({ path: paths.dirname(resource.path) }), environmentService);
732+
label = getWorkspaceLabel(workspace, environmentService, uriDisplayService);
733+
description = uriDisplayService.getLabel(resource.with({ path: paths.dirname(resource.path) }));
731734
} else if (isWorkspaceIdentifier(workspace)) {
732735
resource = URI.file(workspace.configPath);
733-
label = getWorkspaceLabel(workspace, environmentService);
734-
description = getPathLabel(paths.dirname(workspace.configPath), environmentService);
736+
label = getWorkspaceLabel(workspace, environmentService, uriDisplayService);
737+
description = uriDisplayService.getLabel(dirname(resource));
735738
} else {
736739
resource = URI.file(workspace);
737740
label = getBaseLabel(workspace);
738-
description = getPathLabel(paths.dirname(workspace), environmentService);
741+
description = uriDisplayService.getLabel(dirname(resource));
739742
}
740743

741744
return {
@@ -760,8 +763,8 @@ export abstract class BaseOpenRecentAction extends Action {
760763
this.windowService.openWindow([resource], { forceNewWindow, forceOpenWorkspaceAsFile: isFile });
761764
};
762765

763-
const workspacePicks: IFilePickOpenEntry[] = recentWorkspaces.map((workspace, index) => toPick(workspace, index === 0 ? { label: nls.localize('workspaces', "workspaces") } : void 0, isSingleFolderWorkspaceIdentifier(workspace) ? FileKind.FOLDER : FileKind.ROOT_FOLDER, this.environmentService, !this.isQuickNavigate() ? this.instantiationService.createInstance(RemoveFromRecentlyOpened, workspace) : void 0));
764-
const filePicks: IFilePickOpenEntry[] = recentFiles.map((p, index) => toPick(p, index === 0 ? { label: nls.localize('files', "files"), border: true } : void 0, FileKind.FILE, this.environmentService, !this.isQuickNavigate() ? this.instantiationService.createInstance(RemoveFromRecentlyOpened, p) : void 0));
766+
const workspacePicks: IFilePickOpenEntry[] = recentWorkspaces.map((workspace, index) => toPick(workspace, index === 0 ? { label: nls.localize('workspaces', "workspaces") } : void 0, isSingleFolderWorkspaceIdentifier(workspace) ? FileKind.FOLDER : FileKind.ROOT_FOLDER, this.environmentService, this.uriDisplayService, !this.isQuickNavigate() ? this.instantiationService.createInstance(RemoveFromRecentlyOpened, workspace) : void 0));
767+
const filePicks: IFilePickOpenEntry[] = recentFiles.map((p, index) => toPick(p, index === 0 ? { label: nls.localize('files', "files"), border: true } : void 0, FileKind.FILE, this.environmentService, this.uriDisplayService, !this.isQuickNavigate() ? this.instantiationService.createInstance(RemoveFromRecentlyOpened, p) : void 0));
765768

766769
// focus second entry if the first recent workspace is the current workspace
767770
let autoFocusSecondEntry: boolean = recentWorkspaces[0] && this.contextService.isCurrentWorkspace(recentWorkspaces[0]);
@@ -812,9 +815,10 @@ export class OpenRecentAction extends BaseOpenRecentAction {
812815
@IWorkspaceContextService contextService: IWorkspaceContextService,
813816
@IEnvironmentService environmentService: IEnvironmentService,
814817
@IKeybindingService keybindingService: IKeybindingService,
815-
@IInstantiationService instantiationService: IInstantiationService
818+
@IInstantiationService instantiationService: IInstantiationService,
819+
@IUriDisplayService uriDisplayService: IUriDisplayService
816820
) {
817-
super(id, label, windowService, quickOpenService, contextService, environmentService, keybindingService, instantiationService);
821+
super(id, label, windowService, quickOpenService, contextService, environmentService, uriDisplayService, keybindingService, instantiationService);
818822
}
819823

820824
protected isQuickNavigate(): boolean {
@@ -835,9 +839,10 @@ export class QuickOpenRecentAction extends BaseOpenRecentAction {
835839
@IWorkspaceContextService contextService: IWorkspaceContextService,
836840
@IEnvironmentService environmentService: IEnvironmentService,
837841
@IKeybindingService keybindingService: IKeybindingService,
838-
@IInstantiationService instantiationService: IInstantiationService
842+
@IInstantiationService instantiationService: IInstantiationService,
843+
@IUriDisplayService uriDisplayService: IUriDisplayService
839844
) {
840-
super(id, label, windowService, quickOpenService, contextService, environmentService, keybindingService, instantiationService);
845+
super(id, label, windowService, quickOpenService, contextService, environmentService, uriDisplayService, keybindingService, instantiationService);
841846
}
842847

843848
protected isQuickNavigate(): boolean {

src/vs/workbench/electron-browser/workbench.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ export class Workbench extends Disposable implements IPartService {
336336
serviceCollection.set(IClipboardService, new ClipboardService());
337337

338338
// Uri Display
339-
serviceCollection.set(IUriDisplayService, new UriDisplayService(this.environmentService, this.contextService));
339+
const uriDisplayService = new UriDisplayService(this.environmentService, this.contextService);
340+
serviceCollection.set(IUriDisplayService, uriDisplayService);
341+
this.configurationService.acquireUriDisplayService(uriDisplayService);
340342

341343
// Status bar
342344
this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);

src/vs/workbench/parts/search/browser/openFileHandler.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
88
import * as errors from 'vs/base/common/errors';
99
import * as nls from 'vs/nls';
1010
import * as paths from 'vs/base/common/paths';
11-
import * as labels from 'vs/base/common/labels';
1211
import * as objects from 'vs/base/common/objects';
1312
import { defaultGenerator } from 'vs/base/common/idGenerator';
1413
import URI from 'vs/base/common/uri';
@@ -34,6 +33,8 @@ import { getOutOfWorkspaceEditorResources } from 'vs/workbench/parts/search/comm
3433
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3534
import { prepareQuery, IPreparedQuery } from 'vs/base/parts/quickopen/common/quickOpenScorer';
3635
import { IFileService } from 'vs/platform/files/common/files';
36+
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
37+
import { untildify } from 'vs/base/common/labels';
3738

3839
export class FileQuickOpenModel extends QuickOpenModel {
3940

@@ -125,7 +126,8 @@ export class OpenFileHandler extends QuickOpenHandler {
125126
@IWorkspaceContextService private contextService: IWorkspaceContextService,
126127
@ISearchService private searchService: ISearchService,
127128
@IEnvironmentService private environmentService: IEnvironmentService,
128-
@IFileService private fileService: IFileService
129+
@IFileService private fileService: IFileService,
130+
@IUriDisplayService private uriDisplayService: IUriDisplayService
129131
) {
130132
super();
131133

@@ -145,7 +147,7 @@ export class OpenFileHandler extends QuickOpenHandler {
145147
}
146148

147149
// Untildify file pattern
148-
query.value = labels.untildify(query.value, this.environmentService.userHome);
150+
query.value = untildify(query.value, this.environmentService.userHome);
149151

150152
// Do find results
151153
return this.doFindResults(query, this.cacheState.cacheKey, maxSortedResults);
@@ -171,7 +173,7 @@ export class OpenFileHandler extends QuickOpenHandler {
171173
const fileMatch = complete.results[i];
172174

173175
const label = paths.basename(fileMatch.resource.fsPath);
174-
const description = labels.getPathLabel(resources.dirname(fileMatch.resource), this.environmentService, this.contextService);
176+
const description = this.uriDisplayService.getLabel(resources.dirname(fileMatch.resource), true);
175177

176178
results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
177179
}

0 commit comments

Comments
 (0)