Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Created February 10, 2013 00:03
Show Gist options
  • Save dkandalov/4747666 to your computer and use it in GitHub Desktop.
Save dkandalov/4747666 to your computer and use it in GitHub Desktop.
wrapper for Vcs.ShowHistoryForBlock
import com.intellij.execution.ExecutionManager
import com.intellij.execution.Executor
import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.execution.filters.TextConsoleBuilderFactory
import com.intellij.execution.ui.ConsoleView
import com.intellij.execution.ui.ConsoleViewContentType
import com.intellij.execution.ui.ExecutionConsole
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.execution.ui.actions.CloseAction
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.actions.VcsContextFactory
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod
import com.intellij.unscramble.UnscrambleDialog
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable
import javax.swing.Icon
import javax.swing.JComponent
import javax.swing.JPanel
import java.awt.BorderLayout
import static intellijeval.PluginUtil.*
import com.intellij.openapi.editor.Document
import com.intellij.psi.PsiFileSystemItem
def <T> T findParent(PsiElement element, Closure<T> matches) {
if (element == null) null
else if (matches(element)) element
else findParent(element.parent, matches)
}
registerAction("ContextHistory", "alt shift H") { AnActionEvent event ->
def editor = currentEditorIn(event.project)
if (editor == null) return
def psiElement = currentPsiFileIn(event.project)?.findElementAt(editor.caretModel.offset)
PsiMethod psiMethod = findParent(psiElement, {it instanceof PsiMethod})
if (psiMethod == null) return
def prevOffset = editor.caretModel.offset
editor.caretModel.moveToOffset(psiMethod.textOffset)
def context = ServiceManager.getService(VcsContextFactory.class).createContextOn(event)
def action = ActionManager.instance.getAction("Vcs.ShowHistoryForBlock")
action.actionPerformed(context)
editor.caretModel.moveToOffset(prevOffset)
}
show("registered")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment