diff options
author | Robin Stocker | 2013-04-25 20:23:42 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2013-10-01 07:26:20 +0000 |
commit | 88b5c09d0c7fe468a99f211b6e4ff1dd08ce0ddd (patch) | |
tree | 0edfb6c2d84643c45b8c2402028351340526edf3 /org.eclipse.egit.ui/src | |
parent | 6d06f50979cd7757baa01f65be5c982b2f635a03 (diff) | |
download | egit-88b5c09d0c7fe468a99f211b6e4ff1dd08ce0ddd.tar.gz egit-88b5c09d0c7fe468a99f211b6e4ff1dd08ce0ddd.tar.xz egit-88b5c09d0c7fe468a99f211b6e4ff1dd08ce0ddd.zip |
[historyView] "Search all" option for find toolbar
Sometimes one wants to find a commit by author, sometimes by comment.
Currently this requires the user to switch between those modes.
This change adds a new "All" mode, which just searches all fields. The
performance is good enough that this can be the default mode.
This also fixes a bug where cycling through the options by pressing on
the button would persist the wrong preference value.
Bug: 345410
Change-Id: I1fb6972fe5b4b30264aae1e7069942a363b58f05
Signed-off-by: Robin Stocker <robin@nibor.org>
Diffstat (limited to 'org.eclipse.egit.ui/src')
5 files changed, 124 insertions, 103 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java index 4b11dfc0f4..e3f6cd61cb 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java @@ -16,6 +16,7 @@ import java.io.File; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator; +import org.eclipse.egit.ui.internal.history.FindToolbar; import org.eclipse.egit.ui.internal.staging.StagingView; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jgit.util.FS; @@ -71,7 +72,8 @@ public class PluginPreferenceInitializer extends AbstractPreferenceInitializer { store.setDefault(UIPreferences.RESOURCEHISTORY_REV_SPLIT, UIPreferences.intArrayToString(w)); store.setDefault(UIPreferences.FINDTOOLBAR_IGNORE_CASE, true); - store.setDefault(UIPreferences.FINDTOOLBAR_FIND_IN, 2); + store.setDefault(UIPreferences.FINDTOOLBAR_FIND_IN, + FindToolbar.PREFS_FINDIN_ALL); store.setDefault(UIPreferences.COMMIT_DIALOG_HARD_WRAP_MESSAGE, true); store.setDefault(UIPreferences.COMMIT_DIALOG_SIGNED_OFF_BY, false); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java index 0351cfb17b..51d86dd6d3 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java @@ -4,6 +4,7 @@ * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com> * Copyright (C) 2013, Daniel Megert <daniel_megert@ch.ibm.com> + * Copyright (C) 2013, Robin Stocker <robin@nibor.org> * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -231,6 +232,9 @@ public class UIIcons { /** Stash icon */ public final static ImageDescriptor STASH; + /** Search commit icon */ + public final static ImageDescriptor SEARCH_COMMIT; + /** Hierarchy layout icon */ public final static ImageDescriptor HIERARCHY; @@ -321,6 +325,7 @@ public class UIIcons { SUBMODULES = map("obj16/submodules.gif"); //$NON-NLS-1$ CLEAN = map("obj16/clean_obj.gif"); //$NON-NLS-1$ STASH = map("obj16/stash.png"); //$NON-NLS-1$ + SEARCH_COMMIT = map("obj16/search-commit.gif"); //$NON-NLS-1$ HIERARCHY = map("elcl16/hierarchicalLayout.gif"); //$NON-NLS-1$ FLAT = map("elcl16/flatLayout.gif"); //$NON-NLS-1$ COMPACT = map("elcl16/compactLayout.gif"); //$NON-NLS-1$ 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 c8deef0e8d..b0df444df2 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 @@ -1710,6 +1710,9 @@ public class UIText extends NLS { public static String HistoryPage_findbar_ignorecase; /** */ + public static String HistoryPage_findbar_all; + + /** */ public static String HistoryPage_findbar_commit; /** */ @@ -1722,6 +1725,9 @@ public class UIText extends NLS { public static String HistoryPage_findbar_committer; /** */ + public static String HistoryPage_findbar_changeto_all; + + /** */ public static String HistoryPage_findbar_changeto_commit; /** */ 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 65f5143d5e..cb00a38ca7 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 @@ -3,6 +3,7 @@ * Copyright (C) 2008, Roger C. Soares <rogersoares@intelinet.com.br> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com> + * Copyright (C) 2013, Robin Stocker <robin@nibor.org> * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -60,6 +61,11 @@ import org.eclipse.swt.widgets.Widget; * @see GitHistoryPage */ public class FindToolbar extends Composite { + /** + * Preference value for searching all the fields + */ + public static final int PREFS_FINDIN_ALL = 0; + private static final int PREFS_FINDIN_COMMENTS = 1; private static final int PREFS_FINDIN_AUTHOR = 2; @@ -95,8 +101,14 @@ public class FindToolbar extends Composite { private String lastErrorPattern; + private ToolItem prefsDropDown; + private Menu prefsMenu; + private MenuItem caseItem; + + private MenuItem allItem; + private MenuItem commitIdItem; private MenuItem commentsItem; @@ -109,6 +121,8 @@ public class FindToolbar extends Composite { private Image previousIcon; + private Image allIcon; + private Image commitIdIcon; private Image commentsIcon; @@ -132,6 +146,7 @@ public class FindToolbar extends Composite { errorBackgroundColor = new Color(getDisplay(), new RGB(255, 150, 150)); nextIcon = UIIcons.ELCL16_NEXT.createImage(); previousIcon = UIIcons.ELCL16_PREVIOUS.createImage(); + allIcon = UIIcons.SEARCH_COMMIT.createImage(); commitIdIcon = UIIcons.ELCL16_ID.createImage(); commentsIcon = UIIcons.ELCL16_COMMENTS.createImage(); authorIcon = UIIcons.ELCL16_AUTHOR.createImage(); @@ -166,47 +181,48 @@ public class FindToolbar extends Composite { final ToolBar toolBar = new ToolBar(this, SWT.FLAT); new ToolItem(toolBar, SWT.SEPARATOR); - final ToolItem prefsItem = new ToolItem(toolBar, SWT.DROP_DOWN); + prefsDropDown = new ToolItem(toolBar, SWT.DROP_DOWN); prefsMenu = new Menu(getShell(), SWT.POP_UP); - final MenuItem caseItem = new MenuItem(prefsMenu, SWT.CHECK); + caseItem = new MenuItem(prefsMenu, SWT.CHECK); caseItem.setText(UIText.HistoryPage_findbar_ignorecase); new MenuItem(prefsMenu, SWT.SEPARATOR); - commentsItem = new MenuItem(prefsMenu, SWT.RADIO); + allItem = createFindInMenuItem(); + allItem.setText(UIText.HistoryPage_findbar_all); + allItem.setImage(allIcon); + commentsItem = createFindInMenuItem(); commentsItem.setText(UIText.HistoryPage_findbar_comments); commentsItem.setImage(commentsIcon); - authorItem = new MenuItem(prefsMenu, SWT.RADIO); + authorItem = createFindInMenuItem(); authorItem.setText(UIText.HistoryPage_findbar_author); authorItem.setImage(authorIcon); - commitIdItem = new MenuItem(prefsMenu, SWT.RADIO); + commitIdItem = createFindInMenuItem(); commitIdItem.setText(UIText.HistoryPage_findbar_commit); commitIdItem.setImage(commitIdIcon); - committerItem = new MenuItem(prefsMenu, SWT.RADIO); + committerItem = createFindInMenuItem(); committerItem.setText(UIText.HistoryPage_findbar_committer); committerItem.setImage(committerIcon); - prefsItem.addListener(SWT.Selection, new Listener() { + prefsDropDown.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (event.detail == SWT.ARROW) { - Rectangle itemBounds = prefsItem.getBounds(); + // Arrow clicked, show drop down menu + Rectangle itemBounds = prefsDropDown.getBounds(); Point point = toolBar.toDisplay(itemBounds.x, itemBounds.y + itemBounds.height); prefsMenu.setLocation(point); prefsMenu.setVisible(true); } else { - switch (store.getInt(UIPreferences.FINDTOOLBAR_FIND_IN)) { - case PREFS_FINDIN_COMMENTS: - commentsItem.notifyListeners(SWT.Selection, null); - break; - case PREFS_FINDIN_AUTHOR: - authorItem.notifyListeners(SWT.Selection, null); - break; - case PREFS_FINDIN_COMMITID: - commitIdItem.notifyListeners(SWT.Selection, null); - break; - case PREFS_FINDIN_COMMITTER: - committerItem.notifyListeners(SWT.Selection, null); - break; - } + // Button clicked, cycle to next option + if (allItem.getSelection()) + selectFindInItem(commentsItem); + else if (commentsItem.getSelection()) + selectFindInItem(authorItem); + else if (authorItem.getSelection()) + selectFindInItem(commitIdItem); + else if (commitIdItem.getSelection()) + selectFindInItem(committerItem); + else if (committerItem.getSelection()) + selectFindInItem(allItem); } } }); @@ -227,18 +243,9 @@ public class FindToolbar extends Composite { progressBar.setMinimum(0); progressBar.setMaximum(100); - final FindToolbar thisToolbar = this; patternField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { - final FindToolbarThread finder = new FindToolbarThread(); - finder.pattern = ((Text) e.getSource()).getText(); - finder.fileRevisions = fileRevisions; - finder.toolbar = thisToolbar; - finder.ignoreCase = caseItem.getSelection(); - finder.findInCommitId = commitIdItem.getSelection(); - finder.findInComments = commentsItem.getSelection(); - finder.findInAuthor = authorItem.getSelection(); - finder.findInCommitter = committerItem.getSelection(); + final FindToolbarThread finder = createFinder(); getDisplay().timerExec(200, new Runnable() { public void run() { finder.start(); @@ -253,15 +260,7 @@ public class FindToolbar extends Composite { && findResults.size() == 0) { // If the toolbar was cleared and has a pattern typed, // then we redo the find with the new table data. - final FindToolbarThread finder = new FindToolbarThread(); - finder.pattern = patternField.getText(); - finder.fileRevisions = fileRevisions; - finder.toolbar = thisToolbar; - finder.ignoreCase = caseItem.getSelection(); - finder.findInCommitId = commitIdItem.getSelection(); - finder.findInComments = commentsItem.getSelection(); - finder.findInAuthor = authorItem.getSelection(); - finder.findInCommitter = committerItem.getSelection(); + final FindToolbarThread finder = createFinder(); finder.start(); patternField.setSelection(0, 0); } else { @@ -332,66 +331,16 @@ public class FindToolbar extends Composite { .getBoolean(UIPreferences.FINDTOOLBAR_IGNORE_CASE)); int selectedPrefsItem = store.getInt(UIPreferences.FINDTOOLBAR_FIND_IN); - - commentsItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - prefsItem.setImage(commentsIcon); - prefsItem - .setToolTipText(UIText.HistoryPage_findbar_changeto_author); - prefsItemChanged(PREFS_FINDIN_AUTHOR, commentsItem); - } - }); - if (selectedPrefsItem == PREFS_FINDIN_COMMENTS) { - commentsItem.setSelection(true); - prefsItem.setImage(commentsIcon); - prefsItem - .setToolTipText(UIText.HistoryPage_findbar_changeto_author); - } - - authorItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - prefsItem.setImage(authorIcon); - prefsItem - .setToolTipText(UIText.HistoryPage_findbar_changeto_commit); - prefsItemChanged(PREFS_FINDIN_COMMITID, authorItem); - } - }); - if (selectedPrefsItem == PREFS_FINDIN_AUTHOR) { - authorItem.setSelection(true); - prefsItem.setImage(authorIcon); - prefsItem - .setToolTipText(UIText.HistoryPage_findbar_changeto_commit); - } - - commitIdItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - prefsItem.setImage(commitIdIcon); - prefsItem - .setToolTipText(UIText.HistoryPage_findbar_changeto_committer); - prefsItemChanged(PREFS_FINDIN_COMMITTER, commitIdItem); - } - }); - if (selectedPrefsItem == PREFS_FINDIN_COMMITID) { - commitIdItem.setSelection(true); - prefsItem.setImage(commitIdIcon); - prefsItem - .setToolTipText(UIText.HistoryPage_findbar_changeto_committer); - } - - committerItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - prefsItem.setImage(committerIcon); - prefsItem - .setToolTipText(UIText.HistoryPage_findbar_changeto_comments); - prefsItemChanged(PREFS_FINDIN_COMMENTS, committerItem); - } - }); - if (selectedPrefsItem == PREFS_FINDIN_COMMITTER) { - committerItem.setSelection(true); - prefsItem.setImage(committerIcon); - prefsItem - .setToolTipText(UIText.HistoryPage_findbar_changeto_comments); - } + if (selectedPrefsItem == PREFS_FINDIN_ALL) + selectFindInItem(allItem); + else if (selectedPrefsItem == PREFS_FINDIN_COMMENTS) + selectFindInItem(commentsItem); + else if (selectedPrefsItem == PREFS_FINDIN_AUTHOR) + selectFindInItem(authorItem); + else if (selectedPrefsItem == PREFS_FINDIN_COMMITID) + selectFindInItem(commitIdItem); + else if (selectedPrefsItem == PREFS_FINDIN_COMMITTER) + selectFindInItem(committerItem); registerDisposal(); } @@ -404,6 +353,7 @@ public class FindToolbar extends Composite { errorBackgroundColor.dispose(); nextIcon.dispose(); previousIcon.dispose(); + allIcon.dispose(); commitIdIcon.dispose(); commentsIcon.dispose(); authorIcon.dispose(); @@ -412,7 +362,42 @@ public class FindToolbar extends Composite { }); } - private void prefsItemChanged(int findin, MenuItem item) { + private MenuItem createFindInMenuItem() { + final MenuItem menuItem = new MenuItem(prefsMenu, SWT.RADIO); + menuItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + selectFindInItem(menuItem); + } + }); + return menuItem; + } + + private void selectFindInItem(final MenuItem menuItem) { + if (menuItem == allItem) + selectFindInItem(menuItem, PREFS_FINDIN_ALL, allIcon, + UIText.HistoryPage_findbar_changeto_comments); + else if (menuItem == commentsItem) + selectFindInItem(menuItem, PREFS_FINDIN_COMMENTS, commentsIcon, + UIText.HistoryPage_findbar_changeto_author); + else if (menuItem == authorItem) + selectFindInItem(menuItem, PREFS_FINDIN_AUTHOR, authorIcon, + UIText.HistoryPage_findbar_changeto_commit); + else if (menuItem == commitIdItem) + selectFindInItem(menuItem, PREFS_FINDIN_COMMITID, commitIdIcon, + UIText.HistoryPage_findbar_changeto_committer); + else if (menuItem == committerItem) + selectFindInItem(menuItem, PREFS_FINDIN_COMMITTER, committerIcon, + UIText.HistoryPage_findbar_changeto_all); + } + + private void selectFindInItem(MenuItem menuItem, int preferenceValue, + Image dropDownIcon, String dropDownToolTip) { + prefsDropDown.setImage(dropDownIcon); + prefsDropDown.setToolTipText(dropDownToolTip); + findInPreferenceChanged(preferenceValue, menuItem); + } + + private void findInPreferenceChanged(int findin, MenuItem item) { store.setValue(UIPreferences.FINDTOOLBAR_FIND_IN, findin); if (store.needsSaving()){ try { @@ -421,6 +406,7 @@ public class FindToolbar extends Composite { Activator.handleError(e.getMessage(), e, false); } } + allItem.setSelection(false); commitIdItem.setSelection(false); commentsItem.setSelection(false); authorItem.setSelection(false); @@ -429,6 +415,26 @@ public class FindToolbar extends Composite { clear(); } + private FindToolbarThread createFinder() { + final FindToolbarThread finder = new FindToolbarThread(); + finder.pattern = patternField.getText(); + finder.fileRevisions = fileRevisions; + finder.toolbar = this; + finder.ignoreCase = caseItem.getSelection(); + if (allItem.getSelection()) { + finder.findInCommitId = true; + finder.findInComments = true; + finder.findInAuthor = true; + finder.findInCommitter = true; + } else { + finder.findInCommitId = commitIdItem.getSelection(); + finder.findInComments = commentsItem.getSelection(); + finder.findInAuthor = authorItem.getSelection(); + finder.findInCommitter = committerItem.getSelection(); + } + return finder; + } + /** * Sets the table that will have its selected items changed by this toolbar. * Sets the list to be searched. 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 7f83e62042..6da0214f89 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 @@ -592,10 +592,12 @@ HistoryPage_findbar_find=Find: HistoryPage_findbar_next=Next HistoryPage_findbar_previous=Previous HistoryPage_findbar_ignorecase=Ignore Case +HistoryPage_findbar_all=All HistoryPage_findbar_commit=Id HistoryPage_findbar_comments=Comments HistoryPage_findbar_author=Author HistoryPage_findbar_committer=Committer +HistoryPage_findbar_changeto_all=Change to All HistoryPage_findbar_changeto_commit=Change to Id HistoryPage_findbar_changeto_comments=Change to Comments HistoryPage_findbar_changeto_author=Change to Author |