Skip to content

Commit

Permalink
fix(category-list): fix icon with vs-seti icon theme (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
laggage authored Mar 23, 2022
1 parent 330b88b commit 86fd8c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/services/check-workspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { commands, workspace } from 'vscode';
import { refreshPostCategoriesList } from '../commands/post-category/refresh-post-categories-list';
import { globalState } from './global-state';
import { PostFileMapManager } from './post-file-map';
import { Settings } from './settings.service';
Expand All @@ -12,9 +13,14 @@ export const isTargetWorkspace = (): boolean => {

export const observeConfigurationChange = () => {
globalState.extensionContext?.subscriptions.push(
workspace.onDidChangeConfiguration(ev =>
ev.affectsConfiguration(Settings.prefix) ? isTargetWorkspace() : false
)
workspace.onDidChangeConfiguration(ev => {
if (ev.affectsConfiguration(Settings.prefix)) {
isTargetWorkspace();
}
if (ev.affectsConfiguration(`${Settings.iconThemePrefix}.${Settings.iconThemeKey}`)) {
refreshPostCategoriesList();
}
})
);
isTargetWorkspace();
};
Expand Down
14 changes: 14 additions & 0 deletions src/services/settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ export class Settings {
return `cnblogsClientForVSCode`;
}

static get iconThemePrefix() {
return 'workbench';
}

static get iconThemeKey() {
return `iconTheme`;
}

static get iconTheme() {
return <'vs-seti' | 'vs-minimal' | undefined | string>(
workspace.getConfiguration(this.iconThemePrefix).get<string>(this.iconThemeKey)
);
}

static get configuration() {
return workspace.getConfiguration(this.prefix);
}
Expand Down
14 changes: 13 additions & 1 deletion src/tree-view-providers/categories-view-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import { commands, Event, EventEmitter, MessageOptions, ThemeIcon, TreeDataProvi
import { PostCategories, PostCategory } from '../models/post-category';
import { globalState } from '../services/global-state';
import { postCategoryService } from '../services/post-category.service';
import { Settings } from '../services/settings.service';

const categoryIcon = () => {
const iconTheme = Settings.iconTheme;
let iconId = 'folder';
switch (iconTheme) {
case 'vs-seti':
iconId = 'file-directory';
break;
}
return new ThemeIcon(iconId);
};

export class PostCategoriesViewDataProvider implements TreeDataProvider<PostCategory> {
private static _instance: PostCategoriesViewDataProvider;
Expand Down Expand Up @@ -36,7 +48,7 @@ export class PostCategoriesViewDataProvider implements TreeDataProvider<PostCate
getTreeItem(element: PostCategory): TreeItem | Thenable<TreeItem> {
const label = `${element.title}(${element.count})`;
return Object.assign(new TreeItem(label), {
iconPath: new ThemeIcon('folder'),
iconPath: categoryIcon(),
contextValue: 'cnb-post-category',
} as TreeItem);
}
Expand Down

0 comments on commit 86fd8c7

Please sign in to comment.