use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.
the class RenameBranchOnCommitHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Repository repository = getRepository(event);
if (repository == null)
return null;
List<Ref> branchesOfCommit = getBranchesOfCommit(getSelection(event));
// this should have been checked by isEnabled()
if (branchesOfCommit.isEmpty())
return null;
final Shell shell = getPart(event).getSite().getShell();
final Ref branchToRename;
if (branchesOfCommit.size() > 1) {
BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(shell, branchesOfCommit, UIText.RenameBranchOnCommitHandler_SelectBranchDialogTitle, UIText.RenameBranchOnCommitHandler_SelectBranchDialogMessage, SWT.SINGLE);
if (dlg.open() != Window.OK)
return null;
branchToRename = dlg.getSelectedNode();
} else
branchToRename = branchesOfCommit.get(0);
new BranchRenameDialog(shell, repository, branchToRename).open();
return null;
}
use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.
the class DeleteTagOnCommitHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Repository repository = getRepository(event);
if (repository == null)
return null;
final Shell shell = getPart(event).getSite().getShell();
IStructuredSelection selection = getSelection(event);
List<Ref> tags = getTagsOfCommit(selection);
// this should have been checked by isEnabled()
if (tags.isEmpty())
return null;
// show a dialog in case there are multiple tags on the selected commit
final List<Ref> tagsToDelete;
if (tags.size() > 1) {
BranchSelectionDialog<Ref> dialog = new BranchSelectionDialog<>(shell, tags, UIText.DeleteTagOnCommitHandler_SelectTagDialogTitle, UIText.DeleteTagOnCommitHandler_SelectTagDialogMessage, SWT.MULTI);
if (dialog.open() != Window.OK)
return null;
tagsToDelete = dialog.getSelectedNodes();
} else {
String tagName = Repository.shortenRefName(tags.get(0).getName());
String message = MessageFormat.format(UIText.DeleteTagCommand_messageConfirmSingleTag, tagName);
boolean confirmed = MessageDialog.openConfirm(shell, UIText.DeleteTagCommand_titleConfirm, message);
if (!confirmed)
return null;
tagsToDelete = tags;
}
try {
deleteTagsAsTask(shell, repository, tagsToDelete);
} catch (InvocationTargetException e1) {
Activator.handleError(UIText.RepositoriesView_TagDeletionFailureMessage, e1.getCause(), true);
} catch (InterruptedException e1) {
// ignore
}
return null;
}
use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.
the class MergeHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ObjectId commitId = getSelectedCommitId(event);
Repository repository = getRepository(event);
if (repository == null) {
return null;
}
Shell shell = HandlerUtil.getActiveShellChecked(event);
if (!MergeActionHandler.checkMergeIsPossible(repository, shell) || LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
return null;
}
List<Ref> nodes;
try {
nodes = getBranchesOfCommit(getSelection(event), repository, true);
} catch (IOException e) {
throw new ExecutionException(UIText.AbstractHistoryCommitHandler_cantGetBranches, e);
}
String refName;
if (nodes.isEmpty()) {
refName = commitId.getName();
} else if (nodes.size() == 1) {
refName = nodes.get(0).getName();
} else {
BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(shell, nodes, UIText.MergeHandler_SelectBranchTitle, UIText.MergeHandler_SelectBranchMessage, SWT.SINGLE);
if (dlg.open() == Window.OK) {
refName = dlg.getSelectedNode().getName();
} else {
return null;
}
}
MergeOperation op = new MergeOperation(repository, refName);
MergeActionHandler.doMerge(repository, op, refName);
return null;
}
use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.
the class DeleteBranchOnCommitHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Repository repository = getRepository(event);
if (repository == null)
return null;
IStructuredSelection selection = getSelection(event);
int totalBranchCount;
List<Ref> branchesOfCommit;
try {
totalBranchCount = getBranchesOfCommit(selection, repository, false).size();
branchesOfCommit = getBranchesOfCommit(selection, repository, true);
} catch (IOException e) {
throw new ExecutionException(UIText.AbstractHistoryCommitHandler_cantGetBranches, e);
}
// this should have been checked by isEnabled()
if (branchesOfCommit.isEmpty())
return null;
final List<Ref> unmergedBranches = new ArrayList<>();
final Shell shell = getPart(event).getSite().getShell();
final List<Ref> branchesToDelete;
// tracking branch
if (totalBranchCount > 1) {
BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(shell, branchesOfCommit, UIText.DeleteBranchOnCommitHandler_SelectBranchDialogTitle, UIText.DeleteBranchOnCommitHandler_SelectBranchDialogMessage, SWT.MULTI);
if (dlg.open() != Window.OK)
return null;
branchesToDelete = dlg.getSelectedNodes();
} else
branchesToDelete = branchesOfCommit;
try {
new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask(UIText.DeleteBranchCommand_DeletingBranchesProgress, branchesToDelete.size());
for (Ref refNode : branchesToDelete) {
int result = deleteBranch(repository, refNode, false);
if (result == DeleteBranchOperation.REJECTED_CURRENT) {
throw new CoreException(Activator.createErrorStatus(UIText.DeleteBranchCommand_CannotDeleteCheckedOutBranch, null));
} else if (result == DeleteBranchOperation.REJECTED_UNMERGED) {
unmergedBranches.add(refNode);
} else
monitor.worked(1);
}
} catch (CoreException ex) {
throw new InvocationTargetException(ex);
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e1) {
Activator.handleError(UIText.RepositoriesView_BranchDeletionFailureMessage, e1.getCause(), true);
} catch (InterruptedException e1) {
// ignore
}
if (!unmergedBranches.isEmpty()) {
MessageDialog messageDialog = new UnmergedBranchDialog<>(shell, unmergedBranches);
if (messageDialog.open() == Window.OK) {
try {
new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask(UIText.DeleteBranchCommand_DeletingBranchesProgress, unmergedBranches.size());
for (Ref node : unmergedBranches) {
deleteBranch(repository, node, true);
monitor.worked(1);
}
} catch (CoreException ex) {
throw new InvocationTargetException(ex);
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e1) {
Activator.handleError(UIText.RepositoriesView_BranchDeletionFailureMessage, e1.getCause(), true);
} catch (InterruptedException e1) {
// ignore
}
}
}
return null;
}
use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.
the class CheckoutCommitHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ObjectId commitId = getSelectedCommitId(event);
Repository repo = getRepository(event);
final BranchOperationUI op;
List<Ref> nodes;
try {
nodes = getBranchesOfCommit(getSelection(event), repo, true);
} catch (IOException e) {
throw new ExecutionException(UIText.AbstractHistoryCommitHandler_cantGetBranches, e);
}
if (nodes.isEmpty()) {
op = BranchOperationUI.checkout(repo, commitId.name());
} else if (nodes.size() == 1) {
op = BranchOperationUI.checkout(repo, nodes.get(0).getName());
} else {
BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(HandlerUtil.getActiveShellChecked(event), nodes, UIText.CheckoutHandler_SelectBranchTitle, UIText.CheckoutHandler_SelectBranchMessage, SWT.SINGLE);
if (dlg.open() == Window.OK) {
op = BranchOperationUI.checkout(repo, dlg.getSelectedNode().getName());
} else {
op = null;
}
}
if (op == null)
return null;
op.start();
return null;
}
Aggregations