Permalink
Browse files

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>
  • Loading branch information...
1 parent b87a870 commit db663caab8ef13e9a56a1faa741eba330532d011 @robinst robinst committed with msohn Mar 9, 2013
@@ -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.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.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 @@ private boolean isInRebasingState(Repository repo) {
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) {
@@ -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 @@
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);
}
}
@@ -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 void setEnabled(Object evaluationContext) {
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 void setEnabled(Object evaluationContext) {
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;

0 comments on commit db663ca

Please sign in to comment.