Skip to content

Commit 3b530e1

Browse files
committed
Changed the functionality of the regex search with control decorations
1 parent d50e66d commit 3b530e1

File tree

8 files changed

+164
-28
lines changed

8 files changed

+164
-28
lines changed

bundles/org.eclipse.search.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ Require-Bundle:
1919
org.eclipse.text;bundle-version="3.13.100"
2020
Bundle-RequiredExecutionEnvironment: JavaSE-17
2121
Automatic-Module-Name: org.eclipse.search.core
22+
Import-Package: org.eclipse.jface.fieldassist,
23+
org.eclipse.swt.graphics

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Export-Package: org.eclipse.search.internal.ui;x-internal:=true,
1717
org.eclipse.search2.internal.ui.basic.views;x-internal:=true,
1818
org.eclipse.search2.internal.ui.text;x-internal:=true,
1919
org.eclipse.search2.internal.ui.text2;x-internal:=true
20+
Import-Package: org.eclipse.ui.internal.findandreplace
2021
Require-Bundle:
2122
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
2223
org.eclipse.core.resources;bundle-version="[3.14.0,4.0.0)",
@@ -29,7 +30,8 @@ Require-Bundle:
2930
org.eclipse.ui.forms;bundle-version="[3.4.0,4.0.0)",
3031
org.eclipse.ltk.core.refactoring;bundle-version="[3.5.0,4.0.0)",
3132
org.eclipse.ltk.ui.refactoring;bundle-version="[3.5.0,4.0.0)",
32-
org.eclipse.search.core;bundle-version="[3.16.0,4.0.0)";visibility:=reexport
33+
org.eclipse.search.core;bundle-version="[3.16.0,4.0.0)";visibility:=reexport,
34+
org.eclipse.ui.browser;bundle-version="3.8.400"
3335
Bundle-RequiredExecutionEnvironment: JavaSE-17
3436
Automatic-Module-Name: org.eclipse.search
3537
Service-Component: OSGI-INF/*.xml

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

Lines changed: 14 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

@@ -140,6 +141,8 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
140141
*/
141142
private String[] fPreviousExtensions;
142143
private Label fFileNamePatternDescription;
144+
private ControlDecoration fPatternDecoration;
145+
143146

144147

