Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler2010-08-11 14:35:20 +0000
committerMathias Kinzler2010-08-11 14:35:20 +0000
commitcf12cbbba845bbaab24f312b481551915b319294 (patch)
treec5247f170e498d162acf1bd250f1715e8859e0a1
parent96faaecf12d7e42fb2058b583472b4b733e08594 (diff)
downloadegit-cf12cbbba845bbaab24f312b481551915b319294.tar.gz
egit-cf12cbbba845bbaab24f312b481551915b319294.tar.xz
egit-cf12cbbba845bbaab24f312b481551915b319294.zip
History View: improve "enablement" calculation.
With the new command-based menu contributions implemented for the history view, we get lots of "Could not get the current input from the history view" messages in the log. This is because the enablement if calculated even if the history is not visible at all. This change does the calculation properly. Bug: 322255 Change-Id: I113532b98350434034564f03f9ab05627c4663e6 Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java43
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CheckoutCommitHandler.java12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java26
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareWithWorkingTreeHandler.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateBranchOnCommitHandler.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreatePatchHandler.java18
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateTagOnCommitHandler.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/ShowVersionsHandler.java12
9 files changed, 81 insertions, 77 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index 1551c3976..6de0f2b35 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -463,6 +463,13 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener {
.addRefsChangedListener(this);
}
+ /**
+ * @return the selection provider
+ */
+ public RevObjectSelectionProvider getSelectionProvider() {
+ return revObjectSelectionProvider;
+ }
+
private Runnable refschangedRunnable;
public void onRefsChanged(final RefsChangedEvent e) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java
index ed96eaa50..411692e55 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java
@@ -24,6 +24,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.jface.util.OpenStrategy;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -32,6 +33,7 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Tag;
import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.team.ui.history.IHistoryPage;
import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
import org.eclipse.ui.IEditorInput;
@@ -40,6 +42,7 @@ import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IReusableEditor;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
@@ -64,12 +67,7 @@ abstract class AbstractHistoryCommanndHandler extends AbstractHandler {
protected IStructuredSelection getSelection(ExecutionEvent event)
throws ExecutionException {
- ISelection selection;
- if (event != null)
- selection = HandlerUtil.getCurrentSelectionChecked(event);
- else
- selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage().getSelection();
+ ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection instanceof IStructuredSelection) {
return (IStructuredSelection) selection;
}
@@ -77,13 +75,7 @@ abstract class AbstractHistoryCommanndHandler extends AbstractHandler {
}
protected Object getInput(ExecutionEvent event) throws ExecutionException {
- IWorkbenchPart part;
- if (event != null)
- part = getPart(event);
- else
- part = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage().getActivePart();
-
+ IWorkbenchPart part = getPart(event);
if (!(part instanceof IHistoryView))
throw new ExecutionException(
UIText.AbstractHistoryCommanndHandler_NoInputMessage);
@@ -184,4 +176,29 @@ abstract class AbstractHistoryCommanndHandler extends AbstractHandler {
}
return tags;
}
+
+ protected GitHistoryPage getPage() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (window == null)
+ return null;
+ if (window.getActivePage() == null)
+ return null;
+ IWorkbenchPart part = window.getActivePage().getActivePart();
+ if (!(part instanceof IHistoryView))
+ return null;
+ IHistoryView view = (IHistoryView) part;
+ IHistoryPage page = view.getHistoryPage();
+ if (page instanceof GitHistoryPage)
+ return (GitHistoryPage) page;
+ return null;
+ }
+
+ protected IStructuredSelection getSelection(GitHistoryPage page) {
+ ISelection pageSelection = page.getSelectionProvider().getSelection();
+ if (pageSelection instanceof IStructuredSelection) {
+ return (IStructuredSelection) pageSelection;
+ } else
+ return new StructuredSelection();
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CheckoutCommitHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CheckoutCommitHandler.java
index 757fef497..dd33d6d27 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CheckoutCommitHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CheckoutCommitHandler.java
@@ -26,6 +26,7 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.egit.ui.internal.repository.tree.RefNode;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNodeType;
@@ -203,13 +204,10 @@ public class CheckoutCommitHandler extends AbstractHistoryCommanndHandler {
@Override
public boolean isEnabled() {
- try {
- IStructuredSelection sel = getSelection(null);
- return sel.size() == 1
- && sel.getFirstElement() instanceof RevCommit;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ GitHistoryPage page = getPage();
+ if (page == null)
return false;
- }
+ IStructuredSelection sel = getSelection(page);
+ return sel.size() == 1 && sel.getFirstElement() instanceof RevCommit;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java
index beba2e32a..f076fcdc5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareVersionsHandler.java
@@ -16,14 +16,13 @@ import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.egit.core.project.RepositoryMapping;
-import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.CompareUtils;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
/**
* Compare the file contents of two commits.
@@ -64,21 +63,14 @@ public class CompareVersionsHandler extends AbstractHistoryCommanndHandler {
@Override
public boolean isEnabled() {
- try {
- IWorkbenchPart part = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage().getActivePart();
- if (!(part instanceof IHistoryView))
- return false;
- IHistoryView view = (IHistoryView) part;
- if (!(view.getHistoryPage().getInput() instanceof IFile))
- return false;
- IStructuredSelection sel = getSelection(null);
- Object[] selected = sel.toArray();
- return selected.length == 2 && selected[0] instanceof RevCommit
- && selected[1] instanceof RevCommit;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ GitHistoryPage page = getPage();
+ if (page == null)
return false;
- }
+ if (!(page.getInput() instanceof IFile))
+ return false;
+ IStructuredSelection sel = getSelection(page);
+ Object[] selected = sel.toArray();
+ return selected.length == 2 && selected[0] instanceof RevCommit
+ && selected[1] instanceof RevCommit;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareWithWorkingTreeHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareWithWorkingTreeHandler.java
index 764b9c161..e802475ae 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareWithWorkingTreeHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CompareWithWorkingTreeHandler.java
@@ -15,9 +15,9 @@ import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.egit.core.project.RepositoryMapping;
-import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.CompareUtils;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
@@ -51,13 +51,11 @@ public class CompareWithWorkingTreeHandler extends
@Override
public boolean isEnabled() {
- try {
- int size = getSelection(null).size();
- return IFile.class.isAssignableFrom(getInput(null).getClass())
- && size == 1;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ GitHistoryPage page = getPage();
+ if (page == null)
return false;
- }
+ int size = getSelection(page).size();
+ return IFile.class.isAssignableFrom(page.getInput().getClass())
+ && size == 1;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateBranchOnCommitHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateBranchOnCommitHandler.java
index 8232a4e8f..f888d7d0f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateBranchOnCommitHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateBranchOnCommitHandler.java
@@ -12,9 +12,9 @@ import java.io.IOException;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.ValidationUtils;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
@@ -62,13 +62,10 @@ public class CreateBranchOnCommitHandler extends AbstractHistoryCommanndHandler
@Override
public boolean isEnabled() {
- try {
- IStructuredSelection sel = getSelection(null);
- return sel.size() == 1
- && sel.getFirstElement() instanceof RevCommit;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ GitHistoryPage page = getPage();
+ if (page == null)
return false;
- }
+ IStructuredSelection sel = getSelection(page);
+ return sel.size() == 1 && sel.getFirstElement() instanceof RevCommit;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreatePatchHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreatePatchHandler.java
index 58569fc24..bea7b4012 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreatePatchHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreatePatchHandler.java
@@ -12,8 +12,8 @@ import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.core.project.RepositoryMapping;
-import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.history.GitCreatePatchWizard;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -41,15 +41,13 @@ public class CreatePatchHandler extends AbstractHistoryCommanndHandler {
@Override
public boolean isEnabled() {
- try {
- IStructuredSelection selection = getSelection(null);
- if (selection.size() != 1)
- return false;
- RevCommit commit = (RevCommit) selection.getFirstElement();
- return (commit.getParentCount() == 1);
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ GitHistoryPage page = getPage();
+ if (page == null)
return false;
- }
+ IStructuredSelection selection = getSelection(page);
+ if (selection.size() != 1)
+ return false;
+ RevCommit commit = (RevCommit) selection.getFirstElement();
+ return (commit.getParentCount() == 1);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateTagOnCommitHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateTagOnCommitHandler.java
index 55084fc3e..b5c7bfbc9 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateTagOnCommitHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CreateTagOnCommitHandler.java
@@ -13,9 +13,9 @@ import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.op.TagOperation;
-import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.ValidationUtils;
import org.eclipse.egit.ui.internal.dialogs.CreateTagDialog;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.jgit.lib.Constants;
@@ -64,13 +64,10 @@ public class CreateTagOnCommitHandler extends AbstractHistoryCommanndHandler {
@Override
public boolean isEnabled() {
- try {
- IStructuredSelection sel = getSelection(null);
- return sel.size() == 1
- && sel.getFirstElement() instanceof RevCommit;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ GitHistoryPage page = getPage();
+ if (page == null)
return false;
- }
+ IStructuredSelection sel = getSelection(page);
+ return sel.size() == 1 && sel.getFirstElement() instanceof RevCommit;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/ShowVersionsHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/ShowVersionsHandler.java
index b00df2665..c161c6385 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/ShowVersionsHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/ShowVersionsHandler.java
@@ -25,6 +25,7 @@ import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.CompareUtils;
import org.eclipse.egit.ui.internal.EgitUiEditorUtils;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jgit.lib.ObjectId;
@@ -110,12 +111,11 @@ public class ShowVersionsHandler extends AbstractHistoryCommanndHandler {
@Override
public boolean isEnabled() {
- try {
- int size = getSelection(null).size();
- return size >= 1
- && IFile.class.isAssignableFrom(getInput(null).getClass());
- } catch (ExecutionException e) {
+ GitHistoryPage page = getPage();
+ if (page == null)
return false;
- }
+ int size = getSelection(page).size();
+ return size >= 1
+ && IFile.class.isAssignableFrom(page.getInput().getClass());
}
}

Back to the top