// Path: src/main/java/gitflow/ui/GitflowStartBugfixDialog.java
// public class GitflowStartBugfixDialog extends AbstractBranchStartDialog {
// 
//     public GitflowStartBugfixDialog(Project project, GitRepository repo) {
//         super(project, repo);
//     }
// 
//     @Override
//     protected String getLabel() {
//         return "bugfix";
//     }
// 
//     @Override
//     protected String getDefaultBranch() {
//         return GitflowConfigUtil.getInstance(getProject(), myRepo).developBranch;
//     }
// }
// 
// Path: src/main/java/gitflow/ui/NotifyUtil.java
// public class NotifyUtil
// {
//     private static final NotificationGroup TOOLWINDOW_NOTIFICATION = NotificationGroup.toolWindowGroup(
//             "Gitflow Errors", ToolWindowId.VCS, true);
//     private static final NotificationGroup STICKY_NOTIFICATION = new NotificationGroup(
//             "Gitflow Errors", NotificationDisplayType.STICKY_BALLOON, true);
//     private static final NotificationGroup BALLOON_NOTIFICATION = new NotificationGroup(
//             "Gitflow Notifications", NotificationDisplayType.BALLOON, true);
// 
//     public static void notifySuccess(Project project, String title, String message) {
//         notify(NotificationType.INFORMATION, BALLOON_NOTIFICATION, project, title, message);
//     }
// 
// 	public static void notifyInfo(Project project, String title, String message) {
// 		notify(NotificationType.INFORMATION, TOOLWINDOW_NOTIFICATION, project, title, message);
// 	}
// 
//     public static void notifyError(Project project, String title, String message) {
//         notify(NotificationType.ERROR, TOOLWINDOW_NOTIFICATION, project, title, message);
//     }
// 
//     public static void notifyError(Project project, String title, Exception exception) {
//         notify(NotificationType.ERROR, STICKY_NOTIFICATION, project, title, exception.getMessage());
//     }
// 
//     private static void notify(NotificationType type, NotificationGroup group, Project project, String title, String message) {
//         group.createNotification(title, message, type, null).notify(project);
//     }
// }


import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import git4idea.commands.GitCommandResult;
import git4idea.repo.GitRepository;
import gitflow.ui.GitflowStartBugfixDialog;
import gitflow.ui.NotifyUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

        final String bugfixName = dialog.getNewBranchName();
        final String baseBranchName = dialog.getBaseBranchName();

        this.runAction(e.getProject(), baseBranchName, bugfixName, null);
    }

    @Override
    public void runAction(final Project project, final String baseBranchName, final String bugfixName, @Nullable final Runnable callInAwtLater){
        super.runAction(project, baseBranchName, bugfixName, callInAwtLater);

        new Task.Backgroundable(myProject, "Starting bugfix " + bugfixName, false) {
            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                final GitCommandResult commandResult = createBugfixBranch(baseBranchName, bugfixName);
                if (callInAwtLater != null && commandResult.success()) {
                    callInAwtLater.run();
                }
            }
        }.queue();
    }

    private GitCommandResult createBugfixBranch(String baseBranchName, String bugfixName) {
        GitflowErrorsListener errorListener = new GitflowErrorsListener(myProject);
        GitCommandResult result = myGitflow.startBugfix(myRepo, bugfixName, baseBranchName, errorListener);

        if (result.success()) {
            String startedBugfixMessage = String.format("A new branch '%s%s' was created, based on '%s'", branchUtil.getPrefixBugfix(), bugfixName, baseBranchName);
            NotifyUtil.notifySuccess(myProject, bugfixName, startedBugfixMessage);
        } else {
// Path: src/main/java/gitflow/ui/GitflowStartBugfixDialog.java
// public class GitflowStartBugfixDialog extends AbstractBranchStartDialog {
// 
//     public GitflowStartBugfixDialog(Project project, GitRepository repo) {
//         super(project, repo);
//     }
// 
//     @Override
//     protected String getLabel() {
//         return "bugfix";
//     }
// 
//     @Override
//     protected String getDefaultBranch() {
//         return GitflowConfigUtil.getInstance(getProject(), myRepo).developBranch;
//     }
// }
// 
// Path: src/main/java/gitflow/ui/NotifyUtil.java
// public class NotifyUtil
// {
//     private static final NotificationGroup TOOLWINDOW_NOTIFICATION = NotificationGroup.toolWindowGroup(
//             "Gitflow Errors", ToolWindowId.VCS, true);
//     private static final NotificationGroup STICKY_NOTIFICATION = new NotificationGroup(
//             "Gitflow Errors", NotificationDisplayType.STICKY_BALLOON, true);
//     private static final NotificationGroup BALLOON_NOTIFICATION = new NotificationGroup(
//             "Gitflow Notifications", NotificationDisplayType.BALLOON, true);
// 
//     public static void notifySuccess(Project project, String title, String message) {
//         notify(NotificationType.INFORMATION, BALLOON_NOTIFICATION, project, title, message);
//     }
// 
// 	public static void notifyInfo(Project project, String title, String message) {
// 		notify(NotificationType.INFORMATION, TOOLWINDOW_NOTIFICATION, project, title, message);
// 	}
// 
//     public static void notifyError(Project project, String title, String message) {
//         notify(NotificationType.ERROR, TOOLWINDOW_NOTIFICATION, project, title, message);
//     }
// 
//     public static void notifyError(Project project, String title, Exception exception) {
//         notify(NotificationType.ERROR, STICKY_NOTIFICATION, project, title, exception.getMessage());
//     }
// 
//     private static void notify(NotificationType type, NotificationGroup group, Project project, String title, String message) {
//         group.createNotification(title, message, type, null).notify(project);
//     }
// }


// Path: src/main/java/gitflow/actions/StartBugfixAction.java
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import git4idea.commands.GitCommandResult;
import git4idea.repo.GitRepository;
import gitflow.ui.GitflowStartBugfixDialog;
import gitflow.ui.NotifyUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;


        final String bugfixName = dialog.getNewBranchName();
        final String baseBranchName = dialog.getBaseBranchName();

        this.runAction(e.getProject(), baseBranchName, bugfixName, null);
    }

    @Override
    public void runAction(final Project project, final String baseBranchName, final String bugfixName, @Nullable final Runnable callInAwtLater){
        super.runAction(project, baseBranchName, bugfixName, callInAwtLater);

        new Task.Backgroundable(myProject, "Starting bugfix " + bugfixName, false) {
            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                final GitCommandResult commandResult = createBugfixBranch(baseBranchName, bugfixName);
                if (callInAwtLater != null && commandResult.success()) {
                    callInAwtLater.run();
                }
            }
        }.queue();
    }

    private GitCommandResult createBugfixBranch(String baseBranchName, String bugfixName) {
        GitflowErrorsListener errorListener = new GitflowErrorsListener(myProject);
        GitCommandResult result = myGitflow.startBugfix(myRepo, bugfixName, baseBranchName, errorListener);

        if (result.success()) {
            String startedBugfixMessage = String.format("A new branch '%s%s' was created, based on '%s'", branchUtil.getPrefixBugfix(), bugfixName, baseBranchName);
            NotifyUtil.notifySuccess(myProject, bugfixName, startedBugfixMessage);
        } else {
            NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details");