1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VSCodeのツリービューに更新ボタンを配置する方法

1
Last updated at Posted at 2023-03-29

VSCode拡張機能を開発する時、ツリービューを実装するケースがあると思います。

その際に、ツリービューのタイトルの右端に、更新ボタンのようなアイコンを配置して、それがクリックされたタイミングで特定のコマンドが実行されるようにしたい場合、次のようにcontributesフィールドを設定します。

package.json
"contributes": {
  "views": {
    "explorer": [
      {
        "id": "sampleTreeView",
        "name": "Sample Tree View"
      }
    ]
  },
  "commands": [
    {
      "command": "sampleTreeView.refresh",
      "title": "Refresh",
      "icon": {
        "light": "resources/light/refresh.svg",
        "dark": "resources/dark/refresh.svg"
      }
    },
  ],
  "menus": {
    "view/title": [
      {
        "command": "sampleTreeView.refresh",
        "when": "view == sampleTreeView",
        "group": "navigation"
      }
    ]
  }
}

タイトルの右端にアイコンを表示したいので、view/titleキーを使って設定します。もし、ツリービューに並んでいる各要素を右クリックした際に、特定のコマンドのタイトルをコンテキストメニューのフォーマットに沿って表示したい場合は、view/item/contextキーを使います。

2.png

もし、...の中にコマンドの存在感を隠したい場合は、groupnavigationを指定するのではなく、inlineを設定します。

1.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?