提交 c9c396c7 编写于 作者: B Benjamin Pasero

tildify path label if possible (fixes #24045)

上级 ebf71dae
......@@ -12,7 +12,7 @@ import { IMatch } from 'vs/base/common/filters';
import uri from 'vs/base/common/uri';
import paths = require('vs/base/common/paths');
import types = require('vs/base/common/types');
import { IWorkspaceProvider, getPathLabel } from 'vs/base/common/labels';
import { IWorkspaceProvider, getPathLabel, IUserHomeProvider } from 'vs/base/common/labels';
export interface IIconLabelCreationOptions {
supportHighlights?: boolean;
......@@ -99,17 +99,17 @@ export class IconLabel {
export class FileLabel extends IconLabel {
constructor(container: HTMLElement, file: uri, provider: IWorkspaceProvider) {
constructor(container: HTMLElement, file: uri, provider: IWorkspaceProvider, userHome?: IUserHomeProvider) {
super(container);
this.setFile(file, provider);
this.setFile(file, provider, userHome);
}
public setFile(file: uri, provider: IWorkspaceProvider): void {
public setFile(file: uri, provider: IWorkspaceProvider, userHome: IUserHomeProvider): void {
const path = getPath(file);
const parent = paths.dirname(path);
this.setValue(paths.basename(path), parent && parent !== '.' ? getPathLabel(parent, provider) : '', { title: path });
this.setValue(paths.basename(path), parent && parent !== '.' ? getPathLabel(parent, provider, userHome) : '', { title: path });
}
}
......
......@@ -25,6 +25,10 @@ export interface IWorkspaceProvider {
};
}
export interface IUserHomeProvider {
userHome: string;
}
export class PathLabelProvider implements ILabelProvider {
private root: string;
......@@ -37,7 +41,7 @@ export class PathLabelProvider implements ILabelProvider {
}
}
export function getPathLabel(resource: URI | string, basePathProvider?: URI | string | IWorkspaceProvider): string {
export function getPathLabel(resource: URI | string, basePathProvider?: URI | string | IWorkspaceProvider, userHomeProvider?: IUserHomeProvider): string {
const absolutePath = getPath(resource);
if (!absolutePath) {
return null;
......@@ -57,7 +61,12 @@ export function getPathLabel(resource: URI | string, basePathProvider?: URI | st
return normalize(absolutePath.charAt(0).toUpperCase() + absolutePath.slice(1), true); // convert c:\something => C:\something
}
return normalize(absolutePath, true);
let res = normalize(absolutePath, true);
if (!platform.isWindows && userHomeProvider) {
res = tildify(res, userHomeProvider.userHome);
}
return res;
}
function getPath(arg1: URI | string | IWorkspaceProvider): string {
......
......@@ -18,6 +18,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IEnvironmentService } from "vs/platform/environment/common/environment";
export interface IEditorLabel {
name: string;
......@@ -43,7 +44,8 @@ export class ResourceLabel extends IconLabel {
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService,
@IModeService private modeService: IModeService,
@IModelService private modelService: IModelService
@IModelService private modelService: IModelService,
@IEnvironmentService protected environmentService: IEnvironmentService
) {
super(container, options);
......@@ -113,7 +115,7 @@ export class ResourceLabel extends IconLabel {
if (this.options && typeof this.options.title === 'string') {
title = this.options.title;
} else if (resource) {
title = getPathLabel(resource.fsPath);
title = getPathLabel(resource.fsPath, void 0, this.environmentService);
}
if (!this.computedIconClasses) {
......@@ -164,7 +166,7 @@ export class FileLabel extends ResourceLabel {
this.setLabel({
resource,
name: !options.hideLabel ? paths.basename(resource.fsPath) : void 0,
description: !options.hidePath ? getPathLabel(paths.dirname(resource.fsPath), this.contextService) : void 0
description: !options.hidePath ? getPathLabel(paths.dirname(resource.fsPath), this.contextService, this.environmentService) : void 0
}, options);
}
}
......
......@@ -51,6 +51,7 @@ import { IListService } from 'vs/platform/list/browser/listService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { SIDE_BAR_BACKGROUND } from "vs/workbench/common/theme";
import { attachQuickOpenStyler } from "vs/platform/theme/common/styler";
import { IEnvironmentService } from "vs/platform/environment/common/environment";
const HELP_PREFIX = '?';
......@@ -1112,7 +1113,8 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
@IModelService private modelService: IModelService,
@ITextFileService private textFileService: ITextFileService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService
@IConfigurationService private configurationService: IConfigurationService,
@IEnvironmentService environmentService: IEnvironmentService
) {
super(editorService);
......@@ -1127,7 +1129,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
const resourceInput = input as IResourceInput;
this.resource = resourceInput.resource;
this.label = paths.basename(resourceInput.resource.fsPath);
this.description = labels.getPathLabel(paths.dirname(this.resource.fsPath), contextService);
this.description = labels.getPathLabel(paths.dirname(this.resource.fsPath), contextService, environmentService);
this.dirty = this.resource && this.textFileService.isDirty(this.resource);
if (this.dirty && this.textFileService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY) {
......
......@@ -71,7 +71,7 @@ export class TitlebarPart extends Part implements ITitleService {
this.isPure = true;
this.activeEditorListeners = [];
this.workspacePath = contextService.hasWorkspace() ? labels.tildify(labels.getPathLabel(contextService.getWorkspace().resource), environmentService.userHome) : '';
this.workspacePath = contextService.hasWorkspace() ? labels.getPathLabel(contextService.getWorkspace().resource, void 0, environmentService) : '';
this.init();
......
......@@ -18,6 +18,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import Event, { Emitter } from 'vs/base/common/event';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { telemetryURIDescriptor } from 'vs/platform/telemetry/common/telemetryUtils';
import { IEnvironmentService } from "vs/platform/environment/common/environment";
/**
* An editor input to be used for untitled text buffers.
......@@ -46,7 +47,8 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
initialValue: string,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@ITextFileService private textFileService: ITextFileService
@ITextFileService private textFileService: ITextFileService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super();
......@@ -92,7 +94,7 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
}
public getDescription(): string {
return this.hasAssociatedFilePath ? labels.getPathLabel(paths.dirname(this.resource.fsPath), this.contextService) : null;
return this.hasAssociatedFilePath ? labels.getPathLabel(paths.dirname(this.resource.fsPath), this.contextService, this.environmentService) : null;
}
public isDirty(): boolean {
......
......@@ -48,6 +48,7 @@ import { ITextModelResolverService } from 'vs/editor/common/services/resolverSer
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { withFocussedFilesExplorer, revealInOSCommand, revealInExplorerCommand, copyPathCommand } from 'vs/workbench/parts/files/browser/fileCommands';
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { IEnvironmentService } from "vs/platform/environment/common/environment";
export interface IEditableData {
action: IAction;
......@@ -1168,7 +1169,8 @@ export class GlobalCompareResourcesAction extends Action {
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IHistoryService private historyService: IHistoryService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IMessageService private messageService: IMessageService
@IMessageService private messageService: IMessageService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super(id, label);
}
......@@ -1202,7 +1204,7 @@ export class GlobalCompareResourcesAction extends Action {
}
label = paths.basename(resource.fsPath);
description = resource.scheme === 'file' ? labels.getPathLabel(paths.dirname(resource.fsPath), this.contextService) : void 0;
description = resource.scheme === 'file' ? labels.getPathLabel(paths.dirname(resource.fsPath), this.contextService, this.environmentService) : void 0;
return <IHistoryPickEntry>{ input, resource, label, description };
}).filter(p => !!p);
......
......@@ -41,6 +41,7 @@ import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/c
import { ResourceContextKey } from 'vs/workbench/common/resourceContextKey';
import { IWorkbenchThemeService, IFileIconTheme } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { isLinux } from 'vs/base/common/platform';
import { IEnvironmentService } from "vs/platform/environment/common/environment";
export class ExplorerView extends CollapsibleViewletView {
......@@ -90,7 +91,8 @@ export class ExplorerView extends CollapsibleViewletView {
@IKeybindingService keybindingService: IKeybindingService,
@IContextKeyService contextKeyService: IContextKeyService,
@IConfigurationService private configurationService: IConfigurationService,
@IWorkbenchThemeService private themeService: IWorkbenchThemeService
@IWorkbenchThemeService private themeService: IWorkbenchThemeService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super(actionRunner, false, nls.localize('explorerSection', "Files Explorer Section"), messageService, keybindingService, contextMenuService, headerSize);
......@@ -111,7 +113,7 @@ export class ExplorerView extends CollapsibleViewletView {
public renderHeader(container: HTMLElement): void {
const titleDiv = $('div.title').appendTo(container);
$('span').text(this.contextService.getWorkspace().name).title(labels.getPathLabel(this.contextService.getWorkspace().resource.fsPath)).appendTo(titleDiv);
$('span').text(this.contextService.getWorkspace().name).title(labels.getPathLabel(this.contextService.getWorkspace().resource.fsPath, void 0, this.environmentService)).appendTo(titleDiv);
super.renderHeader(container);
}
......
......@@ -143,7 +143,7 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
public getDescription(): string {
if (!this.description) {
this.description = labels.getPathLabel(paths.dirname(this.resource.fsPath), this.contextService);
this.description = labels.getPathLabel(paths.dirname(this.resource.fsPath), this.contextService, this.environmentService);
}
return this.description;
......@@ -156,10 +156,10 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
title = this.shortTitle ? this.shortTitle : (this.shortTitle = this.getName());
break;
case Verbosity.MEDIUM:
title = this.mediumTitle ? this.mediumTitle : (this.mediumTitle = labels.getPathLabel(this.resource, this.contextService));
title = this.mediumTitle ? this.mediumTitle : (this.mediumTitle = labels.getPathLabel(this.resource, this.contextService, this.environmentService));
break;
case Verbosity.LONG:
title = this.longTitle ? this.longTitle : (this.longTitle = labels.tildify(labels.getPathLabel(this.resource), this.environmentService.userHome));
title = this.longTitle ? this.longTitle : (this.longTitle = labels.getPathLabel(this.resource, void 0, this.environmentService));
break;
}
......
......@@ -30,6 +30,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IQueryOptions, ISearchService, ISearchStats, ISearchQuery } from 'vs/platform/search/common/search';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentService } from "vs/platform/environment/common/environment";
export class FileQuickOpenModel extends QuickOpenModel {
......@@ -119,7 +120,8 @@ export class OpenFileHandler extends QuickOpenHandler {
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkbenchThemeService private themeService: IWorkbenchThemeService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@ISearchService private searchService: ISearchService
@ISearchService private searchService: ISearchService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super();
......@@ -166,7 +168,7 @@ export class OpenFileHandler extends QuickOpenHandler {
const fileMatch = complete.results[i];
const label = paths.basename(fileMatch.resource.fsPath);
const description = labels.getPathLabel(paths.dirname(fileMatch.resource.fsPath), this.contextService);
const description = labels.getPathLabel(paths.dirname(fileMatch.resource.fsPath), this.contextService, this.environmentService);
results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
}
......
......@@ -24,6 +24,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceSymbolProvider, getWorkspaceSymbols } from 'vs/workbench/parts/search/common/search';
import { IEnvironmentService } from "vs/platform/environment/common/environment";
class SymbolEntry extends EditorQuickOpenEntry {
......@@ -34,7 +35,8 @@ class SymbolEntry extends EditorQuickOpenEntry {
private _provider: IWorkspaceSymbolProvider,
@IConfigurationService private _configurationService: IConfigurationService,
@IWorkspaceContextService private _contextService: IWorkspaceContextService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEnvironmentService private _environmentService: IEnvironmentService
) {
super(editorService);
}
......@@ -50,7 +52,7 @@ class SymbolEntry extends EditorQuickOpenEntry {
public getDescription(): string {
let result = this._bearing.containerName;
if (!result && this._bearing.location.uri) {
result = labels.getPathLabel(this._bearing.location.uri, this._contextService);
result = labels.getPathLabel(this._bearing.location.uri, this._contextService, this._environmentService);
}
return result;
}
......
......@@ -22,6 +22,7 @@ import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import nls = require('vs/nls');
import { getPathLabel, IWorkspaceProvider } from 'vs/base/common/labels';
import { IEnvironmentService } from "vs/platform/environment/common/environment";
export interface IEditorPart {
openEditor(input?: IEditorInput, options?: IEditorOptions | ITextEditorOptions, sideBySide?: boolean): TPromise<BaseEditor>;
......@@ -47,7 +48,8 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
editorPart: IEditorPart | IWorkbenchEditorService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IWorkspaceContextService private workspaceContextService: IWorkspaceContextService,
@IInstantiationService private instantiationService?: IInstantiationService
@IInstantiationService private instantiationService: IInstantiationService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
this.editorPart = editorPart;
this.fileInputDescriptor = Registry.as<IEditorRegistry>(Extensions.Editors).getDefaultFileInput();
......@@ -224,7 +226,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
if (resourceDiffInput.leftResource && resourceDiffInput.rightResource) {
return this.createInput({ resource: resourceDiffInput.leftResource }).then(leftInput => {
return this.createInput({ resource: resourceDiffInput.rightResource }).then(rightInput => {
const label = resourceDiffInput.label || toDiffLabel(resourceDiffInput.leftResource, resourceDiffInput.rightResource, this.workspaceContextService);
const label = resourceDiffInput.label || this.toDiffLabel(resourceDiffInput.leftResource, resourceDiffInput.rightResource, this.workspaceContextService, this.environmentService);
return new DiffEditorInput(label, resourceDiffInput.description, leftInput, rightInput);
});
......@@ -265,13 +267,13 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
return typedFileInput;
});
}
}
function toDiffLabel(res1: URI, res2: URI, context: IWorkspaceProvider): string {
const leftName = getPathLabel(res1.fsPath, context);
const rightName = getPathLabel(res2.fsPath, context);
private toDiffLabel(res1: URI, res2: URI, context: IWorkspaceProvider, environment: IEnvironmentService): string {
const leftName = getPathLabel(res1.fsPath, context, environment);
const rightName = getPathLabel(res2.fsPath, context, environment);
return nls.localize('compareLabels', "{0} ↔ {1}", leftName, rightName);
return nls.localize('compareLabels', "{0} ↔ {1}", leftName, rightName);
}
}
export interface IEditorOpenHandler {
......@@ -297,13 +299,15 @@ export class DelegatingWorkbenchEditorService extends WorkbenchEditorService {
@IUntitledEditorService untitledEditorService: IUntitledEditorService,
@IInstantiationService instantiationService: IInstantiationService,
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEnvironmentService environmentService: IEnvironmentService
) {
super(
editorService,
untitledEditorService,
workspaceContextService,
instantiationService
instantiationService,
environmentService
);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册