in idea-plugin/src/main/java/org/jetbrains/bunches/idea/actions/SwitchAction.kt [16:76]
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
val basePath = project.basePath
if (basePath == null) {
Messages.showMessageDialog("BasePath not found", "Switch error", Messages.getErrorIcon())
return
}
val extensions = BunchFileUtils.bunchExtensions(project)
if (extensions == null) {
Messages.showMessageDialog("Can't find list of supported bunches", "Switch error", Messages.getErrorIcon())
return
}
val vcsRoots = BunchFileUtils.getGitRoots(project).mapNotNull { it.path }
if (vcsRoots.isEmpty()) {
Messages.showMessageDialog("No git root for project found", "Switch error", Messages.getErrorIcon())
return
}
val dialog = SwitchDialogKt(project, extensions, vcsRoots.map { it.path })
if (!dialog.showAndGet()) {
return
}
val bunchPath = BunchFileUtils.bunchPath(project)
if (bunchPath == null) {
return
}
val switchSettings = dialog.getParameters()
val settings = Settings(
switchSettings.repoPath,
bunchPath,
switchSettings.branch,
switchSettings.commitMessage,
switchSettings.stepByStep,
switchSettings.doCleanup
)
ProgressManager.getInstance().run(
object : Task.Backgroundable(project, "Bunch Switch", false) {
override fun run(indicator: ProgressIndicator) {
doSwitch(settings)
}
override fun onThrowable(error: Throwable) {
Messages.showErrorDialog(project, error.message, "Switch error")
Notification(
"Bunch tool",
"Switch error",
error.message ?: "Switch fail",
NotificationType.ERROR
).notify(project)
}
override fun onSuccess() {
BunchFileUtils.updateGitLog(project)
}
}
)
}