Skip to content

Commit 6651eaa

Browse files
committed
Changed the functionality of the regex search with control decorations
1 parent 090a18a commit 6651eaa

File tree

6 files changed

+132
-51
lines changed

6 files changed

+132
-51
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,9 +1852,7 @@ private void internalConditionalExpandToLevel(Widget widget, int level,
18521852
Function<Widget, Boolean> shouldChildrenExpand) {
18531853
if (level == ALL_LEVELS || level > 0) {
18541854
Object data = widget.getData();
1855-
if (widget instanceof Item it && data != null && !isExpandable(it, null, data)) {
1856-
return;
1857-
}
1855+
18581856
createChildren(widget, false);
18591857
// XXX for performance widget should be expanded after expanding children:
18601858
if (widget instanceof Item it) {
@@ -1872,6 +1870,9 @@ private void internalConditionalExpandToLevel(Widget widget, int level,
18721870
}
18731871
}
18741872
}
1873+
if (widget instanceof Item it && data != null && !isExpandable(it, null, data)) {
1874+
return;
1875+
}
18751876
// XXX expanding here fails on linux
18761877
}
18771878
}

bundles/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import org.eclipse.jface.dialogs.ErrorDialog;
5555
import org.eclipse.jface.dialogs.IDialogSettings;
5656
import org.eclipse.jface.fieldassist.ComboContentAdapter;
57-
import org.eclipse.jface.resource.JFaceColors;
57+
import org.eclipse.jface.fieldassist.ControlDecoration;
5858
import org.eclipse.jface.viewers.ISelection;
5959

6060
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
@@ -68,6 +68,7 @@
6868
import org.eclipse.ui.IWorkingSetManager;
6969
import org.eclipse.ui.PlatformUI;
7070
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
71+
import org.eclipse.ui.internal.SearchDecoration;
7172

7273
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
7374

