Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-06-23 20:22:17 +0000
committerMatthias Sohn2016-08-25 14:52:57 +0000
commitbc712de04c05c0e7746ace56a37e51acbaa64cfd (patch)
tree6d6856b190da70a370a9620273ddf989285d5b8c
parente6209ce05aa4224239977d81123acab7041ca6a5 (diff)
downloadegit-bc712de04c05c0e7746ace56a37e51acbaa64cfd.tar.gz
egit-bc712de04c05c0e7746ace56a37e51acbaa64cfd.tar.xz
egit-bc712de04c05c0e7746ace56a37e51acbaa64cfd.zip
GitHistoryPage: move the search widget into the toolbar
This necessitates being more careful with global action registrations. These previously used updateActionBars(), which updates also the toolbars, which messes up when the focus changes from the history page to the search bar's text input: one needed two clicks to set the focus on the search bar. Resolved by updating only the global menu manager when we changed only global action handlers. ToolbarManager has a number of problems correctly re-displaying a changing toolbar with dynamic items. In particular, it is not sufficient to only update the ToolbarManager. It is in this case necessary to use updateActionBars() indeed, which does much more and manages to re-layout and re-position the toolbar properly. However, it messes up with the background of the Composite containing the ToolBar. This was worked around by some ugly back-and-forth with the focus. Some more focus juggling had to be done to get the history view (and thus its status line manager) to activate when the focus was elsewhere and the user then clicked directly into the search bar, thus focusing it. The search result indicator ("1/n") had to be moved out of the toolbar itself. Instead there's now a listener interface that gets handed that text and that then can display it as it sees fit. In this implementation, it's simply written to the status bar. I also had experimented with using a tooltip, but that becomes a hassle very quickly. And tooltips belong to clan MacLeod: there can be only one. Bug: 496278 Change-Id: I5adc521d19b0b99ee98bc573a807c72ba7d5caed Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java8
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java34
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindToolbar.java459
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java325
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/HistoryPageInput.java34
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties4
9 files changed, 689 insertions, 187 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index 5ac0b7680..77122751a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -508,7 +508,10 @@ public class UIText extends NLS {
public static String GitHistoryPage_FindMenuLabel;
/** */
- public static String GitHistoryPage_FindTooltip;
+ public static String GitHistoryPage_FindShowTooltip;
+
+ /** */
+ public static String GitHistoryPage_FindHideTooltip;
/** */
public static String GitHistoryPage_FolderType;
@@ -1963,6 +1966,9 @@ public class UIText extends NLS {
public static String HistoryPage_findbar_find;
/** */
+ public static String HistoryPage_findbar_find_msg;
+
+ /** */
public static String HistoryPage_findbar_next;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java
index cf32020eb..c22fbbb33 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java
@@ -351,7 +351,7 @@ public class CommitFileDiffViewer extends TableViewer {
ActionFactory.SELECT_ALL.getId(), null);
pageSite.getActionBars().setGlobalActionHandler(
ActionFactory.COPY.getId(), null);
- pageSite.getActionBars().updateActionBars();
+ pageSite.getActionBars().getMenuManager().update(false);
}
@Override
@@ -361,7 +361,7 @@ public class CommitFileDiffViewer extends TableViewer {
ActionFactory.SELECT_ALL.getId(), selectAll);
pageSite.getActionBars().setGlobalActionHandler(
ActionFactory.COPY.getId(), copy);
- pageSite.getActionBars().updateActionBars();
+ pageSite.getActionBars().getMenuManager().update(false);
}
});
}
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 11d4a7592..b5b92e828 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
@@ -283,7 +283,7 @@ class CommitGraphTable {
ActionFactory.SELECT_ALL.getId(), null);
site.getActionBars().setGlobalActionHandler(
ActionFactory.COPY.getId(), null);
- site.getActionBars().updateActionBars();
+ site.getActionBars().getMenuManager().update(false);
}
@Override
@@ -292,7 +292,7 @@ class CommitGraphTable {
ActionFactory.SELECT_ALL.getId(), selectAll);
site.getActionBars().setGlobalActionHandler(
ActionFactory.COPY.getId(), copy);
- site.getActionBars().updateActionBars();
+ site.getActionBars().getMenuManager().update(false);
}
});
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java
index a9e7f24ae..13d0cd793 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java
@@ -202,7 +202,7 @@ class CommitMessageViewer extends HyperlinkSourceViewer {
ActionFactory.SELECT_ALL.getId(), null);
site.getActionBars().setGlobalActionHandler(
ActionFactory.COPY.getId(), null);
- site.getActionBars().updateActionBars();
+ site.getActionBars().getMenuManager().update(false);
}
@Override
@@ -211,7 +211,7 @@ class CommitMessageViewer extends HyperlinkSourceViewer {
ActionFactory.SELECT_ALL.getId(), selectAll);
site.getActionBars().setGlobalActionHandler(
ActionFactory.COPY.getId(), copy);
- site.getActionBars().updateActionBars();
+ site.getActionBars().getMenuManager().update(false);
}
});
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java
index 5b07e6f6c..decfd39f1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindResults.java
@@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jgit.revwalk.RevFlag;
import org.eclipse.jgit.revwalk.RevObject;
@@ -38,16 +39,28 @@ public class FindResults {
private boolean overflow;
- private final IFindListener listener;
+ private final CopyOnWriteArrayList<IFindListener> listeners = new CopyOnWriteArrayList<>();
/**
- * Creates a new results object notifying the given listener upon changes.
+ * Adds the given listener to be notified when search results are added or
+ * the results are cleared. Has no effect if the listener is already
+ * registered.
*
* @param listener
- * to notify
+ * to add
*/
- public FindResults(IFindListener listener) {
- this.listener = listener;
+ public void addFindListener(IFindListener listener) {
+ listeners.addIfAbsent(listener);
+ }
+
+ /**
+ * Removes the given listener if it was registered.
+ *
+ * @param listener
+ * to remove
+ */
+ public void removeFindListener(IFindListener listener) {
+ listeners.remove(listener);
}
/**
@@ -178,8 +191,13 @@ public class FindResults {
matchesMap.clear();
revObjList.clear();
keysArray = null;
+ boolean hadItems = matchesCount > 0;
matchesCount = 0;
- listener.cleared();
+ if (hadItems) {
+ for (IFindListener listener : listeners) {
+ listener.cleared();
+ }
+ }
}
/**
@@ -197,7 +215,9 @@ public class FindResults {
revObjList.add(revObj);
revObj.add(highlight);
keysArray = null;
- listener.itemAdded(matchIx, revObj);
+ for (IFindListener listener : listeners) {
+ listener.itemAdded(matchIx, revObj);
+ }
}
private Integer[] getkeysArray() {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindToolbar.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindToolbar.java
index eecf52164..e01ef44b9 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindToolbar.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FindToolbar.java
@@ -17,6 +17,7 @@ import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
@@ -24,8 +25,12 @@ import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevFlag;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.swt.SWT;
@@ -33,6 +38,7 @@ import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
@@ -44,11 +50,9 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
@@ -56,7 +60,6 @@ import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
-import org.eclipse.swt.widgets.Widget;
/**
* A toolbar for the history page.
@@ -66,6 +69,27 @@ import org.eclipse.swt.widgets.Widget;
* @see GitHistoryPage
*/
public class FindToolbar extends Composite {
+
+ /**
+ * Interface to receive status messages from the {@link FindToolbar}. The
+ * toolbar produces messages indicating a search result overflow, or the
+ * number of hits, or, when navigation among search results occurs, which
+ * entry is the current one.
+ */
+ public interface StatusListener {
+
+ /**
+ * Invoked whenever the {@link FindToolbar} produces a new message. The
+ * message may be empty.
+ *
+ * @param originator
+ * of the message
+ * @param text
+ * of the message
+ */
+ public void setMessage(FindToolbar originator, String text);
+ }
+
/**
* Preference value for searching all the fields
*/
@@ -88,6 +112,8 @@ public class FindToolbar extends Composite {
*/
private final FindResults findResults;
+ private IFindListener listener;
+
private IPersistentPreferenceStore store = (IPersistentPreferenceStore) Activator.getDefault().getPreferenceStore();
private List<Listener> eventList = new ArrayList<>();
@@ -98,11 +124,11 @@ public class FindToolbar extends Composite {
private Text patternField;
- private Button nextButton;
+ private ModifyListener patternModifyListener;
- private Button previousButton;
+ private Action findNextAction;
- private Label currentPositionLabel;
+ private Action findPreviousAction;
private String lastErrorPattern;
@@ -124,10 +150,6 @@ public class FindToolbar extends Composite {
private MenuItem referenceItem;
- private Image nextIcon;
-
- private Image previousIcon;
-
private Image allIcon;
private Image commitIdIcon;
@@ -145,6 +167,15 @@ public class FindToolbar extends Composite {
private int currentPosition = -1;
/**
+ * Id of a commit that shall be moved to initially if it is part of the
+ * search results. If not set, or there is no such commit in the search
+ * results, the first search result will be revealed.
+ */
+ private ObjectId preselect;
+
+ private CopyOnWriteArrayList<StatusListener> layoutListeners = new CopyOnWriteArrayList<>();
+
+ /**
* Creates the toolbar.
*
* @param parent
@@ -152,7 +183,10 @@ public class FindToolbar extends Composite {
*/
public FindToolbar(Composite parent) {
super(parent, SWT.NULL);
- findResults = new FindResults(createFindListener());
+ findResults = new FindResults();
+ listener = createFindListener();
+ findResults.addFindListener(listener);
+ setBackground(null);
createToolbar();
}
@@ -160,9 +194,6 @@ public class FindToolbar extends Composite {
errorBackgroundColor = new Color(getDisplay(), new RGB(255, 150, 150));
ResourceManager resourceManager = Activator.getDefault()
.getResourceManager();
- nextIcon = UIIcons.getImage(resourceManager, UIIcons.ELCL16_NEXT);
- previousIcon = UIIcons.getImage(resourceManager,
- UIIcons.ELCL16_PREVIOUS);
allIcon = UIIcons.getImage(resourceManager, UIIcons.SEARCH_COMMIT);
commitIdIcon = UIIcons.getImage(resourceManager,
UIIcons.ELCL16_ID);
@@ -173,31 +204,45 @@ public class FindToolbar extends Composite {
UIIcons.ELCL16_COMMITTER);
branchesIcon = UIIcons.getImage(resourceManager, UIIcons.BRANCHES);
GridLayout findLayout = new GridLayout();
- findLayout.marginHeight = 2;
- findLayout.marginWidth = 2;
+ findLayout.marginHeight = 0;
+ findLayout.marginBottom = 1;
+ findLayout.marginWidth = 0;
findLayout.numColumns = 5;
setLayout(findLayout);
- setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
patternField = new Text(this,
SWT.SEARCH | SWT.ICON_CANCEL | SWT.ICON_SEARCH);
GridData findTextData = new GridData(SWT.FILL, SWT.LEFT, true, false);
- findTextData.minimumWidth = 50;
+ findTextData.minimumWidth = 150;
patternField.setLayoutData(findTextData);
+ patternField.setMessage(UIText.HistoryPage_findbar_find_msg);
patternField.setTextLimit(100);
-
- nextButton = new Button(this, SWT.PUSH);
- nextButton.setImage(nextIcon);
- nextButton.setText(UIText.HistoryPage_findbar_next);
- nextButton.setToolTipText(UIText.FindToolbar_NextTooltip);
-
- previousButton = new Button(this, SWT.PUSH);
- previousButton.setImage(previousIcon);
- previousButton.setText(UIText.HistoryPage_findbar_previous);
- previousButton.setToolTipText(UIText.FindToolbar_PreviousTooltip);
-
- final ToolBar toolBar = new ToolBar(this, SWT.FLAT);
- new ToolItem(toolBar, SWT.SEPARATOR);
+ patternField.setFont(JFaceResources.getDialogFont());
+ ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL);
+ findNextAction = new Action() {
+ @Override
+ public void run() {
+ findNext();
+ }
+ };
+ findNextAction.setImageDescriptor(UIIcons.ELCL16_NEXT);
+ findNextAction.setText(UIText.HistoryPage_findbar_next);
+ findNextAction.setToolTipText(UIText.FindToolbar_NextTooltip);
+ findNextAction.setEnabled(false);
+ manager.add(findNextAction);
+ findPreviousAction = new Action() {
+ @Override
+ public void run() {
+ findPrevious();
+ }
+ };
+ findPreviousAction.setImageDescriptor(UIIcons.ELCL16_PREVIOUS);
+ findPreviousAction.setText(UIText.HistoryPage_findbar_previous);
+ findPreviousAction.setToolTipText(UIText.FindToolbar_PreviousTooltip);
+ findPreviousAction.setEnabled(false);
+ manager.add(findPreviousAction);
+ final ToolBar toolBar = manager.createControl(this);
prefsDropDown = new ToolItem(toolBar, SWT.DROP_DOWN);
prefsMenu = new Menu(getShell(), SWT.POP_UP);
@@ -251,93 +296,39 @@ public class FindToolbar extends Composite {
}
});
- currentPositionLabel = new Label(this, SWT.NULL);
- GridData totalLabelData = new GridData();
- totalLabelData.horizontalAlignment = SWT.FILL;
- totalLabelData.grabExcessHorizontalSpace = true;
- currentPositionLabel.setLayoutData(totalLabelData);
- currentPositionLabel.setAlignment(SWT.RIGHT);
- currentPositionLabel.setText(""); //$NON-NLS-1$
-
- patternField.addModifyListener(new ModifyListener() {
+ patternModifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
final FindToolbarJob finder = createFinder();
- finder.setUser(true);
+ finder.setUser(false);
finder.schedule(200);
}
- });
+ };
+
+ patternField.addModifyListener(patternModifyListener);
patternField.addSelectionListener(new SelectionAdapter() {
+
@Override
public void widgetDefaultSelected(SelectionEvent e) {
if (e.detail != SWT.ICON_CANCEL
&& !patternField.getText().isEmpty()) {
// ENTER or the search icon clicked
final FindToolbarJob finder = createFinder();
- finder.setUser(true);
+ finder.setUser(false);
finder.schedule();
}
}
});
- final Listener findButtonsListener = new Listener() {
- @Override
- public void handleEvent(Event event) {
- if (patternField.getText().length() > 0
- && findResults.size() == 0) {
- // If the toolbar was cleared and has a pattern typed,
- // then we redo the find with the new table data.
- final FindToolbarJob finder = createFinder();
- finder.setUser(true);
- finder.schedule();
- patternField.setSelection(0, 0);
- } else {
- int currentIx = historyTable.getSelectionIndex();
- int newIx = -1;
- if (event.widget == nextButton) {
- newIx = findResults.getIndexAfter(currentIx);
- if (newIx == -1) {
- newIx = findResults.getFirstIndex();
- }
- } else {
- newIx = findResults.getIndexBefore(currentIx);
- if (newIx == -1) {
- newIx = findResults.getLastIndex();
- }
- }
- sendEvent(event.widget, newIx);
-
- String current = null;
- currentPosition = findResults.getMatchNumberFor(newIx);
- if (currentPosition == -1) {
- current = "-"; //$NON-NLS-1$
- } else {
- current = String.valueOf(currentPosition);
- }
- currentPositionLabel
- .setText(current + '/' + findResults.size());
- }
- }
- };
- nextButton.addListener(SWT.Selection, findButtonsListener);
- previousButton.addListener(SWT.Selection, findButtonsListener);
-
patternField.addKeyListener(new KeyAdapter() {
- private Event event = new Event();
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ARROW_DOWN) {
- if (nextButton.isEnabled()) {
- event.widget = nextButton;
- findButtonsListener.handleEvent(event);
- }
+ findNext();
} else if (e.keyCode == SWT.ARROW_UP) {
- if (previousButton.isEnabled()) {
- event.widget = previousButton;
- findButtonsListener.handleEvent(event);
- }
+ findPrevious();
}
}
});
@@ -382,16 +373,167 @@ public class FindToolbar extends Composite {
@Override
public void widgetDisposed(DisposeEvent e) {
+ findResults.removeFindListener(listener);
+ findResults.clear();
+ listener = null;
if (job != null) {
job.cancel();
job = null;
}
prefsMenu.dispose();
errorBackgroundColor.dispose();
+ if (historyTable != null && !historyTable.isDisposed()) {
+ historyTable.clearAll();
+ }
}
});
}
+ /**
+ * Defines the commit to be set initially. If {@code null} or the search
+ * results do not contain such a commit, the first search result will be
+ * revealed.
+ *
+ * @param commitId
+ * to reveal
+ */
+ public void setPreselect(ObjectId commitId) {
+ preselect = commitId;
+ }
+
+ @Override
+ public boolean setFocus() {
+ return patternField.setFocus();
+ }
+
+ /**
+ * Sets the text of the widget's search text field, and optionally triggers
+ * a search.
+ *
+ * @param text
+ * to set
+ * @param search
+ * if {@code true}, triggers a search after having set the text
+ */
+ public void setText(String text, boolean search) {
+ if (!search) {
+ patternField.removeModifyListener(patternModifyListener);
+ }
+ patternField.setText(text);
+ if (!search) {
+ patternField.addModifyListener(patternModifyListener);
+ }
+ }
+
+ /**
+ * Sets the text of the widget's search text field without triggering a
+ * search.
+ *
+ * @param text
+ * to set
+ */
+ public void setText(String text) {
+ setText(text, false);
+ }
+
+ /**
+ * Retrieves the current text in the widget's search text field.
+ *
+ * @return the text
+ */
+ public String getText() {
+ return patternField.getText();
+ }
+
+ @Override
+ public void addListener(int evtType, Listener mouseListener) {
+ patternField.addListener(evtType, mouseListener);
+ }
+
+ @Override
+ public void removeListener(int evtType, Listener mouseListener) {
+ patternField.removeListener(evtType, mouseListener);
+ }
+
+ @Override
+ public void addKeyListener(KeyListener keyListener) {
+ patternField.addKeyListener(keyListener);
+ }
+
+ @Override
+ public void removeKeyListener(KeyListener keyListener) {
+ patternField.removeKeyListener(keyListener);
+ }
+
+ /**
+ * Adds the given listener to the widget, if it hasn't been added yet.
+ *
+ * @param layoutListener
+ * to add
+ */
+ public void addStatusListener(StatusListener layoutListener) {
+ layoutListeners.addIfAbsent(layoutListener);
+ }
+
+ /**
+ * Removes the given listener if it had been added.
+ *
+ * @param layoutListener
+ * to remove
+ */
+ public void removeStatusListener(StatusListener layoutListener) {
+ layoutListeners.remove(layoutListener);
+ }
+
+ private void notifyStatus(String text) {
+ for (StatusListener l : layoutListeners) {
+ l.setMessage(this, text);
+ }
+ }
+
+ private void findNext() {
+ find(true);
+ }
+
+ private void findPrevious() {
+ find(false);
+ }
+
+ private void find(boolean next) {
+ if (patternField.getText().length() > 0 && findResults.size() == 0) {
+ // If the toolbar was cleared and has a pattern typed,
+ // then we redo the find with the new table data.
+ final FindToolbarJob finder = createFinder();
+ finder.setUser(false);
+ finder.schedule();
+ patternField.setSelection(0, 0);
+ } else {
+ int currentIx = historyTable.getSelectionIndex();
+ int newIx = -1;
+ if (next) {
+ newIx = findResults.getIndexAfter(currentIx);
+ if (newIx == -1) {
+ newIx = findResults.getFirstIndex();
+ }
+ } else {
+ newIx = findResults.getIndexBefore(currentIx);
+ if (newIx == -1) {
+ newIx = findResults.getLastIndex();
+ }
+ }
+ notifyListeners(newIx);
+
+ String current = null;
+ currentPosition = findResults.getMatchNumberFor(newIx);
+ if (currentPosition == -1) {
+ current = "-"; //$NON-NLS-1$
+ } else {
+ current = String.valueOf(currentPosition);
+ }
+ notifyStatus(current + '/' + findResults.size());
+ }
+ }
+
private MenuItem createFindInMenuItem() {
final MenuItem menuItem = new MenuItem(prefsMenu, SWT.RADIO);
menuItem.addSelectionListener(new SelectionAdapter() {
@@ -486,8 +628,10 @@ public class FindToolbar extends Composite {
@Override
public void run() {
- if (myJob != job) {
- // Job superseded by another one
+ if (myJob != job
+ || myJob.fileRevisions != fileRevisions) {
+ // Job superseded by another one; or input
+ // changed
return;
}
if (!isDisposed()) {
@@ -515,6 +659,9 @@ public class FindToolbar extends Composite {
// this may cause a FindBugs warning, but
// copying the array is probably not a good
// idea
+ if (job != null) {
+ job.cancel();
+ }
this.fileRevisions = commitArray;
this.historyTable = historyTable;
findResults.setHighlightFlag(hFlag);
@@ -522,44 +669,44 @@ public class FindToolbar extends Composite {
private void findCompletionUpdate(String pattern, boolean overflow) {
int total = findResults.size();
+ String label;
if (total > 0) {
String position = (currentPosition < 0) ? "1" //$NON-NLS-1$
: Integer.toString(currentPosition);
if (overflow) {
- currentPositionLabel.setText(UIText.HistoryPage_findbar_exceeded
- + ' ' + position + '/' + total);
+ label = UIText.HistoryPage_findbar_exceeded + ' ' + position
+ + '/' + total;
} else {
- currentPositionLabel.setText(position + '/' + total);
+ label = position + '/' + total;
}
if (currentPosition < 0) {
currentPosition = 1;
int ix = findResults.getFirstIndex();
- sendEvent(null, ix);
+ notifyListeners(ix);
}
patternField.setBackground(null);
- nextButton.setEnabled(true);
- previousButton.setEnabled(true);
+ findNextAction.setEnabled(total > 1);
+ findPreviousAction.setEnabled(total > 1);
lastErrorPattern = null;
} else {
currentPosition = -1;
if (pattern.length() > 0) {
patternField.setBackground(errorBackgroundColor);
- currentPositionLabel
- .setText(UIText.HistoryPage_findbar_notFound);
+ label = UIText.HistoryPage_findbar_notFound;
// Don't keep beeping every time if the user is deleting
// a long not found pattern
if (lastErrorPattern == null
|| !lastErrorPattern.startsWith(pattern)) {
getDisplay().beep();
- nextButton.setEnabled(false);
- previousButton.setEnabled(false);
+ findNextAction.setEnabled(false);
+ findPreviousAction.setEnabled(false);
}
lastErrorPattern = pattern;
} else {
patternField.setBackground(null);
- currentPositionLabel.setText(""); //$NON-NLS-1$
- nextButton.setEnabled(false);
- previousButton.setEnabled(false);
+ label = ""; //$NON-NLS-1$
+ findNextAction.setEnabled(false);
+ findPreviousAction.setEnabled(false);
lastErrorPattern = null;
}
}
@@ -567,19 +714,21 @@ public class FindToolbar extends Composite {
if (overflow) {
Display display = getDisplay();
- currentPositionLabel.setForeground(display
- .getSystemColor(SWT.COLOR_RED));
display.beep();
- } else {
- currentPositionLabel.setForeground(null);
}
+ notifyStatus(label);
}
/**
* Clears the toolbar.
*/
void clear() {
- patternField.setBackground(null);
+ if (!isDisposed()) {
+ patternField.setBackground(null);
+ if (patternField.getText().length() > 0) {
+ patternField.selectAll();
+ }
+ }
lastErrorPattern = null;
if (job != null) {
@@ -588,20 +737,18 @@ public class FindToolbar extends Composite {
}
findResults.clear();
-
- if (patternField.getText().length() > 0) {
- patternField.selectAll();
- }
}
- private void sendEvent(Widget widget, int index) {
- Event event = new Event();
- event.type = SWT.Selection;
- event.index = index;
- event.widget = widget;
- event.data = fileRevisions[index];
- for (Listener listener : eventList) {
- listener.handleEvent(event);
+ private void notifyListeners(int index) {
+ if (index >= 0) {
+ Event event = new Event();
+ event.type = SWT.Selection;
+ event.index = index;
+ event.widget = this;
+ event.data = fileRevisions[index];
+ for (Listener toNotify : eventList) {
+ toNotify.handleEvent(event);
+ }
}
}
@@ -609,11 +756,21 @@ public class FindToolbar extends Composite {
* Adds a selection event listener. The toolbar generates events when it
* selects an item in the history table
*
- * @param listener
+ * @param selectionListener
* the listener that will receive the event
*/
- void addSelectionListener(Listener listener) {
- eventList.add(listener);
+ public void addSelectionListener(Listener selectionListener) {
+ eventList.add(selectionListener);
+ }
+
+ /**
+ * Removes a selection listener if it had been added.
+ *
+ * @param selectionListener
+ * to remove
+ */
+ public void removeSelectionListener(Listener selectionListener) {
+ eventList.remove(selectionListener);
}
private IFindListener createFindListener() {
@@ -624,31 +781,46 @@ public class FindToolbar extends Composite {
private long lastUpdate = 0L;
@Override
- public void itemAdded(int index, RevObject rev) {
+ public void itemAdded(final int index, RevObject rev) {
long now = System.currentTimeMillis();
- if (now - lastUpdate > UPDATE_INTERVAL) {
+ if (preselect != null && preselect.equals(rev.getId())
+ || preselect == null && currentPosition < 0) {
+ currentPosition = findResults.getMatchNumberFor(index);
+ preselect = null;
+ getDisplay().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ notifyListeners(index);
+ }
+ });
+ }
+ if (now - lastUpdate > UPDATE_INTERVAL && !isDisposed()) {
final boolean firstUpdate = lastUpdate == 0L;
lastUpdate = now;
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
+ if (isDisposed()) {
+ return;
+ }
int total = findResults.size();
- currentPositionLabel.setForeground(null);
if (total > 0) {
+ String label;
if (currentPosition == -1) {
- currentPositionLabel.setText("-/" + total); //$NON-NLS-1$
+ label = "-/" + total; //$NON-NLS-1$
} else {
- currentPositionLabel.setText(
- Integer.toString(currentPosition)
- + '/' + total);
+ label = Integer.toString(currentPosition)
+ + '/' + total;
}
- nextButton.setEnabled(true);
- previousButton.setEnabled(true);
+ findNextAction.setEnabled(total > 1);
+ findPreviousAction.setEnabled(total > 1);
patternField.setBackground(null);
if (firstUpdate) {
historyTable.clearAll();
}
+ notifyStatus(label);
} else {
clear();
}
@@ -675,13 +847,16 @@ public class FindToolbar extends Composite {
private void clear() {
currentPosition = -1;
- currentPositionLabel.setText(""); //$NON-NLS-1$
- nextButton.setEnabled(false);
- previousButton.setEnabled(false);
- if (historyTable != null) {
+ if (!isDisposed()) {
+ findNextAction.setEnabled(false);
+ findPreviousAction.setEnabled(false);
+ notifyStatus(""); //$NON-NLS-1$
+ }
+ if (historyTable != null && !historyTable.isDisposed()) {
historyTable.clearAll();
}
}
};
}
+
}
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 2523b8922..6f6a575b4 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
@@ -8,7 +8,7 @@
* Copyright (C) 2012-2013 Robin Stocker <robin@nibor.org>
* Copyright (C) 2012, Fran├žois Rey <eclipse.org_@_francois_._rey_._name>
* Copyright (C) 2015, IBM Corporation (Dani Megert <daniel_megert@ch.ibm.com>)
- * Copyright (C) 2015, Thomas Wolf <thomas.wolf@paranor.ch>
+ * Copyright (C) 2015, 2016 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 v1.0
@@ -49,6 +49,7 @@ import org.eclipse.egit.ui.internal.commit.DiffStyleRangeFormatter;
import org.eclipse.egit.ui.internal.commit.DiffViewer;
import org.eclipse.egit.ui.internal.dialogs.HyperlinkSourceViewer;
import org.eclipse.egit.ui.internal.dialogs.HyperlinkTokenScanner;
+import org.eclipse.egit.ui.internal.history.FindToolbar.StatusListener;
import org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode;
import org.eclipse.egit.ui.internal.repository.tree.FileNode;
import org.eclipse.egit.ui.internal.repository.tree.FolderNode;
@@ -56,14 +57,16 @@ import org.eclipse.egit.ui.internal.repository.tree.RefNode;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
import org.eclipse.egit.ui.internal.repository.tree.TagNode;
import org.eclipse.egit.ui.internal.trace.GitTraceLocation;
-import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ControlContribution;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.bindings.keys.SWTKeySupport;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
@@ -94,6 +97,7 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.diff.DiffConfig;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
@@ -132,6 +136,9 @@ import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
@@ -144,10 +151,12 @@ import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.team.ui.history.HistoryPage;
import org.eclipse.team.ui.history.IHistoryView;
+import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.editors.text.EditorsUI;
@@ -307,6 +316,11 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
createActions();
}
+ private static String formatAccelerator(int accelerator) {
+ return SWTKeySupport.getKeyFormatterForPlatform().format(
+ SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
+ }
+
private void createActions() {
createFindToolbarAction();
createRefreshAction();
@@ -333,24 +347,49 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
private void createFindToolbarAction() {
findAction = new Action(UIText.GitHistoryPage_FindMenuLabel,
UIIcons.ELCL16_FIND) {
+
@Override
public void run() {
historyPage.store.setValue(
UIPreferences.RESOURCEHISTORY_SHOW_FINDTOOLBAR,
isChecked());
- if (historyPage.store.needsSaving())
+ if (historyPage.store.needsSaving()) {
try {
historyPage.store.save();
} catch (IOException e) {
Activator.handleError(e.getMessage(), e, false);
}
- historyPage.layout();
+ }
+ historyPage.searchBar.setVisible(isChecked());
}
+
+ @Override
+ public void setChecked(boolean checked) {
+ super.setChecked(checked);
+ int accelerator = getAccelerator();
+ if (checked) {
+ setToolTipText(
+ NLS.bind(UIText.GitHistoryPage_FindHideTooltip,
+ formatAccelerator(accelerator)));
+ } else {
+ setToolTipText(
+ NLS.bind(UIText.GitHistoryPage_FindShowTooltip,
+ formatAccelerator(accelerator)));
+ }
+ }
+
};
- findAction
- .setChecked(historyPage.store
- .getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_FINDTOOLBAR));
- findAction.setToolTipText(UIText.GitHistoryPage_FindTooltip);
+ // TODO: how not to hard-wire this?
+ findAction.setAccelerator(SWT.MOD1 | 'F');
+ findAction.setEnabled(false);
+ // Gets enabled once we have commits
+ boolean isChecked = historyPage.store
+ .getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_FINDTOOLBAR);
+ findAction.setChecked(isChecked);
+ historyPage.getSite().getActionBars().setGlobalActionHandler(
+ ActionFactory.FIND.getId(), findAction);
+ historyPage.getSite().getActionBars().getMenuManager()
+ .update(false);
}
private void createRefreshAction() {
@@ -698,9 +737,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
/** Viewer displaying file difference implied by {@link #graph}'s commit. */
private CommitFileDiffViewer fileViewer;
- /** Toolbar to find commits in the history view. */
- private FindToolbar findToolbar;
-
/** A label showing a warning icon */
private Composite warningComposite;
@@ -768,6 +804,9 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
private final HistoryPageRule pageSchedulingRule;
+ /** Toolbar to find commits in the history view. */
+ private SearchBar searchBar;
+
/**
* Determine if the input can be shown in this viewer.
*
@@ -816,6 +855,222 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
}
+ private interface ICommitsProvider {
+
+ Object getSearchContext();
+
+ SWTCommit[] getCommits();
+
+ RevFlag getHighlight();
+ }
+
+ private static class SearchBar extends ControlContribution {
+
+ private IActionBars bars;
+
+ private FindToolbar toolbar;
+
+ private Object searchContext;
+
+ private String lastText;
+
+ private ObjectId lastObjectId;
+
+ private Object lastSearchContext;
+
+ private ICommitsProvider provider;
+
+ private final CommitGraphTable graph;
+
+ private final IAction openCloseToggle;
+
+ /**
+ * "Go to next/previous" from the {@link FindToolbar} sends
+ * {@link SWT#Selection} events with the chosen {@link RevCommit} as
+ * data.
+ */
+ private final Listener selectionListener = new Listener() {
+
+ @Override
+ public void handleEvent(Event evt) {
+ final RevCommit commit = (RevCommit) evt.data;
+ lastObjectId = commit.getId();
+ graph.selectCommit(commit);
+ }
+ };
+
+ /**
+ * Listener to close the search bar on Ctrl/Cmd-F or on ESC.
+ */
+ private final KeyListener keyListener = new KeyAdapter() {
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ int key = SWTKeySupport.convertEventToUnmodifiedAccelerator(e);
+ if (key == openCloseToggle.getAccelerator() || key == SWT.ESC) {
+ setVisible(false);
+ e.doit = false;
+ }
+ }
+ };
+
+ /**
+ * Listener to display status messages from the asynchronous find. (Is
+ * called in the UI thread.)
+ */
+ private final StatusListener statusListener = new StatusListener() {
+
+ @Override
+ public void setMessage(FindToolbar originator, String text) {
+ IStatusLineManager status = bars.getStatusLineManager();
+ if (status != null) {
+ status.setMessage(text);
+ }
+ }
+ };
+
+ /**
+ * Listener to ensure that the history view is fully activated when the
+ * user clicks into the search bar's text widget. This makes sure our
+ * status manager gets activated and thus shows the status messages. We
+ * don't get a focus event when the user clicks in the field; and
+ * fiddling with the focus in a FocusListener could get hairy anyway.
+ */
+ private final Listener mouseListener = new Listener() {
+
+ private boolean hasFocus;
+
+ private boolean hadFocusOnMouseDown;
+
+ @Override
+ public void handleEvent(Event e) {
+ switch (e.type) {
+ case SWT.FocusIn:
+ toolbar.getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ hasFocus = true;
+ }
+ });
+
+ break;
+ case SWT.FocusOut:
+ hasFocus = false;
+ break;
+ case SWT.MouseDown:
+ hadFocusOnMouseDown = hasFocus;
+ break;
+ case SWT.MouseUp:
+ if (!hadFocusOnMouseDown) {
+ graph.getControl().setFocus();
+ toolbar.setFocus();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ };
+
+ public SearchBar(String id, CommitGraphTable graph,
+ IAction openCloseAction, IActionBars bars) {
+ super(id);
+ super.setVisible(false);
+ this.graph = graph;
+ this.openCloseToggle = openCloseAction;
+ this.bars = bars;
+ }
+
+ private void beforeHide() {
+ lastText = toolbar.getText();
+ lastSearchContext = searchContext;
+ statusListener.setMessage(toolbar, ""); //$NON-NLS-1$
+ // It will be disposed by the IToolBarManager
+ toolbar = null;
+ openCloseToggle.setChecked(false);
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ if (visible != isVisible()) {
+ if (!visible) {
+ beforeHide();
+ }
+ super.setVisible(visible);
+ // Update the toolbar. Will dispose our FindToolbar widget on
+ // hide, and will create a new one (through createControl())
+ // on show. It'll also reposition the toolbar, if needed.
+ // Note: just doing bars.getToolBarManager().update(true);
+ // messes up big time (doesn't resize or re-position).
+ bars.updateActionBars();
+ if (visible && toolbar != null) {
+ openCloseToggle.setChecked(true);
+ // If the toolbar was moved below the tabs, we now have
+ // the wrong background. It disappears when one clicks
+ // elsewhere. Looks like an inactive selection... Let's
+ // fix that: parent is the ToolBar, grand-parent is a
+ // Composite with the freak background.
+ // toolbar.getParent().getParent().setBackground(null);
+ // Doesn't help?! Let's try changing the focus:
+ graph.getControl().setFocus();
+ toolbar.setFocus();
+ } else if (!visible && !graph.getControl().isDisposed()) {
+ graph.getControl().setFocus();
+ }
+ }
+ }
+
+ @Override
+ protected Control createControl(Composite parent) {
+ toolbar = new FindToolbar(parent);
+ toolbar.setBackground(null);
+ toolbar.addKeyListener(keyListener);
+ toolbar.addListener(SWT.FocusIn, mouseListener);
+ toolbar.addListener(SWT.FocusOut, mouseListener);
+ toolbar.addListener(SWT.MouseDown, mouseListener);
+ toolbar.addListener(SWT.MouseUp, mouseListener);
+ toolbar.addStatusListener(statusListener);
+ toolbar.addSelectionListener(selectionListener);
+ boolean hasInput = provider != null;
+ if (hasInput) {
+ setInput(provider);
+ }
+ if (lastText != null) {
+ if (lastSearchContext != null
+ && lastSearchContext.equals(searchContext)) {
+ toolbar.setPreselect(lastObjectId);
+ }
+ toolbar.setText(lastText, hasInput);
+ }
+ lastSearchContext = null;
+ lastObjectId = null;
+ // This fixes the wrong background when Eclipse starts up with the
+ // search bar visible.
+ toolbar.getDisplay().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ if (toolbar != null && !toolbar.isDisposed()) {
+ // See setVisible() above. Somehow, we need this, too.
+ graph.getControl().setFocus();
+ toolbar.setFocus();
+ }
+ }
+ });
+ return toolbar;
+ }
+
+ public void setInput(ICommitsProvider provider) {
+ this.provider = provider;
+ if (toolbar != null) {
+ searchContext = provider.getSearchContext();
+ toolbar.setInput(provider.getHighlight(),
+ graph.getTableView().getTable(), provider.getCommits());
+ }
+ }
+
+ }
+
@Override
public void createControl(final Composite parent) {
trace = GitTraceLocation.HISTORYVIEW.isActive();
@@ -990,8 +1245,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
});
- findToolbar = new FindToolbar(historyControl);
-
layoutSashForm(graphDetailSplit,
UIPreferences.RESOURCEHISTORY_GRAPH_SPLIT);
layoutSashForm(revInfoSplit, UIPreferences.RESOURCEHISTORY_REV_SPLIT);
@@ -1008,6 +1261,11 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
myRefsChangedHandle = Repository.getGlobalListenerList()
.addRefsChangedListener(this);
+ IToolBarManager manager = getSite().getActionBars().getToolBarManager();
+ searchBar = new SearchBar(GitHistoryPage.class.getName() + ".searchBar", //$NON-NLS-1$
+ graph, actions.findAction, getSite().getActionBars());
+ manager.prependToGroup("org.eclipse.team.ui.historyView", searchBar); //$NON-NLS-1$
+ getSite().getActionBars().updateActionBars();
if (trace)
GitTraceLocation.getTrace().traceExit(
GitTraceLocation.HISTORYVIEW.getLocation());
@@ -1063,8 +1321,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_REV_COMMENT);
final boolean showFiles = store
.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_REV_DETAIL);
- final boolean showFindToolbar = store
- .getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_FINDTOOLBAR);
if (showComment && showFiles) {
graphDetailSplit.setMaximizedControl(null);
@@ -1077,12 +1333,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
revInfoSplit.setMaximizedControl(fileViewer.getControl());
} else if (!showComment && !showFiles)
graphDetailSplit.setMaximizedControl(graph.getControl());
- if (showFindToolbar)
- ((GridData) findToolbar.getLayoutData()).heightHint = SWT.DEFAULT;
- else {
- ((GridData) findToolbar.getLayoutData()).heightHint = 0;
- findToolbar.clear();
- }
historyControl.layout();
}
@@ -1131,12 +1381,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
graph.selectCommit(c);
}
});
- findToolbar.addSelectionListener(new Listener() {
- @Override
- public void handleEvent(Event event) {
- graph.selectCommit((RevCommit) event.data);
- }
- });
}
private void initActions() {
@@ -1739,8 +1983,29 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
GitTraceLocation.getTrace().trace(
GitTraceLocation.HISTORYVIEW.getLocation(),
"Setting input to table"); //$NON-NLS-1$
- findToolbar.setInput(highlightFlag, graph.getTableView()
- .getTable(), asArray);
+ final Object currentInput = getInput();
+ searchBar.setInput(new ICommitsProvider() {
+
+ @Override
+ public Object getSearchContext() {
+ return currentInput;
+ }
+
+ @Override
+ public SWTCommit[] getCommits() {
+ return asArray;
+ }
+
+ @Override
+ public RevFlag getHighlight() {
+ return highlightFlag;
+ }
+ });
+ actions.findAction.setEnabled(true);
+ if (store.getBoolean(
+ UIPreferences.RESOURCEHISTORY_SHOW_FINDTOOLBAR)) {
+ searchBar.setVisible(true);
+ }
if (incomplete)
setWarningText(UIText.GitHistoryPage_ListIncompleteWarningMessage);
else
@@ -1953,7 +2218,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
return !o.equals(n);
}
- private SWTWalk createNewWalk(Repository db, AnyObjectId headId) {
+ private @NonNull SWTWalk createNewWalk(Repository db, AnyObjectId headId) {
currentHeadId = headId;
SWTWalk walk = new SWTWalk(db);
try {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/HistoryPageInput.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/HistoryPageInput.java
index b62aefadb..46dad346c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/HistoryPageInput.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/HistoryPageInput.java
@@ -200,4 +200,38 @@ public class HistoryPageInput {
}
return result;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof HistoryPageInput)) {
+ return false;
+ }
+ HistoryPageInput other = (HistoryPageInput) obj;
+ return repo == other.repo && singleFile == other.singleFile
+ && singleItem == other.singleItem
+ && listEquals(files, other.files)
+ && listEquals(list, other.list);
+ }
+
+ private <T> boolean listEquals(List<? extends T> a, List<? extends T> b) {
+ if (a == b) {
+ return true;
+ }
+ if (a == null || b == null) {
+ return false;
+ }
+ return Arrays.equals(a.toArray(), b.toArray());
+ }
+
+ @Override
+ public int hashCode() {
+ return (repo == null ? 0 : repo.hashCode())
+ ^ (singleFile == null ? 0 : singleFile.hashCode())
+ ^ (singleItem == null ? 0 : singleItem.hashCode())
+ ^ (files == null ? 0 : Arrays.hashCode(files.toArray()))
+ ^ (list == null ? 0 : Arrays.hashCode(list.toArray()));
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index 296f582d6..8dc34c313 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -188,7 +188,8 @@ GitHistoryPage_FileNotInCommit={0} not in {1}
GitHistoryPage_FileOrFolderPartOfGitDirMessage=File or folder {0} is part of the repository''s Git directory
GitHistoryPage_FileType=File
GitHistoryPage_FindMenuLabel=Find &Toolbar
-GitHistoryPage_FindTooltip=Show Find Toolbar
+GitHistoryPage_FindShowTooltip=Show Find Toolbar ({0})
+GitHistoryPage_FindHideTooltip=Hide Find Toolbar ({0})
GitHistoryPage_FolderType=Folder
GitHistoryPage_ModifyMenuLabel=Modi&fy
GitHistoryPage_MultiResourcesType={0} resources
@@ -680,6 +681,7 @@ HistoryPage_authorDateColumn=Authored Date
HistoryPage_refreshJob=Reading history from Git repository ''{0}''
HistoryPage_findbar_find=Search in history for ''{0}''
+HistoryPage_findbar_find_msg=Find
HistoryPage_findbar_next=Next
HistoryPage_findbar_previous=Previous
HistoryPage_findbar_ignorecase=Ignore Case

Back to the top