mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 10:17:50 +08:00
plugin_components.md: relayout
This commit is contained in:
parent
20b1688ba3
commit
041524d972
@ -6,21 +6,34 @@ title: Plugin Components
|
||||
> **WARNING** When writing new plugins, creating components should be avoided.
|
||||
> Any existing components should be migrated to services, extensions, or listeners (see below).
|
||||
|
||||
Plugin components are a legacy feature supported for compatibility with plugins created for older versions of the IntelliJ Platform.
|
||||
Plugins using components do not support [dynamic loading](dynamic_plugins.md) (the ability to install, update, and uninstall plugins without restarting the IDE).
|
||||
Plugin components are a legacy feature supported for compatibility with plugins created for older versions of the IntelliJ Platform. Plugins using components do not support [dynamic loading](dynamic_plugins.md) (the ability to install, update, and uninstall plugins without restarting the IDE).
|
||||
|
||||
Plugin components are defined using `<application-components>`, `<project-components>`, and `<module-components>` tags in a `plugin.xml` file.
|
||||
Plugin components are defined in the `<application-components>`, `<project-components>`, and `<module-components>` sections in a [Plugin Configuration File](plugin_configuration_file.md).
|
||||
|
||||
## Migration
|
||||
To migrate existing code from components to more modern APIs, please use the following guidelines:
|
||||
|
||||
* To manage some state or logic that is only needed when the user performs a specific operation, use a [Service](plugin_services.md).
|
||||
* To store the state of your plugin at the application or project level, use a [Service](plugin_services.md), and implement the `PersistentStateComponent` interface.
|
||||
See [Persisting State of Components](/basics/persisting_state_of_components.md) for details.
|
||||
* To subscribe to events, use a [listener](plugin_listeners.md) or create an [extension](plugin_extensions.md) for a dedicated extension point (for example, `com.intellij.editorFactoryListener`) if one exists for the event to subscribe to.
|
||||
* Executing code on application startup should be avoided whenever possible because it slows down startup.
|
||||
Plugin code should only be executed when projects are opened or when the user invokes an action of a plugin.
|
||||
If this cannot be avoided, add a [listener](plugin_listeners.md) subscribing to the [AppLifecycleListener](upsource:///platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java) topic.
|
||||
* To execute code when a project is being opened, provide [StartupActivity](upsource:///platform/core-api/src/com/intellij/openapi/startup/StartupActivity.java) implementation and register an [extension](plugin_extensions.md) for the `com.intellij.postStartupActivity` or `com.intellij.backgroundPostStartupActivity` extension point (the latter is supported starting with version 2019.3 of the platform).
|
||||
* To execute code on project closing or application shutdown, implement the `Disposable` interface in a [Service](plugin_services.md) and place the code in the `dispose()` method.
|
||||
Alternatively, use `Disposer.register()` passing a `Project` or `Application` service instance as the `parent` argument (see [Choosing a Disposable Parent](/basics/disposers.md#choosing-a-disposable-parent)).
|
||||
To migrate existing code from components to more modern APIs, please see the following guidelines.
|
||||
|
||||
### Manage State
|
||||
|
||||
To manage some state or logic that is only needed when the user performs a specific operation, use a [Service](plugin_services.md).
|
||||
|
||||
### Persisting State
|
||||
|
||||
To store the state of your plugin at the application or project level, use a [Service](plugin_services.md), and implement the `PersistentStateComponent` interface. See [Persisting State of Components](/basics/persisting_state_of_components.md) for details.
|
||||
|
||||
### Subscribing to Events
|
||||
|
||||
To subscribe to events, use a [listener](plugin_listeners.md) or create an [extension](plugin_extensions.md) for a dedicated extension point (for example, `com.intellij.editorFactoryListener`) if one exists for the event to subscribe to.
|
||||
|
||||
### Application Startup
|
||||
|
||||
Executing code on application startup should be avoided whenever possible because it slows down startup. Plugin code should only be executed when projects are opened (see [Project Open](#project-open)) or when the user invokes an action of a plugin. If this cannot be avoided, add a [listener](plugin_listeners.md) subscribing to the [AppLifecycleListener](upsource:///platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java) topic.
|
||||
|
||||
### Project Open
|
||||
|
||||
To execute code when a project is being opened, provide [StartupActivity](upsource:///platform/core-api/src/com/intellij/openapi/startup/StartupActivity.java) implementation and register an [extension](plugin_extensions.md) for the `com.intellij.postStartupActivity` or `com.intellij.backgroundPostStartupActivity` extension point (the latter is supported starting with version 2019.3 of the platform).
|
||||
|
||||
### Application/Project Close
|
||||
|
||||
To execute code on project closing or application shutdown, implement the `Disposable` interface in a [Service](plugin_services.md) and place the code in the `dispose()` method. Alternatively, use `Disposer.register()` passing a `Project` or `Application` service instance as the `parent` argument (see [Choosing a Disposable Parent](/basics/disposers.md#choosing-a-disposable-parent)).
|
||||
|
Loading…
x
Reference in New Issue
Block a user