Skip to content

Commit a0eee8a

Browse files
committed
Changed the functionality of the regex search with control decorations
1 parent a022116 commit a0eee8a

File tree

5 files changed

+148
-47
lines changed

5 files changed

+148
-47
lines changed

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/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

Lines changed: 27 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() {
@@ -1061,4 +1077,15 @@ private void setContentAssistsEnablement(boolean enable) {
10611077
private void updateContentAssistAvailability() {
10621078
setContentAssistsEnablement(findReplaceLogic.isAvailableAndActive(SearchOptions.REGEX));
10631079
}
1080+
1081+
private void decorate() {
1082+
searchBar.addModifyListener(event -> {
1083+
if (regexSearchButton.getSelection()) {
1084+
searchDecoration.decorateA(controldecoration, getFindString());
1085+
} else
1086+
controldecoration.hide();
1087+
});
1088+
1089+
}
1090+
10641091
}

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

Lines changed: 29 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,8 @@ public void modifyText(ModifyEvent e) {
196196
* @since 3.0
197197
*/
198198
private boolean fGiveFocusToFindField = true;
199+
private ControlDecoration fFindFieldDecoration;
200+
private SearchDecoration fFindFieldSearchDecoration = new SearchDecoration();
199201

200202
/**
201203
* Holds the mnemonic/button pairs for all buttons.
@@ -311,7 +313,7 @@ public void widgetSelected(SelectionEvent e) {
311313
writeSelection();
312314
updateButtonState(!somethingFound);
313315
updateFindHistory();
314-
evaluateFindReplaceStatus();
316+
decorate();
315317
}
316318
});
317319
setGridData(fFindNextButton, SWT.FILL, true, SWT.FILL, false);
@@ -325,7 +327,7 @@ public void widgetSelected(SelectionEvent e) {
325327
writeSelection();
326328
updateButtonState();
327329
updateFindAndReplaceHistory();
328-
evaluateFindReplaceStatus();
330+
decorate();
329331
}
330332
});
331333
setGridData(fSelectAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -342,7 +344,7 @@ public void widgetSelected(SelectionEvent e) {
342344
}
343345
updateButtonState();
344346
updateFindAndReplaceHistory();
345-
evaluateFindReplaceStatus();
347+
decorate();
346348
}
347349
});
348350
setGridData(fReplaceFindButton, SWT.FILL, false, SWT.FILL, false);
@@ -356,7 +358,7 @@ public void widgetSelected(SelectionEvent e) {
356358
}
357359
updateButtonState();
358360
updateFindAndReplaceHistory();
359-
evaluateFindReplaceStatus();
361+
decorate();
360362
}
361363
});
362364
setGridData(fReplaceSelectionButton, SWT.FILL, false, SWT.FILL, false);
@@ -370,7 +372,7 @@ public void widgetSelected(SelectionEvent e) {
370372
writeSelection();
371373
updateButtonState();
372374
updateFindAndReplaceHistory();
373-
evaluateFindReplaceStatus();
375+
decorate();
374376
}
375377
});
376378
setGridData(fReplaceAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -634,6 +636,8 @@ private Composite createInputPanel(Composite parent) {
634636
FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider(
635637
true);
636638
fFindField = new Combo(panel, SWT.DROP_DOWN | SWT.BORDER);
639+
fFindFieldDecoration = new ControlDecoration(fFindField, SWT.BOTTOM | SWT.LEFT);
640+
637641
fContentAssistFindField = new ContentAssistCommandAdapter(fFindField, contentAdapter, findProposer,
638642
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
639643
setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
@@ -750,6 +754,11 @@ public void widgetDefaultSelected(SelectionEvent e) {
750754
@Override
751755
public void widgetSelected(SelectionEvent e) {
752756
boolean newState = fIsRegExCheckBox.getSelection();
757+
if (!newState) {
758+
fFindFieldDecoration.hide();
759+
} else {
760+
fFindFieldSearchDecoration.decorateA(fFindFieldDecoration, getFindString());
761+
}
753762
setupFindReplaceLogic();
754763
storeSettings();
755764
updateButtonState();
@@ -1050,9 +1059,10 @@ private void addDecorationMargin(Control control) {
10501059
if (!(layoutData instanceof GridData))
10511060
return;
10521061
GridData gd = (GridData) layoutData;
1053-
FieldDecoration dec = FieldDecorationRegistry.getDefault()
1062+
1063+
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
10541064
.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
1055-
gd.horizontalIndent = dec.getImage().getBounds().width;
1065+
gd.horizontalIndent = fieldDecoration.getImage().getBounds().width;
10561066
}
10571067

10581068
/**
@@ -1102,7 +1112,6 @@ private void updateButtonState(boolean disableReplace) {
11021112
}
11031113
}
11041114

1105-
11061115
/**
11071116
* Updates the given combo with the given content.
11081117
*
@@ -1335,19 +1344,15 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
13351344
}
13361345
}
13371346

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

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

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