145148
private static class SearchPatternData {
@@ -450,6 +453,7 @@ public void setVisible(boolean visible) {
450453
}
451454

452455
final void updateOKStatus() {
456+
fPatternDecoration.hide();
453457
boolean regexStatus= validateRegex();
454458
getContainer().setPerformActionEnabled(regexStatus);
455459
}
@@ -481,22 +485,19 @@ public void createControl(Composite parent) {
481485
PlatformUI.getWorkbench().getHelpSystem().setHelp(result, ISearchHelpContextIds.TEXT_SEARCH_PAGE);
482486
}
483487

484-
private boolean validateRegex() {
488+
private boolean validateRegex() {
489+
485490
if (fIsRegExCheckbox.getSelection()) {
486491
try {
487492
PatternConstructor.createPattern(fPattern.getText(), fIsCaseSensitive, true);
488493
} 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
494+
SearchDecoration searchDecoration = new SearchDecoration();
495+
496+
searchDecoration.decorateA(fPatternDecoration, fPattern.getText());
495497
return false;
496498
}
497-
statusMessage(false, ""); //$NON-NLS-1$
498499
} else {
499-
statusMessage(false, SearchMessages.SearchPage_containingText_hint);
500+
fPatternDecoration.hide();
500501
}
501502
return true;
502503
}
@@ -510,8 +511,11 @@ private void addTextPatternControls(Composite group) {
510511
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
511512
label.setFont(group.getFont());
512513

514+
513515
// Pattern combo
514516
fPattern= new Combo(group, SWT.SINGLE | SWT.BORDER);
517+
fPatternDecoration = new ControlDecoration(fPattern, SWT.BOTTOM | SWT.LEFT);
518+
515519
// Not done here to prevent page from resizing
516520
// fPattern.setItems(getPreviousSearchPatterns());
517521
fPattern.addSelectionListener(new SelectionAdapter() {
@@ -561,7 +565,6 @@ public void widgetSelected(SelectionEvent e) {
561565
public void widgetSelected(SelectionEvent e) {
562566
fIsRegExSearch= fIsRegExCheckbox.getSelection();
563567
updateOKStatus();
564-
565568
writeConfiguration();
566569
fPatterFieldContentAssist.setEnabled(fIsRegExSearch);
567570
fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
@@ -860,15 +863,4 @@ private void writeConfiguration() {
860863

861864
}
862865

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ Require-Bundle:
3636
org.eclipse.jface.notifications
3737
Bundle-RequiredExecutionEnvironment: JavaSE-17
3838
Automatic-Module-Name: org.eclipse.ui.workbench.texteditor
39+
Import-Package: org.eclipse.search.internal.core.text

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

Lines changed: 28 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,8 +148,13 @@ private final class KeyboardShortcuts {
146148
private Color normalTextForegroundColor;
147149
private boolean positionAtTop = true;
148150
private final TargetPartVisibilityHandler targetPartVisibilityHandler;
151+
152+
private ControlDecoration controldecoration;
153+
private SearchDecoration searchDecoration;
154+
149155
private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField;
150156

157+
151158
public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) {
152159
super(parent);
153160
createFindReplaceLogic(target);
@@ -157,6 +164,7 @@ public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget
157164
targetPart = part;
158165
targetPartVisibilityHandler = new TargetPartVisibilityHandler(targetPart, this::asyncExecIfOpen, this::close,
159166
this::updatePlacementAndVisibility);
167+
this.searchDecoration = new SearchDecoration();
160168
}
161169

162170
@Override
@@ -581,6 +589,11 @@ private void createRegexSearchButton() {
581589
wholeWordSearchButton.setEnabled(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD));
582590
updateIncrementalSearch();
583591
updateContentAssistAvailability();
592+
if (!regexSearchButton.getSelection()) {
593+
controldecoration.hide();
594+
} else {
595+
searchDecoration.decorateA(controldecoration, getFindString());
596+
}
584597
}).withShortcuts(KeyboardShortcuts.OPTION_REGEX).build();
585598
regexSearchButton.setSelection(findReplaceLogic.isActive(SearchOptions.REGEX));
586599
}
@@ -650,6 +663,7 @@ private void createSearchBar() {
650663
HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "searchhistory", //$NON-NLS-1$
651664
HISTORY_SIZE);
652665
searchBar = new HistoryTextWrapper(searchHistory, searchBarContainer, SWT.SINGLE);
666+
controldecoration = new ControlDecoration(searchBar, SWT.BOTTOM | SWT.LEFT);
653667
GridDataFactory.fillDefaults().grab(true, true).align(GridData.FILL, GridData.FILL).applyTo(searchBar);
654668
searchBar.forceFocus();
655669
searchBar.selectAll();
@@ -674,6 +688,8 @@ public void focusLost(FocusEvent e) {
674688
});
675689
searchBar.setMessage(FindReplaceMessages.FindReplaceOverlay_searchBar_message);
676690
contentAssistSearchField = createContentAssistField(searchBar, true);
691+
692+
decorate();
677693
}
678694

679695
private void updateIncrementalSearch() {
@@ -991,6 +1007,7 @@ private void performSearch(boolean forward) {
9911007
activateInFindReplacerIf(SearchOptions.FORWARD, oldForwardSearchSetting);
9921008
evaluateFindReplaceStatus();
9931009
searchBar.storeHistory();
1010+
9941011
}
9951012

9961013
private void updateFromTargetSelection() {
@@ -1061,4 +1078,15 @@ private void setContentAssistsEnablement(boolean enable) {
10611078
private void updateContentAssistAvailability() {
10621079
setContentAssistsEnablement(findReplaceLogic.isAvailableAndActive(SearchOptions.REGEX));
10631080
}
1081+
1082+
public void decorate() {
1083+
searchBar.addModifyListener(event -> {
1084+
if (regexSearchButton.getSelection()) {
1085+
searchDecoration.decorateA(controldecoration, getFindString());
1086+
} else
1087+
controldecoration.hide();
1088+
});
1089+
1090+
}
1091+
10641092
}

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
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;
5455
import org.eclipse.jface.resource.JFaceColors;
@@ -64,6 +65,7 @@
6465

6566
import org.eclipse.ui.PlatformUI;
6667
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
68+
import org.eclipse.ui.internal.SearchDecoration;
6769
import org.eclipse.ui.internal.findandreplace.FindReplaceLogic;
6870
import org.eclipse.ui.internal.findandreplace.FindReplaceLogicMessageGenerator;
6971
import org.eclipse.ui.internal.findandreplace.FindReplaceMessages;
@@ -147,7 +149,8 @@ public void modifyText(ModifyEvent e) {
147149
fIgnoreNextEvent = false;
148150
return;
149151
}
150-
evaluateFindReplaceStatus();
152+
modificationHandler.run();
153+
decorate();
151154

152155
updateButtonState(!findReplaceLogic.isActive(SearchOptions.INCREMENTAL));
153156
}
@@ -196,6 +199,8 @@ public void modifyText(ModifyEvent e) {
196199
* @since 3.0
197200
*/
198201
private boolean fGiveFocusToFindField = true;
202+
private ControlDecoration fFindFieldDecoration;
203+
private SearchDecoration fFindFieldSearchDecoration = new SearchDecoration();
199204

200205
/**
201206
* Holds the mnemonic/button pairs for all buttons.
@@ -312,6 +317,8 @@ public void widgetSelected(SelectionEvent e) {
312317
updateButtonState(!somethingFound);
313318
updateFindHistory();
314319
evaluateFindReplaceStatus();
320+
321+
decorate();
315322
}
316323
});
317324
setGridData(fFindNextButton, SWT.FILL, true, SWT.FILL, false);
@@ -326,6 +333,7 @@ public void widgetSelected(SelectionEvent e) {
326333
updateButtonState();
327334
updateFindAndReplaceHistory();
328335
evaluateFindReplaceStatus();
336+
decorate();
329337
}
330338
});
331339
setGridData(fSelectAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -343,6 +351,8 @@ public void widgetSelected(SelectionEvent e) {
343351
updateButtonState();
344352
updateFindAndReplaceHistory();
345353
evaluateFindReplaceStatus();
354+
355+
decorate();
346356
}
347357
});
348358
setGridData(fReplaceFindButton, SWT.FILL, false, SWT.FILL, false);
@@ -357,6 +367,8 @@ public void widgetSelected(SelectionEvent e) {
357367
updateButtonState();
358368
updateFindAndReplaceHistory();
359369
evaluateFindReplaceStatus();
370+
371+
decorate();
360372
}
361373
});
362374
setGridData(fReplaceSelectionButton, SWT.FILL, false, SWT.FILL, false);
@@ -371,6 +383,8 @@ public void widgetSelected(SelectionEvent e) {
371383
updateButtonState();
372384
updateFindAndReplaceHistory();
373385
evaluateFindReplaceStatus();
386+
387+
decorate();
374388
}
375389
});
376390
setGridData(fReplaceAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -634,6 +648,8 @@ private Composite createInputPanel(Composite parent) {
634648
FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider(
635649
true);
636650
fFindField = new Combo(panel, SWT.DROP_DOWN | SWT.BORDER);
651+
fFindFieldDecoration = new ControlDecoration(fFindField, SWT.BOTTOM | SWT.LEFT);
652+
637653
fContentAssistFindField = new ContentAssistCommandAdapter(fFindField, contentAdapter, findProposer,
638654
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
639655
setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
@@ -750,6 +766,11 @@ public void widgetDefaultSelected(SelectionEvent e) {
750766
@Override
751767
public void widgetSelected(SelectionEvent e) {
752768
boolean newState = fIsRegExCheckBox.getSelection();
769+
if (!newState) {
770+
fFindFieldDecoration.hide();
771+
} else {
772+
fFindFieldSearchDecoration.decorateA(fFindFieldDecoration, getFindString());
773+
}
753774
setupFindReplaceLogic();
754775
storeSettings();
755776
updateButtonState();
@@ -1050,9 +1071,10 @@ private void addDecorationMargin(Control control) {
10501071
if (!(layoutData instanceof GridData))
10511072
return;
10521073
GridData gd = (GridData) layoutData;
1053-
FieldDecoration dec = FieldDecorationRegistry.getDefault()
1074+
1075+
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
10541076
.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
1055-
gd.horizontalIndent = dec.getImage().getBounds().width;
1077+
gd.horizontalIndent = fieldDecoration.getImage().getBounds().width;
10561078
}
10571079

10581080
/**
@@ -1335,6 +1357,17 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
13351357
}
13361358
}
13371359

1360+
public void decorate() {
1361+
1362+
fFindField.addModifyListener(event -> {
1363+
if (fIsRegExCheckBox.getSelection()) {
1364+
fFindFieldSearchDecoration.decorateA(fFindFieldDecoration, fFindField.getText());
1365+
} else {
1366+
fFindFieldDecoration.hide();
1367+
}
1368+
});
1369+
}
1370+
13381371
/**
13391372
* Evaluate the status of the FindReplaceLogic object.
13401373
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Plugin.name
44
Bundle-SymbolicName: org.eclipse.ui; singleton:=true
5-
Bundle-Version: 3.206.200.qualifier
5+
Bundle-Version: 3.207.0.qualifier
6+
Export-Package: org.eclipse.ui.internal
67
Bundle-Activator: org.eclipse.ui.internal.UIPlugin
78
Bundle-ActivationPolicy: lazy
89
Bundle-Vendor: %Plugin.providerName
910
Bundle-Localization: plugin
10-
Export-Package: org.eclipse.ui.internal;x-internal:=true
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)