简体   繁体   English

如何从扩展代码中检测 VSCode 面板可见性?

[英]How to detect VSCode panel visibility from the extension code?

I would like to create an extension to toggle all the currently visible panels by a single shortcut.我想创建一个扩展,通过一个快捷方式切换所有当前可见的面板。 So something like the command "Hide/show All Tool Windows" from JetBrains IDEs, which I think is still missing in VS Code.因此,类似于 JetBrains IDE 中的“隐藏/显示所有工具窗口”命令,我认为 VS Code 中仍然缺少该命令。

VS Code can have up to 3 panels visible: VS Code 最多可以显示 3 个面板:

  • Sidebar (the left-side panel)侧边栏(左侧面板)
  • Panel (the bottom panel)面板(底部面板)
  • AuxiliaryBar (the new right-side panel) AuxiliaryBar(新的右侧面板)

For that purpose, I need to detect the current state of all the panels from the extension code, so I can toggle only the panel(s) which are currently visible.为此,我需要从扩展代码中检测所有面板的当前 state,因此我只能切换当前可见的面板。

But alas I can't find it anywhere in the documentation.但可惜我在文档中的任何地方都找不到它。 This page ( https://code.visualstudio.com/api/references/when-clause-contexts ) contains several variables like sideBarVisible , but I really don't get how to access those context variables from the vscode namespace which you can access from the extension.此页面( https://code.visualstudio.com/api/references/when-clause-contexts )包含几个变量,例如sideBarVisible ,但我真的不知道如何从您可以访问的 vscode 命名空间访问这些上下文变量从扩展。

import * as vscode from 'vscode';

So, is there a way how to detect if the panel is open or closed from the extension code?那么,有没有办法从扩展代码中检测面板是打开还是关闭?

Do you really need to know whether they are open or closed?你真的需要知道它们是开放的还是封闭的? Can't you just toggle them all?你不能全部切换吗?

vscode.commands.executeCommand('workbench.action.toggleSidebarVisibility')
vscode.commands.executeCommand('workbench.action.togglePanel')
vscode.commands.executeCommand('workbench.action.toggleAuxiliaryBar')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM