This commit is contained in:
Jonathan Cook
2019-10-23 15:01:44 +02:00
parent db85c8f275
commit 684ec0d2e3
20486 changed files with 1642483 additions and 0 deletions
@@ -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="eugene@baeldung.com" 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>
Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

@@ -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");
}
}
@@ -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());
}
}