override fun actionPerformed()

in idea-plugin/src/main/java/org/jetbrains/bunches/idea/actions/CleanupAction.kt [18:75]


    override fun actionPerformed(e: AnActionEvent) {
        val project = e.project ?: return

        val basePath = project.basePath
        if (basePath == null) {
            Messages.showMessageDialog("BasePath not found", "Cleanup error", Messages.getErrorIcon())
            return
        }
        val extensions = BunchFileUtils.bunchExtensions(project, true)
        if (extensions == null) {
            Messages.showMessageDialog("Can't find list of supported bunches", "Cleanup error", Messages.getErrorIcon())
            return
        }
        val dialog = CleanupDialogKt(project, extensions)
        if (!dialog.showAndGet()) {
            return
        }

        val repoPath = vcsRootPath(project)
        if (repoPath == null) {
            return
        }

        val bunchPath = bunchPath(project)
        if (bunchPath == null) {
            return
        }

        val cleanupSettings = dialog.getParameters()
        val settings = Settings(
            repoPath,
            bunchPath,
            cleanupSettings.extension,
            cleanupSettings.commitTitle,
            cleanupSettings.isNoCommit
        )

        ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Bunch Cleanup", false) {
            override fun run(indicator: ProgressIndicator) {
                cleanup(settings)
            }

            override fun onThrowable(error: Throwable) {
                Notification(
                    "Bunch tool",
                    "Cleanup error",
                    error.message ?: "Cleanup fail",
                    NotificationType.ERROR
                ).notify(project)
            }

            override fun onSuccess() {
                if (!settings.isNoCommit) {
                    BunchFileUtils.updateGitLog(project)
                }
            }
        })
    }