Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Muschel2019-11-17 13:14:23 -0500
committerThomas Wolf2019-11-21 07:31:23 -0500
commit3a5278d31e3b5d357407fffa50675b02df7022d5 (patch)
treec80ac5abdb9d67a5ce6c0be5a8ad9961665bdece
parent23006a9d29099d4c790a7c3e9e28bf8b376d5561 (diff)
downloadegit-3a5278d31e3b5d357407fffa50675b02df7022d5.tar.gz
egit-3a5278d31e3b5d357407fffa50675b02df7022d5.tar.xz
egit-3a5278d31e3b5d357407fffa50675b02df7022d5.zip
"Switch To" should allow to take a commit/hash as input
Add a new menu entry to open the CommitSelectionDialog to be able to check out an arbitrary commit. Give all menu items an icon. Bug: 451087 Change-Id: I5b0596f52334c0876a868de76d776075b6a2adb9 Signed-off-by: Simon Muschel <smuschel@gmx.de> Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java26
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitNonWSChangesTest.java8
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java42
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties5
5 files changed, 69 insertions, 16 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
index 3c16f9692..7448f0bc8 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2014 Tasktop Technologies.
+ * Copyright (c) 2014, 2019 Tasktop Technologies and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
*
* Contributors:
* Tomasz Zarna (Tasktop) - initial API and implementation
+ * Simon Muschel <smuschel@gmx.de - Bug 451087
*****************************************************************************/
package org.eclipse.egit.ui.internal.actions;
@@ -64,8 +65,8 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase {
switchToMenu = new SwitchToMenu();
handlerService = mock(IHandlerService.class);
IServiceLocator serviceLocator = mock(IServiceLocator.class);
- when(serviceLocator.getService(IHandlerService.class)).thenReturn(
- handlerService);
+ when(serviceLocator.getService(IHandlerService.class))
+ .thenReturn(handlerService);
switchToMenu.initialize(serviceLocator);
}
@@ -80,8 +81,7 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase {
@Test
public void selectionNotAdaptableToRepository() {
- mockSelection(
- new StructuredSelection(new Object()));
+ mockSelection(new StructuredSelection(new Object()));
MenuItem[] items = fillMenu();
@@ -141,18 +141,20 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase {
MenuItem[] items = fillMenu();
- assertEquals(6, items.length);
+ assertEquals(7, items.length);
assertTextEquals(UIText.SwitchToMenu_NewBranchMenuLabel, items[0]);
assertStyleEquals(SWT.SEPARATOR, items[1]);
assertTextEquals("master", items[2]);
assertTextEquals("stable", items[3]);
assertStyleEquals(SWT.SEPARATOR, items[4]);
- assertTextEquals(UIText.SwitchToMenu_OtherMenuLabel, items[5]);
+ assertTextEquals(UIText.SwitchToMenu_CommitMenuLabel, items[5]);
+ assertTextEquals(UIText.SwitchToMenu_OtherMenuLabel, items[6]);
}
@Test
public void selectionWithRepositoryHavingOver20Branches() throws Exception {
- Repository repo = lookupRepository(createProjectAndCommitToRepository());
+ Repository repo = lookupRepository(
+ createProjectAndCommitToRepository());
for (int i = 0; i < SwitchToMenu.MAX_NUM_MENU_ENTRIES; i++) {
createBranch(repo, "refs/heads/change/" + i);
}
@@ -162,7 +164,7 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase {
MenuItem[] items = fillMenu();
- assertEquals(24, items.length);
+ assertEquals(25, items.length);
assertTextEquals(UIText.SwitchToMenu_NewBranchMenuLabel, items[0]);
assertStyleEquals(SWT.SEPARATOR, items[1]);
assertTextEquals("change/0", items[2]);
@@ -187,7 +189,8 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase {
assertTextEquals("change/19", items[21]);
// "master" and "stable" didn't make it
assertStyleEquals(SWT.SEPARATOR, items[22]);
- assertTextEquals(UIText.SwitchToMenu_OtherMenuLabel, items[23]);
+ assertTextEquals(UIText.SwitchToMenu_CommitMenuLabel, items[23]);
+ assertTextEquals(UIText.SwitchToMenu_OtherMenuLabel, items[24]);
}
@Test
@@ -298,7 +301,8 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
- Menu menu = new Menu(new Shell(PlatformUI.getWorkbench().getDisplay()));
+ Menu menu = new Menu(
+ new Shell(PlatformUI.getWorkbench().getDisplay()));
switchToMenu.fill(menu, 0 /* index */);
items[0] = menu.getItems();
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitNonWSChangesTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitNonWSChangesTest.java
index 350f33be1..9abb4d53d 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitNonWSChangesTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitNonWSChangesTest.java
@@ -23,6 +23,7 @@ import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jgit.lib.Repository;
@@ -42,6 +43,9 @@ import org.junit.runner.RunWith;
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public class CommitNonWSChangesTest extends LocalRepositoryTestCase {
+
+ private static final TestUtil myUtil = new TestUtil();
+
private File repositoryFile;
private Repository repository;
@@ -122,6 +126,8 @@ public class CommitNonWSChangesTest extends LocalRepositoryTestCase {
TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH);
SWTBotTree tree = repoView.bot().tree();
TestUtil.waitUntilTreeHasNodeContainsText(bot, tree, REPO1, 10000);
- tree.getAllItems()[0].contextMenu("Commit...").click();
+ TestUtil.navigateTo(tree, REPO1).select();
+ ContextMenuHelper.clickContextMenu(tree,
+ myUtil.getPluginLocalizedValue("RepoViewCommit.label"));
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index 36d9a1cda..fea64c5b3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -19,6 +19,7 @@
* Copyright (C) 2016, Lars Vogel <Lars.Vogel@vogella.com>
* Copyright (C) 2017, Wim Jongman <wim.jongman@remainsoftware.com> bug 358152
* Copyright (C) 2019, Alexander Nittka <alex@nittka.de> bug 545123
+ * Copyright (C) 2019, Simon Muschel <smuschel@gmx.de> - Bug 451087
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -5295,6 +5296,9 @@ public class UIText extends NLS {
public static String SwitchToMenu_OtherMenuLabel;
/** */
+ public static String SwitchToMenu_CommitMenuLabel;
+
+ /** */
public static String GitMergeEditorInput_CalculatingDiffTaskName;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
index 20675976c..82ed542a3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2011, 2016 Mathias Kinzler <mathias.kinzler@sap.com> and others.
+ * Copyright (C) 2011, 2019 Mathias Kinzler <mathias.kinzler@sap.com> and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* Thomas Wolf <thomas.wolf@paranor.ch> - Bug 486594
+ * Simon Muschel <smuschel@gmx.de> - Bug 451087
*******************************************************************************/
package org.eclipse.egit.ui.internal.actions;
@@ -31,6 +32,7 @@ import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.branch.BranchOperationUI;
import org.eclipse.egit.ui.internal.dialogs.CheckoutDialog;
+import org.eclipse.egit.ui.internal.history.CommitSelectionDialog;
import org.eclipse.egit.ui.internal.repository.CreateBranchWizard;
import org.eclipse.egit.ui.internal.selection.SelectionUtils;
import org.eclipse.jface.action.ContributionItem;
@@ -40,6 +42,7 @@ import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jgit.lib.CheckoutEntry;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.Repository;
@@ -69,6 +72,10 @@ public class SwitchToMenu extends ContributionItem implements
private final Image checkedOutImage;
+ private final Image commitImage;
+
+ private final Image othersImage;
+
/**
*/
public SwitchToMenu() {
@@ -87,6 +94,8 @@ public class SwitchToMenu extends ContributionItem implements
UIIcons.CREATE_BRANCH);
checkedOutImage = UIIcons.getImage(pluginResources,
UIIcons.CHECKED_OUT_BRANCH);
+ commitImage = UIIcons.getImage(pluginResources, UIIcons.CHANGESET);
+ othersImage = UIIcons.getImage(pluginResources, UIIcons.BRANCHES);
}
@Override
@@ -114,9 +123,12 @@ public class SwitchToMenu extends ContributionItem implements
int itemCount = createMostActiveBranchesMenuItems(menu, repositories);
- if (!isMultipleSelection(repositories) && itemCount > 0) {
+ if (!isMultipleSelection(repositories)) {
createSeparator(menu);
- createOtherMenuItem(menu, repositories[0]);
+ createSwitchToCommitItem(menu, repositories[0]);
+ if (itemCount > 0) {
+ createOtherMenuItem(menu, repositories[0]);
+ }
}
if (itemCount == 0 && isMultipleSelection(repositories)) {
@@ -253,6 +265,7 @@ public class SwitchToMenu extends ContributionItem implements
private void createOtherMenuItem(Menu menu, Repository repository) {
MenuItem others = new MenuItem(menu, SWT.PUSH);
others.setText(UIText.SwitchToMenu_OtherMenuLabel);
+ others.setImage(othersImage);
others.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -267,6 +280,29 @@ public class SwitchToMenu extends ContributionItem implements
});
}
+ private void createSwitchToCommitItem(Menu menu, Repository repository) {
+ MenuItem switchToCommit = new MenuItem(menu, SWT.PUSH);
+ switchToCommit.setText(UIText.SwitchToMenu_CommitMenuLabel);
+ switchToCommit.setImage(commitImage);
+ switchToCommit.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (repository != null) {
+ CommitSelectionDialog dialog = new CommitSelectionDialog(
+ e.display.getActiveShell(), repository);
+ if (dialog.open() == Window.OK) {
+ ObjectId commitId = dialog.getCommitId();
+ if (commitId != null) {
+ BranchOperationUI
+ .checkout(repository, commitId.getName())
+ .start();
+ }
+ }
+ }
+ }
+ });
+ }
+
private void createDisabledMenu(Menu menu, String text) {
MenuItem disabled = new MenuItem(menu, SWT.PUSH);
disabled.setText(text);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index 47497c6f0..a882aceb2 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1,5 +1,6 @@
###############################################################################
-# Copyright (c) 2005, 2016, 2017, 2019 Shawn Pearce and others.
+# Copyright (c) 2005, 2019 Shawn Pearce and others.
+#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
@@ -23,6 +24,7 @@
# Denis Zygann <d.zygann@web.de> - 473919 Add tooltip text for sorting files action
# Wim Jongman <wim.jongman@remainsoftware.com - 358152
# Alexander Nittka <alex@nittka.de> - 545123
+# Simon Muschel <smuschel@gmx.de> - Bug 451087
###############################################################################
AbortRebaseCommand_CancelDialogMessage=The abort operation was canceled.
AbortRebaseCommand_JobName=Aborting Rebase
@@ -1898,6 +1900,7 @@ SquashHandler_InternalError=An internal error occurred
SquashHandler_JobName=Squashing {0} Commits
SwitchToMenu_NewBranchMenuLabel=&New Branch...
SwitchToMenu_OtherMenuLabel=&Other...
+SwitchToMenu_CommitMenuLabel=&Commit...
SwitchToMenu_NoCommonBranchesFound=No common branches found
GitActionContributor_ExpandAll=Expand All
GitActionContributor_Push=Push

Back to the top