Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[preferences] fix the display of file icons #7011

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}