Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Last active September 2, 2021 11:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkandalov/277800d12ecbfc533fcd to your computer and use it in GitHub Desktop.
Save dkandalov/277800d12ecbfc533fcd to your computer and use it in GitHub Desktop.
Prototype of google popup search mini-plugin
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