Search in sources :

Example 1 with BranchSwitchConfirmationDialog

use of com.oxygenxml.git.view.dialog.BranchSwitchConfirmationDialog in project oxygen-git-client-addon by oxygenxml.

the class BranchSelectionCombo method treatBranchSelectedEvent.

/**
 * Treat a branch name selection event.
 *
 * @param event The event to treat.
 */
private void treatBranchSelectedEvent(final ItemEvent event) {
    final String branchName = (String) event.getItem();
    final BranchInfo currentBranchInfo = GIT_ACCESS.getBranchInfo();
    final String currentBranchName = currentBranchInfo.getBranchName();
    if (branchName.equals(currentBranchName)) {
        return;
    }
    final RepositoryState repoState = RepoUtil.getRepoState().orElse(null);
    if (RepoUtil.isNonConflictualRepoWithUncommittedChanges(repoState)) {
        SwingUtilities.invokeLater(() -> {
            BranchSwitchConfirmationDialog dialog = new BranchSwitchConfirmationDialog(branchName);
            dialog.setVisible(true);
            int answer = dialog.getResult();
            if (answer == OKOtherAndCancelDialog.RESULT_OTHER) {
                tryCheckingOutBranch(currentBranchInfo, branchName);
            } else if (answer == OKOtherAndCancelDialog.RESULT_OK) {
                boolean wasStashCreated = StashUtil.stashChanges();
                if (wasStashCreated) {
                    tryCheckingOutBranch(currentBranchInfo, branchName);
                }
            } else {
                restoreCurrentBranchSelectionInMenu();
            }
        });
    } else {
        tryCheckingOutBranch(currentBranchInfo, branchName);
    }
}
Also used : BranchSwitchConfirmationDialog(com.oxygenxml.git.view.dialog.BranchSwitchConfirmationDialog) BranchInfo(com.oxygenxml.git.service.BranchInfo) RepositoryState(org.eclipse.jgit.lib.RepositoryState)

Example 2 with BranchSwitchConfirmationDialog

use of com.oxygenxml.git.view.dialog.BranchSwitchConfirmationDialog in project oxygen-git-client-addon by oxygenxml.

the class BranchTreeMenuActionsProvider method showUncommittedChangesWhenChangingBranchMsg.

/**
 * Show a message when there are uncommitted changes and we try to switch repo.
 *
 * @param newBranch The branch to set.
 *
 * @return The option chosen by the user. OKCancelDialog#RESULT_OK or OKCancelDialog#RESULT_CANCEL.
 */
private int showUncommittedChangesWhenChangingBranchMsg(String newBranch) {
    BranchSwitchConfirmationDialog dialog = new BranchSwitchConfirmationDialog(newBranch);
    dialog.setVisible(true);
    return dialog.getResult();
}
Also used : BranchSwitchConfirmationDialog(com.oxygenxml.git.view.dialog.BranchSwitchConfirmationDialog)

Aggregations

BranchSwitchConfirmationDialog (com.oxygenxml.git.view.dialog.BranchSwitchConfirmationDialog)2 BranchInfo (com.oxygenxml.git.service.BranchInfo)1 RepositoryState (org.eclipse.jgit.lib.RepositoryState)1