Skip to content

Commit

Permalink
feat(model): 书签模型优化, 移除 customColor字段, 完全使用color 字段
Browse files Browse the repository at this point in the history
  • Loading branch information
czfadmin committed May 12, 2024
1 parent 57388c8 commit 02b71a6
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 108 deletions.
46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,30 @@
"title": "%bookmark-manager.changeSetting%",
"icon": "$(bookmark)",
"category": "Bookmark Manager (BM)"
},
{
"command": "bookmark-manager.revealInExplorer",
"title": "%bookmark-manager.revealInExplorer%",
"icon": "$(bookmark)",
"category": "Bookmark Manager (BM)"
},
{
"command": "bookmark-manager.sortedByCustom",
"title": "%bookmark-manager.sortedByCustom%",
"icon": "$(bookmark)",
"category": "Bookmark Manager (BM)"
},
{
"command": "bookmark-manager.sortedByLineNumber",
"title": "%bookmark-manager.sortedByLineNumber%",
"icon": "$(bookmark)",
"category": "Bookmark Manager (BM)"
},
{
"command": "bookmark-manager.sortedByCreateTime",
"title": "%bookmark-manager.sortedByCreateTime%",
"icon": "$(bookmark)",
"category": "Bookmark Manager (BM)"
}
],
"views": {
Expand Down Expand Up @@ -510,6 +534,20 @@
"group": "bookmarksActionsGroup2@1"
}
],
"bookmark-manager.codeSortedSubmenu": [
{
"command": "bookmark-manager.sortedByLineNumber",
"group": "group@1"
},
{
"command": "bookmark-manager.sortedByCustom",
"group": "group@2"
},
{
"command": "bookmark-manager.sortedByCreateTime",
"group": "group@3"
}
],
"bookmark-manager.codeGroupSubmenu": [
{
"command": "bookmark-manager.groupedByDefault",
Expand Down Expand Up @@ -569,6 +607,10 @@
{
"submenu": "bookmark-manager.codeGroupSubmenu",
"when": "view === bookmark-manager"
},
{
"submenu": "bookmark-manager.codeSortedSubmenu",
"when": "view === bookmark-manager"
}
],
"view/item/context": [
Expand Down Expand Up @@ -707,6 +749,10 @@
{
"id": "bookmark-manager.codeGroupSubmenu",
"label": "%bookmark-manager.group%"
},
{
"id": "bookmark-manager.codeSortedSubmenu",
"label": "%bookmark-manager.sortMenu%"
}
],
"keybindings": {
Expand Down
7 changes: 6 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@
"bookmark-manager.showWalkthroughs": "Show walkthroughs",
"bookmark-manager.changeSetting": "Change setting",
"bookmark-manager.ignoreFolders": "When this is set, the creation of the storage file `bookmark-manager.json` in the `.vscode` directory under the folder directory in this array will be automatically ignored.",
"bookmark-manager.logLevel": "Log level"
"bookmark-manager.logLevel": "Log level",
"bookmark-manager.revealInExplorer": "Reveal in explorer",
"bookmark-manager.sortMenu": "Sort",
"bookmark-manager.sortedByCustom": "Sorted by custom",
"bookmark-manager.sortedByLineNumber": "Sorted by line number",
"bookmark-manager.sortedByCreateTime": "Sorted by create time"
}
7 changes: 6 additions & 1 deletion package.nls.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@
"bookmark-manager.showWalkthroughs": "显示交互指南",
"bookmark-manager.changeSetting": "更改设置",
"bookmark-manager.ignoreFolders": "当设置此项时, 将自动忽略在此数组中的文件夹目录下的`.vscode`目录中创建存储文件`bookmark-manager.json`",
"bookmark-manager.logLevel": "日志级别"
"bookmark-manager.logLevel": "日志级别",
"bookmark-manager.revealInExplorer": "在Explorer中显示",
"bookmark-manager.sortMenu": "排序方式",
"bookmark-manager.sortedByCustom": "自定义排序",
"bookmark-manager.sortedByLineNumber": "行号",
"bookmark-manager.sortedByCreateTime": "创建时间"
}
12 changes: 3 additions & 9 deletions src/commands/bookmark/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ export async function changeBookmarkColor(ctx: LineBookmarkContext) {
if (!controller) {
return;
}
bookmark.updateColor({
...bookmark.customColor,
name: newColor,
});
bookmark.updateColor(newColor);
}

