Last active
September 2, 2021 11:46
-
-
Save dkandalov/277800d12ecbfc533fcd to your computer and use it in GitHub Desktop.
Prototype of google popup search mini-plugin
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
import com.intellij.ide.BrowserUtil | |
import com.intellij.openapi.actionSystem.AnActionEvent | |
import com.intellij.openapi.progress.ProgressIndicator | |
import groovy.json.JsonSlurper | |
import static liveplugin.PluginUtil.registerAction | |
import static liveplugin.PluginUtil.show | |
import static liveplugin.PluginUtil.showPopupSearch | |
registerAction("GoogleSearchAction", "ctrl alt shift G") { AnActionEvent event -> | |
def itemProvider = { String pattern, ProgressIndicator indicator -> | |
googleSuggestionsFor(pattern) | |
} | |
showPopupSearch("Google quick search", event.project, itemProvider) { String item -> | |
BrowserUtil.open("http://www.google.com/search?q=${item}") | |
} | |
} | |
List<String> googleSuggestionsFor(String text) { | |
text = URLEncoder.encode(text, "UTF-8") | |
def json = "http://suggestqueries.google.com/complete/search?client=firefox&q=$text".toURL().text | |
new JsonSlurper().parseText(json)[1].toList() | |
} | |
if (!isIdeStartup) show("Loaded GoogleSearchAction<br/>Use ctrl+alt+shift+G to run it") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment