forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAEL-1990: IntelliJ plugin example (eugenp#4942)
* Initial revision * Add actions and plugin config * Add language tag to search action * Cleanup before submitting
- Loading branch information
1 parent
62fa3aa
commit 387f9e7
Showing
50 changed files
with
134 additions
and
548 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
intelliJ/stackoverflow-plugin/resources/META-INF/plugin.xml
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,62 @@ | ||
<idea-plugin> | ||
<id>com.baeldung.intellij.stackoverflowplugin</id> | ||
<name>Stack Overflow Plugin for IntelliJ</name> | ||
<version>1.0</version> | ||
<vendor email="[email protected]" url="http://www.baeldung.com">Baeldung</vendor> | ||
|
||
<description><![CDATA[ | ||
Plugin to help search Stack Overflow from inside IntelliJ | ||
]]></description> | ||
|
||
<change-notes><![CDATA[ | ||
<ul> | ||
<li>1.0 - Initial release</li> | ||
</ul> | ||
]]> | ||
</change-notes> | ||
|
||
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description --> | ||
<idea-version since-build="173.0"/> | ||
|
||
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html | ||
on how to target different products --> | ||
<!-- uncomment to enable plugin in all products | ||
<depends>com.intellij.modules.lang</depends> | ||
--> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<!-- Add your extensions here --> | ||
</extensions> | ||
|
||
<actions> | ||
|
||
<!-- Add Ask question action to Tools Menu --> | ||
<action id="StackOverflow.AskQuestion.ToolsMenu" | ||
class="com.baeldung.intellij.stackoverflowplugin.AskQuestionAction" | ||
text="Ask Question on Stack Overflow" | ||
icon="so-icon-16x16.png" | ||
description="Ask a Question on Stack Overflow"> | ||
<add-to-group group-id="ToolsMenu" anchor="last"/> | ||
</action> | ||
|
||
<!-- Add action to search Stack Overflow from file editor --> | ||
<action id="StackOverflow.Search.Editor" | ||
class="com.baeldung.intellij.stackoverflowplugin.SearchAction" | ||
text="Search on Stack Overflow" | ||
icon="so-icon-16x16.png" | ||
description="Search on Stack Overflow"> | ||
<add-to-group group-id="EditorPopupMenu" anchor="last"/> | ||
</action> | ||
|
||
<!-- Add action to search Stack Overflow from console editor --> | ||
<action id="StackOverflow.Search.Console" | ||
class="com.baeldung.intellij.stackoverflowplugin.SearchAction" | ||
text="Search on Stack Overflow" | ||
icon="so-icon-16x16.png" | ||
description="Search on Stack Overflow"> | ||
<add-to-group group-id="ConsoleEditorPopupMenu" anchor="last"/> | ||
</action> | ||
|
||
</actions> | ||
|
||
</idea-plugin> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions
14
...stackoverflow-plugin/src/com/baeldung/intellij/stackoverflowplugin/AskQuestionAction.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,14 @@ | ||
package com.baeldung.intellij.stackoverflowplugin; | ||
|
||
import com.intellij.ide.BrowserUtil; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
|
||
public class AskQuestionAction extends AnAction | ||
{ | ||
@Override | ||
public void actionPerformed(AnActionEvent e) | ||
{ | ||
BrowserUtil.browse("https://stackoverflow.com/questions/ask"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...lliJ/stackoverflow-plugin/src/com/baeldung/intellij/stackoverflowplugin/SearchAction.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,58 @@ | ||
package com.baeldung.intellij.stackoverflowplugin; | ||
|
||
import com.intellij.ide.BrowserUtil; | ||
import com.intellij.lang.Language; | ||
import com.intellij.openapi.actionSystem.ActionManager; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.editor.CaretModel; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.psi.PsiFile; | ||
|
||
public class SearchAction extends AnAction | ||
{ | ||
/** | ||
* Convert selected text to a URL friendly string. | ||
* @param e | ||
*/ | ||
@Override | ||
public void actionPerformed(AnActionEvent e) | ||
{ | ||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); | ||
CaretModel caretModel = editor.getCaretModel(); | ||
|
||
// For searches from the editor, we should also get file type information | ||
// to help add scope to the search using the Stack overflow search syntax. | ||
// | ||
// https://stackoverflow.com/help/searching | ||
|
||
String languageTag = ""; | ||
PsiFile file = e.getData(CommonDataKeys.PSI_FILE); | ||
if(file != null) | ||
{ | ||
Language lang = e.getData(CommonDataKeys.PSI_FILE).getLanguage(); | ||
languageTag = "+[" + lang.getDisplayName().toLowerCase() + "]"; | ||
} | ||
|
||
// The update method below is only called periodically so need | ||
// to be careful to check for selected text | ||
if(caretModel.getCurrentCaret().hasSelection()) | ||
{ | ||
String query = caretModel.getCurrentCaret().getSelectedText().replace(' ', '+') + languageTag; | ||
BrowserUtil.browse("https://stackoverflow.com/search?q=" + query); | ||
} | ||
} | ||
|
||
/** | ||
* Only make this action visible when text is selected. | ||
* @param e | ||
*/ | ||
@Override | ||
public void update(AnActionEvent e) | ||
{ | ||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); | ||
CaretModel caretModel = editor.getCaretModel(); | ||
e.getPresentation().setEnabledAndVisible(caretModel.getCurrentCaret().hasSelection()); | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
out/production/generated-sources8/src.main.resources.reladomo.ReladomoClassList.xml.log
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
76 changes: 0 additions & 76 deletions
76
out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/README.txt
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...80/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/src/main/webapp/WEB-INF/web.xml
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
.../main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/src/main/webapp/index.jsp
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.