Bug 487093 - You can too easily clear the search history
Changes included:
* ask for confirmation on clear search history
Change-Id: I99d48be2a1e5fd1c775aef62a10ddca0d473e3b1
Signed-off-by: Robert Roth <robert.roth.off@gmail.com>
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/RemoveAllSearchesAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/RemoveAllSearchesAction.java
index 4869e85..39b1bcd 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/RemoveAllSearchesAction.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/RemoveAllSearchesAction.java
@@ -10,11 +10,15 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Robert Roth (robert.roth.off@gmail.com) - Bug 487093: You can too easily clear the search history
*******************************************************************************/
package org.eclipse.search2.internal.ui;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.search.internal.ui.SearchPlugin;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.NewSearchUI;
@@ -26,12 +30,37 @@
setToolTipText(SearchMessages.RemoveAllSearchesAction_tooltip);
}
+ /**
+ * Returns whether to ask for confirmation on search history clear. Consults the preference and prompts the user if
+ * necessary.
+ *
+ * @return <code>true</code> if clear search history should be confirmed by user, and <code>false</code>
+ * otherwise.
+ */
+ private boolean promptForConfirmation() {
+
+ MessageDialog dialog= new MessageDialog(SearchPlugin.getActiveWorkbenchShell(),
+ SearchMessages.RemoveAllSearchesAction_tooltip, // title
+ null, // image
+ SearchMessages.RemoveAllSearchesAction_confirm_message, // message
+ MessageDialog.CONFIRM,
+ new String[] {SearchMessages.RemoveAllSearchesAction_confirm_label, IDialogConstants.CANCEL_LABEL},
+ IDialogConstants.OK_ID);
+
+ dialog.open();
+ if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
+ return false;
+ }
+ return true;
+ }
+
@Override
public void run() {
ISearchQuery[] queries= NewSearchUI.getQueries();
- for (ISearchQuery querie : queries) {
- if (!NewSearchUI.isQueryRunning(querie)) {
- InternalSearchUI.getInstance().removeQuery(querie);
+ if (promptForConfirmation()) {
+ for (ISearchQuery querie : queries) {
+ if (!NewSearchUI.isQueryRunning(querie))
+ InternalSearchUI.getInstance().removeQuery(querie);
}
}
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.java
index 7a3de33..75adbe4 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.java
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.java
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Robert Roth (robert.roth.off@gmail.com) - Bug 487093: You can too easily clear the search history
*******************************************************************************/
package org.eclipse.search2.internal.ui;
@@ -102,5 +103,7 @@
public static String RetrieverAction_empty_selection;
public static String RetrieverAction_error_title;
public static String RetrieverAction_error_message;
+ public static String RemoveAllSearchesAction_confirm_label;
+ public static String RemoveAllSearchesAction_confirm_message;
}
diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties
index 8a92054..6cf4d5e 100644
--- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties
+++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchMessages.properties
@@ -33,6 +33,8 @@
RetrieverAction_dialog_title=Text Search
RetrieverAction_error_message=The search could not be initialized.
RemoveAllSearchesAction_tooltip=Clear Search History
+RemoveAllSearchesAction_confirm_label=&Clear History
+RemoveAllSearchesAction_confirm_message=Are you sure you want to clear the search history?
RetrieverAction_empty_selection=Could not evaluate a text selection.
RemoveAllMatchesAction_label=Remove All Matches
RemoveAllMatchesAction_tooltip=Remove All Matches