Commit 97c1f567 by xieshixiang

idea插件开发

parents
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State />
</expanded-state>
<selected-state>
<State>
<id>Android</id>
</State>
</selected-state>
</profile-state>
</entry>
</component>
</project>
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="date" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AnalysisProjectProfileManager">
<option name="PROJECT_PROFILE" />
<option name="USE_PROJECT_LEVEL_SETTINGS" value="false" />
<list size="0" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="IntelliJ IDEA IU-201.7846.76" project-jdk-type="IDEA JDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SuppressionsComponent">
<option name="suppComments" value="[]" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/idea_plugin.iml" filepath="$PROJECT_DIR$/idea_plugin.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<idea-plugin>
<id>com.your.company.my_gradle_plugin</id>
<name>Plugn display name here</name>
<vendor email="xie@yourcompany.com" url="http://www.hik.com">hik</vendor>
<description>Enter short description for you1 plugin here.</description>
<version>1.0.0</version>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<!--uncomment to enable plugin in all products-->
<depends>com.intellij.modules.lang</depends>
<actions>
<!-- package:action -->
<action id="com.hik.action.PopupDialogAction" class="com.hik.action.PopupDialogAction"
text="PopupDialogAction" description="PopupDialogAction">
<add-to-group group-id="ToolsMenu" anchor="first"/>
</action>
<!-- package:action -->
<!-- package:popup -->
<!-- ActionGroupPopupAction -->
<action id="com.hik.popup.ActionGroupPopupAction" class="com.hik.popup.ActionGroupPopupAction"
text="ActionGroupPopupAction" description="ActionGroupPopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 1" keymap="$default"/>
</action>
<group id="popupGroup"/>
<action class="com.hik.popup.CustomFirstAction" id="com.hik.popup.CustomFirstAction"
text="CustomFirstAction" description="CustomFirstAction">
<add-to-group group-id="popupGroup" anchor="first"/>
</action>
<action class="com.hik.popup.CustomSecondAction" id="com.hik.popup.CustomSecondAction"
text="CustomSecondAction" description="CustomSecondAction">
<add-to-group group-id="popupGroup" anchor="after" relative-to-action="com.hik.popup.CustomFirstAction"/>
</action>
<!-- ActionGroupPopupAction -->
<!-- ComponentPopupAction -->
<action id="com.hik.popup.ComponentPopupAction" class="com.hik.popup.ComponentPopupAction"
text="ComponentPopupAction" description="ComponentPopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 2" keymap="$default"/>
</action>
<!-- ComponentPopupAction -->
<!-- ConfirmPopupAction -->
<action id="com.hik.popup.ConfirmPopupAction" class="com.hik.popup.ConfirmPopupAction"
text="ConfirmPopupAction" description="ConfirmPopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 3" keymap="$default"/>
</action>
<!-- ConfirmPopupAction -->
<!-- ConfirmPopupAction -->
<action id="com.hik.popup.MultiChoosePopupAction" class="com.hik.popup.MultiChoosePopupAction"
text="MultiChoosePopupAction" description="MultiChoosePopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 4" keymap="$default"/>
</action>
<!-- ConfirmPopupAction -->
<!-- SubGroupPopupAction -->
<action id="com.hik.popup.SubGroupPopupAction" class="com.hik.popup.SubGroupPopupAction"
text="SubGroupPopupAction" description="SubGroupPopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 5" keymap="$default"/>
<!--<keyboard-shortcut first-keystroke="control alt 5" keymap="Mac OS X 10.5+"/>-->
</action>
<group id="subOuterGroup"/>
<!--popup为true代表这是一个子菜单 -->
<group id="subInnerGroup" popup="true" text="SubInnerGroup">
<add-to-group group-id="subOuterGroup" anchor="first"/>
<action class="com.hik.popup.SubAction" id="subAction"
text="SubAction" description="SubAction">
</action>
</group>
<!-- SubGroupPopupAction -->
<!-- package:popup -->
<!-- package:notification -->
<action id="com.hik.notification.HintNotificationAction" class="com.hik.notification.HintNotificationAction"
text="HintNotificationAction" description="HintNotificationAction">
<add-to-group group-id="ToolsMenu" anchor="first"/>
</action>
<!-- package:notification -->
<!-- package:file.chooser -->
<action id="com.hik.file.chooser.FileChooserAction" class="com.hik.file.chooser.FileChooserAction"
text="FileChooserAction" description="FileChooserAction">
<add-to-group group-id="ToolsMenu" anchor="after"
relative-to-action="com.hik.notification.HintNotificationAction"/>
</action>
<!-- package:file.chooser -->
<!-- package:jblist -->
<action id="com.hik.jblist.ListAction" class="com.hik.jblist.ListAction"
text="ListAction" description="ListAction">
<add-to-group group-id="ToolsMenu" anchor="after"
relative-to-action="com.hik.file.chooser.FileChooserAction"/>
</action>
<!-- package:jblist -->
<!-- package:tree -->
<action id="com.hik.tree.TreeAction" class="com.hik.tree.TreeAction"
text="TreeAction" description="TreeAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.jblist.ListAction"/>
</action>
<!-- package:tree -->
<!-- package:jbsplitter -->
<action id="com.hik.jbsplitter.JBSplitterAction" class="com.hik.jbsplitter.JBSplitterAction"
text="JBSplitterAction" description="JBSplitterAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.tree.TreeAction"/>
</action>
<!-- package:jbsplitter -->
<!-- package:jbtab -->
<action id="com.hik.jbtab.JBTabAction" class="com.hik.jbtab.JBTabAction"
text="JBTabAction" description="JBTabAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.jbsplitter.JBSplitterAction"/>
</action>
<!-- package:jbtab -->
<!-- package:editor.component -->
<action id="com.hik.editor.component.EditorIllustrationAction"
class="com.hik.editor.component.EditorIllustrationAction"
text="Editor Replace Text" description="Replaces selected text with 'Replacement'.">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</action>
<action id="com.hik.editor.component.EditorAreaIllustration"
class="com.hik.editor.component.EditorAreaIllustration"
text="Caret Position" description="Caret Position">
<add-to-group group-id="EditorPopupMenu" anchor="after"
relative-to-action="com.hik.editor.component.EditorIllustrationAction"/>
</action>
<action id="com.hik.editor.component.EditorHandlerIllustration"
class="com.hik.editor.component.EditorHandlerIllustration"
text="EditorHandlerIllustration" description="EditorHandlerIllustration">
<add-to-group group-id="EditorPopupMenu" anchor="after"
relative-to-action="com.hik.editor.component.EditorAreaIllustration"/>
</action>
<!-- package:editor.component -->
<!-- package:project -->
<action id="com.hik.project.GetContentSourceRootAction" class="com.hik.project.GetContentSourceRootAction"
text="GetContentSourceRootAction" description="GetContentSourceRootAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.jbtab.JBTabAction"/>
</action>
<action id="com.hik.project.ProjectFileIndexAction" class="com.hik.project.ProjectFileIndexAction"
text="ProjectFileIndexAction" description="ProjectFileIndexAction">
<add-to-group group-id="ToolsMenu" anchor="after"
relative-to-action="com.hik.project.GetContentSourceRootAction"/>
</action>
<action id="com.hik.project.ProjectSdkAction" class="com.hik.project.ProjectSdkAction"
text="ProjectSdkAction" description="ProjectSdkAction">
<add-to-group group-id="ToolsMenu" anchor="after"
relative-to-action="com.hik.project.ProjectFileIndexAction"/>
</action>
<action id="com.hik.project.ProjectStructureAction" class="com.hik.project.ProjectStructureAction"
text="ProjectStructureAction" description="ProjectStructureAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.project.ProjectSdkAction"/>
</action>
<!-- package:project -->
<!-- package:toolview-->
<action id="com.hik.toolview.ConsoleViewAction" class="com.hik.toolview.ConsoleViewAction"
text="ConsoleViewAction" description="ConsoleViewAction">
<add-to-group group-id="ToolsMenu" anchor="last"/>
</action>
<!-- package:toolview-->
<!--<group id="NewGroupId" text="MyMenu" popup="true">-->
<!-- <add-to-group group-id="MainMenu" anchor="last"/>-->
<!--</group>-->
<!--<action id="MyCreateProjectActionId" class="com.hik.project.MyCreateProjectAction"-->
<!-- text="MyCreateProjectAction" description="MyCreateProjectAction">-->
<!-- <add-to-group group-id="NewGroupId" anchor="last"/>-->
<!--</action>-->
</actions>
<!-- package:toolwindow -->
<extensions defaultExtensionNs="com.intellij">
<!-- package:dialog-->
<!-- secondary:true表示设置在tool window bar最下方 -->
<toolWindow id="customer tool window" anchor="right" factoryClass="com.hik.dialog.MyToolWindowFactory"
secondary="true"/>
<!-- package:dialog-->
<!-- package:run.configuration -->
<configurationType implementation="com.hik.run.configuration.DemoConfigurationType"/>
<!-- package:run.configuration -->
<!-- package:run.configuration.multi.factory -->
<configurationType implementation="com.hik.run.configuration.multi.factory.MultiFactoryConfigurationType"/>
<!-- package:run.configuration.multi.factory -->
<!-- package:setting -->
<applicationService serviceImplementation="com.hik.setting.Settings"/>
<applicationConfigurable instance="com.hik.setting.MainSetting" dynamic="true"/>
<!-- package:setting -->
<!-- package:persisting.state.component-->
<applicationConfigurable instance="com.hik.persisting.state.component.PropertiesComponentApplicationSetting"
dynamic="true"/>
<projectConfigurable instance="com.hik.persisting.state.component.PropertiesComponentProjectSetting"
dynamic="true"/>
<!-- package:persisting.state.component-->
<!-- package:toolview-->
<executor implementation="com.hik.toolview.CustomRunExecutor" id="CustomRunExecutor"/>
<!-- package:toolview-->
<!-- package:run.configuration.persistent -->
<!-- <configurationType implementation="com.hik.run.configuration.persisent.PersistentConfigurationType"/>-->
<!-- package:run.configuration.persistent -->
</extensions>
<!-- package:toolwindow -->
</idea-plugin>
\ No newline at end of file
<svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="20" height="20">
<path d="M862.709333 116.042667a32 32 0 1 1 45.248 45.248L455.445333 613.813333a32 32 0 1 1-45.258666-45.258666L862.709333 116.053333zM853.333333 448a32 32 0 0 1 64 0v352c0 64.8-52.533333 117.333333-117.333333 117.333333H224c-64.8 0-117.333333-52.533333-117.333333-117.333333V224c0-64.8 52.533333-117.333333 117.333333-117.333333h341.333333a32 32 0 0 1 0 64H224a53.333333 53.333333 0 0 0-53.333333 53.333333v576a53.333333 53.333333 0 0 0 53.333333 53.333333h576a53.333333 53.333333 0 0 0 53.333333-53.333333V448z"></path>
</svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" transform="translate(1 1)">
<rect width="14" height="14" fill="#000"/>
<rect width="5" height="1" x="1" y="11" fill="#FFFEFE"/>
<path fill="#FFFEFE"
d="M1,5.96113281 L1.85546875,5.96113281 C1.89648438,6.30390625 2.2421875,6.52363281 2.74023438,6.52363281 C3.20019531,6.52363281 3.52539063,6.30097656 3.52539063,5.98164062 C3.52539063,5.71210937 3.31445313,5.55683594 2.79589844,5.44550781 L2.24511719,5.32832031 C1.47460938,5.1671875 1.09667969,4.76582031 1.09667969,4.12128906 C1.09667969,3.32441406 1.73828125,2.8 2.71386719,2.8 C3.64550781,2.8 4.3046875,3.32148437 4.33105469,4.07441406 L3.49902344,4.07441406 C3.45800781,3.74042969 3.14746094,3.51777344 2.71972656,3.51777344 C2.27734375,3.51777344 1.984375,3.72285156 1.984375,4.04511719 C1.984375,4.30585937 2.18652344,4.45527344 2.68164063,4.56074219 L3.19140625,4.66914062 C4.04101563,4.84785156 4.40722656,5.2140625 4.40722656,5.8703125 C4.40722656,6.72285156 3.75390625,7.24433594 2.69335938,7.24433594 C1.68554688,7.24433594 1.03222656,6.74921875 1,5.96113281 Z M5.19603365,2.90546875 L6.86009615,2.90546875 C8.11693209,2.90546875 8.84349459,3.6671875 8.84349459,4.99140625 C8.84349459,6.36542969 8.12572115,7.1359375 6.86009615,7.1359375 L5.19603365,7.1359375 L5.19603365,2.90546875 Z M6.08079927,3.66132812 L6.08079927,6.38007812 L6.71947115,6.38007812 C7.50169771,6.38007812 7.94115084,5.89960937 7.94115084,5.00605469 C7.94115084,4.15058594 7.48704927,3.66132812 6.71947115,3.66132812 L6.08079927,3.66132812 Z M10.5170673,7.1359375 L9.63230167,7.1359375 L9.63230167,2.90839844 L10.5170673,2.90839844 L10.5170673,4.7921875 L10.5698017,4.7921875 L12.1313251,2.90839844 L13.1157001,2.90839844 L11.5746845,4.76289062 L13.2240985,7.1359375 L12.1635517,7.1359375 L10.9360126,5.36640625 L10.5170673,5.86152344 L10.5170673,7.1359375 Z"/>
</g>
</svg>
<idea-plugin>
<id>com.your.company.my_gradle_plugin</id>
<name>Plugn display name here</name>
<vendor email="xie@yourcompany.com" url="http://www.hik.com">hik</vendor>
<description>Enter short description for you1 plugin here.</description>
<version>1.0.0</version>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<!--uncomment to enable plugin in all products-->
<depends>com.intellij.modules.lang</depends>
<actions>
<!-- package:action -->
<action id="com.hik.action.PopupDialogAction" class="com.hik.action.PopupDialogAction"
text="PopupDialogAction" description="PopupDialogAction">
<add-to-group group-id="ToolsMenu" anchor="first"/>
</action>
<!-- package:action -->
<!-- package:popup -->
<!-- ActionGroupPopupAction -->
<action id="com.hik.popup.ActionGroupPopupAction" class="com.hik.popup.ActionGroupPopupAction"
text="ActionGroupPopupAction" description="ActionGroupPopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 1" keymap="$default"/>
</action>
<group id="popupGroup"/>
<action class="com.hik.popup.CustomFirstAction" id="com.hik.popup.CustomFirstAction"
text="CustomFirstAction" description="CustomFirstAction">
<add-to-group group-id="popupGroup" anchor="first"/>
</action>
<action class="com.hik.popup.CustomSecondAction" id="com.hik.popup.CustomSecondAction"
text="CustomSecondAction" description="CustomSecondAction">
<add-to-group group-id="popupGroup" anchor="after" relative-to-action="com.hik.popup.CustomFirstAction"/>
</action>
<!-- ActionGroupPopupAction -->
<!-- ComponentPopupAction -->
<action id="com.hik.popup.ComponentPopupAction" class="com.hik.popup.ComponentPopupAction"
text="ComponentPopupAction" description="ComponentPopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 2" keymap="$default"/>
</action>
<!-- ComponentPopupAction -->
<!-- ConfirmPopupAction -->
<action id="com.hik.popup.ConfirmPopupAction" class="com.hik.popup.ConfirmPopupAction"
text="ConfirmPopupAction" description="ConfirmPopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 3" keymap="$default"/>
</action>
<!-- ConfirmPopupAction -->
<!-- ConfirmPopupAction -->
<action id="com.hik.popup.MultiChoosePopupAction" class="com.hik.popup.MultiChoosePopupAction"
text="MultiChoosePopupAction" description="MultiChoosePopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 4" keymap="$default"/>
</action>
<!-- ConfirmPopupAction -->
<!-- SubGroupPopupAction -->
<action id="com.hik.popup.SubGroupPopupAction" class="com.hik.popup.SubGroupPopupAction"
text="SubGroupPopupAction" description="SubGroupPopupAction">
<add-to-group group-id="PopupMenuActions" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt 5" keymap="$default"/>
<!--<keyboard-shortcut first-keystroke="control alt 5" keymap="Mac OS X 10.5+"/>-->
</action>
<group id="subOuterGroup"/>
<!--popup为true代表这是一个子菜单 -->
<group id="subInnerGroup" popup="true" text="SubInnerGroup">
<add-to-group group-id="subOuterGroup" anchor="first"/>
<action class="com.hik.popup.SubAction" id="subAction"
text="SubAction" description="SubAction">
</action>
</group>
<!-- SubGroupPopupAction -->
<!-- package:popup -->
<!-- package:notification -->
<action id="com.hik.notification.HintNotificationAction" class="com.hik.notification.HintNotificationAction"
text="HintNotificationAction" description="HintNotificationAction">
<add-to-group group-id="ToolsMenu" anchor="first"/>
</action>
<!-- package:notification -->
<!-- package:file.chooser -->
<action id="com.hik.file.chooser.FileChooserAction" class="com.hik.file.chooser.FileChooserAction"
text="FileChooserAction" description="FileChooserAction">
<add-to-group group-id="ToolsMenu" anchor="after"
relative-to-action="com.hik.notification.HintNotificationAction"/>
</action>
<!-- package:file.chooser -->
<!-- package:jblist -->
<action id="com.hik.jblist.ListAction" class="com.hik.jblist.ListAction"
text="ListAction" description="ListAction">
<add-to-group group-id="ToolsMenu" anchor="after"
relative-to-action="com.hik.file.chooser.FileChooserAction"/>
</action>
<!-- package:jblist -->
<!-- package:tree -->
<action id="com.hik.tree.TreeAction" class="com.hik.tree.TreeAction"
text="TreeAction" description="TreeAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.jblist.ListAction"/>
</action>
<!-- package:tree -->
<!-- package:jbsplitter -->
<action id="com.hik.jbsplitter.JBSplitterAction" class="com.hik.jbsplitter.JBSplitterAction"
text="JBSplitterAction" description="JBSplitterAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.tree.TreeAction"/>
</action>
<!-- package:jbsplitter -->
<!-- package:jbtab -->
<action id="com.hik.jbtab.JBTabAction" class="com.hik.jbtab.JBTabAction"
text="JBTabAction" description="JBTabAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.jbsplitter.JBSplitterAction"/>
</action>
<!-- package:jbtab -->
<!-- package:editor.component -->
<action id="com.hik.editor.component.EditorIllustrationAction"
class="com.hik.editor.component.EditorIllustrationAction"
text="Editor Replace Text" description="Replaces selected text with 'Replacement'.">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</action>
<action id="com.hik.editor.component.EditorAreaIllustration"
class="com.hik.editor.component.EditorAreaIllustration"
text="Caret Position" description="Caret Position">
<add-to-group group-id="EditorPopupMenu" anchor="after"
relative-to-action="com.hik.editor.component.EditorIllustrationAction"/>
</action>
<action id="com.hik.editor.component.EditorHandlerIllustration"
class="com.hik.editor.component.EditorHandlerIllustration"
text="EditorHandlerIllustration" description="EditorHandlerIllustration">
<add-to-group group-id="EditorPopupMenu" anchor="after"
relative-to-action="com.hik.editor.component.EditorAreaIllustration"/>
</action>
<!-- package:editor.component -->
<!-- package:project -->
<action id="com.hik.project.GetContentSourceRootAction" class="com.hik.project.GetContentSourceRootAction"
text="GetContentSourceRootAction" description="GetContentSourceRootAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.jbtab.JBTabAction"/>
</action>
<action id="com.hik.project.ProjectFileIndexAction" class="com.hik.project.ProjectFileIndexAction"
text="ProjectFileIndexAction" description="ProjectFileIndexAction">
<add-to-group group-id="ToolsMenu" anchor="after"
relative-to-action="com.hik.project.GetContentSourceRootAction"/>
</action>
<action id="com.hik.project.ProjectSdkAction" class="com.hik.project.ProjectSdkAction"
text="ProjectSdkAction" description="ProjectSdkAction">
<add-to-group group-id="ToolsMenu" anchor="after"
relative-to-action="com.hik.project.ProjectFileIndexAction"/>
</action>
<action id="com.hik.project.ProjectStructureAction" class="com.hik.project.ProjectStructureAction"
text="ProjectStructureAction" description="ProjectStructureAction">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.hik.project.ProjectSdkAction"/>
</action>
<!-- package:project -->
<!-- package:toolview-->
<action id="com.hik.toolview.ConsoleViewAction" class="com.hik.toolview.ConsoleViewAction"
text="ConsoleViewAction" description="ConsoleViewAction">
<add-to-group group-id="ToolsMenu" anchor="last"/>
</action>
<!-- package:toolview-->
<!--<group id="NewGroupId" text="MyMenu" popup="true">-->
<!-- <add-to-group group-id="MainMenu" anchor="last"/>-->
<!--</group>-->
<!--<action id="MyCreateProjectActionId" class="com.hik.project.MyCreateProjectAction"-->
<!-- text="MyCreateProjectAction" description="MyCreateProjectAction">-->
<!-- <add-to-group group-id="NewGroupId" anchor="last"/>-->
<!--</action>-->
</actions>
<!-- package:toolwindow -->
<extensions defaultExtensionNs="com.intellij">
<!-- package:dialog-->
<!-- secondary:true表示设置在tool window bar最下方 -->
<toolWindow id="customer tool window" anchor="right" factoryClass="com.hik.dialog.MyToolWindowFactory"
secondary="true"/>
<!-- package:dialog-->
<!-- package:run.configuration -->
<configurationType implementation="com.hik.run.configuration.DemoConfigurationType"/>
<!-- package:run.configuration -->
<!-- package:run.configuration.multi.factory -->
<configurationType implementation="com.hik.run.configuration.multi.factory.MultiFactoryConfigurationType"/>
<!-- package:run.configuration.multi.factory -->
<!-- package:setting -->
<applicationService serviceImplementation="com.hik.setting.Settings"/>
<applicationConfigurable instance="com.hik.setting.MainSetting" dynamic="true"/>
<!-- package:setting -->
<!-- package:persisting.state.component-->
<applicationConfigurable instance="com.hik.persisting.state.component.PropertiesComponentApplicationSetting"
dynamic="true"/>
<projectConfigurable instance="com.hik.persisting.state.component.PropertiesComponentProjectSetting"
dynamic="true"/>
<!-- package:persisting.state.component-->
<!-- package:toolview-->
<executor implementation="com.hik.toolview.CustomRunExecutor" id="CustomRunExecutor"/>
<!-- package:toolview-->
<!-- package:run.configuration.persistent -->
<!-- <configurationType implementation="com.hik.run.configuration.persisent.PersistentConfigurationType"/>-->
<!-- package:run.configuration.persistent -->
</extensions>
<!-- package:toolwindow -->
</idea-plugin>
\ No newline at end of file
<svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="20" height="20">
<path d="M862.709333 116.042667a32 32 0 1 1 45.248 45.248L455.445333 613.813333a32 32 0 1 1-45.258666-45.258666L862.709333 116.053333zM853.333333 448a32 32 0 0 1 64 0v352c0 64.8-52.533333 117.333333-117.333333 117.333333H224c-64.8 0-117.333333-52.533333-117.333333-117.333333V224c0-64.8 52.533333-117.333333 117.333333-117.333333h341.333333a32 32 0 0 1 0 64H224a53.333333 53.333333 0 0 0-53.333333 53.333333v576a53.333333 53.333333 0 0 0 53.333333 53.333333h576a53.333333 53.333333 0 0 0 53.333333-53.333333V448z"></path>
</svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" transform="translate(1 1)">
<rect width="14" height="14" fill="#000"/>
<rect width="5" height="1" x="1" y="11" fill="#FFFEFE"/>
<path fill="#FFFEFE"
d="M1,5.96113281 L1.85546875,5.96113281 C1.89648438,6.30390625 2.2421875,6.52363281 2.74023438,6.52363281 C3.20019531,6.52363281 3.52539063,6.30097656 3.52539063,5.98164062 C3.52539063,5.71210937 3.31445313,5.55683594 2.79589844,5.44550781 L2.24511719,5.32832031 C1.47460938,5.1671875 1.09667969,4.76582031 1.09667969,4.12128906 C1.09667969,3.32441406 1.73828125,2.8 2.71386719,2.8 C3.64550781,2.8 4.3046875,3.32148437 4.33105469,4.07441406 L3.49902344,4.07441406 C3.45800781,3.74042969 3.14746094,3.51777344 2.71972656,3.51777344 C2.27734375,3.51777344 1.984375,3.72285156 1.984375,4.04511719 C1.984375,4.30585937 2.18652344,4.45527344 2.68164063,4.56074219 L3.19140625,4.66914062 C4.04101563,4.84785156 4.40722656,5.2140625 4.40722656,5.8703125 C4.40722656,6.72285156 3.75390625,7.24433594 2.69335938,7.24433594 C1.68554688,7.24433594 1.03222656,6.74921875 1,5.96113281 Z M5.19603365,2.90546875 L6.86009615,2.90546875 C8.11693209,2.90546875 8.84349459,3.6671875 8.84349459,4.99140625 C8.84349459,6.36542969 8.12572115,7.1359375 6.86009615,7.1359375 L5.19603365,7.1359375 L5.19603365,2.90546875 Z M6.08079927,3.66132812 L6.08079927,6.38007812 L6.71947115,6.38007812 C7.50169771,6.38007812 7.94115084,5.89960937 7.94115084,5.00605469 C7.94115084,4.15058594 7.48704927,3.66132812 6.71947115,3.66132812 L6.08079927,3.66132812 Z M10.5170673,7.1359375 L9.63230167,7.1359375 L9.63230167,2.90839844 L10.5170673,2.90839844 L10.5170673,4.7921875 L10.5698017,4.7921875 L12.1313251,2.90839844 L13.1157001,2.90839844 L11.5746845,4.76289062 L13.2240985,7.1359375 L12.1635517,7.1359375 L10.9360126,5.36640625 L10.5170673,5.86152344 L10.5170673,7.1359375 Z"/>
</g>
</svg>
package com.hik.action;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.pom.Navigatable;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/2/28 9:18 上午
*/
public class PopupDialogAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// 获取当前工程
Project project = e.getProject();
// e.getPresentation() 获取当前组建
StringBuffer dialogMsg = new StringBuffer(e.getPresentation().getText() + " selected");
String dialogTitle = e.getPresentation().getDescription();
// 获取当前选中对象
Navigatable nav = e.getData(CommonDataKeys.NAVIGATABLE);
if (nav != null) {
// 选中对象文件名或者目录名称,此处为全路径
dialogMsg.append(String.format("\nSelected elements:%s", nav.toString()));
}
Messages.showMessageDialog(project, dialogMsg.toString(), dialogTitle.toString(),
Messages.getInformationIcon());
}
@Override
public void update(@NotNull AnActionEvent e) {
System.out.println(e.getProject().getName());
}
}
package com.hik.dialog;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.ValidationInfo;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
/**
* @author wengyongcheng
* @since 2020/3/2 10:36 下午
*/
public class CustomDialogWrapper extends DialogWrapper {
private JTextField inputTextField;
private CustomOKAction okAction;
private DialogWrapperExitAction exitAction;
public CustomDialogWrapper() {
super(true);
init();
setTitle("自定义dialog");
}
/**
* 创建视图
*
* @return
*/
@Nullable
@Override
protected JComponent createCenterPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JLabel label = new JLabel("这就是自定义dialog");
label.setPreferredSize(new Dimension(100, 100));
panel.add(label, BorderLayout.CENTER);
inputTextField = new JTextField();
panel.add(inputTextField, BorderLayout.NORTH);
return panel;
}
/**
* 校验数据
*
* @return 通过必须返回null,不通过返回一个 ValidationInfo 信息
*/
@Nullable
@Override
protected ValidationInfo doValidate() {
String text = inputTextField.getText();
if (StringUtils.isNotBlank(text)) {
return null;
} else {
return new ValidationInfo("校验不通过");
}
}
/**
* 覆盖默认的ok/cancel按钮
*
* @return
*/
@NotNull
@Override
protected Action[] createActions() {
exitAction = new DialogWrapperExitAction("自定义cancel按钮", CANCEL_EXIT_CODE);
okAction = new CustomOKAction();
// 设置默认的焦点按钮
okAction.putValue(DialogWrapper.DEFAULT_ACTION, true);
return new Action[]{okAction, exitAction};
}
/**
* 自定义 ok Action
*/
protected class CustomOKAction extends DialogWrapperAction {
protected CustomOKAction() {
super("自定义ok按钮");
}
@Override
protected void doAction(ActionEvent e) {
// 点击ok的时候进行数据校验
ValidationInfo validationInfo = doValidate();
if (validationInfo != null) {
Messages.showMessageDialog(validationInfo.message, "校验不通过", Messages.getInformationIcon());
} else {
close(CANCEL_EXIT_CODE);
}
}
}
}
package com.hik.dialog;
import com.intellij.openapi.wm.ToolWindow;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/1 10:30 下午
*/
public class MyToolWindow {
private JButton hideButton;
private JButton dialogButton;
private JPanel myToolWindowContent;
public MyToolWindow(ToolWindow toolWindow) {
init();
hideButton.addActionListener(e -> toolWindow.hide(null));
}
private void init() {
dialogButton = new JButton("触发自定义dialog");
dialogButton.addActionListener(e -> {
if (new CustomDialogWrapper().showAndGet()) {
// 监听弹框消失,相当于show 和 getExitCode方法的结合
System.out.println("show and get");
}
});
hideButton = new JButton("取消");
myToolWindowContent = new JPanel();
myToolWindowContent.add(dialogButton);
myToolWindowContent.add(hideButton);
}
public JPanel getContent() {
return myToolWindowContent;
}
}
package com.hik.dialog;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/1 10:31 下午
*/
public class MyToolWindowFactory implements ToolWindowFactory, Condition<Project> {
/**
* 创建 tool window
*
* @param project
* @param toolWindow
*/
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
MyToolWindow myToolWindow = new MyToolWindow(toolWindow);
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
Content content = contentFactory.createContent(myToolWindow.getContent(), "自定义tool window", false);
toolWindow.getContentManager().addContent(content);
}
/**
* 控制tool window是否展示
*
* @param project
* @return
*/
@Override
public boolean value(Project project) {
return true;
}
}
package com.hik.editor.component;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.VisualPosition;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
/**
* If conditions support it, makes a menu visible to display information
* about the caret.
*
* @see AnAction
*/
public class EditorAreaIllustration extends AnAction {
/**
* Displays a message with information about the current caret.
*
* @param e Event related to this action
*/
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
// Get access to the editor and caret model. update() validated editor's existence.
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
final CaretModel caretModel = editor.getCaretModel();
// Getting the primary caret ensures we get the correct one of a possible many.
final Caret primaryCaret = caretModel.getPrimaryCaret();
// Get the caret information
LogicalPosition logicalPos = primaryCaret.getLogicalPosition();
VisualPosition visualPos = primaryCaret.getVisualPosition();
int caretOffset = primaryCaret.getOffset();
// Build and display the caret report.
StringBuilder report = new StringBuilder(logicalPos.toString() + "\n");
report.append(visualPos.toString() + "\n");
report.append("Offset: " + caretOffset);
Messages.showInfoMessage(report.toString(), "Caret Parameters Inside The Editor");
}
/**
* Sets visibility and enables this action menu item if:
* A project is open,
* An editor is active,
*
* @param e Event related to this action
*/
@Override
public void update(@NotNull final AnActionEvent e) {
// Get required data keys
final Project project = e.getProject();
final Editor editor = e.getData(CommonDataKeys.EDITOR);
//Set visibility only in case of existing project and editor
e.getPresentation().setEnabledAndVisible(project != null && editor != null);
}
}
package com.hik.editor.component;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
import com.intellij.openapi.editor.actionSystem.TypedAction;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/10 2:32 下午
*/
public class EditorHandlerIllustration extends AnAction {
static {
final EditorActionManager editorActionManager = EditorActionManager.getInstance();
final TypedAction typedAction = editorActionManager.getTypedAction();
typedAction.setupHandler(new MyTypedHandler());
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
EditorActionHandler editorActionHandler =
EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
editorActionHandler.execute(editor, editor.getCaretModel().getPrimaryCaret(), e.getDataContext());
}
@Override
public void update(@NotNull AnActionEvent e) {
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
final Project project = e.getProject();
boolean menuAllowed = false;
if (editor != null && project != null) {
menuAllowed = !editor.getCaretModel().getAllCarets().isEmpty();
}
e.getPresentation().setEnabledAndVisible(menuAllowed);
}
}
package com.hik.editor.component;
import com.hik.icons.EditorBasicsIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/9 9:29 下午
*/
public class EditorIllustrationAction extends AnAction {
public EditorIllustrationAction() {
super(EditorBasicsIcons.Sdk_default_icon);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
final Document document = editor.getDocument();
// 获取选中文本起始索引和结束索引
Caret primaryCaret = editor.getCaretModel().getPrimaryCaret();
int start = primaryCaret.getSelectionStart();
int end = primaryCaret.getSelectionEnd();
// 执行文本替换
WriteCommandAction.runWriteCommandAction(project, () ->
document.replaceString(start, end, "editor_basics")
);
// 对替换后的文本移除选中效果
primaryCaret.removeSelection();
}
@Override
public void update(@NotNull AnActionEvent e) {
Project project = e.getProject();
Editor editor = e.getData(CommonDataKeys.EDITOR);
e.getPresentation().setEnabledAndVisible(project != null && editor != null
&& editor.getSelectionModel().hasSelection());
}
}
package com.hik.editor.component;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.TypedActionHandler;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/10 2:36 下午
*/
public class MyTypedHandler implements TypedActionHandler {
@Override
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
final Document document = editor.getDocument();
final Project project = editor.getProject();
Runnable runnable = () -> document.insertString(0, "test");
WriteCommandAction.runWriteCommandAction(project, runnable);
}
}
package com.hik.file.chooser;
import com.intellij.ide.util.TreeFileChooser;
import com.intellij.ide.util.TreeFileChooserFactory;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/5 11:23 下午
*/
public class FileChooserAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// 方式1,直接使用 FileChooser.chooseFile
FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(true, true, true, true, true, true);
// VirtualFile virtualFile = FileChooser.chooseFile(chooserDescriptor, e.getProject(), null);
//
// if(virtualFile != null) {
// Messages.showMessageDialog(virtualFile.getName(), "获取到的文件名称", Messages.getInformationIcon());
// } else {
// Messages.showMessageDialog("文件名称为空", "文件名称为空", Messages.getInformationIcon());
// }
// 方式二,直接使用FileChooser.chooseFiles
// VirtualFile toSelect = LocalFileSystem.getInstance().findFileByPath(File.separator + "Users" + File
// .separator + "wengyongcheng" + File.separator + "swagger-html" + File.separator);
// FileChooser.chooseFiles(chooserDescriptor, null, toSelect, virtualFiles -> {
// if (CollectionUtils.isNotEmpty(virtualFiles)) {
// for (VirtualFile file : virtualFiles) {
// Messages.showMessageDialog(file.getPath(), file.getName(), Messages.getInformationIcon());
// }
// }
// });
// 方式三,自定义文件选择窗口视图
// new FileChooserDialogWrapper().showAndGet();
// 方式四 树形文件选择器
TreeFileChooserFactory instance = TreeFileChooserFactory.getInstance(e.getProject());
TreeFileChooser.PsiFileFilter fileFilter = file -> file.getName().endsWith(".java");
TreeFileChooser javaFileChooser = instance.createFileChooser("java文件选择器", null, null, fileFilter);
javaFileChooser.showDialog();
PsiFile selectedFile = javaFileChooser.getSelectedFile();
if (selectedFile != null) {
Messages.showMessageDialog(selectedFile.getVirtualFile().getPath(),
selectedFile.getVirtualFile().getName(), Messages.getInformationIcon());
}
}
}
package com.hik.file.chooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.TextBrowseFolderListener;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.io.File;
/**
* @author wengyongcheng
* @since 2020/3/6 11:55 下午
*/
public class FileChooserDialogWrapper extends DialogWrapper {
private TextFieldWithBrowseButton textFieldWithBrowseButton;
private JTextField fileTextFiled;
public FileChooserDialogWrapper() {
super(true);
init();
setTitle("文件选择对话框");
}
@Nullable
@Override
protected JComponent createCenterPanel() {
JPanel panel = new JPanel();
textFieldWithBrowseButton = new TextFieldWithBrowseButton();
fileTextFiled = new JTextField();
FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(true, true, true, true, true, true);
TextBrowseFolderListener listener = new TextBrowseFolderListener(chooserDescriptor);
textFieldWithBrowseButton.addBrowseFolderListener(listener);
textFieldWithBrowseButton.setText(File.separator + "Users" + File.separator + "wengyongcheng" + File.separator + "swagger-html" + File.separator);
panel.setLayout(new BorderLayout());
panel.setPreferredSize(new Dimension(400, 40));
panel.add(textFieldWithBrowseButton, BorderLayout.CENTER);
return panel;
}
@Nullable
@Override
protected ValidationInfo doValidate() {
String filePath = textFieldWithBrowseButton.getText();
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(filePath);
if (virtualFile != null) {
Messages.showMessageDialog(virtualFile.getPath(), virtualFile.getName(), Messages.getInformationIcon());
}
return null;
}
}
package com.hik.icons;
import com.intellij.openapi.util.IconLoader;
import javax.swing.*;
public class EditorBasicsIcons {
public static final Icon Sdk_default_icon = IconLoader.getIcon("/icons/sdk_16.svg");
}
package com.hik.jblist;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.AnActionButton;
import com.intellij.ui.components.JBList;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/7 9:38 下午
*/
public class ExtraButtonAction extends AnActionButton {
private JBList list;
private DefaultListModel<Integer> model;
public ExtraButtonAction(DefaultListModel<Integer> model, JBList list) {
super("Extra", IconLoader.getIcon("/icons/edit.svg"));
this.model = model;
this.list = list;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
int index = list.getSelectedIndex();
String newValue = Messages.showInputDialog(model.get(index) + "", "Edit", Messages.getInformationIcon());
if (StringUtils.isNotBlank(newValue)) {
model.add(index, Integer.valueOf(newValue));
}
}
}
package com.hik.jblist;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/5 11:23 下午
*/
public class ListAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
new ListDialogWrapper().showAndGet();
}
}
package com.hik.jblist;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.ui.ColoredListCellRenderer;
import com.intellij.ui.ListSpeedSearch;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.components.JBList;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
/**
* @author wengyongcheng
* @since 2020/3/6 11:55 下午
*/
public class ListDialogWrapper extends DialogWrapper {
private JBList<Integer> list;
private DefaultListModel<Integer> defaultListModel;
public ListDialogWrapper() {
super(true);
init();
setTitle("JBList");
}
@Nullable
@Override
protected JComponent createCenterPanel() {
defaultListModel = new DefaultListModel<>();
for (int i = 0; i < 10; i++) {
defaultListModel.addElement(i);
}
list = new JBList<>(defaultListModel);
// 修饰每一行的元素
ColoredListCellRenderer<Integer> coloredListCellRenderer = new ColoredListCellRenderer<Integer>() {
@Override
protected void customizeCellRenderer(@NotNull JList<? extends Integer> list, Integer value, int index,
boolean selected, boolean hasFocus) {
append(value + "-suffix");
}
};
list.setCellRenderer(coloredListCellRenderer);
// 触发快速查找
new ListSpeedSearch<>(list);
// 增加工具栏(新增按钮、删除按钮、上移按钮、下移按钮)
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(list);
// 新增元素动作
decorator.setAddAction(actionButton -> addAction());
// 自定义按钮
decorator.addExtraAction(new ExtraButtonAction(defaultListModel, list));
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(decorator.createPanel(), BorderLayout.CENTER);
return panel;
}
private void addAction() {
String newItem = Messages.showInputDialog("Input A Item", "Add", Messages.getInformationIcon());
if (StringUtils.isNotBlank(newItem)) {
defaultListModel.addElement(Integer.valueOf(newItem));
}
}
@Nullable
@Override
protected ValidationInfo doValidate() {
Integer value = list.getSelectedValue();
if (value != null) {
Messages.showMessageDialog(value + "", value + "", Messages.getInformationIcon());
}
return null;
}
}
package com.hik.jbsplitter;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/8 2:39 下午
*/
public class JBSplitterAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
new JBSplitterDialogWrapper().showAndGet();
}
}
package com.hik.jbsplitter;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.JBSplitter;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
/**
* @author wengyongcheng
* @since 2020/3/8 2:40 下午
*/
public class JBSplitterDialogWrapper extends DialogWrapper {
private JBSplitter splitter;
public JBSplitterDialogWrapper() {
super(true);
init();
setTitle("JBSplitter");
}
@Nullable
@Override
protected JComponent createCenterPanel() {
splitter = new JBSplitter();
JPanel firstPanel = new JPanel();
firstPanel.add(new JLabel("First Panel"));
firstPanel.setBorder(BorderFactory.createTitledBorder("First Panel"));
splitter.setFirstComponent(firstPanel);
JPanel secondPanel = new JPanel();
secondPanel.add(new JLabel("Second Panel"));
secondPanel.setBorder(BorderFactory.createTitledBorder("Second Panel"));
splitter.setSecondComponent(secondPanel);
// 记录当前俩个组件的比例,存放到map中,key即为该值
splitter.setSplitterProportionKey("customProportionKey");
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(splitter, BorderLayout.CENTER);
return panel;
}
}
package com.hik.jbtab;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/8 3:41 下午
*/
public class JBTabAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
new JBTabDialogWrapper(e.getProject()).showAndGet();
}
}
package com.hik.jbtab;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.tabs.JBTabs;
import com.intellij.ui.tabs.TabInfo;
import com.intellij.ui.tabs.impl.JBTabsImpl;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
/**
* @author wengyongcheng
* @since 2020/3/8 3:41 下午
*/
public class JBTabDialogWrapper extends DialogWrapper {
private JBTabs tabs;
private Project project;
public JBTabDialogWrapper(Project project) {
super(true);
this.project = project;
init();
}
@Nullable
@Override
protected JComponent createCenterPanel() {
tabs = new JBTabsImpl(project);
JPanel firstTabPanel = new JPanel();
firstTabPanel.add(new JLabel("First Tab"));
TabInfo firstTabInfo = new TabInfo(firstTabPanel);
firstTabInfo.setText("First Tab");
tabs.addTab(firstTabInfo);
JPanel secondTabPanel = new JPanel();
secondTabPanel.add(new JLabel("Second Tab"));
TabInfo secondTabInfo = new TabInfo(secondTabPanel);
secondTabInfo.setText("Second Tab");
tabs.addTab(secondTabInfo);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(tabs.getComponent(), BorderLayout.CENTER);
return panel;
}
}
package com.hik.notification;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/4 11:11 下午
*/
public class HintNotificationAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
//HintManager.getInstance().showErrorHint(CommonDataKeys.EDITOR.getData(e.getDataContext()),"错误信息");
// HintManager.getInstance().showQuestionHint(CommonDataKeys.EDITOR.getData(e.getDataContext()),
// "questionAction", 0, 0, () -> {
// Messages.showMessageDialog("question", "Question", Messages.getInformationIcon());
// return true;
// });
//
// HintManager.getInstance().showInformationHint(CommonDataKeys.EDITOR.getData(e.getDataContext()),
// "information");
// 第三个参数logByDefault代表是否记入event log
NotificationGroup notificationGroup = new NotificationGroup("notificationGroup", NotificationDisplayType.NONE
, true);
Notification notification = notificationGroup.createNotification();
notification.setContent("notification");
Notifications.Bus.notify(notification);
Notification infoNotification = notificationGroup.createNotification(NotificationType.INFORMATION);
infoNotification.setContent("info");
Notifications.Bus.notify(infoNotification);
Notification errorNotification = notificationGroup.createNotification("error", NotificationType.ERROR);
Notifications.Bus.notify(errorNotification);
//
// Notification messageNotification = notificationGroup.createNotification("messageType", MessageType.WARNING);
// Notifications.Bus.notify(messageNotification);
//
// Notification subTitleNotification = notificationGroup.createNotification("title", "subTitle", "content",
// NotificationType.WARNING);
// Notifications.Bus.notify(subTitleNotification);
//
// Notification eventNotification = notificationGroup.createNotification("title", "content", NotificationType
// .WARNING, new NotificationListener() {
// @Override
// public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
// Messages.showMessageDialog(event.getURL().toString(), "Url", Messages.getInformationIcon());
// }
// });
// Notifications.Bus.notify(eventNotification);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.hik.persisting.state.component.PropertiesComponentApplicationSetting">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="6b451" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Application"/>
</properties>
</component>
<vspacer id="ab877">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="b845b" class="javax.swing.JTextField" binding="textField" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>
package com.hik.persisting.state.component;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/17 9:22 上午
* application 级别的properties Component
*/
public class PropertiesComponentApplicationSetting implements Configurable {
private static final String APPLICATION_KEY = "applicationKey";
private JTextField textField;
private JPanel mainPanel;
public PropertiesComponentApplicationSetting() {
textField.setText(PropertiesComponent.getInstance().getValue(APPLICATION_KEY));
}
@Nls(capitalization = Nls.Capitalization.Title)
@Override
public String getDisplayName() {
return "Application Level Properties Component";
}
@Nullable
@Override
public JComponent createComponent() {
return mainPanel;
}
@Override
public boolean isModified() {
return !StringUtils.equals(textField.getText(), PropertiesComponent.getInstance().getValue(APPLICATION_KEY));
}
@Override
public void apply() throws ConfigurationException {
PropertiesComponent.getInstance().setValue(APPLICATION_KEY, textField.getText());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.hik.persisting.state.component.PropertiesComponentProjectSetting">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d005" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Project"/>
</properties>
</component>
<vspacer id="fe3ea">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="2e2ad" class="javax.swing.JTextField" binding="textField" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>
package com.hik.persisting.state.component;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/17 10:00 上午
* project 级别的 properties component
*/
public class PropertiesComponentProjectSetting implements Configurable {
private static final String PROJECT_KEY = "projectKey";
private JTextField textField;
private JPanel mainPanel;
private Project project;
public PropertiesComponentProjectSetting() {
Project[] projects = ProjectManager.getInstance().getOpenProjects();
this.project = projects.length > 0 ? projects[0] : ProjectManager.getInstance().getDefaultProject();
textField.setText(PropertiesComponent.getInstance(project).getValue(getKey()));
}
@Nls(capitalization = Nls.Capitalization.Title)
@Override
public String getDisplayName() {
return "Project Level Properties Component";
}
@Nullable
@Override
public JComponent createComponent() {
return mainPanel;
}
@Override
public boolean isModified() {
return !StringUtils.equals(textField.getText(), PropertiesComponent.getInstance(project).getValue(getKey()));
}
@Override
public void apply() throws ConfigurationException {
PropertiesComponent.getInstance(project).setValue(getKey(), textField.getText());
}
private String getKey() {
return this.project.getName() + "-" + PROJECT_KEY;
}
}
package com.hik.popup;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.JBPopupListener;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.ui.popup.ListPopup;
import org.jetbrains.annotations.NotNull;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
* @author wengyongcheng
* @since 2020/3/3 10:48 下午
*/
public class ActionGroupPopupAction extends AnAction implements ListSelectionListener, JBPopupListener {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// 单选,action被选中可以触发对应的actionPerformed方法
DefaultActionGroup actionGroup = (DefaultActionGroup) ActionManager.getInstance().getAction("popupGroup");
ListPopup listPopup = JBPopupFactory.getInstance().createActionGroupPopup("popup", actionGroup,
e.getDataContext(), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
listPopup.showInFocusCenter();
listPopup.addListSelectionListener(this);
listPopup.addListener(this);
}
/**
* 上下键选择事件,仅仅是改变,而不是按住回车之后的选择
*
* @param e
*/
@Override
public void valueChanged(ListSelectionEvent e) {
int firstIndex = e.getFirstIndex();
int lastIndex = e.getLastIndex();
boolean valueIsAdjusting = e.getValueIsAdjusting();
System.out.println("firstIndex:" + firstIndex);
System.out.println("lastIndex:" + lastIndex);
System.out.println("valueIsAdjusting:" + valueIsAdjusting);
}
/**
* popup 关闭监听
*
* @param event
*/
@Override
public void onClosed(@NotNull LightweightWindowEvent event) {
JBPopup jbPopup = event.asPopup();
System.out.println("关闭popup");
jbPopup.cancel();
}
}
package com.hik.popup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.popup.ComponentPopupBuilder;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.JBPopupListener;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
/**
* @author wengyongcheng
* @since 2020/3/3 10:48 下午
*/
public class ComponentPopupAction extends AnAction implements ListSelectionListener, JBPopupListener {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// 自定义popup样式
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JTextField textField = new JTextField("fdas");
panel.add(textField, BorderLayout.NORTH);
JButton button = new JButton("提交");
panel.add(button, BorderLayout.CENTER);
ComponentPopupBuilder componentPopupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel,
textField);
JBPopup popup = componentPopupBuilder.createPopup();
popup.setRequestFocus(true);
popup.showInBestPositionFor(e.getDataContext());
}
/**
* 上下键选择事件,仅仅是改变,而不是按住回车之后的选择
*
* @param e
*/
@Override
public void valueChanged(ListSelectionEvent e) {
int firstIndex = e.getFirstIndex();
int lastIndex = e.getLastIndex();
boolean valueIsAdjusting = e.getValueIsAdjusting();
System.out.println("firstIndex:" + firstIndex);
System.out.println("lastIndex:" + lastIndex);
System.out.println("valueIsAdjusting:" + valueIsAdjusting);
}
/**
* popup 关闭监听
*
* @param event
*/
@Override
public void onClosed(@NotNull LightweightWindowEvent event) {
JBPopup jbPopup = event.asPopup();
System.out.println("关闭popup");
jbPopup.cancel();
}
}
package com.hik.popup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.JBPopupListener;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.ui.popup.ListPopup;
import org.jetbrains.annotations.NotNull;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
* @author wengyongcheng
* @since 2020/3/3 10:48 下午
*/
public class ConfirmPopupAction extends AnAction implements ListSelectionListener, JBPopupListener {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// 确认类型popup,展示俩个选项,对应执行俩种操作,TODO 这里不知道为什么选中其中一个之后必定会先弹出no信息框
ListPopup confirmation = JBPopupFactory.getInstance().createConfirmation("confirm", "yes", "no",
() -> Messages.showMessageDialog("yes", "yes", Messages.getInformationIcon()),
() -> Messages.showMessageDialog("no", "no", Messages.getInformationIcon()), 0);
confirmation.showInBestPositionFor(e.getDataContext());
}
/**
* 上下键选择事件,仅仅是改变,而不是按住回车之后的选择
*
* @param e
*/
@Override
public void valueChanged(ListSelectionEvent e) {
int firstIndex = e.getFirstIndex();
int lastIndex = e.getLastIndex();
boolean valueIsAdjusting = e.getValueIsAdjusting();
System.out.println("firstIndex:" + firstIndex);
System.out.println("lastIndex:" + lastIndex);
System.out.println("valueIsAdjusting:" + valueIsAdjusting);
}
/**
* popup 关闭监听
*
* @param event
*/
@Override
public void onClosed(@NotNull LightweightWindowEvent event) {
JBPopup jbPopup = event.asPopup();
System.out.println("关闭popup");
jbPopup.cancel();
}
}
package com.hik.popup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/4 11:06 上午
*/
public class CustomFirstAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Messages.showMessageDialog("第一个action触发", "第一个action", Messages.getInformationIcon());
}
}
package com.hik.popup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/4 11:06 上午
*/
public class CustomSecondAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Messages.showMessageDialog("第二个action触发", "第二个action", Messages.getInformationIcon());
}
}
package com.hik.popup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.popup.IPopupChooserBuilder;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.JBPopupListener;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import org.jetbrains.annotations.NotNull;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author wengyongcheng
* @since 2020/3/3 10:48 下午
*/
public class MultiChoosePopupAction extends AnAction implements ListSelectionListener, JBPopupListener {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// 可以多选,如果传入的list是action,选中不会触发对应的actionPerformed方法
IPopupChooserBuilder<String> popupChooserBuilder =
JBPopupFactory.getInstance().createPopupChooserBuilder(Stream.of("value1", "value2").collect(Collectors.toList()));
JBPopup popup = popupChooserBuilder.createPopup();
popup.showInBestPositionFor(e.getDataContext());
}
/**
* 上下键选择事件,仅仅是改变,而不是按住回车之后的选择
*
* @param e
*/
@Override
public void valueChanged(ListSelectionEvent e) {
int firstIndex = e.getFirstIndex();
int lastIndex = e.getLastIndex();
boolean valueIsAdjusting = e.getValueIsAdjusting();
System.out.println("firstIndex:" + firstIndex);
System.out.println("lastIndex:" + lastIndex);
System.out.println("valueIsAdjusting:" + valueIsAdjusting);
}
/**
* popup 关闭监听
*
* @param event
*/
@Override
public void onClosed(@NotNull LightweightWindowEvent event) {
JBPopup jbPopup = event.asPopup();
System.out.println("关闭popup");
jbPopup.cancel();
}
}
package com.hik.popup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/4 5:28 下午
*/
public class SubAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Messages.showMessageDialog("nest", "nest", Messages.getInformationIcon());
}
}
package com.hik.popup;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.JBPopupListener;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.ui.popup.ListPopup;
import org.jetbrains.annotations.NotNull;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
* @author wengyongcheng
* @since 2020/3/3 10:48 下午
*/
public class SubGroupPopupAction extends AnAction implements ListSelectionListener, JBPopupListener {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// 嵌套action
DefaultActionGroup actionGroup = (DefaultActionGroup) ActionManager.getInstance().getAction("subOuterGroup");
ListPopup listPopup = JBPopupFactory.getInstance().createActionGroupPopup("SubOuterGroup", actionGroup,
e.getDataContext(), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
listPopup.showInFocusCenter();
listPopup.addListSelectionListener(this);
listPopup.addListener(this);
}
/**
* 上下键选择事件,仅仅是改变,而不是按住回车之后的选择
*
* @param e
*/
@Override
public void valueChanged(ListSelectionEvent e) {
int firstIndex = e.getFirstIndex();
int lastIndex = e.getLastIndex();
boolean valueIsAdjusting = e.getValueIsAdjusting();
System.out.println("firstIndex:" + firstIndex);
System.out.println("lastIndex:" + lastIndex);
System.out.println("valueIsAdjusting:" + valueIsAdjusting);
}
/**
* popup 关闭监听
*
* @param event
*/
@Override
public void onClosed(@NotNull LightweightWindowEvent event) {
JBPopup jbPopup = event.asPopup();
System.out.println("关闭popup");
jbPopup.cancel();
}
}
package com.hik.project;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* @menu: GetContentSourceRootAction
* @author: xieshixiang@hikcreate.com
* @time:2020/10/13 9:31
**/
public class GetContentSourceRootAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
VirtualFile[] virtualFiles = ProjectRootManager.getInstance(project).getContentSourceRoots();
String sourceRoot = Arrays.stream(virtualFiles).map(VirtualFile::getUrl).collect(Collectors.joining("\n"));
Messages.showInfoMessage("Source roots for project: " + project.getName() + " are " + sourceRoot, "Project " +
"Properties");
}
}
\ No newline at end of file
package com.hik.project;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
/**
* @menu: ProjectFileIndexAction
* @author: xieshixiang@hikcreate.com
* @time:2020/10/13 9:32
**/
public class ProjectFileIndexAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
Editor editor = e.getData(CommonDataKeys.EDITOR);
if (project == null || editor == null) {
return;
}
Document document = editor.getDocument();
VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file == null) {
Messages.showInfoMessage("Unknown File", "Project File Index");
} else {
ProjectFileIndex fileIndex = ProjectFileIndex.getInstance(project);
Messages.showInfoMessage("Module: " + fileIndex.getModuleForFile(file) + "\n" +
"Is In Source: " + fileIndex.isInSource(file) + "\n" +
"Module content root: " + fileIndex.getContentRootForFile(file) + "\n" +
"Source root: " + fileIndex.getSourceRootForFile(file) + "\n" +
"Is library file: " + fileIndex.isLibraryClassFile(file) + "\n" +
"Is in library classes: " + fileIndex.isInLibraryClasses(file) +
", Is in library source: " + fileIndex.isInLibrarySource(file),
"Main File Info for" + file.getName());
}
}
}
\ No newline at end of file
package com.hik.project;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
/**
* @menu: ProjectSdkAction
* @author: xieshixiang@hikcreate.com
* @time:2020/10/13 9:33
**/
public class ProjectSdkAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project != null) {
Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
if (projectSdk != null) {
String origProjectSdkName = projectSdk.getName();
WriteCommandAction.runWriteCommandAction(project, () ->
ProjectRootManager.getInstance(project).setProjectSdkName("newProjectSdkName")
);
Messages.showInfoMessage("origProjectSdkName:" + origProjectSdkName, "Change Project SDK Name Success");
} else {
Messages.showInfoMessage("Unknown Project SDK", "Change Project SDK Name Fail");
}
} else {
Messages.showInfoMessage("Unknown Project", "Change Project SDK Name Fail");
}
}
}
\ No newline at end of file
package com.hik.project;
import com.intellij.ProjectTopics;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import org.jetbrains.annotations.NotNull;
/**
* @menu: ProjectStructureAction
* @author: xieshixiang@hikcreate.com
* @time:2020/10/13 9:34
**/
public class ProjectStructureAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null) {
System.out.println("null");
return;
}
project.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(@NotNull ModuleRootEvent event) {
System.out.println(event.toString());
}
});
}
}
\ No newline at end of file
package com.hik.run.configuration;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/10 5:01 下午
*/
public class DemoConfigurationFactory extends ConfigurationFactory {
private static final String FACTORY_NAME = "Demo configuration factory";
protected DemoConfigurationFactory(@NotNull ConfigurationType type) {
super(type);
}
@NotNull
@Override
public RunConfiguration createTemplateConfiguration(@NotNull Project project) {
return new DemoRunConfiguration(project, this, "Demo");
}
@NotNull
@Override
public String getName() {
return FACTORY_NAME;
}
}
package com.hik.run.configuration;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.icons.AllIcons;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/10 4:59 下午
*/
public class DemoConfigurationType implements ConfigurationType {
@NotNull
@Override
public String getDisplayName() {
return "DemoRunConfiguration";
}
@Nls
@Override
public String getConfigurationTypeDescription() {
return "Demo Run Configuration Desc";
}
@Override
public Icon getIcon() {
return AllIcons.General.Information;
}
@NotNull
@Override
public String getId() {
return "DemoRunConfiguration";
}
@Override
public ConfigurationFactory[] getConfigurationFactories() {
return new ConfigurationFactory[]{new DemoConfigurationFactory(this)};
}
}
package com.hik.run.configuration;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author wengyongcheng
* @since 2020/3/10 5:03 下午
*/
public class DemoRunConfiguration extends RunConfigurationBase {
protected DemoRunConfiguration(@NotNull Project project, @Nullable ConfigurationFactory factory,
@Nullable String name) {
super(project, factory, name);
}
@NotNull
@Override
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
return new DemoSettingsEditor();
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
}
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.hik.run.configuration.DemoSettingsEditor">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="da5f">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="6aea0" class="com.intellij.openapi.ui.LabeledComponent" binding="scriptName" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<name value=""/>
<requestFocusEnabled value="true"/>
<text value="Script File"/>
</properties>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>
package com.hik.run.configuration;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/11 11:29 上午
*/
public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
private JPanel panel;
private LabeledComponent<TextFieldWithBrowseButton> scriptName;
private void createUIComponents() {
scriptName = new LabeledComponent<>();
scriptName.setComponent(new TextFieldWithBrowseButton());
}
@Override
protected void resetEditorFrom(@NotNull DemoRunConfiguration s) {
}
@Override
protected void applyEditorTo(@NotNull DemoRunConfiguration s) throws ConfigurationException {
}
@NotNull
@Override
protected JComponent createEditor() {
return panel;
}
}
package com.hik.run.configuration.multi.factory;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author wengyongcheng
* @since 2020/3/10 5:03 下午
*/
public class FirstConfiguration extends RunConfigurationBase {
protected FirstConfiguration(@NotNull Project project, @Nullable ConfigurationFactory factory,
@Nullable String name) {
super(project, factory, name);
}
@NotNull
@Override
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
return new FirstSettingsEditor();
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
}
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
return null;
}
}
package com.hik.run.configuration.multi.factory;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/10 5:01 下午
*/
public class FirstConfigurationFactory extends ConfigurationFactory {
private static final String FACTORY_NAME = "First configuration factory";
protected FirstConfigurationFactory(@NotNull ConfigurationType type) {
super(type);
}
@NotNull
@Override
public RunConfiguration createTemplateConfiguration(@NotNull Project project) {
return new FirstConfiguration(project, this, "First");
}
@NotNull
@Override
public String getName() {
return FACTORY_NAME;
}
}
package com.hik.run.configuration.multi.factory;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
/**
* @author wengyongcheng
* @since 2020/3/11 3:43 下午
*/
public class FirstSettingsEditor extends SettingsEditor<FirstConfiguration> {
private JPanel panel;
private JLabel label;
@Override
protected void resetEditorFrom(@NotNull FirstConfiguration s) {
}
@Override
protected void applyEditorTo(@NotNull FirstConfiguration s) throws ConfigurationException {
}
@NotNull
@Override
protected JComponent createEditor() {
label = new JLabel("First Label");
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(label, BorderLayout.CENTER);
return panel;
}
}
package com.hik.run.configuration.multi.factory;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.icons.AllIcons;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/10 4:59 下午
*/
public class MultiFactoryConfigurationType implements ConfigurationType {
@NotNull
@Override
public String getDisplayName() {
return "MultiFactoryRunConfiguration";
}
@Nls
@Override
public String getConfigurationTypeDescription() {
return "Multi Factory Run Configuration Desc";
}
@Override
public Icon getIcon() {
return AllIcons.General.Information;
}
@NotNull
@Override
public String getId() {
return "MultiFactoryRunConfiguration";
}
@Override
public ConfigurationFactory[] getConfigurationFactories() {
return new ConfigurationFactory[]{new FirstConfigurationFactory(this), new SecondConfigurationFactory(this)};
}
}
package com.hik.run.configuration.multi.factory;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author wengyongcheng
* @since 2020/3/10 5:03 下午
*/
public class SecondConfiguration extends RunConfigurationBase {
protected SecondConfiguration(@NotNull Project project, @Nullable ConfigurationFactory factory,
@Nullable String name) {
super(project, factory, name);
}
@NotNull
@Override
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
return new SecondSettingsEditor();
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
}
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
return null;
}
}
package com.hik.run.configuration.multi.factory;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/10 5:01 下午
*/
public class SecondConfigurationFactory extends ConfigurationFactory {
private static final String FACTORY_NAME = "Second configuration factory";
protected SecondConfigurationFactory(@NotNull ConfigurationType type) {
super(type);
}
@NotNull
@Override
public RunConfiguration createTemplateConfiguration(@NotNull Project project) {
return new SecondConfiguration(project, this, "Second");
}
@NotNull
@Override
public String getName() {
return FACTORY_NAME;
}
}
package com.hik.run.configuration.multi.factory;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
/**
* @author wengyongcheng
* @since 2020/3/11 3:43 下午
*/
public class SecondSettingsEditor extends SettingsEditor<SecondConfiguration> {
private JPanel panel;
private JLabel label;
@Override
protected void resetEditorFrom(@NotNull SecondConfiguration s) {
}
@Override
protected void applyEditorTo(@NotNull SecondConfiguration s) throws ConfigurationException {
}
@NotNull
@Override
protected JComponent createEditor() {
label = new JLabel("Second Label");
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(label, BorderLayout.CENTER);
return panel;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.hik.setting.MainSetting">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="3e3d">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="e973e" class="javax.swing.JTextField" binding="textField" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="71ed" class="javax.swing.JLabel" binding="label">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Main Setting"/>
</properties>
</component>
</children>
</grid>
</form>
package com.hik.setting;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/14 10:16 下午
*/
public class MainSetting implements Configurable, Configurable.Composite {
private JTextField textField;
private JLabel label;
private JPanel mainPanel;
private Settings settings = Settings.getInstance();
public MainSetting() {
init();
}
private void init() {
this.settings = Settings.getInstance();
textField.setText(settings.getSettingMap().get("mainSetting"));
}
@Nls(capitalization = Nls.Capitalization.Title)
@Override
public String getDisplayName() {
return "Main Setting";
}
/**
* 通过方法返回定义的子设置组件
*
* @return
*/
@NotNull
@Override
public Configurable[] getConfigurables() {
Configurable[] configurables = new Configurable[1];
configurables[0] = new SubSetting();
return configurables;
}
@Nullable
@Override
public JComponent createComponent() {
return mainPanel;
}
/**
* 设置apply按钮是否可用,数据修改时被调用
*
* @return
*/
@Override
public boolean isModified() {
String origSetting = settings.getSettingMap().get("mainSetting");
String newSetting = textField.getText();
return !StringUtils.equals(origSetting, newSetting);
}
/**
* 点击apply按钮后被调用
*
* @throws ConfigurationException
*/
@Override
public void apply() throws ConfigurationException {
settings.getSettingMap().put("mainSetting", textField.getText());
}
/**
* reset按钮被点击时触发
*/
@Override
public void reset() {
init();
}
}
package com.hik.setting;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
/**
* @author wengyongcheng
* @since 2020/3/14 10:27 下午
*/
@State(name = "MainSetting", storages = @Storage("main-setting.xml"))
public class Settings implements PersistentStateComponent<Settings> {
private Map<String, String> settingMap;
public Settings() {
init();
}
public static Settings getInstance() {
return ServiceManager.getService(Settings.class);
}
public Map<String, String> getSettingMap() {
return settingMap;
}
public void setSettingMap(Map<String, String> settingMap) {
this.settingMap = settingMap;
}
private void init() {
settingMap = new HashMap<>();
}
@Nullable
@Override
public Settings getState() {
return this;
}
/**
* 新的组件状态被加载时,调用该方法,如果IDE运行期间,保存数据的文件被从外部修改,则该方法会被再次调用
*
* @param state
*/
@Override
public void loadState(@NotNull Settings state) {
setSettingMap(state.getSettingMap());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.hik.setting.SubSetting">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="dbedb" class="javax.swing.JLabel" binding="label">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Sub Setting"/>
</properties>
</component>
<vspacer id="b6f48">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="ed34" class="javax.swing.JTextField" binding="testField" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>
package com.hik.setting;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/3/14 10:20 下午
*/
public class SubSetting implements Configurable {
private JPanel mainPanel;
private JTextField testField;
private JLabel label;
public SubSetting() {
}
@Nls(capitalization = Nls.Capitalization.Title)
@Override
public String getDisplayName() {
return "Sub Setting";
}
@Nullable
@Override
public JComponent createComponent() {
return mainPanel;
}
@Override
public boolean isModified() {
return false;
}
@Override
public void apply() throws ConfigurationException {
}
}
package com.hik.toolview;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.project.Project;
/**
* @author wengyongcheng
* @since 2020/7/13 9:12 下午
*/
public class ConfigUtil {
public static void setRunning(Project project, boolean value) {
PropertiesComponent.getInstance(project).setValue(StringConst.RUNNING_KEY, value);
}
public static boolean getRunning(Project project) {
return PropertiesComponent.getInstance(project).getBoolean(StringConst.RUNNING_KEY);
}
}
package com.hik.toolview;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/7/11 2:06 下午
*/
public class ConsoleViewAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
runExecutor(e.getProject());
}
public void runExecutor(Project project) {
if (project == null) {
return;
}
CustomExecutor executor = new CustomExecutor(project);
// 设置restart和stop
executor.withReturn(() -> runExecutor(project)).withStop(() -> ConfigUtil.setRunning(project, false), () ->
ConfigUtil.getRunning(project));
executor.run();
}
}
package com.hik.toolview;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/7/11 4:12 下午
*/
public class CustomAction extends AnAction {
public CustomAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
super(text, description, icon);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Messages.showMessageDialog("custom action", "Custom Action", Messages.getInformationIcon());
}
}
package com.hik.toolview;
import com.intellij.execution.DefaultExecutionResult;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.ExecutionManager;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.filters.TextConsoleBuilder;
import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.execution.ui.RunnerLayoutUi;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.ui.content.Content;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
/**
* @author wengyongcheng
* @since 2020/7/11 2:02 下午
*/
public class CustomExecutor implements Disposable {
private ConsoleView consoleView = null;
private Project project = null;
private Runnable rerunAction;
private Runnable stopAction;
private Computable<Boolean> stopEnabled;
public CustomExecutor(@NotNull Project project) {
this.project = project;
this.consoleView = createConsoleView(project);
}
public CustomExecutor withReturn(Runnable returnAction) {
this.rerunAction = returnAction;
return this;
}
public CustomExecutor withStop(Runnable stopAction, Computable<Boolean> stopEnabled) {
this.stopAction = stopAction;
this.stopEnabled = stopEnabled;
return this;
}
private ConsoleView createConsoleView(Project project) {
TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
ConsoleView console = consoleBuilder.getConsole();
return console;
}
@Override
public void dispose() {
Disposer.dispose(this);
}
public void run() {
if (project.isDisposed()) {
return;
}
Executor executor = CustomRunExecutor.getRunExecutorInstance();
if (executor == null) {
return;
}
final RunnerLayoutUi.Factory factory = RunnerLayoutUi.Factory.getInstance(project);
RunnerLayoutUi layoutUi = factory.create("runnerId", "runnerTitle", "sessionName", project);
final JPanel consolePanel = createConsolePanel(consoleView);
RunContentDescriptor descriptor = new RunContentDescriptor(new RunProfile() {
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
return null;
}
@NotNull
@Override
public String getName() {
return "name";
}
@Nullable
@Override
public Icon getIcon() {
return null;
}
}, new DefaultExecutionResult(), layoutUi);
descriptor.setExecutionId(System.nanoTime());
final Content content = layoutUi.createContent("contentId", consolePanel, "displayName",
AllIcons.Debugger.Console, consolePanel);
content.setCloseable(false);
layoutUi.addContent(content);
layoutUi.getOptions().setLeftToolbar(createActionToolbar(consolePanel, consoleView, layoutUi, descriptor,
executor), "RunnerToolbar");
Disposer.register(descriptor, this);
Disposer.register(content, consoleView);
if (stopAction != null) {
Disposer.register(consoleView, () -> stopAction.run());
}
ExecutionManager.getInstance(project).getContentManager().showRunContent(executor, descriptor);
}
private ActionGroup createActionToolbar(JPanel consolePanel, ConsoleView consoleView, RunnerLayoutUi layoutUi,
RunContentDescriptor descriptor, Executor executor) {
final DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(new RerunAction(consolePanel, consoleView));
actionGroup.add(new StopAction());
actionGroup.add(consoleView.createConsoleActions()[2]);
actionGroup.add(consoleView.createConsoleActions()[3]);
actionGroup.add(consoleView.createConsoleActions()[5]);
actionGroup.add(new CustomAction("custom action", "custom action", IconUtil.ICON));
return actionGroup;
}
private JPanel createConsolePanel(ConsoleView consoleView) {
JPanel panel = new JPanel();
panel.add(consoleView.getComponent(), BorderLayout.CENTER);
return panel;
}
private class RerunAction extends AnAction implements DumbAware {
private final ConsoleView consoleView;
public RerunAction(JComponent consolePanel, ConsoleView consoleView) {
super("Rerun", "Rerun", AllIcons.Actions.Restart);
this.consoleView = consoleView;
registerCustomShortcutSet(CommonShortcuts.getRerun(), consolePanel);
}
@Override
public void actionPerformed(AnActionEvent e) {
Disposer.dispose(consoleView);
rerunAction.run();
}
@Override
public void update(AnActionEvent e) {
e.getPresentation().setVisible(rerunAction != null);
e.getPresentation().setIcon(AllIcons.Actions.Restart);
}
}
private class StopAction extends AnAction implements DumbAware {
public StopAction() {
super("Stop", "Stop", AllIcons.Actions.Suspend);
}
@Override
public void actionPerformed(AnActionEvent e) {
stopAction.run();
}
@Override
public void update(AnActionEvent e) {
e.getPresentation().setVisible(stopAction != null);
e.getPresentation().setEnabled(stopEnabled != null && stopEnabled.compute());
}
}
}
package com.hik.toolview;
import com.intellij.execution.filters.ConsoleFilterProvider;
import com.intellij.execution.filters.Filter;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/7/11 1:32 下午
*/
public class CustomProvider implements ConsoleFilterProvider {
@NotNull
@Override
public Filter[] getDefaultFilters(@NotNull Project project) {
return new Filter[0];
}
}
package com.hik.toolview;
import com.intellij.execution.Executor;
import com.intellij.execution.ExecutorRegistry;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/7/11 2:15 下午
*/
public class CustomRunExecutor extends Executor {
public static final String TOOL_WINDOW_ID = "tool window plugin";
public static Executor getRunExecutorInstance() {
return ExecutorRegistry.getInstance().getExecutorById(StringConst.PLUGIN_ID);
}
@Override
public String getToolWindowId() {
return TOOL_WINDOW_ID;
}
@Override
public Icon getToolWindowIcon() {
return IconUtil.ICON;
}
@NotNull
@Override
public Icon getIcon() {
return IconUtil.ICON;
}
@Override
public Icon getDisabledIcon() {
return IconUtil.ICON;
}
@Override
public String getDescription() {
return TOOL_WINDOW_ID;
}
@NotNull
@Override
public String getActionName() {
return TOOL_WINDOW_ID;
}
@NotNull
@Override
public String getId() {
return StringConst.PLUGIN_ID;
}
@NotNull
@Override
public String getStartActionText() {
return TOOL_WINDOW_ID;
}
@Override
public String getContextActionId() {
return "custom context action id";
}
@Override
public String getHelpId() {
return TOOL_WINDOW_ID;
}
}
package com.hik.toolview;
import com.intellij.openapi.util.IconLoader;
import javax.swing.*;
/**
* @author wengyongcheng
* @since 2020/7/11 2:42 下午
*/
public class IconUtil {
public static final Icon ICON = IconLoader.getIcon("/icons/edit.svg");
}
package com.hik.toolview;
/**
* @author wengyongcheng
* @since 2020/7/11 2:18 下午
*/
public class StringConst {
public static final String PLUGIN_ID = "plugin id";
public static final String RUNNING_KEY = "runningKey";
}
package com.hik.toolwindow;
import com.intellij.openapi.wm.ToolWindow;
import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author wengyongcheng
* @since 2020/3/1 10:30 下午
*/
public class MyToolWindow {
private JButton hideButton;
private JLabel datetimeLabel;
private JPanel myToolWindowContent;
public MyToolWindow(ToolWindow toolWindow) {
init();
hideButton.addActionListener(e -> toolWindow.hide(null));
}
private void init() {
datetimeLabel = new JLabel();
datetimeLabel.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
hideButton = new JButton("取消");
myToolWindowContent = new JPanel();
myToolWindowContent.add(datetimeLabel);
myToolWindowContent.add(hideButton);
}
public JPanel getContent() {
return myToolWindowContent;
}
}
package com.hik.toolwindow;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/1 10:31 下午
*/
public class MyToolWindowFactory implements ToolWindowFactory, Condition<Project> {
/**
* 创建 tool window
*
* @param project
* @param toolWindow
*/
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
MyToolWindow myToolWindow = new MyToolWindow(toolWindow);
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
Content content = contentFactory.createContent(myToolWindow.getContent(), "自定义tool window", false);
toolWindow.getContentManager().addContent(content);
}
/**
* 控制tool window是否展示
*
* @param project
* @return
*/
@Override
public boolean value(Project project) {
return false;
}
}
package com.hik.tree;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
/**
* @author wengyongcheng
* @since 2020/3/7 10:21 下午
*/
public class TreeAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
new TreeDialogWrapper().showAndGet();
}
}
package com.hik.tree;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.treeStructure.Tree;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import java.awt.*;
/**
* @author wengyongcheng
* @since 2020/3/7 10:22 下午
*/
public class TreeDialogWrapper extends DialogWrapper {
private Tree tree;
private DefaultTreeModel model;
public TreeDialogWrapper() {
super(true);
init();
setTitle("Tree");
}
@Nullable
@Override
protected JComponent createCenterPanel() {
// 创建节点
DefaultMutableTreeNode child1Leaf1 = new DefaultMutableTreeNode();
child1Leaf1.setUserObject("child1Leaf1");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode();
child1.add(child1Leaf1);
child1.setUserObject("child1");
DefaultMutableTreeNode child1Leaf2 = new DefaultMutableTreeNode();
child1Leaf2.setUserObject("child1Leaf2");
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode();
child2.add(child1Leaf2);
child2.setUserObject("child2");
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
root.setUserObject("root");
root.add(child1);
root.add(child2);
// 创建数据模型
model = new DefaultTreeModel(root);
tree = new Tree(model);
tree.setDragEnabled(true);
tree.setExpandableItemsEnabled(true);
// 快速查找
new TreeSpeedSearch(tree);
// 自定义样式
ColoredTreeCellRenderer coloredTreeCellRenderer = new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
append(value + "-suffix");
}
};
tree.setCellRenderer(coloredTreeCellRenderer);
// 工具栏
ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(tree);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(toolbarDecorator.createPanel(), BorderLayout.CENTER);
return panel;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment