Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-07-30 16:07:50 -0400
committerMichael Keppler2019-08-21 07:07:10 -0400
commit9a0e6920c9e134d8a7848ca289645e79f9e4d6fa (patch)
tree52d7dc0c155a92d515b667af544fc05ee98dc79c /org.eclipse.egit.ui/src/org/eclipse
parentf9c82928f45f5e9ab33ab04a08904e1b6d2ebfa6 (diff)
downloadegit-9a0e6920c9e134d8a7848ca289645e79f9e4d6fa.tar.gz
egit-9a0e6920c9e134d8a7848ca289645e79f9e4d6fa.tar.xz
egit-9a0e6920c9e134d8a7848ca289645e79f9e4d6fa.zip
History: keep commit selected if branches to show change
Keep the currently selected commit selected when the user toggles first-parent, show all branches, show additional refs, or the follow renames settings. Additionally, try to avoid jumping around in the history. Previously, the code simply tried to keep the table at the current top row index. But that doesn't really help when the branches to show change. (It may have been fine for incremental loading.) Newly, try to keep the current top commit shown by name. For incremental loading this gives the same result; for other use cases it reduces the jumping around quite a bit. Change-Id: Id20ba2bf97fccb60fdba629240e1681489871fb5 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java66
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java54
2 files changed, 90 insertions, 30 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
index b5b55e0ab..b262c19a4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
@@ -7,7 +7,7 @@
* Copyright (C) 2011-2012, Matthias Sohn <matthias.sohn@sap.com>
* Copyright (C) 2012-2013, Robin Stocker <robin@nibor.org>
* Copyright (C) 2012, Daniel Megert <daniel_megert@ch.ibm.com>
- * Copyright (C) 2016, Thomas Wolf <thomas.wolf@paranor.ch>
+ * Copyright (C) 2016-2019, Thomas Wolf <thomas.wolf@paranor.ch>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -147,6 +147,8 @@ class CommitGraphTable {
private SWTCommitList allCommits;
+ private SWTCommit[] allCommitsArray;
+
private int allCommitsLength = 0;
// used for resolving PlotCommit objects by ids
@@ -270,6 +272,7 @@ class CommitGraphTable {
@Override
public void widgetDisposed(final DisposeEvent e) {
clipboard.dispose();
+ allCommitsArray = null;
}
});
@@ -422,45 +425,78 @@ class CommitGraphTable {
void setInput(final RevFlag hFlag, final SWTCommitList list,
final SWTCommit[] asArray, HistoryPageInput input, boolean keepPosition) {
- int topIndex = -1;
+ Table t = table.getTable();
+ String topCommitName = null;
if (keepPosition) {
- topIndex = table.getTable().getTopIndex();
+ int i = t.getTopIndex();
+ if (i >= 0 && i < t.getItemCount()
+ && i < allCommitsLength
+ && allCommitsArray != null) {
+ // We have a virtual table, so item.getData() may return null...
+ topCommitName = allCommitsArray[i].getId().name();
+ }
}
setHistoryPageInput(input);
final SWTCommitList oldList = allCommits;
highlight = hFlag;
allCommits = list;
int newAllCommitsLength = asArray == null ? 0 : asArray.length;
- table.setInput(asArray);
+ int topIndex = -1;
if (newAllCommitsLength > 0) {
if (oldList != list || allCommitsLength < newAllCommitsLength) {
- initCommitsMap(asArray);
+ topIndex = initCommitsMap(asArray, topCommitName);
+ } else {
+ topIndex = findCommit(asArray, topCommitName);
+ }
+ }
+ allCommitsArray = asArray;
+ allCommitsLength = newAllCommitsLength;
+ table.setInput(asArray);
+ if (newAllCommitsLength > 0) {
+ if (commitToShow != null) {
+ selectCommit(commitToShow);
+ }
+ if (keepPosition && topIndex >= 0) {
+ t.setTopIndex(topIndex);
}
} else {
- table.getTable().deselectAll();
+ t.deselectAll();
// Fire an event
table.setSelection(table.getSelection());
}
- allCommitsLength = newAllCommitsLength;
- if (commitToShow != null) {
- selectCommit(commitToShow);
- }
- if (keepPosition) {
- table.getTable().setTopIndex(topIndex);
- }
}
void setHistoryPageInput(HistoryPageInput input) {
this.input = input;
}
- private void initCommitsMap(SWTCommit[] asArray) {
+ private int initCommitsMap(SWTCommit[] asArray, String topName) {
+ int topIndex = -1;
commitsMap = new HashMap<>();
for (SWTCommit commit : asArray) {
if (commit != null) {
- commitsMap.put(commit.getId().name(), commit);
+ String name = commit.getId().name();
+ commitsMap.put(name, commit);
+ if (name.equals(topName)) {
+ topIndex = commitsMap.size() - 1;
+ }
+ }
+ }
+ return topIndex;
+ }
+
+ private int findCommit(SWTCommit[] asArray, String topName) {
+ int index = 0;
+ for (SWTCommit commit : asArray) {
+ if (commit != null) {
+ String name = commit.getId().name();
+ if (name.equals(topName)) {
+ return index;
+ }
}
+ index++;
}
+ return -1;
}
private void createColumns(Table rawTable) {
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 479632c30..6b87ed98b 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
@@ -516,7 +516,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
@Override
void apply(boolean value) {
- historyPage.refresh();
+ historyPage.refresh(historyPage.selectedCommit());
}
};
showAllBranchesAction.setImageDescriptor(UIIcons.BRANCH);
@@ -554,7 +554,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
historyPage.saveStoreIfNeeded();
}
- historyPage.refresh();
+ historyPage.refresh(historyPage.selectedCommit());
}
/**
@@ -573,7 +573,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
});
}
- historyPage.refresh();
+ historyPage.refresh(historyPage.selectedCommit());
}
@Override
@@ -626,7 +626,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
@Override
void apply(boolean value) {
- historyPage.refresh();
+ historyPage.refresh(historyPage.selectedCommit());
}
};
actionsToDispose.add(showAdditionalRefsAction);
@@ -638,7 +638,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
UIText.GitHistoryPage_FollowRenames) {
@Override
void apply(boolean follow) {
- historyPage.refresh();
+ historyPage.refresh(historyPage.selectedCommit());
}
};
followRenamesAction.apply(followRenamesAction.isChecked());
@@ -1868,11 +1868,15 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
@Override
public void refresh() {
+ refresh(null);
+ }
+
+ private void refresh(RevCommit prevSelection) {
if (repoHasBeenRemoved(getCurrentRepo())) {
clearHistoryPage();
}
this.input = null;
- inputSet();
+ inputSet(prevSelection);
}
/**
@@ -1890,6 +1894,15 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
return graph.getTableView();
}
+ private RevCommit selectedCommit() {
+ IStructuredSelection selection = graph.getTableView()
+ .getStructuredSelection();
+ if (!selection.isEmpty()) {
+ return Adapters.adapt(selection.getFirstElement(), RevCommit.class);
+ }
+ return null;
+ }
+
@Override
public void onRefsChanged(final RefsChangedEvent e) {
if (input == null || e.getRepository() != input.getRepository())
@@ -1997,6 +2010,10 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
@Override
public boolean inputSet() {
+ return inputSet(null);
+ }
+
+ private boolean inputSet(RevCommit prevSelection) {
try {
if (trace)
GitTraceLocation.getTrace().traceEntry(
@@ -2130,15 +2147,22 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
return false;
}
- if (showHead)
- showHead(repo);
- if (showRef)
- showRef(ref, repo);
- if (showTag)
- showTag(ref, repo);
- if (selection != null)
- graph.selectCommitStored(selection);
-
+ if (prevSelection != null) {
+ graph.selectCommitStored(prevSelection);
+ } else {
+ if (showHead) {
+ showHead(repo);
+ }
+ if (showRef) {
+ showRef(ref, repo);
+ }
+ if (showTag) {
+ showTag(ref, repo);
+ }
+ if (selection != null) {
+ graph.selectCommitStored(selection);
+ }
+ }
return true;
} finally {
if (trace)

Back to the top