Skip to content

Commit

Permalink
[preferences] fix the display of file icons
Browse files Browse the repository at this point in the history
Fixes eclipse-theia#6990
Fixes eclipse-theia#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 <[email protected]>
  • Loading branch information
vince-fugnitto authored and Sean Hellum committed Mar 12, 2020
1 parent 7ad939e commit 4dab668
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
27 changes: 25 additions & 2 deletions packages/preferences/src/browser/preferences-tree-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -305,6 +311,10 @@ export class PreferencesEditorsContainer extends DockPanel {
super.onUpdateRequest(msg);
}

onBeforeDetach(): void {
this.toDisposeOnDetach.dispose();
}

protected async onAfterAttach(msg: Message): Promise<void> {
this.userPreferenceEditorWidget = await this.getUserPreferenceEditorWidget();
this.addWidget(this.userPreferenceEditorWidget);
Expand All @@ -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<PreferencesEditorWidget> {
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;
Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/preferences/src/browser/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 4dab668

Please sign in to comment.