Skip to content

Commit

Permalink
BAEL-1990: IntelliJ plugin example (eugenp#4942)
Browse files Browse the repository at this point in the history
* Initial revision

* Add actions and plugin config

* Add language tag to search action

* Cleanup before submitting
  • Loading branch information
michael-pratt authored and jzheaux committed Aug 22, 2018
1 parent 62fa3aa commit 387f9e7
Show file tree
Hide file tree
Showing 50 changed files with 134 additions and 548 deletions.
62 changes: 62 additions & 0 deletions intelliJ/stackoverflow-plugin/resources/META-INF/plugin.xml
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.
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");
}
}
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());
}
}

This file was deleted.

20 changes: 0 additions & 20 deletions out/production/introduction/views/index.scala.html

This file was deleted.

23 changes: 0 additions & 23 deletions out/production/introduction/views/main.scala.html

This file was deleted.

13 changes: 0 additions & 13 deletions out/production/main122/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions out/production/main151/com/baeldung/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions out/production/main151/com/baeldung/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions out/production/main155/com/baeldung/git/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions out/production/main173/log4j.properties

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 387f9e7

Please sign in to comment.