Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize context menu in Visual Studio Code?

Is it possible to customize context menu in Visual Studio Code ?

Currently it looks like this.

enter image description here

I need to add two more menu options to this.

Something like "Go Back" and "Go Forward".

Can this be done ?

like image 260
Adam Avatar asked Oct 12 '17 16:10

Adam


People also ask

Where is context menu in VS Code?

For those who don't know, the context menu is the little menu that opens when you click with the right button of the mouse on some empty space of the folder.

Where is the context menu in Visual Studio?

To do this, select the form in Visual Studio and scroll through the properties in the Properties panel until you find the ContextMenuStrip property. Click on the down arrow in the value field and select TextBoxMenu to associate this menu with the form.

How do I change VS Code layout?

Select File > Preferences > Settings (or press Ctrl+,) to edit the user settings. json file. To edit workspace settings, select the WORKSPACE SETTINGS tab to edit the workspace settings.


1 Answers

Yes, you can can add menu items to the context menu by creating a personal extension for your own use. In your extension, in package.json, add a contributes.menus section. The text editor context menu is called editor/context.

(If you haven't developed an extension before, start with Microsoft's Your First Extension tutorial.)

It may help to look at another extension that adds items to the context menu. One (of many) extension that does this is Bookmarks, which adds three context menu entries. The relevant parts of its package.json are:

{
    "name": "Bookmarks",
    ...
    "contributes": {
        ...
        "menus": {
            ...
            "editor/context": [
                {
                    "command": "bookmarks.toggle",
                    "group": "bookmarks",
                    "when": "editorTextFocus && config.bookmarks.showCommandsInContextMenu"
                },
                {
                    "command": "bookmarks.jumpToNext",
                    "group": "bookmarks@1",
                    "when": "editorTextFocus && config.bookmarks.showCommandsInContextMenu"
                },
                {
                    "command": "bookmarks.jumpToPrevious",
                    "group": "bookmarks@1",
                    "when": "editorTextFocus && config.bookmarks.showCommandsInContextMenu"
                }
            ],
            ....
        },
        ....
    },
    ....
}

The command can be any command; it does not have to be one installed by your extension.

The API docs are a bit vague about the meaning of the group attribute:

Last, a group property defines sorting and grouping of menu items.

Its meaning is described more fully under Sorting of groups. A word like "bookmarks" establishes a group of menu entries separated from other groups by a horizontal rule, with groups ordered alphabetically, and the "@<number>" suffix controls ordering within each group:

Screenshot of three added context menu items

like image 184
Scott McPeak Avatar answered Sep 18 '22 08:09

Scott McPeak