From 4dab66888225bb9edf3de95b91796f3dc8664df0 Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Wed, 29 Jan 2020 12:31:49 -0500 Subject: [PATCH] [preferences] fix the display of file icons Fixes #6990 Fixes #7010 - fixes an issue where the file icon was not properly displayed - fixes an issue where the file icon was not properly updated based on the current file icon theme. This problem is solved by programmatically getting the icon based on the `file-icon` using the `labelProvider#getIcon` method. Signed-off-by: vince-fugnitto --- .../src/browser/preferences-tree-widget.ts | 27 +++++++++++++++++-- .../preferences/src/browser/style/index.css | 6 +++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/preferences/src/browser/preferences-tree-widget.ts b/packages/preferences/src/browser/preferences-tree-widget.ts index 649db1184478c..d74c113bc24bf 100644 --- a/packages/preferences/src/browser/preferences-tree-widget.ts +++ b/packages/preferences/src/browser/preferences-tree-widget.ts @@ -35,7 +35,8 @@ import { TreeProps, TreeWidget, WidgetManager, - PreferenceProvider + PreferenceProvider, + LabelProvider } from '@theia/core/lib/browser'; import { UserPreferenceProvider } from './user-preference-provider'; import { WorkspacePreferenceProvider } from './workspace-preference-provider'; @@ -254,6 +255,9 @@ export class PreferencesEditorsContainer extends DockPanel { @inject(EditorManager) protected readonly editorManager: EditorManager; + @inject(LabelProvider) + protected readonly labelProvider: LabelProvider; + @inject(PreferenceProvider) @named(PreferenceScope.User) protected readonly userPreferenceProvider: UserPreferenceProvider; @@ -278,6 +282,8 @@ export class PreferencesEditorsContainer extends DockPanel { this.onInitEmitter ); + protected readonly toDisposeOnDetach = new DisposableCollection(); + constructor( @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService, @inject(FileSystem) protected readonly fileSystem: FileSystem, @@ -305,6 +311,10 @@ export class PreferencesEditorsContainer extends DockPanel { super.onUpdateRequest(msg); } + onBeforeDetach(): void { + this.toDisposeOnDetach.dispose(); + } + protected async onAfterAttach(msg: Message): Promise { this.userPreferenceEditorWidget = await this.getUserPreferenceEditorWidget(); this.addWidget(this.userPreferenceEditorWidget); @@ -313,12 +323,25 @@ export class PreferencesEditorsContainer extends DockPanel { super.onAfterAttach(msg); this.onInitEmitter.fire(undefined); + this.toDisposeOnDetach.push( + this.labelProvider.onDidChange(() => { + // Listen to changes made by the label provider and apply updates to the preference editors. + const icon = this.labelProvider.getIcon(new URI('settings.json')); + this.userPreferenceEditorWidget.title.iconClass = icon; + if (this.workspacePreferenceEditorWidget) { + // Explicitly update the workspace preference title to `Workspace` for single and multi-root workspaces. + this.workspacePreferenceEditorWidget.title.label = 'Workspace'; + this.workspacePreferenceEditorWidget.title.iconClass = icon; + } + }) + ); } protected async getUserPreferenceEditorWidget(): Promise { const userPreferenceUri = this.userPreferenceProvider.getConfigUri(); const userPreferences = await this.editorManager.getOrCreateByUri(userPreferenceUri) as PreferencesEditorWidget; userPreferences.title.label = 'User'; + userPreferences.title.iconClass = this.labelProvider.getIcon(new URI('settings.json')); userPreferences.title.caption = `User Preferences: ${await this.getPreferenceEditorCaption(userPreferenceUri)}`; userPreferences.scope = PreferenceScope.User; return userPreferences; @@ -344,7 +367,7 @@ export class PreferencesEditorsContainer extends DockPanel { if (workspacePreferences) { workspacePreferences.title.label = 'Workspace'; workspacePreferences.title.caption = `Workspace Preferences: ${await this.getPreferenceEditorCaption(workspacePreferenceUri!)}`; - workspacePreferences.title.iconClass = 'database-icon medium-yellow file-icon'; + workspacePreferences.title.iconClass = this.labelProvider.getIcon(new URI('settings.json')); workspacePreferences.editor.setLanguage('jsonc'); workspacePreferences.scope = PreferenceScope.Workspace; } diff --git a/packages/preferences/src/browser/style/index.css b/packages/preferences/src/browser/style/index.css index 9d920b013b1d1..7a1dae291168a 100644 --- a/packages/preferences/src/browser/style/index.css +++ b/packages/preferences/src/browser/style/index.css @@ -17,3 +17,9 @@ #preferences_container_widget .p-SplitPanel-handle { border-right: var(--theia-border-width) solid var(--theia-editorGroup-border); } + +#preferences_container_widget .p-TabBar-tabIcon { + align-items: center; + display: flex; + line-height: var(--theia-content-line-height) !important; +}