Skip to content

Commit

Permalink
adding shortcut for the workbench
Browse files Browse the repository at this point in the history
  • Loading branch information
deniswsrosa committed May 19, 2024
1 parent 7407a75 commit 24ebc46
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public class CBSJsonKeyInspection extends LocalInspectionTool {
return new JsonInspectionVisitor(holder);
}

return null;
return new JsonElementVisitor();
}


private static class JsonInspectionVisitor extends JsonElementVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/couchbase/intellij/tree/TreeToolBarBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -139,6 +177,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
leftActionGroup.addSeparator();

leftActionGroup.add(newWorkbench);
leftActionGroup.add(newSearchWorkbench);
leftActionGroup.addSeparator();


Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/icons/search_workbench.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 24ebc46

Please sign in to comment.