From 24ebc46090f86d5cb667738397b5117089d5f2ff Mon Sep 17 00:00:00 2001 From: Denis Rosa Date: Sun, 19 May 2024 13:52:25 +0200 Subject: [PATCH] adding shortcut for the workbench --- .../searchworkbench/CBSJsonKeyInspection.java | 3 +- .../intellij/tree/TreeRightClickListener.java | 2 +- .../intellij/tree/TreeToolBarBuilder.java | 39 +++++++++++++++++++ .../assets/icons/search_workbench.svg | 7 ++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/assets/icons/search_workbench.svg diff --git a/src/main/java/com/couchbase/intellij/searchworkbench/CBSJsonKeyInspection.java b/src/main/java/com/couchbase/intellij/searchworkbench/CBSJsonKeyInspection.java index f1f3d711..b183962b 100644 --- a/src/main/java/com/couchbase/intellij/searchworkbench/CBSJsonKeyInspection.java +++ b/src/main/java/com/couchbase/intellij/searchworkbench/CBSJsonKeyInspection.java @@ -38,8 +38,9 @@ public class CBSJsonKeyInspection extends LocalInspectionTool { return new JsonInspectionVisitor(holder); } - return null; + return new JsonElementVisitor(); } + private static class JsonInspectionVisitor extends JsonElementVisitor { diff --git a/src/main/java/com/couchbase/intellij/tree/TreeRightClickListener.java b/src/main/java/com/couchbase/intellij/tree/TreeRightClickListener.java index c2fb4e4e..8f975ba9 100644 --- a/src/main/java/com/couchbase/intellij/tree/TreeRightClickListener.java +++ b/src/main/java/com/couchbase/intellij/tree/TreeRightClickListener.java @@ -63,7 +63,7 @@ public class TreeRightClickListener { - private static int searchWorkbenchCounter = 0; + public static int searchWorkbenchCounter = 0; public static void handle(Tree tree, Project project, JPanel toolbarPanel, MouseEvent e, DefaultMutableTreeNode clickedNode) { Object userObject = clickedNode.getUserObject(); diff --git a/src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java b/src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java index 6a117a71..ce77a77f 100644 --- a/src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java +++ b/src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java @@ -64,6 +64,44 @@ public void update(AnActionEvent e) { newWorkbench.getTemplatePresentation().setIcon(IconLoader.getIcon("/assets/icons/new_query.svg", CouchbaseWindowContent.class)); + + AnAction newSearchWorkbench = new AnAction("New Search Workbench") { + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + ApplicationManager.getApplication().runWriteAction(() -> { + try { + Project project = e.getProject(); + TreeRightClickListener.searchWorkbenchCounter++; + String fileName = "search" + TreeRightClickListener.searchWorkbenchCounter + ".cbs.json"; + String fileContent = """ + { + "query": { + "query": "your_query_here" + }, + "fields": ["*"] + } + """; + VirtualFile virtualFile = new LightVirtualFile(fileName, FileTypeManager.getInstance().getFileTypeByExtension("cbs.json"), fileContent); + FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); + fileEditorManager.openFile(virtualFile, true); + } catch (Exception ex) { + Log.error(ex); + ex.printStackTrace(); + } + }); + } + + @Override + public void update(AnActionEvent e) { + boolean shouldEnable = ActiveCluster.getInstance().hasSearchService(); + e.getPresentation().setEnabled(shouldEnable); + e.getPresentation().setVisible(shouldEnable); + } + }; + + newSearchWorkbench.getTemplatePresentation().setIcon(IconLoader.getIcon("/assets/icons/search_workbench.svg", CouchbaseWindowContent.class)); + + AnAction addConnectionAction = new AnAction("Add New Connection") { @Override public void actionPerformed(@NotNull AnActionEvent e) { @@ -139,6 +177,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { leftActionGroup.addSeparator(); leftActionGroup.add(newWorkbench); + leftActionGroup.add(newSearchWorkbench); leftActionGroup.addSeparator(); diff --git a/src/main/resources/assets/icons/search_workbench.svg b/src/main/resources/assets/icons/search_workbench.svg new file mode 100644 index 00000000..75aee469 --- /dev/null +++ b/src/main/resources/assets/icons/search_workbench.svg @@ -0,0 +1,7 @@ + + + window with lupe + + +