diff --git a/src/main/java/cn/memoryzy/json/action/toolwindow/ScrollToTheEndAction.java b/src/main/java/cn/memoryzy/json/action/toolwindow/ScrollToTheEndAction.java
index fd53dd3..72953a8 100644
--- a/src/main/java/cn/memoryzy/json/action/toolwindow/ScrollToTheEndAction.java
+++ b/src/main/java/cn/memoryzy/json/action/toolwindow/ScrollToTheEndAction.java
@@ -1,6 +1,9 @@
package cn.memoryzy.json.action.toolwindow;
+import cn.hutool.core.util.StrUtil;
import cn.memoryzy.json.bundle.JsonAssistantBundle;
+import cn.memoryzy.json.ui.panel.JsonAssistantToolWindowPanel;
+import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actions.ScrollToTheEndToolbarAction;
@@ -27,6 +30,12 @@ public ScrollToTheEndAction(@NotNull Editor editor, SimpleToolWindowPanel simple
presentation.setIcon(JsonAssistantIcons.ToolWindow.SCROLL_DOWN);
}
-
+ @Override
+ public void update(@NotNull AnActionEvent e) {
+ e.getPresentation().setEnabled(
+ getEventProject(e) != null
+ && StrUtil.isNotBlank(editor.getDocument().getText())
+ && JsonAssistantToolWindowPanel.isEditorCardDisplayed(simpleToolWindowPanel));
+ }
}
diff --git a/src/main/java/cn/memoryzy/json/action/toolwindow/ToggleUseSoftWrapsAction.java b/src/main/java/cn/memoryzy/json/action/toolwindow/ToggleUseSoftWrapsAction.java
index 3b66179..5a41aab 100644
--- a/src/main/java/cn/memoryzy/json/action/toolwindow/ToggleUseSoftWrapsAction.java
+++ b/src/main/java/cn/memoryzy/json/action/toolwindow/ToggleUseSoftWrapsAction.java
@@ -2,16 +2,21 @@
import cn.hutool.core.util.StrUtil;
import cn.memoryzy.json.bundle.JsonAssistantBundle;
+import cn.memoryzy.json.constant.PluginConstant;
import cn.memoryzy.json.ui.panel.JsonAssistantToolWindowPanel;
+import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.openapi.actionSystem.Toggleable;
import com.intellij.openapi.actionSystem.UpdateInBackground;
+import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actions.AbstractToggleUseSoftWrapsAction;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
import com.intellij.openapi.ui.SimpleToolWindowPanel;
import icons.JsonAssistantIcons;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
/**
* @author Memory
@@ -22,13 +27,6 @@ public class ToggleUseSoftWrapsAction extends AbstractToggleUseSoftWrapsAction i
private final EditorEx editor;
private final SimpleToolWindowPanel simpleToolWindowPanel;
- /**
- * Creates new {@code AbstractToggleUseSoftWrapsAction} object.
- *
- * @param appliancePlace defines type of the place where soft wraps are applied
- * @param global indicates if soft wraps should be changed for the current editor only or for the all editors
- * used at the target appliance place
- */
public ToggleUseSoftWrapsAction(EditorEx editor, SimpleToolWindowPanel simpleToolWindowPanel) {
super(SoftWrapAppliancePlaces.MAIN_EDITOR, false);
this.editor = editor;
@@ -40,11 +38,35 @@ public ToggleUseSoftWrapsAction(EditorEx editor, SimpleToolWindowPanel simpleToo
presentation.setIcon(JsonAssistantIcons.ToolWindow.SOFT_WRAP);
}
+ @Override
+ public void setSelected(@NotNull AnActionEvent e, boolean state) {
+ super.setSelected(e, state);
+ // 存储状态
+ saveToPropertiesComponent(state);
+ }
+
@Override
public void update(@NotNull AnActionEvent e) {
- e.getPresentation().setEnabled(
- getEventProject(e) != null
- && StrUtil.isNotBlank(editor.getDocument().getText())
- && JsonAssistantToolWindowPanel.isEditorCardDisplayed(simpleToolWindowPanel));
+ boolean enabled = getEventProject(e) != null
+ && StrUtil.isNotBlank(editor.getDocument().getText())
+ && JsonAssistantToolWindowPanel.isEditorCardDisplayed(simpleToolWindowPanel);
+
+ final Presentation presentation = e.getPresentation();
+ if (enabled) {
+ boolean selected = isSelected(e);
+ Toggleable.setSelected(presentation, selected);
+ }
+
+ presentation.setEnabled(enabled);
+ }
+
+ @Override
+ protected @Nullable Editor getEditor(@NotNull AnActionEvent e) {
+ return editor;
+ }
+
+ private void saveToPropertiesComponent(boolean state) {
+ PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
+ propertiesComponent.setValue(PluginConstant.SOFT_WRAPS_SELECT_STATE, state + "");
}
}
diff --git a/src/main/java/cn/memoryzy/json/constant/PluginConstant.java b/src/main/java/cn/memoryzy/json/constant/PluginConstant.java
index 0a5c9cb..532e87d 100644
--- a/src/main/java/cn/memoryzy/json/constant/PluginConstant.java
+++ b/src/main/java/cn/memoryzy/json/constant/PluginConstant.java
@@ -23,6 +23,11 @@ public interface PluginConstant {
*/
String AUXILIARY_TREE_TOOLWINDOW_ID = "JsonAssistant.ToolWindow.AuxiliaryTree";
+ /**
+ * 选择的软换行状态 Key
+ */
+ String SOFT_WRAPS_SELECT_STATE = JsonAssistantPlugin.PLUGIN_ID_NAME + ".SOFT_WRAPS_SELECT_STATE";
+
/**
* Json 编辑器卡片名称
*/
diff --git a/src/main/java/cn/memoryzy/json/ui/JsonAssistantToolWindowComponentProvider.java b/src/main/java/cn/memoryzy/json/ui/JsonAssistantToolWindowComponentProvider.java
index edd6a00..a02052b 100644
--- a/src/main/java/cn/memoryzy/json/ui/JsonAssistantToolWindowComponentProvider.java
+++ b/src/main/java/cn/memoryzy/json/ui/JsonAssistantToolWindowComponentProvider.java
@@ -26,6 +26,7 @@
import cn.memoryzy.json.ui.panel.JsonAssistantToolWindowPanel;
import cn.memoryzy.json.util.UIManager;
import cn.memoryzy.json.util.*;
+import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionPlaces;
@@ -35,6 +36,7 @@
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.*;
+import com.intellij.openapi.editor.actions.AbstractToggleUseSoftWrapsAction;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.event.DocumentEvent;
@@ -196,6 +198,13 @@ private void changeEditorAppearance(EditorEx editor, boolean hasText) {
JComponent component = editor.getComponent();
component.setFont(UIManager.consolasFont(15));
component.setBorder(JBUI.Borders.customLine(editor.getBackgroundColor(), 0, 4, 0, 0));
+
+ // 切换软换行状态
+ PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
+ String value = propertiesComponent.getValue(PluginConstant.SOFT_WRAPS_SELECT_STATE);
+ if (null != value) {
+ AbstractToggleUseSoftWrapsAction.toggleSoftWraps(editor, null, Boolean.parseBoolean(value));
+ }
}
@@ -207,11 +216,11 @@ public JComponent createToolbar(SimpleToolWindowPanel simpleToolWindowPanel) {
actionGroup.add(new JsonStructureToolWindowAction(editor, simpleToolWindowPanel));
actionGroup.add(new JsonQueryAction(editor, simpleToolWindowPanel));
actionGroup.add(Separator.create());
- actionGroup.add(new SaveToDiskAction(editor, simpleToolWindowPanel));
- actionGroup.add(new ClearEditorAction(editor, simpleToolWindowPanel));
- actionGroup.add(Separator.create());
actionGroup.add(new ToggleUseSoftWrapsAction(editor, simpleToolWindowPanel));
actionGroup.add(new ScrollToTheEndAction(editor, simpleToolWindowPanel));
+ actionGroup.add(Separator.create());
+ actionGroup.add(new SaveToDiskAction(editor, simpleToolWindowPanel));
+ actionGroup.add(new ClearEditorAction(editor, simpleToolWindowPanel));
ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.TOOLBAR, actionGroup, false);
return toolbar.getComponent();
diff --git a/src/main/java/cn/memoryzy/json/ui/dialog/JsonToJavaBeanDialog.java b/src/main/java/cn/memoryzy/json/ui/dialog/JsonToJavaBeanDialog.java
index a27013b..a98caff 100644
--- a/src/main/java/cn/memoryzy/json/ui/dialog/JsonToJavaBeanDialog.java
+++ b/src/main/java/cn/memoryzy/json/ui/dialog/JsonToJavaBeanDialog.java
@@ -33,11 +33,14 @@
import com.intellij.psi.util.PsiUtil;
import com.intellij.ui.EditorTextField;
import com.intellij.ui.JBSplitter;
+import com.intellij.ui.TitledSeparator;
+import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.SwingHelper;
+import com.intellij.util.ui.components.BorderLayoutPanel;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -84,6 +87,23 @@ public JsonToJavaBeanDialog(@Nullable Project project, PsiDirectory directory, M
JPanel firstPanel = SwingHelper.newHorizontalPanel(Component.CENTER_ALIGNMENT, label, classNameTextField);
firstPanel.setBorder(JBUI.Borders.emptyLeft(4));
+ // TODO 添加注解、功能选项
+ TitledSeparator titledSeparator = new TitledSeparator("可选参数");
+ JBCheckBox fastJsonCb = new JBCheckBox("FastJson 注解");
+ JBCheckBox jacksonCb = new JBCheckBox("Jackson 注解");
+ JBCheckBox toCamelCb = new JBCheckBox("下划线转驼峰");
+
+ JPanel checkBoxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 13,5));
+ checkBoxPanel.add(fastJsonCb);
+ checkBoxPanel.add(jacksonCb);
+ checkBoxPanel.add(toCamelCb);
+
+ BorderLayoutPanel centerPanel = new BorderLayoutPanel().addToTop(titledSeparator).addToCenter(checkBoxPanel);
+ centerPanel.setBorder(JBUI.Borders.empty(10, 4, 10, 0));
+
+ BorderLayoutPanel borderLayoutPanel = new BorderLayoutPanel().addToTop(firstPanel).addToCenter(centerPanel);
+
+
jsonTextField = new CustomizedLanguageTextEditor(LanguageHolder.JSON5, project, "", true);
jsonTextField.setFont(UIManager.consolasFont(15));
jsonTextField.setPlaceholder(JsonAssistantBundle.messageOnSystem("dialog.deserialize.placeholder.text") + PluginConstant.JSON_EXAMPLE);
@@ -95,7 +115,7 @@ public JsonToJavaBeanDialog(@Nullable Project project, PsiDirectory directory, M
jsonErrorDecorator = new TextEditorErrorPopupDecorator(getRootPane(), jsonTextField);
JBSplitter splitter = new JBSplitter(true, 0.06f);
- splitter.setFirstComponent(firstPanel);
+ splitter.setFirstComponent(borderLayoutPanel);
splitter.setSecondComponent(jsonTextField);
splitter.setResizeEnabled(false);
diff --git a/src/main/java/cn/memoryzy/json/util/JsonUtil.java b/src/main/java/cn/memoryzy/json/util/JsonUtil.java
index a743e0d..ec3668c 100644
--- a/src/main/java/cn/memoryzy/json/util/JsonUtil.java
+++ b/src/main/java/cn/memoryzy/json/util/JsonUtil.java
@@ -156,6 +156,7 @@ public static String formatJson(Object data) {
.serializeSpecialFloatingPointValues()
.serializeNulls()
.setPrettyPrinting()
+ .disableHtmlEscaping()
.create()
.toJson(data);
} catch (Exception e) {
diff --git a/src/main/resources/JsonAssistantIconMappings.json b/src/main/resources/JsonAssistantIconMappings.json
index bc4b43b..1015798 100644
--- a/src/main/resources/JsonAssistantIconMappings.json
+++ b/src/main/resources/JsonAssistantIconMappings.json
@@ -22,7 +22,9 @@
"search.svg": "icons/toolwindow/search.svg",
"structure.svg": "icons/toolwindow/structure.svg",
"delete.svg": "icons/toolwindow/delete.svg",
- "magic.svg": "icons/toolwindow/magic.svg"
+ "magic.svg": "icons/toolwindow/magic.svg",
+ "scrollDown.svg": "icons/toolwindow/scrollDown.svg",
+ "softWrap.svg": "icons/toolwindow/softWrap.svg"
}
}
}
diff --git a/src/main/resources/icons/expui/toolwindow/scrollDown.svg b/src/main/resources/icons/expui/toolwindow/scrollDown.svg
new file mode 100644
index 0000000..f72f532
--- /dev/null
+++ b/src/main/resources/icons/expui/toolwindow/scrollDown.svg
@@ -0,0 +1,16 @@
+
diff --git a/src/main/resources/icons/expui/toolwindow/scrollDown_dark.svg b/src/main/resources/icons/expui/toolwindow/scrollDown_dark.svg
new file mode 100644
index 0000000..b3930b8
--- /dev/null
+++ b/src/main/resources/icons/expui/toolwindow/scrollDown_dark.svg
@@ -0,0 +1,16 @@
+
diff --git a/src/main/resources/icons/expui/toolwindow/softWrap.svg b/src/main/resources/icons/expui/toolwindow/softWrap.svg
new file mode 100644
index 0000000..b9c3f14
--- /dev/null
+++ b/src/main/resources/icons/expui/toolwindow/softWrap.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/main/resources/icons/expui/toolwindow/softWrap_dark.svg b/src/main/resources/icons/expui/toolwindow/softWrap_dark.svg
new file mode 100644
index 0000000..1c1cd16
--- /dev/null
+++ b/src/main/resources/icons/expui/toolwindow/softWrap_dark.svg
@@ -0,0 +1,14 @@
+
diff --git a/src/main/resources/icons/toolwindow/scrollDown.svg b/src/main/resources/icons/toolwindow/scrollDown.svg
index 52a16b4..c3150b8 100644
--- a/src/main/resources/icons/toolwindow/scrollDown.svg
+++ b/src/main/resources/icons/toolwindow/scrollDown.svg
@@ -8,9 +8,9 @@
-
-
-
-
+
+
+
+
diff --git a/src/main/resources/icons/toolwindow/scrollDown_dark.svg b/src/main/resources/icons/toolwindow/scrollDown_dark.svg
new file mode 100644
index 0000000..17583f2
--- /dev/null
+++ b/src/main/resources/icons/toolwindow/scrollDown_dark.svg
@@ -0,0 +1,16 @@
+
diff --git a/src/main/resources/icons/toolwindow/softWrap.svg b/src/main/resources/icons/toolwindow/softWrap.svg
index b7d9924..8966046 100644
--- a/src/main/resources/icons/toolwindow/softWrap.svg
+++ b/src/main/resources/icons/toolwindow/softWrap.svg
@@ -1,14 +1,14 @@
-