-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
590 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/cn/memoryzy/json/action/query/JmesPathToggleAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cn.memoryzy.json.action.query; | ||
|
||
import cn.memoryzy.json.bundle.JsonAssistantBundle; | ||
import cn.memoryzy.json.enums.JsonQuerySchema; | ||
import cn.memoryzy.json.service.persistent.state.QueryState; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.Presentation; | ||
import com.intellij.openapi.project.DumbAwareToggleAction; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author Memory | ||
* @since 2024/12/27 | ||
*/ | ||
public class JmesPathToggleAction extends DumbAwareToggleAction { | ||
|
||
private final QueryState queryState; | ||
|
||
public JmesPathToggleAction(QueryState queryState) { | ||
super(); | ||
this.queryState = queryState; | ||
setEnabledInModalContext(true); | ||
Presentation presentation = getTemplatePresentation(); | ||
presentation.setText(JsonAssistantBundle.messageOnSystem("action.toggle.jmes.text")); | ||
presentation.setDescription(JsonAssistantBundle.messageOnSystem("action.toggle.jmes.description")); | ||
} | ||
|
||
@Override | ||
public boolean isSelected(@NotNull AnActionEvent e) { | ||
return queryState.querySchema == JsonQuerySchema.JMESPath; | ||
} | ||
|
||
@Override | ||
public void setSelected(@NotNull AnActionEvent e, boolean state) { | ||
// 限制单选 | ||
queryState.querySchema = state ? JsonQuerySchema.JMESPath : JsonQuerySchema.JSONPath; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/cn/memoryzy/json/action/query/JsonPathToggleAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cn.memoryzy.json.action.query; | ||
|
||
import cn.memoryzy.json.bundle.JsonAssistantBundle; | ||
import cn.memoryzy.json.enums.JsonQuerySchema; | ||
import cn.memoryzy.json.service.persistent.state.QueryState; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.Presentation; | ||
import com.intellij.openapi.project.DumbAwareToggleAction; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author Memory | ||
* @since 2024/12/27 | ||
*/ | ||
public class JsonPathToggleAction extends DumbAwareToggleAction { | ||
|
||
private final QueryState queryState; | ||
|
||
public JsonPathToggleAction(QueryState queryState) { | ||
super(); | ||
this.queryState = queryState; | ||
setEnabledInModalContext(true); | ||
Presentation presentation = getTemplatePresentation(); | ||
presentation.setText(JsonAssistantBundle.messageOnSystem("action.toggle.jsonpath.text")); | ||
presentation.setDescription(JsonAssistantBundle.messageOnSystem("action.toggle.jsonpath.description")); | ||
} | ||
|
||
@Override | ||
public boolean isSelected(@NotNull AnActionEvent e) { | ||
return queryState.querySchema == JsonQuerySchema.JSONPath; | ||
} | ||
|
||
@Override | ||
public void setSelected(@NotNull AnActionEvent e, boolean state) { | ||
// 限制单选 | ||
queryState.querySchema = state ? JsonQuerySchema.JSONPath : JsonQuerySchema.JMESPath; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/cn/memoryzy/json/action/query/ShowOriginalTextAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cn.memoryzy.json.action.query; | ||
|
||
import cn.memoryzy.json.bundle.JsonAssistantBundle; | ||
import cn.memoryzy.json.service.persistent.state.QueryState; | ||
import cn.memoryzy.json.ui.JsonQueryComponentProvider; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.Presentation; | ||
import com.intellij.openapi.project.DumbAwareToggleAction; | ||
import com.intellij.util.ui.components.BorderLayoutPanel; | ||
import icons.JsonAssistantIcons; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author Memory | ||
* @since 2024/12/27 | ||
*/ | ||
public class ShowOriginalTextAction extends DumbAwareToggleAction { | ||
|
||
private final QueryState queryState; | ||
private final JsonQueryComponentProvider queryComponentProvider; | ||
|
||
public ShowOriginalTextAction(QueryState queryState, JsonQueryComponentProvider queryComponentProvider) { | ||
super(); | ||
this.queryState = queryState; | ||
this.queryComponentProvider = queryComponentProvider; | ||
setEnabledInModalContext(true); | ||
Presentation presentation = getTemplatePresentation(); | ||
presentation.setText(JsonAssistantBundle.messageOnSystem("action.show.original.text.text")); | ||
presentation.setDescription(JsonAssistantBundle.messageOnSystem("action.show.original.text.description")); | ||
presentation.setIcon(JsonAssistantIcons.ToolWindow.TEXT); | ||
} | ||
|
||
|
||
@Override | ||
public boolean isSelected(@NotNull AnActionEvent e) { | ||
return queryState.showOriginalText; | ||
} | ||
|
||
@Override | ||
public void setSelected(@NotNull AnActionEvent e, boolean state) { | ||
queryState.showOriginalText = state; | ||
BorderLayoutPanel docPanel = queryComponentProvider.getDocPanel(); | ||
if (state) { | ||
// 展示 | ||
if (!docPanel.isVisible()) { | ||
docPanel.setVisible(true); | ||
} | ||
|
||
} else { | ||
// 关闭 | ||
if (docPanel.isVisible()) { | ||
docPanel.setVisible(false); | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/cn/memoryzy/json/action/query/SwitchAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cn.memoryzy.json.action.query; | ||
|
||
import cn.memoryzy.json.bundle.JsonAssistantBundle; | ||
import cn.memoryzy.json.service.persistent.state.QueryState; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.Presentation; | ||
import com.intellij.openapi.project.DumbAwareAction; | ||
import com.intellij.openapi.ui.popup.JBPopupFactory; | ||
import com.intellij.tools.SimpleActionGroup; | ||
import icons.JsonAssistantIcons; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* @author Memory | ||
* @since 2024/12/27 | ||
*/ | ||
public class SwitchAction extends DumbAwareAction { | ||
|
||
private final QueryState queryState; | ||
|
||
public SwitchAction(QueryState queryState) { | ||
super(); | ||
this.queryState = queryState; | ||
setEnabledInModalContext(true); | ||
Presentation presentation = getTemplatePresentation(); | ||
presentation.setText(JsonAssistantBundle.messageOnSystem("action.switch.ql.text")); | ||
presentation.setDescription(JsonAssistantBundle.messageOnSystem("action.switch.ql.description")); | ||
presentation.setIcon(JsonAssistantIcons.ToolWindow.SWITCH); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
SimpleActionGroup actionGroup = new SimpleActionGroup(); | ||
actionGroup.add(new JsonPathToggleAction(queryState)); | ||
actionGroup.add(new JmesPathToggleAction(queryState)); | ||
|
||
JBPopupFactory.getInstance() | ||
.createActionGroupPopup(null, actionGroup, e.getDataContext(), JBPopupFactory.ActionSelectionAid.MNEMONICS, true) | ||
.showUnderneathOf((Component) e.getInputEvent().getSource()); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.