Skip to content

Commit 7342d67

Browse files
committed
Changed the functionality of the regex search with control decorations
1 parent a431d71 commit 7342d67

File tree

8 files changed

+157
-47
lines changed

8 files changed

+157
-47
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: 29 additions & 22 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
/**
@@ -148,6 +147,8 @@ public void modifyText(ModifyEvent e) {
148147
return;
149148
}
150149
evaluateFindReplaceStatus();
150+
modificationHandler.run();
151+
decorate();
151152

152153
updateButtonState(!findReplaceLogic.isActive(SearchOptions.INCREMENTAL));
153154
}
@@ -196,6 +197,8 @@ public void modifyText(ModifyEvent e) {
196197
* @since 3.0
197198
*/
198199
private boolean fGiveFocusToFindField = true;
200+
private ControlDecoration fFindFieldDecoration;
201+
private SearchDecoration fFindFieldSearchDecoration = new SearchDecoration();
199202

200203
/**
201204
* Holds the mnemonic/button pairs for all buttons.
@@ -311,7 +314,7 @@ public void widgetSelected(SelectionEvent e) {
311314
writeSelection();
312315
updateButtonState(!somethingFound);
313316
updateFindHistory();
314-
evaluateFindReplaceStatus();
317+
decorate();
315318
}
316319
});
317320
setGridData(fFindNextButton, SWT.FILL, true, SWT.FILL, false);
@@ -325,7 +328,7 @@ public void widgetSelected(SelectionEvent e) {
325328
writeSelection();
326329
updateButtonState();
327330
updateFindAndReplaceHistory();
328-
evaluateFindReplaceStatus();
331+
decorate();
329332
}
330333
});
331334
setGridData(fSelectAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -342,7 +345,7 @@ public void widgetSelected(SelectionEvent e) {
342345
}
343346
updateButtonState();
344347
updateFindAndReplaceHistory();
345-
evaluateFindReplaceStatus();
348+
decorate();
346349
}
347350
});
348351
setGridData(fReplaceFindButton, SWT.FILL, false, SWT.FILL, false);
@@ -356,7 +359,7 @@ public void widgetSelected(SelectionEvent e) {
356359
}
357360
updateButtonState();
358361
updateFindAndReplaceHistory();
359-
evaluateFindReplaceStatus();
362+
decorate();
360363
}
361364
});
362365
setGridData(fReplaceSelectionButton, SWT.FILL, false, SWT.FILL, false);
@@ -370,7 +373,7 @@ public void widgetSelected(SelectionEvent e) {
370373
writeSelection();
371374
updateButtonState();
372375
updateFindAndReplaceHistory();
373-
evaluateFindReplaceStatus();
376+
decorate();
374377
}
375378
});
376379
setGridData(fReplaceAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -634,6 +637,8 @@ private Composite createInputPanel(Composite parent) {
634637
FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider(
635638
true);
636639
fFindField = new Combo(panel, SWT.DROP_DOWN | SWT.BORDER);
640+
fFindFieldDecoration = new ControlDecoration(fFindField, SWT.BOTTOM | SWT.LEFT);
641+
637642
fContentAssistFindField = new ContentAssistCommandAdapter(fFindField, contentAdapter, findProposer,
638643
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
639644
setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
@@ -750,6 +755,11 @@ public void widgetDefaultSelected(SelectionEvent e) {
750755
@Override
751756
public void widgetSelected(SelectionEvent e) {
752757
boolean newState = fIsRegExCheckBox.getSelection();
758+
if (!newState) {
759+
fFindFieldDecoration.hide();
760+
} else {
761+
fFindFieldSearchDecoration.decorateA(fFindFieldDecoration, getFindString());
762+
}
753763
setupFindReplaceLogic();
754764
storeSettings();
755765
updateButtonState();
@@ -1050,9 +1060,10 @@ private void addDecorationMargin(Control control) {
10501060
if (!(layoutData instanceof GridData))
10511061
return;
10521062
GridData gd = (GridData) layoutData;
1053-
FieldDecoration dec = FieldDecorationRegistry.getDefault()
1063+
1064+
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
10541065
.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
1055-
gd.horizontalIndent = dec.getImage().getBounds().width;
1066+
gd.horizontalIndent = fieldDecoration.getImage().getBounds().width;
10561067
}
10571068

10581069
/**
@@ -1335,19 +1346,15 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
13351346
}
13361347
}
13371348

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

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-
}
1351+
fFindField.addModifyListener(event -> {
1352+
if (fIsRegExCheckBox.getSelection()) {
1353+
fFindFieldSearchDecoration.decorateA(fFindFieldDecoration, fFindField.getText());
1354+
} else {
1355+
fFindFieldDecoration.hide();
1356+
}
1357+
});
13511358
}
13521359

13531360
private String getCurrentSelection() {

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)