git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[EGIT PATCH 03/10] Update compare window immediately

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
May 7, 2007, 21:29 UTC
Message-ID
<20070507212926.21546.73538.stgit@lathund.dewire.com>
In-Reply-To
<20070507212636.21546.29280.stgit@lathund.dewire.com>

Compute the commit diff for the selected revision in the history view immediately when one version is selected if selection is made with the left mouse button and a compare window is already open. Thanks to the way git data structures are designed the diff is usually instantenous.

We can't have it this way in the long run. Figure out something better, like adding an icon to the history view for selecting behaviour. Another ugly hack is the way I detect which mouse button was clicked, if any so that right-clicking on a history item does not cause the diff to be changed.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/egit/ui/GitHistoryPage.java    |   47 +++++++++++++++++++----
 1 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
index 8be23ec..4b437a6 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java
@@ -18,6 +18,7 @@ package org.spearce.egit.ui;
 
 import java.io.IOException;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 import org.eclipse.compare.CompareConfiguration;
@@ -42,6 +43,8 @@ import org.eclipse.jface.viewers.TableLayout;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Image;
@@ -83,6 +86,8 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 
 	private IFileRevision[] fileRevisions;
 
+	protected boolean hintShowDiffNow;
+
 	public GitHistoryPage(Object object) {
 		setInput(object);
 	}
@@ -114,6 +119,20 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 				"Compare");
 		final GitCompareRevisionAction compareActionPrev = new GitCompareRevisionAction(
 				"Show commit");
+		tree.addMouseListener(new MouseListener() {
+		
+			public void mouseUp(MouseEvent e) {
+			}
+		
+			public void mouseDown(MouseEvent e) {
+				hintShowDiffNow = e.button==1;
+			}
+		
+			public void mouseDoubleClick(MouseEvent e) {
+			}
+		
+		});
+
 		tree.addSelectionListener(new SelectionAdapter() {
 			public void widgetSelected(SelectionEvent e) {
 				// update the current
@@ -130,16 +149,25 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 				GitProvider provider = (GitProvider)RepositoryProvider
 						.getProvider(project);
 				RepositoryMapping repositoryMapping = provider.getData().getRepositoryMapping(project);
-				ObjectId parentId = (ObjectId)((GitFileRevision)selection2[0]).getCommit().getParentIds().get(0);
 				try {
-					if (selection2.length == 1) {
-						Commit parent = repositoryMapping.getRepository().mapCommit(parentId);
-						IFileRevision previous = new GitFileRevision(parent,
-								((GitFileRevision)selection2[0]).getResource(),
-								((GitFileRevision)selection2[0]).getCount()+1);
-//						compareActionPrev.setCurrentFileRevision(selection2[0]);
-						compareActionPrev.setCurrentFileRevision(null);
-						compareActionPrev.selectionChanged(new StructuredSelection(new IFileRevision[] {selection2[0], previous}));
+					if (selection2.length == 1 && hintShowDiffNow) {
+						List parentIds = ((GitFileRevision)selection2[0]).getCommit().getParentIds();
+						if (parentIds.size() > 0) {
+							ObjectId parentId = (ObjectId)parentIds.get(0);
+							Commit parent = repositoryMapping.getRepository().mapCommit(parentId);
+							IFileRevision previous = new GitFileRevision(parent,
+									((GitFileRevision)selection2[0]).getResource(),
+									((GitFileRevision)selection2[0]).getCount()+1);
+							compareActionPrev.setCurrentFileRevision(null);
+							compareActionPrev.selectionChanged(new StructuredSelection(new IFileRevision[] {selection2[0], previous}));
+							System.out.println("detail="+e.detail);
+							tree.getDisplay().asyncExec(new Runnable() {
+								public void run() {
+									if (GitCompareRevisionAction.findReusableCompareEditor(GitHistoryPage.this.getSite().getPage()) != null)
+										compareActionPrev.run();
+								}
+							});
+						}
 					} else {
 						compareActionPrev.setCurrentFileRevision(null);
 						compareActionPrev.selectionChanged(new StructuredSelection(new IFileRevision[0]));
@@ -148,6 +176,7 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 					// TODO Auto-generated catch block
 					e1.printStackTrace();
 				}
+				hintShowDiffNow = false;
 			}
 		});
 		compareAction.setPage(this);
Previous: Robin RosenbergNext: Robin Rosenberg
Message 4 of 14 in “[EGIT 00/10] This weeks Eclipse patches”
  1. Robin RosenbergMay 7, 2007
  2. 01/10 Fixes due to changes in the Eclipse Team APIRobin Rosenberg, May 7, 2007
  3. 02/10 Recursion and update of all elements regardless of need.Robin Rosenberg, May 7, 2007
  4. 03/10 Update compare window immediatelyRobin Rosenberg, May 7, 2007
  5. 04/10 Bug: Do not crash when showing diff for first version of a fileRobin Rosenberg, May 7, 2007
  6. 05/10 Speed up ObjectId a little.Robin Rosenberg, May 7, 2007
  7. 06/10 Create a generic history walkerRobin Rosenberg, May 7, 2007
  8. 07/10 Cache pack index fullyRobin Rosenberg, May 7, 2007
  9. 08/10 Use ObjectId[] instead of List for parentsRobin Rosenberg, May 7, 2007
  10. 09/10 Run history refresh in backgroundRobin Rosenberg, May 7, 2007
  11. 10/10 Enable a tooltip in the history viewRobin Rosenberg, May 7, 2007
  12. Eclipse support status (was: Re: [EGIT 00/10] This weeks Eclipse patches)Grzegorz Kulewski, May 7, 2007
  13. Shawn O. PearceMay 8, 2007
  14. Shawn O. PearceMay 8, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.