aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2012-02-25 19:05:30 (EST)
committerMatthias Sohn2012-02-25 19:05:30 (EST)
commitcc0b097a1c25c5df6e6bffacc18f5551f8ff5660 (patch)
treec971ab74ba736b0644d08be10d6a18f45b55d990
parent9116e37998a402f5a572bd2403fdbf94b6a8ecf0 (diff)
downloadegit-cc0b097a1c25c5df6e6bffacc18f5551f8ff5660.zip
egit-cc0b097a1c25c5df6e6bffacc18f5551f8ff5660.tar.gz
egit-cc0b097a1c25c5df6e6bffacc18f5551f8ff5660.tar.bz2
Add "Revert" action to Commit Editorrefs/changes/33/5133/3
Bug: 370436 Change-Id: I3d2c0db48b4119a0dfb45d1a68460e52c4d0ec2e Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/plugin.xml9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/RevertHandler.java127
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RevertHandler.java93
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties2
6 files changed, 162 insertions, 77 deletions
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index f0bf4c2..2164af5 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -3977,6 +3977,10 @@
commandId="org.eclipse.egit.ui.history.Revert"
icon="icons/obj16/revert.gif">
</image>
+ <image
+ commandId="org.eclipse.egit.ui.commit.Revert"
+ icon="icons/obj16/revert.gif">
+ </image>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
@@ -4373,6 +4377,11 @@
name="%RevertCommand.name">
</command>
<command
+ defaultHandler="org.eclipse.egit.ui.internal.commit.command.RevertHandler"
+ id="org.eclipse.egit.ui.commit.Revert"
+ name="%RevertCommand.name">
+ </command>
+ <command
defaultHandler="org.eclipse.egit.ui.internal.history.command.MergeHandler"
id="org.eclipse.egit.ui.history.Merge"
name="%MergeCommand.name">
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index 7c0d281..3221bcf 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -3752,7 +3752,7 @@ public class UIText extends NLS {
public static String RevertFailureDialog_Title;
/** */
- public static String RevertHandler_AlreadyRevertedMessae;
+ public static String RevertHandler_AlreadyRevertedMessage;
/** */
public static String RevertHandler_JobName;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java
index 2cdd937..c122ecb 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java
@@ -8,6 +8,7 @@
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
* Daniel Megert <daniel_megert@ch.ibm.com> - Added context menu to the Commit Editor's header text
+ * Tomasz Zarna <Tomasz.Zarna@pl.ibm.com> - Add "Revert" action to Commit Editor
*******************************************************************************/
package org.eclipse.egit.ui.internal.commit;
@@ -20,6 +21,7 @@ import org.eclipse.egit.ui.internal.commit.command.CheckoutHandler;
import org.eclipse.egit.ui.internal.commit.command.CreateBranchHandler;
import org.eclipse.egit.ui.internal.commit.command.CreateTagHandler;
import org.eclipse.egit.ui.internal.commit.command.CherryPickHandler;
+import org.eclipse.egit.ui.internal.commit.command.RevertHandler;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
import org.eclipse.jface.action.ContributionManager;
import org.eclipse.jface.action.ControlContribution;
@@ -190,6 +192,7 @@ public class CommitEditor extends SharedHeaderFormEditor implements
toolbar.add(createCommandContributionItem(CreateBranchHandler.ID));
toolbar.add(createCommandContributionItem(CheckoutHandler.ID));
toolbar.add(createCommandContributionItem(CherryPickHandler.ID));
+ toolbar.add(createCommandContributionItem(RevertHandler.ID));
addContributions(toolbar);
toolbar.update(true);
getSite().setSelectionProvider(new ISelectionProvider() {
@@ -246,10 +249,9 @@ public class CommitEditor extends SharedHeaderFormEditor implements
*/
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
- if (input.getAdapter(RepositoryCommit.class) == null) {
+ if (input.getAdapter(RepositoryCommit.class) == null)
throw new PartInitException(
"Input could not be adapted to commit object"); //$NON-NLS-1$
- }
super.init(site, input);
setPartName(input.getName());
setTitleToolTip(input.getToolTipText());
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/RevertHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/RevertHandler.java
new file mode 100644
index 0000000..be40d61
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/RevertHandler.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tomasz Zarna (IBM) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.commit.command;
+
+import java.text.MessageFormat;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.egit.core.op.RevertCommitOperation;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.commit.RepositoryCommit;
+import org.eclipse.egit.ui.internal.dialogs.RevertFailureDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jgit.api.MergeResult;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Executes the {@link RevertCommitOperation}
+ */
+public class RevertHandler extends CommitCommandHandler {
+
+ /**
+ * Command id
+ */
+ public static final String ID = "org.eclipse.egit.ui.commit.Revert"; //$NON-NLS-1$
+
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+ List<RepositoryCommit> commits = getCommits(event);
+ if (commits.size() == 1) {
+ RepositoryCommit repoCommit = commits.get(0);
+ final RevCommit commit = repoCommit.getRevCommit();
+ Repository repo = repoCommit.getRepository();
+ final Shell shell = getPart(event).getSite().getShell();
+
+ final RevertCommitOperation op = new RevertCommitOperation(repo,
+ commit);
+
+ Job job = new Job(MessageFormat.format(
+ UIText.RevertHandler_JobName, commit.name())) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ op.execute(monitor);
+ RevCommit newHead = op.getNewHead();
+ List<Ref> revertedRefs = op.getRevertedRefs();
+ if (newHead != null && revertedRefs.isEmpty())
+ showRevertedDialog(shell);
+ if (newHead == null)
+ showFailureDialog(shell, commit,
+ op.getFailingResult());
+ } catch (CoreException e) {
+ Activator.handleError(
+ UIText.RevertOperation_InternalError, e, true);
+ }
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ public boolean belongsTo(Object family) {
+ if (JobFamilies.REVERT_COMMIT.equals(family))
+ return true;
+ return super.belongsTo(family);
+ }
+ };
+ job.setUser(true);
+ job.setRule(op.getSchedulingRule());
+ job.schedule();
+ return null;
+ }
+ return null;
+ }
+
+ /**
+ * Shows a dialog with failing result of revert.
+ *
+ * @param shell
+ * the shell to parent the dialog from
+ * @param commit
+ * the commit
+ * @param result
+ * the failing result
+ */
+ private static void showFailureDialog(final Shell shell,
+ final RevCommit commit, final MergeResult result) {
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ RevertFailureDialog.show(shell, commit, result);
+ }
+ });
+ }
+
+ /**
+ * Shows the "No revert performed" dialog.
+ *
+ * @param shell
+ * the shell to parent the dialog from
+ */
+ private static void showRevertedDialog(final Shell shell) {
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ MessageDialog.openWarning(shell,
+ UIText.RevertHandler_NoRevertTitle,
+ UIText.RevertHandler_AlreadyRevertedMessage);
+ }
+ });
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RevertHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RevertHandler.java
index 3aca97d..1e42dc3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RevertHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RevertHandler.java
@@ -12,94 +12,41 @@
package org.eclipse.egit.ui.internal.history.command;
-import java.text.MessageFormat;
-import java.util.List;
-
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.egit.core.op.RevertCommitOperation;
-import org.eclipse.egit.ui.Activator;
-import org.eclipse.egit.ui.JobFamilies;
-import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.CommonUtils;
+import org.eclipse.egit.ui.internal.commit.RepositoryCommit;
import org.eclipse.egit.ui.internal.dialogs.BasicConfigurationDialog;
-import org.eclipse.egit.ui.internal.dialogs.RevertFailureDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jgit.api.MergeResult;
-import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
/**
* Executes the RevertCommit
*/
public class RevertHandler extends AbstractHistoryCommandHandler {
+ /**
+ * Command id
+ */
+ public static final String ID = "org.eclipse.egit.ui.history.Revert"; //$NON-NLS-1$
public Object execute(ExecutionEvent event) throws ExecutionException {
- Repository repo = getRepository(event);
- BasicConfigurationDialog.show(repo);
final RevCommit commit = (RevCommit) getSelection(getPage())
.getFirstElement();
+ if (commit == null)
+ return null;
+ Repository repo = getRepository(event);
+ if (repo == null)
+ return null;
+ BasicConfigurationDialog.show(repo);
- final Shell shell = getPart(event).getSite().getShell();
- final RevertCommitOperation op = new RevertCommitOperation(repo, commit);
-
- Job job = new Job(MessageFormat.format(UIText.RevertHandler_JobName,
- commit.name())) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- op.execute(monitor);
- RevCommit newHead = op.getNewHead();
- List<Ref> revertedRefs = op.getRevertedRefs();
- if (newHead != null && revertedRefs.isEmpty())
- showRevertedDialog(shell);
- if (newHead == null)
- showFailureDialog(shell, commit, op.getFailingResult());
- } catch (CoreException e) {
- Activator.handleError(UIText.RevertOperation_InternalError,
- e, true);
- }
- return Status.OK_STATUS;
- }
-
- @Override
- public boolean belongsTo(Object family) {
- if (JobFamilies.REVERT_COMMIT.equals(family))
- return true;
- return super.belongsTo(family);
- }
- };
- job.setUser(true);
- job.setRule(op.getSchedulingRule());
- job.schedule();
+ final IStructuredSelection selected = new StructuredSelection(
+ new RepositoryCommit(repo, commit));
+ CommonUtils
+ .runCommand(
+ org.eclipse.egit.ui.internal.commit.command.RevertHandler.ID,
+ selected);
return null;
}
-
- private void showFailureDialog(final Shell shell, final RevCommit commit,
- final MergeResult result) {
- shell.getDisplay().syncExec(new Runnable() {
-
- public void run() {
- RevertFailureDialog.show(shell, commit, result);
- }
- });
- }
-
- private void showRevertedDialog(final Shell shell) {
- PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
-
- public void run() {
- MessageDialog.openWarning(shell,
- UIText.RevertHandler_NoRevertTitle,
- UIText.RevertHandler_AlreadyRevertedMessae);
- }
- });
- }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 92a660d..ebaeaad 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -1342,7 +1342,7 @@ RevertFailureDialog_ReasonChangesInIndex=Local Changes in Index
RevertFailureDialog_ReasonChangesInWorkingDirectory=Local Changes in Working Directory
RevertFailureDialog_ReasonDeleteFailure=Unable to Delete
RevertFailureDialog_Title=Revert Failed
-RevertHandler_AlreadyRevertedMessae=The change has already been reverted
+RevertHandler_AlreadyRevertedMessage=The change has already been reverted
RevertHandler_JobName=Reverting Commit {0}
RevertHandler_NoRevertTitle=No revert performed
RevertOperation_Failed=The revert failed