[EGIT PATCH 1/6] Create a selection handler for the revision graph.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This make it possible to associate content menu contributions
with selections in the history graph.

Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
---
 .../egit/ui/internal/history/GitHistoryPage.java   |   11 ++++-
 .../history/RevObjectSelectionProvider.java        |   48 ++++++++++++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/RevObjectSelectionProvider.java

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/GitHistoryPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/GitHistoryPage.java
index 9bcae19..6eaa6e4 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/GitHistoryPage.java
@@ -181,6 +181,11 @@ public class GitHistoryPage extends HistoryPage {
 	 */
 	private List<String> pathFilters;
 
+	/**
+	 * The selection provider tracks the selected revisions for the context menu
+	 */
+	private RevObjectSelectionProvider revObjectSelectionProvider;
+
 	@Override
 	public void createControl(final Composite parent) {
 		GridData gd;
@@ -211,6 +216,7 @@ public class GitHistoryPage extends HistoryPage {
 		layoutSashForm(graphDetailSplit, SPLIT_GRAPH);
 		layoutSashForm(revInfoSplit, SPLIT_INFO);
 
+		revObjectSelectionProvider = new RevObjectSelectionProvider();
 		popupMgr = new MenuManager(null, POPUP_ID);
 		attachCommitSelectionChanged();
 		createLocalToolbarActions();
@@ -221,7 +227,6 @@ public class GitHistoryPage extends HistoryPage {
 		attachContextMenu(graph.getControl());
 		attachContextMenu(commentViewer.getControl());
 		attachContextMenu(fileViewer.getControl());
-
 		layout();
 	}
 
@@ -229,7 +234,8 @@ public class GitHistoryPage extends HistoryPage {
 		popupMgr.add(new Separator());
 		popupMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
 		getSite().registerContextMenu(POPUP_ID, popupMgr,
-				getSite().getSelectionProvider());
+				revObjectSelectionProvider);
+		getSite().setSelectionProvider(revObjectSelectionProvider);
 	}
 
 	private void attachContextMenu(final Control c) {
@@ -299,6 +305,7 @@ public class GitHistoryPage extends HistoryPage {
 				c = (PlotCommit<?>) sel.getFirstElement();
 				commentViewer.setInput(c);
 				fileViewer.setInput(c);
+				revObjectSelectionProvider.setSelection(s);
 			}
 		});
 		commentViewer
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/RevObjectSelectionProvider.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/RevObjectSelectionProvider.java
new file mode 100644
index 0000000..c44b229
--- /dev/null
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/RevObjectSelectionProvider.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * See LICENSE for the full license text, also available.
+ *******************************************************************************/
+package org.spearce.egit.ui.internal.history;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+
+/**
+ * A selection provider for Git revision objects
+ */
+public class RevObjectSelectionProvider implements ISelectionProvider {
+
+	private List<ISelectionChangedListener> listeners = new ArrayList<ISelectionChangedListener>();
+
+	private ISelection selection;
+
+	public void addSelectionChangedListener(ISelectionChangedListener listener) {
+		listeners.add(listener);
+	}
+
+	public ISelection getSelection() {
+		return selection;
+	}
+
+	public void removeSelectionChangedListener(
+			ISelectionChangedListener listener) {
+		listeners.remove(listener);
+	}
+
+	public void setSelection(ISelection selection) {
+		this.selection = selection;
+		SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
+		for (ISelectionChangedListener l : listeners) {
+			l.selectionChanged(event);
+		}
+	}
+
+}
-- 
1.5.6.2.220.g44701

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux