提交 305f0fbb 编写于 作者: B Benjamin Pasero

editorInput.getTitle() for #16623

上级 434da15e
......@@ -76,6 +76,14 @@ function getPath(arg1: URI | string | IWorkspaceProvider): string {
return (<URI>arg1).fsPath;
}
export function tildify(path: string, userHome: string): string {
if (path && (platform.isMacintosh || platform.isLinux) && path.indexOf(userHome) === 0) {
path = `~${path.substr(userHome.length)}`;
}
return path;
}
/**
* Shortens the paths but keeps them easy to distinguish.
* Replaces not important parts with ellipsis.
......
......@@ -159,6 +159,12 @@ export enum Direction {
RIGHT
}
export enum Verbosity {
SHORT,
MEDIUM,
LONG
}
export interface IEditorInput extends IDisposable {
onDispose: Event<void>;
......@@ -173,6 +179,11 @@ export interface IEditorInput extends IDisposable {
*/
getDescription(verbose?: boolean): string;
/**
* Returns the display title of this input.
*/
getTitle(verbosity?: Verbosity): string;
/**
* Resolves the input.
*/
......
......@@ -11,6 +11,7 @@ import { IEditorGroup, toResource } from 'vs/workbench/common/editor';
import DOM = require('vs/base/browser/dom');
import { TitleControl } from 'vs/workbench/browser/parts/editor/titleControl';
import { EditorLabel } from 'vs/workbench/browser/labels';
import { Verbosity } from 'vs/platform/editor/common/editor';
export class NoTabsTitleControl extends TitleControl {
private titleContainer: HTMLElement;
......@@ -119,12 +120,12 @@ export class NoTabsTitleControl extends TitleControl {
const resource = toResource(editor, { supportSideBySide: true });
const name = editor.getName() || '';
const description = isActive ? (editor.getDescription() || '') : '';
let verboseDescription = editor.getDescription(true) || '';
if (description === verboseDescription) {
verboseDescription = ''; // dont repeat what is already shown
let title = editor.getTitle(Verbosity.LONG);
if (description === title) {
title = ''; // dont repeat what is already shown
}
this.editorLabel.setLabel({ name, description, resource }, { title: verboseDescription, italic: !isPinned, extraClasses: ['title-label'] });
this.editorLabel.setLabel({ name, description, resource }, { title, italic: !isPinned, extraClasses: ['title-label'] });
// Update Editor Actions Toolbar
this.updateEditorActionsToolbar();
......
......@@ -14,7 +14,7 @@ import { isMacintosh } from 'vs/base/common/platform';
import { MIME_BINARY } from 'vs/base/common/mime';
import { shorten } from 'vs/base/common/labels';
import { ActionRunner, IAction } from 'vs/base/common/actions';
import { Position, IEditorInput } from 'vs/platform/editor/common/editor';
import { Position, IEditorInput, Verbosity } from 'vs/platform/editor/common/editor';
import { IEditorGroup, toResource } from 'vs/workbench/common/editor';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyCode } from 'vs/base/common/keyCodes';
......@@ -44,7 +44,7 @@ interface IEditorInputLabel {
name: string;
hasAmbiguousName?: boolean;
description?: string;
verboseDescription?: string;
title?: string;
}
export class TabsTitleControl extends TitleControl {
......@@ -211,11 +211,11 @@ export class TabsTitleControl extends TitleControl {
const label = labels[index];
const name = label.name;
const description = label.hasAmbiguousName && label.description ? label.description : '';
const verboseDescription = label.verboseDescription || '';
const title = label.title || '';
// Container
tabContainer.setAttribute('aria-label', `${name}, tab`);
tabContainer.title = verboseDescription;
tabContainer.title = title;
['off', 'left'].forEach(option => {
const domAction = this.tabOptions.tabCloseButton === option ? DOM.addClass : DOM.removeClass;
domAction(tabContainer, `close-button-${option}`);
......@@ -264,7 +264,7 @@ export class TabsTitleControl extends TitleControl {
editor,
name: editor.getName(),
description,
verboseDescription: editor.getDescription(true)
title: editor.getTitle(Verbosity.LONG)
};
labels.push(item);
......
......@@ -23,12 +23,12 @@ import { IIntegrityService } from 'vs/platform/integrity/common/integrity';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { isMacintosh, isLinux } from 'vs/base/common/platform';
import nls = require('vs/nls');
import * as labels from 'vs/base/common/labels';
import { EditorInput, toResource } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { Verbosity } from 'vs/platform/editor/common/editor';
export class TitlebarPart extends Part implements ITitleService {
......@@ -66,7 +66,7 @@ export class TitlebarPart extends Part implements ITitleService {
this.isPure = true;
this.activeEditorListeners = [];
this.workspacePath = contextService.hasWorkspace() ? this.tildify(labels.getPathLabel(contextService.getWorkspace().resource)) : '';
this.workspacePath = contextService.hasWorkspace() ? labels.tildify(labels.getPathLabel(contextService.getWorkspace().resource), environmentService.userHome) : '';
this.init();
......@@ -163,12 +163,11 @@ export class TitlebarPart extends Part implements ITitleService {
private doGetWindowTitle(): string {
const input = this.editorService.getActiveEditorInput();
const workspace = this.contextService.getWorkspace();
const file = toResource(input, { filter: 'file' });
// Variables
const activeEditorShort = input ? input.getName() : '';
const activeEditorMedium = file ? labels.getPathLabel(file, this.contextService) : activeEditorShort;
const activeEditorLong = file ? this.tildify(labels.getPathLabel(file)) : activeEditorMedium;
const activeEditorShort = input ? input.getTitle(Verbosity.SHORT) : '';
const activeEditorMedium = input ? input.getTitle(Verbosity.MEDIUM) : activeEditorShort;
const activeEditorLong = input ? input.getTitle(Verbosity.LONG) : activeEditorMedium;
const rootName = workspace ? workspace.name : '';
const rootPath = workspace ? this.workspacePath : '';
const dirty = input && input.isDirty() ? TitlebarPart.TITLE_DIRTY : '';
......@@ -187,14 +186,6 @@ export class TitlebarPart extends Part implements ITitleService {
});
}
private tildify(path: string): string {
if (path && (isMacintosh || isLinux) && path.indexOf(this.environmentService.userHome) === 0) {
path = `~${path.substr(this.environmentService.userHome.length)}`;
}
return path;
}
public createContentArea(parent: Builder): Builder {
this.titleContainer = $(parent);
......
......@@ -11,7 +11,7 @@ import types = require('vs/base/common/types');
import URI from 'vs/base/common/uri';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { IEditor, ICommonCodeEditor, IEditorViewState, IEditorOptions as ICodeEditorOptions, IModel } from 'vs/editor/common/editorCommon';
import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position } from 'vs/platform/editor/common/editor';
import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position, Verbosity } from 'vs/platform/editor/common/editor';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { SyncDescriptor, AsyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
......@@ -179,13 +179,15 @@ export abstract class EditorInput implements IEditorInput {
/**
* Returns the description of this input that can be shown to the user. Examples include showing the description of
* the input above the editor area to the side of the name of the input.
*
* @param verbose controls if the description should be short or can contain additional details.
*/
public getDescription(verbose?: boolean): string {
public getDescription(): string {
return null;
}
public getTitle(verbosity?: Verbosity): string {
return this.getName();
}
/**
* Returns the unique type identifier of this input.
*/
......
......@@ -18,6 +18,8 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { telemetryURIDescriptor } from 'vs/platform/telemetry/common/telemetryUtils';
import { Verbosity } from 'vs/platform/editor/common/editor';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
/**
* A file editor input is the input type for the file editor of file system resources.
......@@ -29,7 +31,10 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
private name: string;
private description: string;
private verboseDescription: string;
private shortTitle: string;
private mediumTitle: string;
private longTitle: string;
private toUnbind: IDisposable[];
......@@ -41,7 +46,8 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
preferredEncoding: string,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@ITextFileService private textFileService: ITextFileService
@ITextFileService private textFileService: ITextFileService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super();
......@@ -76,7 +82,9 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
// Reset resource dependent properties
this.name = null;
this.description = null;
this.verboseDescription = null;
this.shortTitle = null;
this.mediumTitle = null;
this.longTitle = null;
}
public getResource(): URI {
......@@ -125,20 +133,23 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
return this.name;
}
public getDescription(verbose?: boolean): string {
if (!verbose) {
if (!this.description) {
this.description = labels.getPathLabel(paths.dirname(this.resource.fsPath), this.contextService);
}
return this.description;
public getDescription(): string {
if (!this.description) {
this.description = labels.getPathLabel(paths.dirname(this.resource.fsPath), this.contextService);
}
if (!this.verboseDescription) {
this.verboseDescription = labels.getPathLabel(this.resource.fsPath);
}
return this.description;
}
return this.verboseDescription;
public getTitle(verbosity: Verbosity): string {
switch (verbosity) {
case Verbosity.SHORT:
return this.shortTitle ? this.shortTitle : (this.shortTitle = this.getName());
case Verbosity.MEDIUM:
return this.mediumTitle ? this.mediumTitle : (this.mediumTitle = labels.getPathLabel(this.resource, this.contextService));
case Verbosity.LONG:
return this.longTitle ? this.longTitle : (this.longTitle = labels.tildify(labels.getPathLabel(this.resource), this.environmentService.userHome));
}
}
public isDirty(): boolean {
......
......@@ -15,6 +15,7 @@ import { EncodingMode } from 'vs/workbench/common/editor';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { FileOperationResult, IFileOperationResult } from 'vs/platform/files/common/files';
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
import { Verbosity } from 'vs/platform/editor/common/editor';
function toResource(path) {
return URI.file(join('C:\\', new Buffer(this.test.fullTitle()).toString('base64'), path));
......@@ -49,7 +50,7 @@ suite('Files - FileEditorInput', () => {
assert(!input.matches(null));
assert.ok(input.getName());
assert.ok(input.getDescription());
assert.ok(input.getDescription(true));
assert.ok(input.getTitle(Verbosity.SHORT));
assert.strictEqual('file.js', input.getName());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册