@@ -140,8 +141,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
140141
*/
141142
private String[] fPreviousExtensions;
142143
private Label fFileNamePatternDescription;
143-
144-
144+
private ControlDecoration fPatternDecoration;
145145
private static class SearchPatternData {
146146
public final boolean isCaseSensitive;
147147
public final boolean isRegExSearch;
@@ -450,6 +450,7 @@ public void setVisible(boolean visible) {
450450
}
451451

452452
final void updateOKStatus() {
453+
fPatternDecoration.hide();
453454
boolean regexStatus= validateRegex();
454455
getContainer().setPerformActionEnabled(regexStatus);
455456
}
@@ -481,22 +482,17 @@ public void createControl(Composite parent) {
481482
PlatformUI.getWorkbench().getHelpSystem().setHelp(result, ISearchHelpContextIds.TEXT_SEARCH_PAGE);
482483
}
483484

484-
private boolean validateRegex() {
485+
private boolean validateRegex() {
486+
485487
if (fIsRegExCheckbox.getSelection()) {
486488
try {
487489
PatternConstructor.createPattern(fPattern.getText(), fIsCaseSensitive, true);
488490
} catch (PatternSyntaxException e) {
489-
String locMessage= e.getLocalizedMessage();
490-
int i= 0;
491-
while (i < locMessage.length() && "\n\r".indexOf(locMessage.charAt(i)) == -1) { //$NON-NLS-1$
492-
i++;
493-
}
494-
statusMessage(true, locMessage.substring(0, i)); // only take first line
491+
SearchDecoration.validateRegex(fPattern.getText(), fPatternDecoration);
495492
return false;
496493
}
497-
statusMessage(false, ""); //$NON-NLS-1$
498494
} else {
499-
statusMessage(false, SearchMessages.SearchPage_containingText_hint);
495+
fPatternDecoration.hide();
500496
}
501497
return true;
502498
}
@@ -512,6 +508,8 @@ private void addTextPatternControls(Composite group) {
512508

513509
// Pattern combo
514510
fPattern= new Combo(group, SWT.SINGLE | SWT.BORDER);
511+
fPatternDecoration = new ControlDecoration(fPattern, SWT.BOTTOM | SWT.LEFT);
512+
515513
// Not done here to prevent page from resizing
516514
// fPattern.setItems(getPreviousSearchPatterns());
517515
fPattern.addSelectionListener(new SelectionAdapter() {
@@ -561,7 +559,6 @@ public void widgetSelected(SelectionEvent e) {
561559
public void widgetSelected(SelectionEvent e) {
562560
fIsRegExSearch= fIsRegExCheckbox.getSelection();
563561
updateOKStatus();
564-
565562
writeConfiguration();
566563
fPatterFieldContentAssist.setEnabled(fIsRegExSearch);
567564
fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
@@ -860,15 +857,4 @@ private void writeConfiguration() {
860857

861858
}
862859

863-
private void statusMessage(boolean error, String message) {
864-
fStatusLabel.setText(message);
865-
if (error) {
866-
fStatusLabel.setForeground(JFaceColors.getErrorText(fStatusLabel.getDisplay()));
867-
}
868-
else {
869-
// use same color as another label to respect styling
870-
fStatusLabel.setForeground(fFileNamePatternDescription.getForeground());
871-
}
872-
}
873-
874860
}

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.eclipse.jface.dialogs.IDialogSettings;
5252
import org.eclipse.jface.dialogs.IPageChangedListener;
5353
import org.eclipse.jface.dialogs.PageChangedEvent;
54+
import org.eclipse.jface.fieldassist.ControlDecoration;
5455
import org.eclipse.jface.fieldassist.TextContentAdapter;
5556
import org.eclipse.jface.layout.GridDataFactory;
5657
import org.eclipse.jface.layout.GridLayoutFactory;
@@ -67,6 +68,7 @@
6768
import org.eclipse.ui.IWorkbenchPartReference;
6869
import org.eclipse.ui.PlatformUI;
6970
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
71+
import org.eclipse.ui.internal.SearchDecoration;
7072
import org.eclipse.ui.internal.findandreplace.FindReplaceLogic;
7173
import org.eclipse.ui.internal.findandreplace.FindReplaceMessages;
7274
import org.eclipse.ui.internal.findandreplace.HistoryStore;
@@ -146,6 +148,9 @@ private final class KeyboardShortcuts {
146148
private Color normalTextForegroundColor;
147149
private boolean positionAtTop = true;
148150
private final TargetPartVisibilityHandler targetPartVisibilityHandler;
151+
152+
private ControlDecoration searchBarDecoration;
153+
149154
private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField;
150155

151156
public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) {
@@ -581,6 +586,7 @@ private void createRegexSearchButton() {
581586
wholeWordSearchButton.setEnabled(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD));
582587
updateIncrementalSearch();
583588
updateContentAssistAvailability();
589+
decorate();
584590
}).withShortcuts(KeyboardShortcuts.OPTION_REGEX).build();
585591
regexSearchButton.setSelection(findReplaceLogic.isActive(SearchOptions.REGEX));
586592
}
@@ -650,6 +656,7 @@ private void createSearchBar() {
650656
HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "searchhistory", //$NON-NLS-1$
651657
HISTORY_SIZE);
652658
searchBar = new HistoryTextWrapper(searchHistory, searchBarContainer, SWT.SINGLE);
659+
searchBarDecoration = new ControlDecoration(searchBar, SWT.BOTTOM | SWT.LEFT);
653660
GridDataFactory.fillDefaults().grab(true, true).align(GridData.FILL, GridData.FILL).applyTo(searchBar);
654661
searchBar.forceFocus();
655662
searchBar.selectAll();
@@ -674,6 +681,9 @@ public void focusLost(FocusEvent e) {
674681
});
675682
searchBar.setMessage(FindReplaceMessages.FindReplaceOverlay_searchBar_message);
676683
contentAssistSearchField = createContentAssistField(searchBar, true);
684+
searchBar.addModifyListener(Event -> {
685+
decorate();
686+
});
677687
}
678688

679689
private void updateIncrementalSearch() {
@@ -1061,4 +1071,13 @@ private void setContentAssistsEnablement(boolean enable) {
10611071
private void updateContentAssistAvailability() {
10621072
setContentAssistsEnablement(findReplaceLogic.isAvailableAndActive(SearchOptions.REGEX));
10631073
}
1074+
1075+
private void decorate() {
1076+
if (regexSearchButton.getSelection()) {
1077+
SearchDecoration.validateRegex(getFindString(), searchBarDecoration);
1078+
} else {
1079+
searchBarDecoration.hide();
1080+
}
1081+
}
1082+
10641083
}

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
import org.eclipse.jface.dialogs.Dialog;
5050
import org.eclipse.jface.dialogs.IDialogSettings;
5151
import org.eclipse.jface.fieldassist.ComboContentAdapter;
52+
import org.eclipse.jface.fieldassist.ControlDecoration;
5253
import org.eclipse.jface.fieldassist.FieldDecoration;
5354
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
54-
import org.eclipse.jface.resource.JFaceColors;
5555
import org.eclipse.jface.util.Util;
5656

5757
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
@@ -64,13 +64,12 @@
6464

6565
import org.eclipse.ui.PlatformUI;
6666
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
67+
import org.eclipse.ui.internal.SearchDecoration;
6768
import org.eclipse.ui.internal.findandreplace.FindReplaceLogic;
68-
import org.eclipse.ui.internal.findandreplace.FindReplaceLogicMessageGenerator;
6969
import org.eclipse.ui.internal.findandreplace.FindReplaceMessages;
7070
import org.eclipse.ui.internal.findandreplace.HistoryStore;
7171
import org.eclipse.ui.internal.findandreplace.IFindReplaceLogic;
7272
import org.eclipse.ui.internal.findandreplace.SearchOptions;
73-
import org.eclipse.ui.internal.findandreplace.status.IFindReplaceStatus;
7473
import org.eclipse.ui.internal.texteditor.SWTUtil;
7574

7675
/**
@@ -147,7 +146,10 @@ public void modifyText(ModifyEvent e) {
147146
fIgnoreNextEvent = false;
148147
return;
149148
}
150-
evaluateFindReplaceStatus();
149+
modificationHandler.run();
150+
fFindField.addModifyListener(event -> {
151+
decorate();
152+
});
151153

152154
updateButtonState(!findReplaceLogic.isActive(SearchOptions.INCREMENTAL));
153155
}
@@ -196,6 +198,7 @@ public void modifyText(ModifyEvent e) {
196198
* @since 3.0
197199
*/
198200
private boolean fGiveFocusToFindField = true;
201+
private ControlDecoration fFindFieldDecoration;
199202

200203
/**
201204
* Holds the mnemonic/button pairs for all buttons.
@@ -311,7 +314,6 @@ public void widgetSelected(SelectionEvent e) {
311314
writeSelection();
312315
updateButtonState(!somethingFound);
313316
updateFindHistory();
314-
evaluateFindReplaceStatus();
315317
}
316318
});
317319
setGridData(fFindNextButton, SWT.FILL, true, SWT.FILL, false);
@@ -325,7 +327,6 @@ public void widgetSelected(SelectionEvent e) {
325327
writeSelection();
326328
updateButtonState();
327329
updateFindAndReplaceHistory();
328-
evaluateFindReplaceStatus();
329330
}
330331
});
331332
setGridData(fSelectAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -342,7 +343,6 @@ public void widgetSelected(SelectionEvent e) {
342343
}
343344
updateButtonState();
344345
updateFindAndReplaceHistory();
345-
evaluateFindReplaceStatus();
346346
}
347347
});
348348
setGridData(fReplaceFindButton, SWT.FILL, false, SWT.FILL, false);
@@ -356,7 +356,6 @@ public void widgetSelected(SelectionEvent e) {
356356
}
357357
updateButtonState();
358358
updateFindAndReplaceHistory();
359-
evaluateFindReplaceStatus();
360359
}
361360
});
362361
setGridData(fReplaceSelectionButton, SWT.FILL, false, SWT.FILL, false);
@@ -370,7 +369,6 @@ public void widgetSelected(SelectionEvent e) {
370369
writeSelection();
371370
updateButtonState();
372371
updateFindAndReplaceHistory();
373-
evaluateFindReplaceStatus();
374372
}
375373
});
376374
setGridData(fReplaceAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -634,6 +632,8 @@ private Composite createInputPanel(Composite parent) {
634632
FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider(
635633
true);
636634
fFindField = new Combo(panel, SWT.DROP_DOWN | SWT.BORDER);
635+
fFindFieldDecoration = new ControlDecoration(fFindField, SWT.BOTTOM | SWT.LEFT);
636+
637637
fContentAssistFindField = new ContentAssistCommandAdapter(fFindField, contentAdapter, findProposer,
638638
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
639639
setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
@@ -750,6 +750,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
750750
@Override
751751
public void widgetSelected(SelectionEvent e) {
752752
boolean newState = fIsRegExCheckBox.getSelection();
753+
decorate();
753754
setupFindReplaceLogic();
754755
storeSettings();
755756
updateButtonState();
@@ -1050,9 +1051,10 @@ private void addDecorationMargin(Control control) {
10501051
if (!(layoutData instanceof GridData))
10511052
return;
10521053
GridData gd = (GridData) layoutData;
1053-
FieldDecoration dec = FieldDecorationRegistry.getDefault()
1054+
1055+
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
10541056
.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
1055-
gd.horizontalIndent = dec.getImage().getBounds().width;
1057+
gd.horizontalIndent = fieldDecoration.getImage().getBounds().width;
10561058
}
10571059

10581060
/**
@@ -1102,7 +1104,6 @@ private void updateButtonState(boolean disableReplace) {
11021104
}
11031105
}
11041106

1105-
11061107
/**
11071108
* Updates the given combo with the given content.
11081109
*
@@ -1335,18 +1336,11 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
13351336
}
13361337
}
13371338

1338-
/**
1339-
* Evaluate the status of the FindReplaceLogic object.
1340-
*/
1341-
private void evaluateFindReplaceStatus() {
1342-
IFindReplaceStatus status = findReplaceLogic.getStatus();
1343-
1344-
String dialogMessage = status.accept(new FindReplaceLogicMessageGenerator());
1345-
fStatusLabel.setText(dialogMessage);
1346-
if (status.isInputValid()) {
1347-
fStatusLabel.setForeground(fReplaceLabel.getForeground());
1339+
private void decorate() {
1340+
if (fIsRegExCheckBox.getSelection()) {
1341+
SearchDecoration.validateRegex(fFindField.getText(), fFindFieldDecoration);
13481342
} else {
1349-
fStatusLabel.setForeground(JFaceColors.getErrorText(fStatusLabel.getDisplay()));
1343+
fFindFieldDecoration.hide();
13501344
}
13511345
}
13521346

bundles/org.eclipse.ui/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Bundle-Activator: org.eclipse.ui.internal.UIPlugin
77
Bundle-ActivationPolicy: lazy
88
Bundle-Vendor: %Plugin.providerName
99
Bundle-Localization: plugin
10-
Export-Package: org.eclipse.ui.internal;x-internal:=true
10+
Export-Package: org.eclipse.ui.internal;x-friends:="org.eclipse.ui.workbench.texteditor,org.eclipse.search"
1111
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
1212
org.eclipse.swt;bundle-version="[3.126.0,4.0.0)";visibility:=reexport,
1313
org.eclipse.jface;bundle-version="[3.34.0,4.0.0)";visibility:=reexport,

0 commit comments

Comments
 (0)