Last active
August 29, 2015 13:56
-
-
Save dkandalov/8840509 to your computer and use it in GitHub Desktop.
Example of listening to VCS updates in IntelliJ (this is mini-plugin for https://github.com/dkandalov/live-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.openapi.module.ModuleManager | |
import com.intellij.openapi.util.Pair | |
import com.intellij.openapi.vcs.ProjectLevelVcsManager | |
import com.intellij.openapi.vcs.VcsKey | |
import com.intellij.openapi.vcs.update.UpdateEnvironment | |
import com.intellij.openapi.vcs.update.UpdatedFilesListener | |
import com.intellij.openapi.vcs.update.UpdatedFilesReverseSide | |
import com.intellij.util.Consumer | |
import com.intellij.util.messages.MessageBusConnection | |
import static liveplugin.PluginUtil.* | |
if (isIdeStartup) return | |
changeGlobalVar("BusVcsUpdateListener"){ MessageBusConnection connection -> | |
if (connection != null) { | |
connection.disconnect() | |
} | |
connection = project.messageBus.connect() | |
connection.subscribe(UpdatedFilesListener.UPDATED_FILES, new UpdatedFilesListener() { | |
@Override void consume(Set<String> files) { | |
show("On bus VCS update: ${files.join(",")}") | |
} | |
}) | |
connection | |
} | |
def listenerManager = ProjectLevelVcsManager.getInstance(project).vcsEventsListenerManager | |
changeGlobalVar("BadVcsUpdateListener"){ key -> | |
if (key != null) listenerManager.removeUpdate(key) | |
key = listenerManager.addUpdate(new Consumer<Pair<VcsKey, Consumer<UpdateEnvironment>>>() { | |
@Override void consume(Pair<VcsKey, Consumer<UpdateEnvironment>> pair) { | |
// for some reason it's called twice on pressing "update project" shortcut | |
// and twice on actual update from VCS | |
show("On listener VCS update: " + pair.first + " " + pair.second) | |
} | |
}) | |
key | |
} | |
show("Listening to VCS updates") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment