-
Notifications
You must be signed in to change notification settings - Fork 56
Context menus added #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,22 @@ | |
<keyboard-shortcut first-keystroke="ctrl ENTER" | ||
keymap="$default"/> | ||
</action> | ||
<action id="GraphDatabaseActionGroup.ExplainQuery" | ||
class="com.neueda.jetbrains.plugin.graphdb.jetbrains.actions.execute.ExplainQueryAction" | ||
text="Explain query" | ||
icon="/general/run.png" | ||
description="Explain query"> | ||
<keyboard-shortcut first-keystroke="ctrl ENTER" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove shortcut |
||
keymap="$default"/> | ||
</action> | ||
<action id="GraphDatabaseActionGroup.ProfileQuery" | ||
class="com.neueda.jetbrains.plugin.graphdb.jetbrains.actions.execute.ProfileQueryAction" | ||
text="Profile query" | ||
icon="/general/run.png" | ||
description="Profile query"> | ||
<keyboard-shortcut first-keystroke="ctrl ENTER" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove shortcut. |
||
keymap="$default"/> | ||
</action> | ||
<add-to-group group-id="EditorPopupMenu"/> | ||
</group> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,16 +68,15 @@ public void actionPerformed(AnActionEvent e) { | |
|
||
Caret caret = editor.getCaretModel().getPrimaryCaret(); | ||
|
||
String content = null; | ||
PsiElement cypherStatement = null; | ||
String query = null; | ||
Map<String, Object> parameters = Collections.emptyMap(); | ||
if (caret.hasSelection()) { | ||
content = caret.getSelectedText(); | ||
query = caret.getSelectedText(); | ||
} else if (psiFile != null) { | ||
if (psiFile.getLanguage().getID().equals(GraphLanguages.CYPHER)) { | ||
cypherStatement = getCypherStatement(psiFile, caret); | ||
PsiElement cypherStatement = getCypherStatement(psiFile, caret); | ||
if (cypherStatement != null) { | ||
content = cypherStatement.getText(); | ||
query = cypherStatement.getText(); | ||
try { // support parameters for PsiElement only | ||
ParametersService service = ServiceManager.getService(project, ParametersService.class); | ||
parameters = service.getParameters(cypherStatement); | ||
|
@@ -89,14 +88,16 @@ public void actionPerformed(AnActionEvent e) { | |
} | ||
} | ||
|
||
Analytics.event("query-content", caret.hasSelection() ? "contentFromSelect" : "contentFromCaret"); | ||
Analytics.event("query-query", caret.hasSelection() ? "contentFromSelect" : "contentFromCaret"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert to "query-content" |
||
|
||
if (content == null) { | ||
if (query == null) { | ||
Notifier.error("Query execution error", "No query selected"); | ||
return; | ||
} | ||
|
||
ExecuteQueryPayload executeQueryPayload = new ExecuteQueryPayload(content, parameters, editor); | ||
query = decorateQuery(query); | ||
|
||
ExecuteQueryPayload executeQueryPayload = new ExecuteQueryPayload(query, parameters, editor); | ||
ConsoleToolWindow.ensureOpen(project); | ||
|
||
if (virtualFile != null) { | ||
|
@@ -132,6 +133,10 @@ public void executeQuery(MessageBus messageBus, DataSourceApi dataSource, Execut | |
executeQueryEvent.executeQuery(dataSource, payload); | ||
} | ||
|
||
protected String decorateQuery(String query) { | ||
return query; | ||
} | ||
|
||
private PsiElement getCypherStatement(PsiFile psiFile, Caret caret) { | ||
return PsiTraversalUtilities.Cypher.getCypherStatementAtOffset(psiFile, caret.getOffset()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.neueda.jetbrains.plugin.graphdb.jetbrains.actions.execute; | ||
|
||
public class ExplainQueryAction extends ExecuteQueryAction { | ||
|
||
@Override | ||
protected String decorateQuery(String query) { | ||
return "EXPLAIN " + super.decorateQuery(query); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.neueda.jetbrains.plugin.graphdb.jetbrains.actions.execute; | ||
|
||
public class ProfileQueryAction extends ExecuteQueryAction { | ||
|
||
@Override | ||
protected String decorateQuery(String query) { | ||
return "PROFILE " + super.decorateQuery(query); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.actions; | ||
|
||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.neueda.jetbrains.plugin.graphdb.database.neo4j.bolt.Neo4jBoltConfiguration; | ||
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.state.DataSourceApi; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public class DataSourceOpenBrowserAction extends AnAction { | ||
|
||
private DataSourceApi dataSource; | ||
|
||
DataSourceOpenBrowserAction(String title, String description, Icon icon, DataSourceApi dataSource) { | ||
super(title, description, icon); | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@Override | ||
public void actionPerformed(AnActionEvent e) { | ||
try { | ||
String host = dataSource.getConfiguration().get(Neo4jBoltConfiguration.HOST); | ||
openWebpage(new URI("http://" + host + ":7474")); | ||
} catch (IOException | URISyntaxException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
private void openWebpage(URI uri) throws IOException { | ||
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; | ||
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { | ||
desktop.browse(uri); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.actions; | ||
|
||
import javax.swing.*; | ||
|
||
public class MetadataLabelFromAction extends MetadataAction { | ||
|
||
private static final String QUERY = "MATCH (n:%s)-[r]->() RETURN type(r),r LIMIT 25"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after "," |
||
|
||
MetadataLabelFromAction(String data, String dataSourceUuid, String title, String description, Icon icon) { | ||
super(data, dataSourceUuid, title, description, icon); | ||
} | ||
|
||
@Override | ||
protected String getQuery(String data) { | ||
return String.format(QUERY, data); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.actions; | ||
|
||
import javax.swing.*; | ||
|
||
public class MetadataLabelToAction extends MetadataAction { | ||
|
||
private static final String QUERY = "MATCH (n:%s)<-[r]-() RETURN TYPE(r),r LIMIT 25"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lowercase "type", space after "," |
||
|
||
MetadataLabelToAction(String data, String dataSourceUuid, String title, String description, Icon icon) { | ||
super(data, dataSourceUuid, title, description, icon); | ||
} | ||
|
||
@Override | ||
protected String getQuery(String data) { | ||
return String.format(QUERY, data); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any other icons that are more suitable here?