tool_windows.md: cleanup

This commit is contained in:
Yann Cébron 2025-04-08 10:03:41 +02:00
parent 7d2f7faf69
commit 65ae4f56d8

View File

@ -13,7 +13,8 @@
</tldr>
_Tool windows_ are child windows of the IDE used to display information.
These windows generally have their own toolbars (referred to as _tool window bars_) along the outer edges of the main window containing one or more _tool window buttons_, which activate panels displayed on the left, bottom, and right sides of the main IDE window.
These windows generally have their own toolbars (referred to as _tool window bars_) along the outer edges of the main window.
These contain one or more _tool window buttons_, which activate panels displayed on the left, bottom, and right sides of the main IDE window.
Each side contains two tool window groups, the primary and the secondary one, and only one tool window from each group can be active at a time.
@ -22,7 +23,7 @@ For example, the <control>Run</control> tool window displays a tab for each acti
There are two main scenarios for the use of tool windows in a plugin.
Using [declarative setup](#declarative-setup), a tool window button is always visible, and the user can activate it and interact with the plugin functionality at any time.
Alternatively, using [programmatic setup](#programmatic-setup), the tool window is created to show the results of a specific operation, and can then be closed after the operation is completed.
Alternatively, using [programmatic setup](#programmatic-setup), the tool window is created to show the results of a specific operation and can then be closed after the operation is completed.
### Declarative Setup
@ -32,7 +33,7 @@ The extension point attributes specify all the data which is necessary to displa
* The `id` attribute (required) of the tool window which corresponds to the text displayed on the tool window button.
To provide a localized text, specify matching `toolwindow.stripe.[id]` message key (escape spaces with `_`) in the [resource bundle](plugin_configuration_file.md#idea-plugin__resource-bundle) (code insight supported in 2020.3 and later).
* The `icon` to display on the tool window button (13x13 pixels, grey and monochromatic; see [](tool_window.md) in UI Guidelines and [](icons.md))
* The `icon` to display on the tool window button (13x13 pixels, gray and monochromatic; see [](tool_window.md) in UI Guidelines and [](icons.md))
* The `anchor`, meaning the side of the screen on which the tool window is displayed ("left" (default), "right" or "bottom")
@ -40,7 +41,7 @@ To provide a localized text, specify matching `toolwindow.stripe.[id]` message k
* The `factoryClass` attribute (required), a class implementing [`ToolWindowFactory`](%gh-ic%/platform/platform-api/src/com/intellij/openapi/wm/ToolWindowFactory.kt).
When the user clicks on the tool window button, the `createToolWindowContent()` method of the factory class is called, and initializes the UI of the tool window.
When the user clicks on the tool window button, the `createToolWindowContent()` method of the factory class is called and initializes the UI of the tool window.
This procedure ensures that unused tool windows don't cause any overhead in startup time or memory usage: if a user does not interact with the tool window, no plugin code will be loaded or executed.
#### Conditional Display
@ -81,15 +82,17 @@ Always use [`ToolWindowManager.invokeLater()`](%gh-ic%/platform/platform-api/src
## Contents (Tabs)
Displaying the contents of many tool windows requires access to [indexes](indexing_and_psi_stubs.md).
Because of that, tool windows are normally disabled while building indexes unless the `ToolWindowFactory` is marked [dumb aware](indexing_and_psi_stubs.md#DumbAwareAPI).
Because of that, tool windows are disabled by default while building indexes unless the `ToolWindowFactory` is marked as [dumb aware](indexing_and_psi_stubs.md#DumbAwareAPI).
As mentioned previously, tool windows can contain multiple contents (tabs).
To manage the contents of a tool window, call [`ToolWindow.getContentManager()`](%gh-ic%/platform/ide-core/src/com/intellij/openapi/wm/ToolWindow.java).
To add a content (tab), first create it by calling [`ContentManager.getFactory().createContent()`](%gh-ic%/platform/ide-core/src/com/intellij/ui/content/ContentManager.java), and then to add it to the tool window using [`ContentManager.addContent()`](%gh-ic%/platform/ide-core/src/com/intellij/ui/content/ContentManager.java).
To add a [`Content`](%gh-ic%/platform/ide-core/src/com/intellij/ui/content/Content.java) (tab), first create it by calling `ContentManager.getFactory().createContent()`,
and then to add it to the tool window using `ContentManager.addContent()`.
Set the preferred focus component via `Content.setPreferredFocusableComponent()`.
Use `Content.setDisposer()` to register associated `Disposable` (see [](disposers.md)).
Use `Content.setDisposer()` to register an associated `Disposable` (see [](disposers.md)).
See [`SimpleToolWindowPanel`](%gh-ic%/platform/platform-api/src/com/intellij/openapi/ui/SimpleToolWindowPanel.java) as a convenient base class, supporting [Toolbars](action_system.md#buildingToolbarPopupMenu) and both vertical/horizontal layout.
See [`SimpleToolWindowPanel`](%gh-ic%/platform/platform-api/src/com/intellij/openapi/ui/SimpleToolWindowPanel.java) as a convenient base class,
supporting [Toolbars](action_system.md#buildingToolbarPopupMenu) and a vertical or horizontal layout.
### Closing Tabs