diff options
author | Robin Stocker | 2013-03-09 13:55:29 +0000 |
---|---|---|
committer | Matthias Sohn | 2013-03-09 23:26:01 +0000 |
commit | db663caab8ef13e9a56a1faa741eba330532d011 (patch) | |
tree | e4f26773fc8385d4f732893f698a333d352b0671 /org.eclipse.egit.ui | |
parent | b87a8703c449d72876e8a20c43b0b54b58cb996f (diff) | |
download | egit-db663caab8ef13e9a56a1faa741eba330532d011.tar.gz egit-db663caab8ef13e9a56a1faa741eba330532d011.tar.xz egit-db663caab8ef13e9a56a1faa741eba330532d011.zip |
Fix rebase pulldown in toolbar not being accessible during rebase
During rebase, the rebase pulldown menu in the toolbar was always
disabled, resulting in no way to do a "abort" or other actions through
the toolbar.
The problem is that the enabled state of the action handler for the main
action also determines whether the pulldown menu can be opened (the
little arrow besides the icon). So instead of disabling it when rebase
is not possible, also enable it during rebase, and check state again
when executing.
In addition to the above, this fixes RebaseActionHandler's enabled state
to behave the same way as RebaseCurrentRefCommand, in that it's also
enabled with a detached HEAD.
Bug: 387184
JGit-Dependency: I9ec8568fa1100d2e9c8d4ca0e347bf77ec6d8734
Change-Id: Ic69f5c952a49f023c0949f04b3e976be1b267fbe
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui')
3 files changed, 46 insertions, 18 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RebaseAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RebaseAction.java index 3755a5b227..e92aeeab44 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RebaseAction.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RebaseAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2011, Dariusz Luksza <dariusz@luksza.org> + * Copyright (C) 2011, 2013 Dariusz Luksza <dariusz@luksza.org> and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,7 +12,6 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.egit.core.internal.indexdiff.IndexDiffCache; import org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry; -import org.eclipse.egit.core.op.RebaseOperation; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.internal.UIIcons; import org.eclipse.egit.ui.internal.UIText; @@ -33,9 +32,10 @@ import org.eclipse.swt.widgets.MenuItem; import org.eclipse.ui.IWorkbenchWindowPulldownDelegate; /** - * An action to rebase the current branch on top of selected one. + * A pulldown action to rebase the current branch, or continue, skip or abort an + * active rebase. * - * @see RebaseOperation + * @see RebaseActionHandler */ public class RebaseAction extends RepositoryAction implements IWorkbenchWindowPulldownDelegate { @@ -109,10 +109,7 @@ public class RebaseAction extends RepositoryAction implements return false; RepositoryState state = repo.getRepositoryState(); - return state == RepositoryState.REBASING - || state == RepositoryState.REBASING_INTERACTIVE - || state == RepositoryState.REBASING_MERGE - || state == RepositoryState.REBASING_REBASING; + return state.isRebasing(); } private boolean canContinue(Repository repo) { diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RebaseActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RebaseActionHandler.java index 92bf9a1427..b84e474595 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RebaseActionHandler.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RebaseActionHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2011, Dariusz Luksza <dariusz@luksza.org> + * Copyright (C) 2011, 2013 Dariusz Luksza <dariusz@luksza.org> and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -10,24 +10,44 @@ package org.eclipse.egit.ui.internal.actions; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.egit.core.op.RebaseOperation; import org.eclipse.egit.ui.internal.commands.shared.RebaseCurrentRefCommand; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.RepositoryState; /** - * An action to rebase the current branch on top of given branch. + * An action to rebase the current branch on top of given branch. This is the + * "main" action of the rebase pulldown, see {@link RebaseAction} for the menu + * items. * - * @see RebaseOperation + * @see RebaseAction */ public class RebaseActionHandler extends RepositoryActionHandler { public Object execute(ExecutionEvent event) throws ExecutionException { - return new RebaseCurrentRefCommand().execute(event); + RebaseCurrentRefCommand rebaseCurrent = new RebaseCurrentRefCommand(); + rebaseCurrent.setEnabled(event.getApplicationContext()); + // Because the enabled state is for both starting a new rebase as well + // as working with an existing rebase, it can be that this is executed + // even though starting a new rebase is not possible. So check enabled + // state again here. See also isEnabled. + if (rebaseCurrent.isEnabled()) + return rebaseCurrent.execute(event); + else + return null; } @Override public boolean isEnabled() { Repository repo = getRepository(); - return repo != null && isLocalBranchCheckedout(repo); + if (repo == null) + return false; + + // Either we want this to be enabled because a new rebase can be started + // (main action) or an active rebase can be continued, skipped or + // aborted (menu items). Even when the main action is not enabled we + // must enable this because otherwise the menu items can not be opened. + RepositoryState state = repo.getRepositoryState(); + return state.isRebasing() + || RebaseCurrentRefCommand.isEnabledForState(repo, state); } } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java index 1dbe286ced..cd984e2d6e 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 SAP AG and others. + * Copyright (c) 2010, 2013 SAP AG and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -93,8 +93,9 @@ public class RebaseCurrentRefCommand extends AbstractRebaseCommandHandler { if (selection instanceof ISelection) { Repository repo = getRepository((ISelection) selection, getActiveEditorInput(ctx)); if (repo != null) { - boolean isSafe = repo.getRepositoryState() == RepositoryState.SAFE; - setBaseEnabled(isSafe && hasHead(repo)); + boolean enabled = isEnabledForState(repo, + repo.getRepositoryState()); + setBaseEnabled(enabled); } else setBaseEnabled(false); return; @@ -103,7 +104,17 @@ public class RebaseCurrentRefCommand extends AbstractRebaseCommandHandler { setBaseEnabled(true); } - private boolean hasHead(Repository repo) { + /** + * @param repo + * @param state + * @return whether this command is enabled for the repository state + */ + public static boolean isEnabledForState(Repository repo, + RepositoryState state) { + return state == RepositoryState.SAFE && hasHead(repo); + } + + private static boolean hasHead(Repository repo) { try { Ref headRef = repo.getRef(Constants.HEAD); return headRef != null && headRef.getObjectId() != null; |