Skip to content

Commit a524e5c

Browse files
feat(context-menu): allow hide specific commands (#123)
Co-authored-by: Hao Liu <[email protected]>
1 parent bf91ed8 commit a524e5c

File tree

3 files changed

+170
-22
lines changed

3 files changed

+170
-22
lines changed

package.json

Lines changed: 152 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,142 @@
527527
"editPresentation": "singlelineText",
528528
"markdownDescription": "博客园 Markdown 语法扩展: 代码块指定行高亮\n\n&nbsp;\n\n使用示例:\n\n```markdown\n\n```typescript {1, 3-4}\nconsole.log(1)\nconsole.log(2)\nconsole.log(3)\nconsole.log(4)\nconsole.log(5)\n```\n\n```"
529529
},
530-
"cnblogsClientForVSCode.ing.enablePublishSelectionToIng": {
531-
"order": 11,
532-
"type": "boolean",
530+
"cnblogsClientForVSCode.menus.context.explorer": {
531+
"type": "object",
532+
"additionalProperties": false,
533+
"default": {
534+
"save-post-file-to-cnblogs": true,
535+
"pull-post-remote-updates": true,
536+
"modify-post-settings": true,
537+
"show-post-to-local-file-info": true,
538+
"open-post-in-blog-admin": true,
539+
"export-post-to-pdf": true,
540+
"copy-post-link": true
541+
},
542+
"markdownDescription": "控制要在资源管理器右键菜单中显示的命令",
543+
"order": 12,
544+
"properties": {
545+
"save-post-file-to-cnblogs": {
546+
"description": "保存到博客园",
547+
"type": "boolean",
548+
"order": 0,
549+
"default": true
550+
},
551+
"pull-post-remote-updates": {
552+
"description": "拉取远程更新",
553+
"type": "boolean",
554+
"order": 1,
555+
"default": true
556+
},
557+
"modify-post-settings": {
558+
"description": "博文设置",
559+
"type": "boolean",
560+
"order": 2,
561+
"default": true
562+
},
563+
"show-post-to-local-file-info": {
564+
"description": "博客园关联博文",
565+
"type": "boolean",
566+
"order": 3,
567+
"default": true
568+
},
569+
"open-post-in-blog-admin": {
570+
"description": "在博客后台中编辑",
571+
"type": "boolean",
572+
"order": 4,
573+
"default": true
574+
},
575+
"export-post-to-pdf": {
576+
"description": "导出pdf",
577+
"type": "boolean",
578+
"order": 5,
579+
"default": true
580+
},
581+
"copy-post-link": {
582+
"description": "复制博文链接",
583+
"type": "boolean",
584+
"order": 6,
585+
"default": true
586+
}
587+
}
588+
},
589+
"cnblogsClientForVSCode.menus.context.editor": {
590+
"type": "object",
591+
"default": {
592+
"save-post-file-to-cnblogs": true,
593+
"pull-post-remote-updates": true,
594+
"modify-post-settings": true,
595+
"show-post-to-local-file-info": true,
596+
"open-post-in-blog-admin": true,
597+
"export-post-to-pdf": true,
598+
"copy-post-link": true,
599+
"upload-clipboard-image": true,
600+
"upload-local-disk-image": true,
601+
"extract-images": true,
602+
"ing:publish-selection": false
603+
},
604+
"properties": {
605+
"save-post-file-to-cnblogs": {
606+
"description": "保存到博客园",
607+
"type": "boolean",
608+
"order": 0
609+
},
610+
"pull-post-remote-updates": {
611+
"description": "拉取远程更新",
612+
"type": "boolean",
613+
"order": 1
614+
},
615+
"modify-post-settings": {
616+
"description": "博文设置",
617+
"type": "boolean",
618+
"order": 2
619+
},
620+
"show-post-to-local-file-info": {
621+
"description": "博客园关联博文",
622+
"type": "boolean",
623+
"order": 3
624+
},
625+
"open-post-in-blog-admin": {
626+
"description": "在博客后台中编辑",
627+
"type": "boolean",
628+
"default": true,
629+
"order": 4
630+
},
631+
"export-post-to-pdf": {
632+
"description": "导出pdf",
633+
"type": "boolean",
634+
"order": 5
635+
},
636+
"copy-post-link": {
637+
"description": "复制博文链接",
638+
"type": "boolean",
639+
"order": 6
640+
},
641+
"upload-clipboard-image": {
642+
"description": "上传剪贴板图片到博客园",
643+
"type": "boolean",
644+
"order": 7
645+
},
646+
"upload-local-disk-image": {
647+
"description": "上传本地图片到博客园",
648+
"type": "boolean",
649+
"order": 8
650+
},
651+
"extract-images": {
652+
"description": "提取图片",
653+
"type": "boolean",
654+
"order": 9
655+
},
656+
"ing:publish-selection": {
657+
"description": "将选中内容发到闪存",
658+
"type": "boolean",
659+
"order": 10
660+
}
661+
},
533662
"scope": "application",
534-
"default": false,
535-
"markdownDescription": "是否允许将选中内容发到闪存\n\n启用后, 编辑上下文菜单将包含\"将选中内容发到闪存\""
663+
"additionalProperties": false,
664+
"markdownDescription": "控制要在编辑器右键菜单中显示的命令",
665+
"order": 13
536666
}
537667
}
538668
}
@@ -959,53 +1089,53 @@
9591089
},
9601090
{
9611091
"command": "vscode-cnb.show-post-to-local-file-info",
962-
"when": "resourceLangId == markdown",
1092+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.show-post-to-local-file-info",
9631093
"group": "cnblogs@1"
9641094
},
9651095
{
9661096
"command": "vscode-cnb.save-post-file-to-cnblogs",
967-
"when": "resourceLangId == markdown",
1097+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.save-post-file-to-cnblogs",
9681098
"group": "cnblogs@2"
9691099
},
9701100
{
9711101
"command": "vscode-cnb.pull-post-remote-updates",
972-
"when": "resourceLangId == markdown",
1102+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.pull-post-remote-updates",
9731103
"group": "cnblogs@3"
9741104
},
9751105
{
9761106
"command": "vscode-cnb.modify-post-settings",
977-
"when": "resourceLangId == markdown",
1107+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.modify-post-settings",
9781108
"group": "cnblogs@4"
9791109
},
9801110
{
9811111
"command": "vscode-cnb.open-post-in-blog-admin",
982-
"when": "resourceLangId == markdown",
1112+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.open-post-in-blog-admin",
9831113
"group": "cnblogs@5"
9841114
},
9851115
{
9861116
"command": "vscode-cnb.upload-clipboard-image",
987-
"when": "resourceLangId == markdown",
1117+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.upload-clipboard-image",
9881118
"group": "cnblogs@6"
9891119
},
9901120
{
9911121
"command": "vscode-cnb.upload-local-disk-image",
992-
"when": "resourceLangId == markdown",
1122+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.upload-local-disk-image",
9931123
"group": "cnblogs@7"
9941124
},
9951125
{
9961126
"command": "vscode-cnb.export-post-to-pdf",
997-
"when": "resourceLangId == markdown",
1127+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.export-post-to-pdf",
9981128
"group": "cnblogs@8"
9991129
},
10001130
{
10011131
"command": "vscode-cnb.extract-images",
1002-
"when": "resourceLangId == markdown",
1132+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.editor.extract-images",
10031133
"group": "cnblogs@9"
10041134
},
10051135
{
10061136
"command": "vscode-cnb.ing.publish-selection",
10071137
"group": "cnblogs@10",
1008-
"when": "config.cnblogsClientForVSCode.ing.enablePublishSelectionToIng"
1138+
"when": "config.cnblogsClientForVSCode.menus.context.editor.ing:publish-selection"
10091139
}
10101140
],
10111141
"editor/title": [
@@ -1028,37 +1158,37 @@
10281158
},
10291159
{
10301160
"command": "vscode-cnb.save-post-file-to-cnblogs",
1031-
"when": "resourceLangId == markdown",
1161+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.explorer.save-post-file-to-cnblogs",
10321162
"group": "cnblogs@2"
10331163
},
10341164
{
10351165
"command": "vscode-cnb.pull-post-remote-updates",
1036-
"when": "resourceLangId == markdown",
1166+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.explorer.pull-post-remote-updates",
10371167
"group": "cnblogs@3"
10381168
},
10391169
{
10401170
"command": "vscode-cnb.modify-post-settings",
1041-
"when": "resourceLangId == markdown",
1171+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.explorer.modify-post-settings",
10421172
"group": "cnblogs@4"
10431173
},
10441174
{
10451175
"command": "vscode-cnb.show-post-to-local-file-info",
1046-
"when": "resourceLangId == markdown",
1176+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.explorer.show-post-to-local-file-info",
10471177
"group": "cnblogs@5"
10481178
},
10491179
{
10501180
"command": "vscode-cnb.open-post-in-blog-admin",
1051-
"when": "resourceLangId == markdown",
1181+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.explorer.open-post-in-blog-admin",
10521182
"group": "cnblogs@6"
10531183
},
10541184
{
10551185
"command": "vscode-cnb.export-post-to-pdf",
1056-
"when": "resourceLangId == markdown",
1186+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.explorer.export-post-to-pdf",
10571187
"group": "cnblogs@7"
10581188
},
10591189
{
10601190
"command": "vscode-cnb.copy-post-link",
1061-
"when": "resourceLangId == markdown",
1191+
"when": "resourceLangId == markdown && config.cnblogsClientForVSCode.menus.context.explorer.copy-post-link",
10621192
"group": "cnblogs@8"
10631193
}
10641194
]

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import extensionUriHandler from '@/utils/uri-handler';
1313
import { IngsListWebviewProvider } from 'src/services/ings-list-webview-provider';
1414
import { extendMarkdownIt } from '@/markdown/extend-markdownIt';
15+
import { Settings } from '@/services/settings.service';
1516

1617
// this method is called when your extension is activated
1718
// your extension is activated the very first time the command is executed
@@ -27,6 +28,7 @@ export function activate(context: vscode.ExtensionContext) {
2728
}, 1000);
2829
observeConfigurationChange();
2930
observeWorkspaceFolderChange();
31+
Settings.migrateEnablePublishSelectionToIng().catch(console.warn);
3032
vscode.window.registerUriHandler(extensionUriHandler);
3133
return {
3234
extendMarkdownIt,

src/services/settings.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ export class Settings {
118118
await this.configuration.update('createLocalPostFileWithCategory', value, ConfigurationTarget.Global);
119119
}
120120

121+
static async migrateEnablePublishSelectionToIng() {
122+
const oldKey = 'ing.enablePublishSelectionToIng';
123+
const isEnablePublishSelectionToIng = this.configuration.get(oldKey);
124+
if (isEnablePublishSelectionToIng === true) {
125+
if (
126+
await this.configuration
127+
.update('menus.context.editor', { 'ing:publish-selection': true }, ConfigurationTarget.Global)
128+
.then(
129+
() => true,
130+
() => false
131+
)
132+
)
133+
await this.configuration.update(oldKey, undefined, ConfigurationTarget.Global);
134+
}
135+
}
136+
121137
private static removeLegacyWorkspaceUri() {
122138
return this.configuration.update(this.workspaceUriKey, undefined, ConfigurationTarget.Global);
123139
}

0 commit comments

Comments
 (0)