export async function changeBookmarkColorName(ctx: LineBookmarkContext) {
Expand All @@ -209,10 +206,7 @@ export async function changeBookmarkColorName(ctx: LineBookmarkContext) {
if (!controller) {
return;
}
bookmark.updateColor({
...bookmark.customColor,
name: newColorName,
});
bookmark.updateColor(newColorName);
}

/**
Expand Down Expand Up @@ -366,4 +360,4 @@ export function showWalkthroughs(args: any) {
);
}

export function revealExplorer(args: any) {}
export function revealInExplorer(args: any) {}
1 change: 1 addition & 0 deletions src/commands/bookmark/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './group';
export * from './view';
export * from './base';
export * from './sort';
export * from './settings';
18 changes: 18 additions & 0 deletions src/commands/bookmark/sort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {resolveBookmarkController} from '../../bootstrap';
import {TreeViewSortedEnum} from '../../types';

const controlller = resolveBookmarkController();
export function sortedByLineNumber(args: any) {
if (!controlller) {return;}
controlller.changeSortType(TreeViewSortedEnum.LINENUMBER);
}

export function sortedByCustom(args: any) {
if (!controlller) {return;}
controlller.changeSortType(TreeViewSortedEnum.CUSTOM);
}

export function sortedByCreateTime(args: any) {
if (!controlller) {return;}
controlller.changeSortType(TreeViewSortedEnum.CREATED_TIME);
}
70 changes: 68 additions & 2 deletions src/controllers/BookmarksController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default class BookmarksController implements IController {
// 监听mst的store的快照, 当快照发生变化时, 将数据保存到存储文件中
this._storeDisposer = onSnapshot(this._store, snapshot => {
this.save();
this._logger.log(getSnapshot(this._store));
this._logger.debug(getSnapshot(this._store));
});
}

Expand Down Expand Up @@ -387,7 +387,73 @@ export default class BookmarksController implements IController {
* @param bookmark
* @param idx
*/
updateBookmarkSortedInfo(bookmark: IBookmark, idx: number) {}
updateBookmarkSortedInfo(bookmark: IBookmark, idx: number) {
let group:
| BookmarksGroupedByCustomType
| BookmarksGroupedByColorType
| BookmarksGroupedByFileType
| undefined;
switch (this._store.groupView) {
case TreeViewGroupEnum.CUSTOM:
group = (this.groupedBookmarks as BookmarksGroupedByCustomType[]).find(
it => it.id === bookmark.groupId,
);

break;

case TreeViewGroupEnum.COLOR:
group = (this.groupedBookmarks as BookmarksGroupedByColorType[]).find(
it => it.color === bookmark.color,
);
break;
case TreeViewGroupEnum.FILE:
case TreeViewGroupEnum.DEFAULT:
group = (this.groupedBookmarks as BookmarksGroupedByFileType[]).find(
it => it.fileUri.fsPath === bookmark.fileUri.fsPath,
);
break;
case TreeViewGroupEnum.WORKSPACE:
const ws = (
this.groupedBookmarks as BookmarksGroupedByWorkspaceType[]
).find(it => it.workspace.name === bookmark.workspaceFolder.name);

group = ws?.files?.find(
it => it.fileUri.fsPath === bookmark.fileUri.fsPath,
);
break;
default:
break;
}

if (!group) {
return;
}

this._updateBookmarkSortedInfo(bookmark, group.bookmarks, idx);
}

private _updateBookmarkSortedInfo(
bookmark: IBookmark,
bookmarks: IBookmark[],
idx: number,
) {
const currentIdx = bookmark.sortedInfo[this.groupView];
if (currentIdx < idx) {
for (let i = idx; i > currentIdx; i--) {
const current = bookmarks[i];
current.updateSortedInfo(this.groupView, i - 1);
}
} else {
for (let i = idx; i < currentIdx; i++) {
const current = bookmarks[i];
current.updateSortedInfo(this.groupView, i + 1);
}
}

// 3. 更新当前书签
bookmark.updateSortedInfo(this.groupView, idx);
this._logger.debug(bookmarks.map(it => it.sortedInfo[this.groupView]));
}
/**
* 将数据写入到`.vscode/bookmark.json`中
* @returns
Expand Down
2 changes: 1 addition & 1 deletion src/providers/BookmarksTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class BookmarkTreeItem extends BaseTreeItem {
this.iconPath = (gutters[_meta.color] || gutters['default']).iconPath;
} else if (this.contextValue === BookmarkTreeItemCtxValueEnum.BOOKMARK) {
const meta = this.meta as IBookmark;
const color = meta.color || meta.customColor.name;
const color = meta.color;
this.iconPath = meta.label
? (tagGutters[color] || tagGutters['default']).iconPath
: (gutters[color] || gutters['default']).iconPath;
Expand Down
3 changes: 1 addition & 2 deletions src/providers/BookmarksTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {resolveBookmarkController} from '../bootstrap';
import BookmarksController from '../controllers/BookmarksController';
import {
BookmarksGroupedByColorType,
BookmarksGroupedByFileWithSortType,
BookmarksGroupedByWorkspaceType,
IBookmark,
} from '../stores/bookmark';
Expand Down Expand Up @@ -66,7 +65,7 @@ export class BookmarksTreeProvider extends BaseTreeProvider<
getChildrenByFile(element?: BookmarkTreeItem | undefined) {
if (!element) {
const bookmarkRootStoreArr = this.controller
.groupedBookmarks as BookmarksGroupedByFileWithSortType[];
.groupedBookmarks as BookmarksGroupedByFileType[];
const children = bookmarkRootStoreArr.map(it => {
let label = this.isRelativePath
? this.getRelativePath(it.fileName)
Expand Down
2 changes: 1 addition & 1 deletion src/services/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class ConfigService implements Disposable {
}

get customColors() {
return this._store.configure!.customColor;
return this._store.configure!.customColors;
}

get configuration() {
Expand Down
24 changes: 12 additions & 12 deletions src/services/LoggerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,58 +83,58 @@ export class LoggerService {
] || LogLevel.Warning;
}

info(msg: any) {
info(...msg: any[]) {
if (LoggerService.logLevel > LogLevel.Info) {
return;
}
logger.output.info(this.prefix, msg);
logger.output.info(this.prefix, ...msg);
logger.telemetry.logUsage('info', {
info: msg,
});
}

log(msg: any) {
log(...msg: any[]) {
if (LoggerService.logLevel > LogLevel.Info) {
return;
}
logger.output.info(this.prefix, msg);
logger.output.info(this.prefix, ...msg);
logger.telemetry.logUsage('log', {
info: msg,
});
}

warn(msg: any) {
warn(...msg: any[]) {
if (LoggerService.logLevel > LogLevel.Warning) {
return;
}
logger.output.warn(this.prefix, msg);
logger.output.warn(this.prefix, ...msg);
logger.telemetry.logUsage('warn', {
info: msg,
});
}

trace(msg: any) {
trace(...msg: any[]) {
if (LoggerService.logLevel > LogLevel.Trace) {
return;
}
logger.output.warn(this.prefix, msg);
logger.output.warn(this.prefix, ...msg);
logger.telemetry.logUsage('warn', {
info: msg,
});
}

debug(msg: string) {
debug(...msg: any[]) {
if (LoggerService.logLevel > LogLevel.Debug) {
return;
}
logger.output.debug(this.prefix, msg);
logger.output.debug(this.prefix, ...msg);
logger.telemetry.logUsage('debug', {
info: msg,
});
}

error(msg: any) {
logger.output.error(this.prefix, msg);
error(...msg: any[]) {
logger.output.error(this.prefix, ...msg);
logger.telemetry.logError('error', {
info: msg,
});
Expand Down
Loading

0 comments on commit 02b71a6

Please sign in to comment.