Skip to content

Commit 08000ed

Browse files
committed
Changed the functionality of the regex search with control decorations
1 parent 83bf670 commit 08000ed

File tree

6 files changed

+143
-50
lines changed

6 files changed

+143
-50
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 & 22 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

@@ -141,6 +142,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
141142
private String[] fPreviousExtensions;
142143
private Label fFileNamePatternDescription;
143144

145+
private ControlDecoration fPatternDecoration;
144146

145147
private static class SearchPatternData {
146148
public final boolean isCaseSensitive;
@@ -450,6 +452,7 @@ public void setVisible(boolean visible) {
450452
}
451453

452454
final void updateOKStatus() {
455+
fPatternDecoration.hide();
453456
boolean regexStatus= validateRegex();
454457
getContainer().setPerformActionEnabled(regexStatus);
455458
}
@@ -481,22 +484,17 @@ public void createControl(Composite parent) {
481484
PlatformUI.getWorkbench().getHelpSystem().setHelp(result, ISearchHelpContextIds.TEXT_SEARCH_PAGE);
482485
}
483486

484-
private boolean validateRegex() {
487+
private boolean validateRegex() {
488+
485489
if (fIsRegExCheckbox.getSelection()) {
486490
try {
487491
PatternConstructor.createPattern(fPattern.getText(), fIsCaseSensitive, true);
488492
} 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
493+
SearchDecoration.validateRegex(fPattern.getText(), fPatternDecoration);
495494
return false;
496495
}
497-
statusMessage(false, ""); //$NON-NLS-1$
498496
} else {
499-
statusMessage(false, SearchMessages.SearchPage_containingText_hint);
497+
fPatternDecoration.hide();
500498
}
501499
return true;
502500
}
@@ -512,6 +510,8 @@ private void addTextPatternControls(Composite group) {
512510

513511
// Pattern combo
514512
fPattern= new Combo(group, SWT.SINGLE | SWT.BORDER);
513+
fPatternDecoration = new ControlDecoration(fPattern, SWT.BOTTOM | SWT.LEFT);
514+
515515
// Not done here to prevent page from resizing
516516
// fPattern.setItems(getPreviousSearchPatterns());
517517
fPattern.addSelectionListener(new SelectionAdapter() {
@@ -561,7 +561,6 @@ public void widgetSelected(SelectionEvent e) {
561561
public void widgetSelected(SelectionEvent e) {
562562
fIsRegExSearch= fIsRegExCheckbox.getSelection();
563563
updateOKStatus();
564-
565564
writeConfiguration();
566565
fPatterFieldContentAssist.setEnabled(fIsRegExSearch);
567566
fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
@@ -860,15 +859,4 @@ private void writeConfiguration() {
860859

861860
}
862861

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-
874862
}

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: 28 additions & 24 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,8 @@ public void modifyText(ModifyEvent e) {
147146
fIgnoreNextEvent = false;
148147
return;
149148
}
150-
evaluateFindReplaceStatus();
149+
modificationHandler.run();
150+
decorate();
151151

152152
updateButtonState(!findReplaceLogic.isActive(SearchOptions.INCREMENTAL));
153153
}
@@ -196,6 +196,7 @@ public void modifyText(ModifyEvent e) {
196196
* @since 3.0
197197
*/
198198
private boolean fGiveFocusToFindField = true;
199+
private ControlDecoration fFindFieldDecoration;
199200

200201
/**
201202
* Holds the mnemonic/button pairs for all buttons.
@@ -311,7 +312,7 @@ public void widgetSelected(SelectionEvent e) {
311312
writeSelection();
312313
updateButtonState(!somethingFound);
313314
updateFindHistory();
314-
evaluateFindReplaceStatus();
315+
decorate();
315316
}
316317
});
317318
setGridData(fFindNextButton, SWT.FILL, true, SWT.FILL, false);
@@ -325,7 +326,7 @@ public void widgetSelected(SelectionEvent e) {
325326
writeSelection();
326327
updateButtonState();
327328
updateFindAndReplaceHistory();
328-
evaluateFindReplaceStatus();
329+
decorate();
329330
}
330331
});
331332
setGridData(fSelectAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -342,7 +343,7 @@ public void widgetSelected(SelectionEvent e) {
342343
}
343344
updateButtonState();
344345
updateFindAndReplaceHistory();
345-
evaluateFindReplaceStatus();
346+
decorate();
346347
}
347348
});
348349
setGridData(fReplaceFindButton, SWT.FILL, false, SWT.FILL, false);
@@ -356,7 +357,7 @@ public void widgetSelected(SelectionEvent e) {
356357
}
357358
updateButtonState();
358359
updateFindAndReplaceHistory();
359-
evaluateFindReplaceStatus();
360+
decorate();
360361
}
361362
});
362363
setGridData(fReplaceSelectionButton, SWT.FILL, false, SWT.FILL, false);
@@ -370,7 +371,7 @@ public void widgetSelected(SelectionEvent e) {
370371
writeSelection();
371372
updateButtonState();
372373
updateFindAndReplaceHistory();
373-
evaluateFindReplaceStatus();
374+
decorate();
374375
}
375376
});
376377
setGridData(fReplaceAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -634,6 +635,8 @@ private Composite createInputPanel(Composite parent) {
634635
FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider(
635636
true);
636637
fFindField = new Combo(panel, SWT.DROP_DOWN | SWT.BORDER);
638+
fFindFieldDecoration = new ControlDecoration(fFindField, SWT.BOTTOM | SWT.LEFT);
639+
637640
fContentAssistFindField = new ContentAssistCommandAdapter(fFindField, contentAdapter, findProposer,
638641
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
639642
setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
@@ -750,6 +753,11 @@ public void widgetDefaultSelected(SelectionEvent e) {
750753
@Override
751754
public void widgetSelected(SelectionEvent e) {
752755
boolean newState = fIsRegExCheckBox.getSelection();
756+
if (!newState) {
757+
fFindFieldDecoration.hide();
758+
} else {
759+
SearchDecoration.validateRegex(fFindField.getText(), fFindFieldDecoration);
760+
}
753761
setupFindReplaceLogic();
754762
storeSettings();
755763
updateButtonState();
@@ -1050,9 +1058,10 @@ private void addDecorationMargin(Control control) {
10501058
if (!(layoutData instanceof GridData))
10511059
return;
10521060
GridData gd = (GridData) layoutData;
1053-
FieldDecoration dec = FieldDecorationRegistry.getDefault()
1061+
1062+
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
10541063
.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
1055-
gd.horizontalIndent = dec.getImage().getBounds().width;
1064+
gd.horizontalIndent = fieldDecoration.getImage().getBounds().width;
10561065
}
10571066

10581067
/**
@@ -1102,7 +1111,6 @@ private void updateButtonState(boolean disableReplace) {
11021111
}
11031112
}
11041113

1105-
11061114
/**
11071115
* Updates the given combo with the given content.
11081116
*
@@ -1335,19 +1343,15 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
13351343
}
13361344
}
13371345

1338-
/**
1339-
* Evaluate the status of the FindReplaceLogic object.
1340-
*/
1341-
private void evaluateFindReplaceStatus() {
1342-
IFindReplaceStatus status = findReplaceLogic.getStatus();
1346+
private void decorate() {
13431347

1344-
String dialogMessage = status.accept(new FindReplaceLogicMessageGenerator());
1345-
fStatusLabel.setText(dialogMessage);
1346-
if (status.isInputValid()) {
1347-
fStatusLabel.setForeground(fReplaceLabel.getForeground());
1348-
} else {
1349-
fStatusLabel.setForeground(JFaceColors.getErrorText(fStatusLabel.getDisplay()));
1350-
}
1348+
fFindField.addModifyListener(event -> {
1349+
if (fIsRegExCheckBox.getSelection()) {
1350+
SearchDecoration.validateRegex(fFindField.getText(), fFindFieldDecoration);
1351+
} else {
1352+
fFindFieldDecoration.hide();
1353+
}
1354+
});
13511355
}
13521356

13531357
private String getCurrentSelection() {

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)