diff --git a/hdc/assist_tools_IntelliJ_plugin/resources/META-INF/plugin.xml b/hdc/assist_tools_IntelliJ_plugin/resources/META-INF/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..570daa1f471976dc1c2b99a903442f57e93dcd61 --- /dev/null +++ b/hdc/assist_tools_IntelliJ_plugin/resources/META-INF/plugin.xml @@ -0,0 +1,29 @@ + + com.kh.tools.ng + Assist Tools + 1.0 + 深圳开鸿数字产业发展有限公司 + + + + com.intellij.modules.lang + com.sk.ng + com.sk.gn + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hdc/assist_tools_IntelliJ_plugin/resources/images/close.png b/hdc/assist_tools_IntelliJ_plugin/resources/images/close.png new file mode 100644 index 0000000000000000000000000000000000000000..32edfa363b1a1f764fade91a3a80fc7f626a0315 Binary files /dev/null and b/hdc/assist_tools_IntelliJ_plugin/resources/images/close.png differ diff --git a/hdc/assist_tools_IntelliJ_plugin/resources/images/cloudic_manager.png b/hdc/assist_tools_IntelliJ_plugin/resources/images/cloudic_manager.png new file mode 100644 index 0000000000000000000000000000000000000000..5764627e6afb5383806b62f945bc47a1459d4ddc Binary files /dev/null and b/hdc/assist_tools_IntelliJ_plugin/resources/images/cloudic_manager.png differ diff --git a/hdc/assist_tools_IntelliJ_plugin/resources/images/gn.png b/hdc/assist_tools_IntelliJ_plugin/resources/images/gn.png new file mode 100644 index 0000000000000000000000000000000000000000..1b4acbe9c4839288088c763afb906497c4d34621 Binary files /dev/null and b/hdc/assist_tools_IntelliJ_plugin/resources/images/gn.png differ diff --git a/hdc/assist_tools_IntelliJ_plugin/resources/images/napi.png b/hdc/assist_tools_IntelliJ_plugin/resources/images/napi.png new file mode 100644 index 0000000000000000000000000000000000000000..81d5e40a6e854c85d789eb33f75f7fec3213b62a Binary files /dev/null and b/hdc/assist_tools_IntelliJ_plugin/resources/images/napi.png differ diff --git a/hdc/assist_tools_IntelliJ_plugin/resources/images/search.png b/hdc/assist_tools_IntelliJ_plugin/resources/images/search.png new file mode 100644 index 0000000000000000000000000000000000000000..b27fc24d3502eed6f9ac7315d85f01c364009338 Binary files /dev/null and b/hdc/assist_tools_IntelliJ_plugin/resources/images/search.png differ diff --git a/hdc/assist_tools_IntelliJ_plugin/resources/images/tools_center.png b/hdc/assist_tools_IntelliJ_plugin/resources/images/tools_center.png new file mode 100644 index 0000000000000000000000000000000000000000..e17aac374806516f7d253811de4096544fd5ce85 Binary files /dev/null and b/hdc/assist_tools_IntelliJ_plugin/resources/images/tools_center.png differ diff --git a/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterDialog.java b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..7d380580d82afe80d68e7a3e0caae6010bd20eb2 --- /dev/null +++ b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterDialog.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2022 Guangzhou Digitalchina Information Technology Co., Ltd. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.kh.tools.dialog; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import com.kh.tools.utils.PluginUtils; +import com.sk.dialog.GenerateDialog; +import com.sk.gn.dialog.GenGenerateDialog; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.Action; +import javax.swing.JComponent; +import java.awt.Desktop; +import java.awt.event.ActionEvent; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +/** + * 自定义确认对话框Wrapper + * + * @author: zhaoxudong@kaihong.com + * @see: tool conversion plug-in + * @version: v1.0.0 + * @since 2022-09-10 + */ +public class ToolCenterDialog extends DialogWrapper { + private static final Logger LOG = Logger.getInstance(ToolCenterDialog.class); + + private final ToolCenterPanel toolCenterPanel; + private Project project; + + /** + * 构造函数 + * @param project Project + */ + public ToolCenterDialog(Project project) { + super(true); + this.project = project; + toolCenterPanel = new ToolCenterPanel(); + setTitle(PluginUtils.TITLE); + init(); + } + + @Override + @Nullable + protected JComponent createCenterPanel() { + return toolCenterPanel.getContentPanel(); + } + + /** + * ok/cancel按钮 + * + * @return Action[] buttos list + */ + @NotNull + @Override + protected Action[] createActions() { + DialogWrapperExitAction exitAction = new DialogWrapperExitAction("Cancel", CANCEL_EXIT_CODE); + ToolCenterDialog.CustomOKAction okAction = new ToolCenterDialog.CustomOKAction(); + okAction.putValue(DialogWrapper.DEFAULT_ACTION, true); + return new Action[]{exitAction, okAction}; + } + + @NotNull + @Override + protected Action[] createLeftSideActions() { + ToolCenterDialog.CustomHelpAction helpAction = new ToolCenterDialog.CustomHelpAction(); + return new Action[]{helpAction}; + } + + /** + * 自定义 next Action + */ + protected class CustomOKAction extends DialogWrapperAction { + + protected CustomOKAction() { + super("Next"); + } + + @Override + protected void doAction(ActionEvent actionEvent) { + if (toolCenterPanel.isSelectButton().equals("Napi")) { + GenerateDialog generateDialog = new GenerateDialog(project, "", "", ""); + generateDialog.showAndGet(); + } else if (toolCenterPanel.isSelectButton().equals("H2ts")) { + GenerateDialog generateDialog = new GenerateDialog(project, "", "", ""); + generateDialog.showAndGet(); + } else if (toolCenterPanel.isSelectButton().equals("Gn")) { + GenGenerateDialog genGenerateDialog = new GenGenerateDialog(project); + genGenerateDialog.showAndGet(); + } else { + LOG.error("action is not exit"); + } + } + } + + /** + * 自定义 help Action + */ + protected class CustomHelpAction extends DialogWrapperAction { + + protected CustomHelpAction() { + super("Help"); + } + + @Override + protected void doAction(ActionEvent actionEvent) { + try { + Desktop.getDesktop().browse(new URI(PluginUtils.URL)); + } catch (URISyntaxException | IOException e) { + LOG.error("Open help error:" + e); + } + } + } +} diff --git a/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterPanel.form b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterPanel.form new file mode 100644 index 0000000000000000000000000000000000000000..6ba4fe2416581d7ba39348ca4c19d9a9bef61caf --- /dev/null +++ b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterPanel.form @@ -0,0 +1,280 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterPanel.java b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..a33d60ea2718a3c972e80f8e125ce9dcedaaf1b7 --- /dev/null +++ b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/dialog/ToolCenterPanel.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2022 Guangzhou Digitalchina Information Technology Co., Ltd. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.kh.tools.dialog; + +import com.kh.tools.utils.PluginUtils; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; +import javax.swing.JTextField; +import javax.swing.KeyStroke; +import javax.swing.border.EmptyBorder; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.KeyEvent; +import java.util.HashMap; + +/** + * 插件中心 + * + * @author: zhaoxudong@kaihong.com + * @see: tool conversion plug-in + * @version: v1.0.0 + * @since 2022-09-16 + */ +public class ToolCenterPanel extends JDialog { + private JPanel contentPane; + private JPanel searchPanel; + private JTextField searchTextField; + private JTabbedPane tabbedPane; + private JLabel toolSecondNameLabel; + private JLabel toolDescLabel; + private JButton buttonNapi; + private JButton buttonNapiName; + private JButton gnButton; + private JButton buttonGn; + private JButton buttonClose; + private JPanel napiPanel; + private JPanel servicePanel; + private String isSelectButton = "Napi"; + + /** + * 构造函数 + */ + public ToolCenterPanel() { + tabbedPane.removeTabAt(1); + setContentPane(contentPane); + setModal(true); + contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + searchTextField.addFocusListener(new FocusListener() { + @Override + public void focusGained(FocusEvent focusEvent) { + searchPanel.setBorder(PluginUtils.BORDER_FOCUS_GAINED); + if (searchTextField.getText().equals("search")) { + searchTextField.setText(""); + } + } + + @Override + public void focusLost(FocusEvent focusEvent) { + searchPanel.setBorder(PluginUtils.BORDER_FOCUS_LOST_SEARCH); + if (searchTextField.getText().trim().length() < 1) { + searchTextField.setText("search"); + } + } + }); + searchTextField.setForeground(Color.white); + searchTextField.setBackground(Color.decode("#3c3f41")); + searchTextField.setBorder(new EmptyBorder(0, 0, 0, 0)); + searchTextField.setCaretColor(Color.white); + searchTextField.setFont(new Font(null, Font.PLAIN, 15)); + setButtonStyle(); + textFieldAction(); + buttonAction(); + } + + private void setButtonStyle() { + buttonClose.setPreferredSize(new Dimension(40, 10)); + buttonClose.setContentAreaFilled(false); + buttonClose.setBorder(new EmptyBorder(0, 0, 0, 0)); + buttonNapiName.setContentAreaFilled(false); + buttonNapiName.setBorder(new EmptyBorder(0, 0, 0, 0)); + gnButton.setContentAreaFilled(false); + gnButton.setBorder(new EmptyBorder(0, 0, 0, 0)); + } + + private void textFieldAction() { + searchTextField.getDocument().addDocumentListener(new DocumentListener() { + HashMap result; + + @Override + public void insertUpdate(DocumentEvent documentEvent) { + result = searchTools(searchTextField.getText().trim()); + if (result.containsKey(buttonNapi.getToolTipText())) { + napiPanel.setVisible(true); + } else { + napiPanel.setVisible(false); + } + if (result.containsKey(buttonGn.getToolTipText())) { + servicePanel.setVisible(true); + } else { + servicePanel.setVisible(false); + } + } + + @Override + public void removeUpdate(DocumentEvent documentEvent) { + result = searchTools(searchTextField.getText().trim()); + if (result.containsKey(buttonNapi.getToolTipText())) { + napiPanel.setVisible(true); + } else { + napiPanel.setVisible(false); + } + if (result.containsKey(buttonGn.getToolTipText())) { + servicePanel.setVisible(true); + } else { + servicePanel.setVisible(false); + } + } + + @Override + public void changedUpdate(DocumentEvent documentEvent) { + } + }); + buttonClose.addActionListener(actionEvent -> searchTextField.setText("search")); + } + + private void buttonAction() { + buttonNapi.addActionListener(e -> { + isSelectButton = "Napi"; + toolSecondNameLabel.setText(buttonNapi.getToolTipText()); + toolDescLabel.setText(PluginUtils.TOOLS.get(buttonNapi.getToolTipText())); + buttonNapiName.setForeground(Color.white); + gnButton.setForeground(Color.decode("#BBBBBB")); + }); + buttonGn.addActionListener(e -> { + isSelectButton = "Gn"; + toolSecondNameLabel.setText(buttonGn.getToolTipText()); + toolDescLabel.setText(PluginUtils.TOOLS.get(buttonGn.getToolTipText())); + gnButton.setForeground(Color.white); + buttonNapiName.setForeground(Color.decode("#BBBBBB")); + }); + } + + private void onCancel() { + dispose(); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(1000, 600); + } + + JPanel getContentPanel() { + return contentPane; + } + + public String isSelectButton() { + return isSelectButton; + } + + /** + * 搜索结果 + * + * @param key 关键字 + * @return 搜索结果 + */ + private HashMap searchTools(String key) { + if (key.equals("search")) { + return PluginUtils.TOOLS; + } + HashMap searchResultList = new HashMap<>(); + for (HashMap.Entry entry : PluginUtils.TOOLS.entrySet()) { + if (entry.getKey().contains(key)) { + searchResultList.put(entry.getKey(), entry.getValue()); + } + } + return searchResultList; + } +} diff --git a/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/ng/AssistCenterMenu.java b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/ng/AssistCenterMenu.java new file mode 100644 index 0000000000000000000000000000000000000000..4c970f57195426fda00de677906f052a702ce482 --- /dev/null +++ b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/ng/AssistCenterMenu.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Guangzhou Digitalchina Information Technology Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.kh.tools.ng; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.Project; +import com.kh.tools.dialog.ToolCenterDialog; +import org.jetbrains.annotations.NotNull; + +/** + * 工具菜单入口 + * + * @author: zhaoxudong@kaihong.com + * @see: tool conversion plug-in + * @version: v1.0.0 + * @since 2022-09-19 + */ +public class AssistCenterMenu extends AnAction { + + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + Project project = anActionEvent.getProject(); + + if (project == null) { + return; + } + ToolCenterDialog wrapper = new ToolCenterDialog(project); + wrapper.showAndGet(); + } +} diff --git a/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/utils/PluginUtils.java b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/utils/PluginUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..aebb33f8754c26b72e6fba320f037f73465b8fb3 --- /dev/null +++ b/hdc/assist_tools_IntelliJ_plugin/src/com/kh/tools/utils/PluginUtils.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.kh.tools.utils; + +import javax.swing.BorderFactory; +import javax.swing.border.Border; +import java.awt.Color; +import java.util.HashMap; + +/** + * 工具类 + * + * @author: zhaoxudong@kaihong.com + * @see: tool conversion plug-in + * @version: v1.0.0 + * @since 2022-09-19 + */ +public class PluginUtils { + + /** + * 项目代码路径 + */ + public static final String URL = ""; + + /** + * 应用名称 + */ + public static final String TITLE = "App dev Tools"; + + /** + * 获取焦点色值 + */ + public static final Border BORDER_FOCUS_GAINED = BorderFactory.createLineBorder(Color.decode("#385584"), 2); + + /** + * 默认色值 + */ + public static final Border BORDER_FOCUS_LOST_SEARCH = BorderFactory.createLineBorder(Color.decode("#646567"), 2); + + /** + * 工具描述 + */ + public static final HashMap TOOLS = new HashMap() { + { + put("NAPI Generator", "NAPI tool generates NAPI framework code by typescript file."); + put("Gn Generator", "The Gn generation tool generates gn scripts by other script type files, or perform " + + "reverse conversion."); + } + }; +}