【问题标题】:add a save item to vscode editor context menu将保存项添加到 vscode 编辑器上下文菜单
【发布时间】:2021-03-28 12:23:16
【问题描述】:

这里是 Vscode 菜鸟,试图在编辑器上下文菜单中获取保存项。我已经做到了:

{
    "name": "vsContextSave",
    "displayName": "vsContextSave",
    "description": "add save item to editor context menu",
    "version": "0.0.0",
    "publisher": "njamescouk",
    "repository": {
        "type": "git",
        "url": ""
    },
    "license": "MIT License",
    "engines": {
        "vscode": "^1.40.0"
    },
    "contributes": {
        "menus": {
            "editor/context": [
                {
                    "command": "workbench.action.files.save",
                    "group": "9_cutcopypaste",
                    "when": "editorTextFocus"
                }
            ]
        }
    },
    "__metadata": {}
}

当包装在 .vscode\extensions 目录中的目录中时,vscode 会看到它,并且 vsContextSave 会显示在扩展列表中并被启用。但是我在上下文菜单中没有看到保存项。

编辑:

我在元数据语句之前插入了一个激活事件,但显然我需要一个带有 activate() 函数的主模块。

"activation Events": ["onStartupFinished"],

【问题讨论】:

  • 你定义了一个空的激活函数
  • 没有。我应该在哪里以及如何做?

标签: visual-studio-code vscode-settings vscode-extensions


【解决方案1】:

这两个文件让您在编辑器中查找、查找文件并保存为上下文菜单项。

extension.js:

不知道这是做什么的,但似乎是必要的

'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const vscode = require("vscode");
function activate(context) {
};

package.json:

{
    "name": "mainContext",
    "displayName": "mainContext",
    "description": "add various items to editor context menu",
    "version": "0.0.0",
    "publisher": "njamescouk",
    "repository": {
        "type": "git",
        "url": ""
    },
    "license": "MIT License",
    "engines": {
        "vscode": "^1.40.0"
    },
    "main": "./extension.js",
    "contributes": {
        "menus": {
            "editor/context": [
                {
                    "command": "workbench.action.files.save",
                    "group": "9_cutcopypaste",
                    "when": "editorTextFocus"
                },
                {
                    "command": "actions.find",
                    "group": "9_cutcopypaste",
                    "when": "editorTextFocus"
                },
                {
                    "command": "workbench.action.quickOpen",
                    "group": "9_cutcopypaste",
                    "when": "editorTextFocus"
                }
            ]
        },
        "commands": [
            {
                "title": "Save",
                "command": "workbench.action.files.save"
            },
            {
                "title": "Find",
                "command": "actions.find"
            },
            {
                "title": "Find file",
                "command": "workbench.action.quickOpen"
            }
        ]
    },
    "activationEvents": [
        "onStartupFinished"
    ],
    "__metadata": {}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 2011-09-21
    • 2019-01-11
    • 1970-01-01
    • 2018-03-17
    • 1970-01-01
    相关资源
    最近更新 更多