mirror of
https://github.com/Microsoft/vscode
synced 2024-11-05 18:29:38 +00:00
window - guard against invalid title settings (#204683)
This commit is contained in:
parent
da36e0eba1
commit
3b5844353f
2 changed files with 33 additions and 23 deletions
|
@ -12,7 +12,7 @@ import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
|
|||
import { EditorResourceAccessor, Verbosity, SideBySideEditor } from 'vs/workbench/common/editor';
|
||||
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
|
||||
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||
import { isWindows, isWeb, isMacintosh } from 'vs/base/common/platform';
|
||||
import { isWindows, isWeb, isMacintosh, isNative } from 'vs/base/common/platform';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { trim } from 'vs/base/common/strings';
|
||||
import { IEditorGroupsContainer } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
|
@ -30,9 +30,23 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
|||
|
||||
const enum WindowSettingNames {
|
||||
titleSeparator = 'window.titleSeparator',
|
||||
title = 'window.title',
|
||||
title = 'window.title'
|
||||
}
|
||||
|
||||
export const defaultWindowTitle = (() => {
|
||||
if (isMacintosh && isNative) {
|
||||
return '${activeEditorShort}${separator}${rootName}${separator}${profileName}'; // macOS has native dirty indicator
|
||||
}
|
||||
|
||||
const base = '${dirty}${activeEditorShort}${separator}${rootName}${separator}${profileName}${separator}${appName}';
|
||||
if (isWeb) {
|
||||
return base + '${separator}${remoteName}'; // Web: always show remote name
|
||||
}
|
||||
|
||||
return base;
|
||||
})();
|
||||
export const defaultWindowTitleSeparator = isMacintosh ? ' \u2014 ' : ' - ';
|
||||
|
||||
export class WindowTitle extends Disposable {
|
||||
|
||||
private static readonly NLS_USER_IS_ADMIN = isWindows ? localize('userIsAdmin', "[Administrator]") : localize('userIsSudo', "[Superuser]");
|
||||
|
@ -324,17 +338,24 @@ export class WindowTitle extends Disposable {
|
|||
const dirty = editor?.isDirty() && !editor.isSaving() ? WindowTitle.TITLE_DIRTY : '';
|
||||
const appName = this.productService.nameLong;
|
||||
const profileName = this.userDataProfileService.currentProfile.isDefault ? '' : this.userDataProfileService.currentProfile.name;
|
||||
const separator = this.configurationService.getValue<string>(WindowSettingNames.titleSeparator);
|
||||
const titleTemplate = this.configurationService.getValue<string>(WindowSettingNames.title);
|
||||
const focusedView: string = this.viewsService.getFocusedViewName();
|
||||
|
||||
// Variables (contributed)
|
||||
const contributedVariables: { [key: string]: string } = {};
|
||||
const variables: Record<string, string> = {};
|
||||
for (const [contextKey, name] of this.variables) {
|
||||
contributedVariables[name] = this.contextKeyService.getContextKeyValue(contextKey) ?? '';
|
||||
variables[name] = this.contextKeyService.getContextKeyValue(contextKey) ?? '';
|
||||
}
|
||||
|
||||
let titleTemplate = this.configurationService.getValue<string>(WindowSettingNames.title);
|
||||
if (typeof titleTemplate !== 'string') {
|
||||
titleTemplate = defaultWindowTitle;
|
||||
}
|
||||
|
||||
let separator = this.configurationService.getValue<string>(WindowSettingNames.titleSeparator);
|
||||
if (typeof separator !== 'string') {
|
||||
separator = defaultWindowTitleSeparator;
|
||||
}
|
||||
|
||||
return template(titleTemplate, {
|
||||
...variables,
|
||||
activeEditorShort,
|
||||
activeEditorLong,
|
||||
activeEditorMedium,
|
||||
|
@ -351,7 +372,6 @@ export class WindowTitle extends Disposable {
|
|||
remoteName,
|
||||
profileName,
|
||||
focusedView,
|
||||
...contributedVariables,
|
||||
separator: { label: separator }
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { isMacintosh, isWindows, isLinux, isWeb, isNative } from 'vs/base/common/platform';
|
||||
import { isMacintosh, isWindows, isLinux, isWeb } from 'vs/base/common/platform';
|
||||
import { ConfigurationMigrationWorkbenchContribution, DynamicWorkbenchSecurityConfiguration, IConfigurationMigrationRegistry, workbenchConfigurationNodeBase, Extensions, ConfigurationKeyValuePairs, problemsConfigurationNodeBase } from 'vs/workbench/common/configuration';
|
||||
import { isStandalone } from 'vs/base/browser/browser';
|
||||
import { WorkbenchPhase, registerWorkbenchContribution2 } from 'vs/workbench/common/contributions';
|
||||
import { ActivityBarPosition, EditorActionsLocation, EditorTabsMode, LayoutSettings } from 'vs/workbench/services/layout/browser/layoutService';
|
||||
import { defaultWindowTitle, defaultWindowTitleSeparator } from 'vs/workbench/browser/parts/titlebar/windowTitle';
|
||||
|
||||
const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
|
||||
|
||||
|
@ -624,23 +625,12 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
|
|||
'properties': {
|
||||
'window.title': {
|
||||
'type': 'string',
|
||||
'default': (() => {
|
||||
if (isMacintosh && isNative) {
|
||||
return '${activeEditorShort}${separator}${rootName}${separator}${profileName}'; // macOS has native dirty indicator
|
||||
}
|
||||
|
||||
const base = '${dirty}${activeEditorShort}${separator}${rootName}${separator}${profileName}${separator}${appName}';
|
||||
if (isWeb) {
|
||||
return base + '${separator}${remoteName}'; // Web: always show remote name
|
||||
}
|
||||
|
||||
return base;
|
||||
})(),
|
||||
'default': defaultWindowTitle,
|
||||
'markdownDescription': windowTitleDescription
|
||||
},
|
||||
'window.titleSeparator': {
|
||||
'type': 'string',
|
||||
'default': isMacintosh ? ' \u2014 ' : ' - ',
|
||||
'default': defaultWindowTitleSeparator,
|
||||
'markdownDescription': localize("window.titleSeparator", "Separator used by {0}.", '`#window.title#`')
|
||||
},
|
||||
[LayoutSettings.COMMAND_CENTER]: {
|
||||
|
|
Loading…
Reference in a new issue