Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Feb 7, 2025
1 parent 4eb9e5d commit a7d66a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions src/vs/workbench/browser/parts/titlebar/windowTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class WindowTitle extends Disposable {

private title: string | undefined;
private titleIncludesFocusedView: boolean = false;
private titleIncludesEditorStateInfo: boolean = false;
private titleIncludesEditorState: boolean = false;

private readonly editorService: IEditorService;

Expand All @@ -104,8 +104,8 @@ export class WindowTitle extends Disposable {
this.editorService = editorService.createScoped(editorGroupsContainer, this._store);
this.windowId = targetWindow.vscodeWindowId;

this.updateTitleIncludesFocusedView();
this.updateTitleIncludesEditorStateInfo();
this.checkTitleVariables();

this.registerListeners();
}

Expand All @@ -130,23 +130,22 @@ export class WindowTitle extends Disposable {
}

private onConfigurationChanged(event: IConfigurationChangeEvent): void {
if (event.affectsConfiguration(WindowSettingNames.title)) {
this.updateTitleIncludesFocusedView();
const affectsTitleConfiguration = event.affectsConfiguration(WindowSettingNames.title);
if (affectsTitleConfiguration) {
this.checkTitleVariables();
}

if (event.affectsConfiguration(WindowSettingNames.title) || event.affectsConfiguration(WindowSettingNames.titleSeparator)) {
if (affectsTitleConfiguration || event.affectsConfiguration(WindowSettingNames.titleSeparator)) {
this.titleUpdater.schedule();
}
}

private updateTitleIncludesFocusedView(): void {
private checkTitleVariables(): void {
const titleTemplate = this.configurationService.getValue<unknown>(WindowSettingNames.title);
this.titleIncludesFocusedView = typeof titleTemplate === 'string' && titleTemplate.includes('${focusedView}');
}

private updateTitleIncludesEditorStateInfo(): void {
const titleTemplate = this.configurationService.getValue<unknown>(WindowSettingNames.title);
this.titleIncludesEditorStateInfo = typeof titleTemplate === 'string' && titleTemplate.includes('${editorStateInfo}');
if (typeof titleTemplate === 'string') {
this.titleIncludesFocusedView = titleTemplate.includes('${focusedView}');
this.titleIncludesEditorState = titleTemplate.includes('${activeEditorState}');
}
}

private onActiveEditorChange(): void {
Expand Down Expand Up @@ -179,7 +178,7 @@ export class WindowTitle extends Disposable {
this.activeEditorListeners.add(textEditorControl.onDidFocusEditorText(() => this.titleUpdater.schedule()));
}
}
if (this.titleIncludesEditorStateInfo) {
if (this.titleIncludesEditorState) {
this.activeEditorListeners.add(this.decorationsService.onDidChangeDecorations(() => this.titleUpdater.schedule()));
}
}
Expand Down Expand Up @@ -298,7 +297,7 @@ export class WindowTitle extends Disposable {
* {dirty}: indicator
* {focusedView}: e.g. Terminal
* {separator}: conditional separator
* {editorStateInfo}: e.g. Modified
* {activeEditorState}: e.g. Modified
*/
getWindowTitle(): string {
const editor = this.editorService.activeEditor;
Expand Down Expand Up @@ -358,7 +357,7 @@ export class WindowTitle extends Disposable {
const appName = this.productService.nameLong;
const profileName = this.userDataProfileService.currentProfile.isDefault ? '' : this.userDataProfileService.currentProfile.name;
const focusedView: string = this.viewsService.getFocusedViewName();
const editorStateInfo = editor?.resource ? this.decorationsService.getDecoration(editor.resource, true)?.tooltip : undefined;
const activeEditorState = editor?.resource ? this.decorationsService.getDecoration(editor.resource, true)?.tooltip : undefined;

const variables: Record<string, string> = {};
for (const [contextKey, name] of this.variables) {
Expand Down Expand Up @@ -393,7 +392,7 @@ export class WindowTitle extends Disposable {
remoteName,
profileName,
focusedView,
editorStateInfo,
activeEditorState,
separator: { label: separator }
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/workbench.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
localize('focusedView', "`${focusedView}`: the name of the view that is currently focused."),
localize('activeRepositoryName', "`${activeRepositoryName}`: the name of the active repository (e.g. vscode)."),
localize('activeRepositoryBranchName', "`${activeRepositoryBranchName}`: the name of the active branch in the active repository (e.g. main)."),
localize('editorStateInfo', "`${editorStateInfo}`: provides information about the state of the editor (e.g. Modified)."),
localize('activeEditorState', "`${activeEditorState}`: provides information about the state of the active editor (e.g. modified)."),
localize('separator', "`${separator}`: a conditional separator (\" - \") that only shows when surrounded by variables with values or static text.")
].join('\n- '); // intentionally concatenated to not produce a string that is too long for translations

Expand Down

0 comments on commit a7d66a3

Please sign in to comment.