Skip to content

Commit eb8bef5

Browse files
jannisCodefedejeanne
authored andcommitted
Changed the functionality of the regex search with control decorations
1 parent a431d71 commit eb8bef5

File tree

10 files changed

+159
-39
lines changed

10 files changed

+159
-39
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: 13 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,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP
140141
*/
141142
private String[] fPreviousExtensions;
142143
private Label fFileNamePatternDescription;
144+
private ControlDecoration decoration;
143145

144146

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

452454
final void updateOKStatus() {
455+
decoration.hide();
453456
boolean regexStatus= validateRegex();
454457
getContainer().setPerformActionEnabled(regexStatus);
455458
}
@@ -481,22 +484,19 @@ 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+
SearchDecoration sDecoration = new SearchDecoration();
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+
495+
sDecoration.decorateA(decoration, fPattern.getText());
495496
return false;
496497
}
497-
statusMessage(false, ""); //$NON-NLS-1$
498498
} else {
499-
statusMessage(false, SearchMessages.SearchPage_containingText_hint);
499+
decoration.hide();
500500
}
501501
return true;
502502
}
@@ -510,8 +510,11 @@ private void addTextPatternControls(Composite group) {
510510
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
511511
label.setFont(group.getFont());
512512

513+
513514
// Pattern combo
514515
fPattern= new Combo(group, SWT.SINGLE | SWT.BORDER);
516+
decoration = new ControlDecoration(fPattern, SWT.BOTTOM | SWT.LEFT);
517+
515518
// Not done here to prevent page from resizing
516519
// fPattern.setItems(getPreviousSearchPatterns());
517520
fPattern.addSelectionListener(new SelectionAdapter() {
@@ -561,7 +564,6 @@ public void widgetSelected(SelectionEvent e) {
561564
public void widgetSelected(SelectionEvent e) {
562565
fIsRegExSearch= fIsRegExCheckbox.getSelection();
563566
updateOKStatus();
564-
565567
writeConfiguration();
566568
fPatterFieldContentAssist.setEnabled(fIsRegExSearch);
567569
fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
@@ -860,15 +862,4 @@ private void writeConfiguration() {
860862

861863
}
862864

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

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: 30 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 decoration;
153+
private SearchDecoration dec;
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.dec = 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+
decoration.hide();
594+
} else {
595+
dec.decorateA(decoration, 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+
decoration = 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,17 @@ private void setContentAssistsEnablement(boolean enable) {
10611078
private void updateContentAssistAvailability() {
10621079
setContentAssistsEnablement(findReplaceLogic.isAvailableAndActive(SearchOptions.REGEX));
10631080
}
1081+
1082+
public void decorate() {
1083+
// decoration = new ControlDecoration(searchBar, SWT.BOTTOM | SWT.LEFT);
1084+
1085+
searchBar.addModifyListener(event -> {
1086+
if (regexSearchButton.getSelection()) {
1087+
dec.decorateA(decoration, getFindString());
1088+
} else
1089+
decoration.hide();
1090+
});
1091+
1092+
}
1093+
10641094
}

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

Lines changed: 25 additions & 13 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
/**
@@ -196,6 +195,8 @@ public void modifyText(ModifyEvent e) {
196195
* @since 3.0
197196
*/
198197
private boolean fGiveFocusToFindField = true;
198+
private ControlDecoration decoration;
199+
private SearchDecoration dec = new SearchDecoration();
199200

200201
/**
201202
* Holds the mnemonic/button pairs for all buttons.
@@ -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+
decoration = 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+
decoration.hide();
758+
} else {
759+
dec.decorateA(decoration, getFindString());
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 dec_one = FieldDecorationRegistry.getDefault()
10541063
.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
1055-
gd.horizontalIndent = dec.getImage().getBounds().width;
1064+
gd.horizontalIndent = dec_one.getImage().getBounds().width;
10561065
}
10571066

10581067
/**
@@ -1339,15 +1348,18 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
13391348
* Evaluate the status of the FindReplaceLogic object.
13401349
*/
13411350
private void evaluateFindReplaceStatus() {
1342-
IFindReplaceStatus status = findReplaceLogic.getStatus();
1351+
decorate();
1352+
}
13431353

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-
}
1354+
public void decorate() {
1355+
1356+
fFindField.addModifyListener(event -> {
1357+
if (fIsRegExCheckBox.getSelection()) {
1358+
dec.decorateA(decoration, fFindField.getText());
1359+
} else {
1360+
decoration.hide();
1361+
}
1362+
});
13511363
}
13521364

13531365
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)