From 8bdef4b07ed440ea1ffd15c0ce5783955e8262f1 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 11 May 2011 15:23:04 +0000 Subject: [PATCH] Bug 341605: Disable search button for missing element selection, by Marko Tomljenovic. --- .../internal/ui/search/CSearchMessages.java | 19 ++-- .../ui/search/CSearchMessages.properties | 3 + .../internal/ui/search/PDOMSearchPage.java | 89 ++++++++++++++++--- 3 files changed, 90 insertions(+), 21 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java index 7bd4f43af07..132696fd130 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2010 IBM Corporation and others. + * Copyright (c) 2003, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,14 +14,9 @@ package org.eclipse.cdt.internal.ui.search; import org.eclipse.osgi.util.NLS; + public final class CSearchMessages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.search.CSearchMessages";//$NON-NLS-1$ - - private CSearchMessages() { - // Do not instantiate - } - + private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.search.CSearchMessages"; //$NON-NLS-1$ public static String group_declarations; public static String group_references; public static String CSearchResultCollector_matches; @@ -40,6 +35,8 @@ public final class CSearchMessages extends NLS { public static String CSearchPage_searchFor_macro; public static String CSearchPage_searchFor_any; public static String CSearchPage_searchFor_classStruct; + public static String CSearchPage_label_note; + public static String CSearchPage_label_activeCodeRemark; public static String CSearchPage_limitTo_label; public static String CSearchPage_limitTo_declarations; public static String CSearchPage_limitTo_definitions; @@ -77,7 +74,6 @@ public final class CSearchMessages extends NLS { public static String SelectionParseAction_SelectedTextNotSymbol_message; public static String SelectionParseAction_SymbolNotFoundInIndex_format; public static String SelectionParseAction_IncludeNotFound_format; - public static String OccurrencesFinder_no_element; public static String OccurrencesFinder_no_binding; public static String OccurrencesFinder_searchfor; @@ -85,7 +81,6 @@ public final class CSearchMessages extends NLS { public static String OccurrencesFinder_label_plural; public static String OccurrencesFinder_occurrence_description; public static String OccurrencesFinder_occurrence_write_description; - public static String PDOMSearchListContentProvider_IndexerNotEnabledMessageFormat; public static String PDOMSearchListContentProvider_ProjectClosedMessageFormat; public static String CSearchMessages_IndexRunningIncompleteWarning; @@ -104,4 +99,8 @@ public final class CSearchMessages extends NLS { static { NLS.initializeMessages(BUNDLE_NAME, CSearchMessages.class); } + + private CSearchMessages() { + // Do not instantiate + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties index 12feae5fdf5..4deb6dd58e0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties @@ -42,6 +42,9 @@ CSearchPage_limitTo_definitions= Definitions CSearchPage_limitTo_references= References CSearchPage_limitTo_allOccurrences= All Occurrences +CSearchPage_label_note=Note: +CSearchPage_label_activeCodeRemark= The C/C++ Search only processes the active code! + CSearchPage_expression_label= Search strin&g (* = any string, ? = any character): CSearchPage_expression_caseSensitive= Case sens&itive diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPage.java index 439ce6c4a29..da02b546303 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPage.java @@ -6,8 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * IBM Corporation + * Doug Schaefer (QNX) - Initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ @@ -24,6 +23,8 @@ import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; @@ -37,6 +38,7 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -338,6 +340,8 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage { layouter.perform(createExpression(result)); layouter.perform(createSearchFor(result), createLimitTo(result), -1); + createNote(result); + setControl(result); fLineManager = getStatusLineManager(); @@ -346,6 +350,54 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage { PlatformUI.getWorkbench().getHelpSystem().setHelp(result, ICHelpContextIds.C_SEARCH_PAGE); } + private void createNote(Composite result) { + // Create a note that tells the user that this search only processes the active code (not grayed out in editor) + GridData gd; + String noteTitle= CSearchMessages.CSearchPage_label_note; + String noteMessage= CSearchMessages.CSearchPage_label_activeCodeRemark; + Composite noteControl= createNoteComposite(JFaceResources.getDialogFont(), result, noteTitle, noteMessage); + gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan= 2; + noteControl.setLayoutData(gd); + } + + /** + * Creates a composite with a highlighted Note entry and a message text. + * This is designed to take up the full width of the page.
+ * This method has been copied from class {@link PreferencePage} + * + * @param font the font to use + * @param composite the parent composite + * @param title the title of the note + * @param message the message for the note + * @return the composite for the note + */ + protected Composite createNoteComposite(Font font, Composite composite, + String title, String message) { + Composite messageComposite = new Composite(composite, SWT.NONE); + GridLayout messageLayout = new GridLayout(); + messageLayout.numColumns = 2; + messageLayout.marginWidth = 0; + messageLayout.marginHeight = 0; + messageComposite.setLayout(messageLayout); + messageComposite.setLayoutData(new GridData( + GridData.HORIZONTAL_ALIGN_FILL)); + messageComposite.setFont(font); + + final Label noteLabel = new Label(messageComposite, SWT.BOLD); + noteLabel.setText(title); + noteLabel.setFont(JFaceResources.getFontRegistry().getBold( + JFaceResources.DIALOG_FONT)); + noteLabel + .setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + + Label messageLabel = new Label(messageComposite, SWT.WRAP); + messageLabel.setText(message); + messageLabel.setFont(font); + return messageComposite; + } + + private IStatusLineManager getStatusLineManager(){ IWorkbenchWindow wbWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); @@ -555,24 +607,39 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage { } private void setPerformActionEnabled() { - boolean enable = true; - // Need a text string to search - if (patternCombo.getText().length() == 0) - enable = false; + if (this.patternCombo.getText().length() == 0) { + getContainer().setPerformActionEnabled(false); + return; + } // Need a type boolean any = false; - for (int i = 0; i < searchForButtons.length; ++i) { - if (searchForButtons[i].getSelection()) { + for (int i = 0; i < this.searchForButtons.length; ++i) { + if (this.searchForButtons[i].getSelection()) { any = true; break; } } - if (!any) - enable = false; + if (!any) { + getContainer().setPerformActionEnabled(false); + return; + } - getContainer().setPerformActionEnabled(enable); + // Set limit to + any = false; + + for (int i = 0; i < this.limitToButtons.length; ++i) { + if (this.limitToButtons[i].getSelection()) { + any = true; + break; + } + } + if (!any) { + getContainer().setPerformActionEnabled(false); + return; + } + getContainer().setPerformActionEnabled(true); } private IDialogSettings getDialogSettings() {