4949import org .eclipse .jface .dialogs .Dialog ;
5050import org .eclipse .jface .dialogs .IDialogSettings ;
5151import org .eclipse .jface .fieldassist .ComboContentAdapter ;
52+ import org .eclipse .jface .fieldassist .ControlDecoration ;
5253import org .eclipse .jface .fieldassist .FieldDecoration ;
5354import org .eclipse .jface .fieldassist .FieldDecorationRegistry ;
5455import org .eclipse .jface .resource .JFaceColors ;
6465
6566import org .eclipse .ui .PlatformUI ;
6667import org .eclipse .ui .fieldassist .ContentAssistCommandAdapter ;
68+ import org .eclipse .ui .internal .SearchDecoration ;
6769import org .eclipse .ui .internal .findandreplace .FindReplaceLogic ;
6870import org .eclipse .ui .internal .findandreplace .FindReplaceLogicMessageGenerator ;
6971import org .eclipse .ui .internal .findandreplace .FindReplaceMessages ;
7072import org .eclipse .ui .internal .findandreplace .HistoryStore ;
7173import org .eclipse .ui .internal .findandreplace .IFindReplaceLogic ;
7274import org .eclipse .ui .internal .findandreplace .SearchOptions ;
7375import org .eclipse .ui .internal .findandreplace .status .IFindReplaceStatus ;
76+ import org .eclipse .ui .internal .findandreplace .status .InvalidRegExStatus ;
7477import org .eclipse .ui .internal .texteditor .SWTUtil ;
7578
7679/**
@@ -147,7 +150,10 @@ public void modifyText(ModifyEvent e) {
147150 fIgnoreNextEvent = false ;
148151 return ;
149152 }
150- evaluateFindReplaceStatus ();
153+ modificationHandler .run ();
154+ fFindField .addModifyListener (event -> {
155+ decorate ();
156+ });
151157
152158 updateButtonState (!findReplaceLogic .isActive (SearchOptions .INCREMENTAL ));
153159 }
@@ -178,6 +184,7 @@ public void modifyText(ModifyEvent e) {
178184 private Button fReplaceSelectionButton , fReplaceFindButton , fFindNextButton , fReplaceAllButton , fSelectAllButton ;
179185 private Combo fFindField , fReplaceField ;
180186 private InputModifyListener fFindModifyListener , fReplaceModifyListener ;
187+ private boolean regexOk = true ;
181188
182189 /**
183190 * Find and replace command adapters.
@@ -196,6 +203,7 @@ public void modifyText(ModifyEvent e) {
196203 * @since 3.0
197204 */
198205 private boolean fGiveFocusToFindField = true ;
206+ private ControlDecoration fFindFieldDecoration ;
199207
200208 /**
201209 * Holds the mnemonic/button pairs for all buttons.
@@ -310,6 +318,7 @@ public void widgetSelected(SelectionEvent e) {
310318
311319 writeSelection ();
312320 updateButtonState (!somethingFound );
321+
313322 updateFindHistory ();
314323 evaluateFindReplaceStatus ();
315324 }
@@ -345,6 +354,7 @@ public void widgetSelected(SelectionEvent e) {
345354 evaluateFindReplaceStatus ();
346355 }
347356 });
357+
348358 setGridData (fReplaceFindButton , SWT .FILL , false , SWT .FILL , false );
349359
350360 fReplaceSelectionButton = makeButton (panel , FindReplaceMessages .FindReplace_ReplaceSelectionButton_label , 104 ,
@@ -634,6 +644,8 @@ private Composite createInputPanel(Composite parent) {
634644 FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider (
635645 true );
636646 fFindField = new Combo (panel , SWT .DROP_DOWN | SWT .BORDER );
647+ fFindFieldDecoration = new ControlDecoration (fFindField , SWT .BOTTOM | SWT .LEFT );
648+
637649 fContentAssistFindField = new ContentAssistCommandAdapter (fFindField , contentAdapter , findProposer ,
638650 ITextEditorActionDefinitionIds .CONTENT_ASSIST_PROPOSALS , new char [0 ], true );
639651 setGridData (fFindField , SWT .FILL , true , SWT .CENTER , false );
@@ -750,6 +762,10 @@ public void widgetDefaultSelected(SelectionEvent e) {
750762 @ Override
751763 public void widgetSelected (SelectionEvent e ) {
752764 boolean newState = fIsRegExCheckBox .getSelection ();
765+ decorate ();
766+ if (!newState ) {
767+ regexOk = true ;
768+ }
753769 setupFindReplaceLogic ();
754770 storeSettings ();
755771 updateButtonState ();
@@ -1050,9 +1066,10 @@ private void addDecorationMargin(Control control) {
10501066 if (!(layoutData instanceof GridData ))
10511067 return ;
10521068 GridData gd = (GridData ) layoutData ;
1053- FieldDecoration dec = FieldDecorationRegistry .getDefault ()
1069+
1070+ FieldDecoration fieldDecoration = FieldDecorationRegistry .getDefault ()
10541071 .getFieldDecoration (FieldDecorationRegistry .DEC_CONTENT_PROPOSAL );
1055- gd .horizontalIndent = dec .getImage ().getBounds ().width ;
1072+ gd .horizontalIndent = fieldDecoration .getImage ().getBounds ().width ;
10561073 }
10571074
10581075 /**
@@ -1092,8 +1109,9 @@ private void updateButtonState(boolean disableReplace) {
10921109 || !isRegExSearchAvailableAndActive ;
10931110
10941111 fWholeWordCheckBox .setEnabled (findReplaceLogic .isAvailable (SearchOptions .WHOLE_WORD ));
1095- fFindNextButton .setEnabled (enable && isFindStringSet );
1096- fSelectAllButton .setEnabled (enable && isFindStringSet && (target instanceof IFindReplaceTargetExtension4 ));
1112+ fFindNextButton .setEnabled (enable && isFindStringSet && regexOk );
1113+ fSelectAllButton .setEnabled (
1114+ enable && isFindStringSet && (target instanceof IFindReplaceTargetExtension4 ) && regexOk );
10971115 fReplaceSelectionButton .setEnabled (
10981116 !disableReplace && enable && isTargetEditable && hasActiveSelection && isSelectionGoodForReplace );
10991117 fReplaceFindButton .setEnabled (!disableReplace && enable && isTargetEditable && isFindStringSet
@@ -1102,7 +1120,6 @@ private void updateButtonState(boolean disableReplace) {
11021120 }
11031121 }
11041122
1105-
11061123 /**
11071124 * Updates the given combo with the given content.
11081125 *
@@ -1335,19 +1352,29 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
13351352 }
13361353 }
13371354
1338- /**
1339- * Evaluate the status of the FindReplaceLogic object.
1340- */
1355+ private void decorate () {
1356+ if (fIsRegExCheckBox .getSelection ()) {
1357+ regexOk = SearchDecoration .validateRegex (fFindField .getText (), fFindFieldDecoration );
1358+ updateButtonState (regexOk );
1359+
1360+ } else {
1361+ fFindFieldDecoration .hide ();
1362+ }
1363+ }
1364+
13411365 private void evaluateFindReplaceStatus () {
13421366 IFindReplaceStatus status = findReplaceLogic .getStatus ();
13431367
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 ()));
1368+ if (!(status instanceof InvalidRegExStatus )) {
1369+ String dialogMessage = status .accept (new FindReplaceLogicMessageGenerator ());
1370+ fStatusLabel .setText (dialogMessage );
1371+ if (status .isInputValid ()) {
1372+ fStatusLabel .setForeground (fReplaceLabel .getForeground ());
1373+ } else {
1374+ fStatusLabel .setForeground (JFaceColors .getErrorText (fStatusLabel .getDisplay ()));
1375+ }
13501376 }
1377+
13511378 }
13521379
13531380 private String getCurrentSelection () {
0 commit comments