72
72
import org .eclipse .ui .internal .findandreplace .FindReplaceMessages ;
73
73
import org .eclipse .ui .internal .findandreplace .HistoryStore ;
74
74
import org .eclipse .ui .internal .findandreplace .SearchOptions ;
75
- import org .eclipse .ui .internal .findandreplace .status .IFindReplaceStatus ;
76
75
import org .eclipse .ui .internal .texteditor .TextEditorPlugin ;
77
76
import org .eclipse .ui .part .MultiPageEditorSite ;
78
77
@@ -149,6 +148,8 @@ private final class KeyboardShortcuts {
149
148
private Color widgetBackgroundColor ;
150
149
private Color overlayBackgroundColor ;
151
150
private Color normalTextForegroundColor ;
151
+ private Color errorTextForegroundColor ;
152
+
152
153
private boolean positionAtTop = true ;
153
154
private ControlDecoration searchBarDecoration ;
154
155
private ContentAssistCommandAdapter contentAssistSearchField , contentAssistReplaceField ;
@@ -336,7 +337,7 @@ public Composite getContainerControl() {
336
337
private void performReplaceAll () {
337
338
BusyIndicator .showWhile (containerControl .getShell () != null ? containerControl .getShell ().getDisplay () : Display .getCurrent (),
338
339
findReplaceLogic ::performReplaceAll );
339
- evaluateFindReplaceStatus ();
340
+ evaluateStatusAfterReplace ();
340
341
replaceBar .storeHistory ();
341
342
searchBar .storeHistory ();
342
343
}
@@ -460,7 +461,7 @@ private void createContainerAndSearchControls(Composite parent) {
460
461
if (insertedInTargetParent ()) {
461
462
parent = parent .getParent ();
462
463
}
463
- retrieveBackgroundColor ();
464
+ retrieveColors ();
464
465
createMainContainer (parent );
465
466
initializeSearchShortcutHandlers ();
466
467
@@ -479,7 +480,7 @@ private void initializeSearchShortcutHandlers() {
479
480
* would otherwise inherit non-fitting custom colors from the containing
480
481
* StyledText.
481
482
*/
482
- private void retrieveBackgroundColor () {
483
+ private void retrieveColors () {
483
484
if (targetPart instanceof StatusTextEditor textEditor ) {
484
485
Control targetWidget = textEditor .getAdapter (ITextViewer .class ).getTextWidget ();
485
486
widgetBackgroundColor = targetWidget .getBackground ();
@@ -492,6 +493,7 @@ private void retrieveBackgroundColor() {
492
493
textBarForRetrievingTheRightColor .dispose ();
493
494
}
494
495
overlayBackgroundColor = retrieveDefaultCompositeBackground ();
496
+ errorTextForegroundColor = JFaceColors .getErrorText (targetControl .getShell ().getDisplay ());
495
497
}
496
498
497
499
private Color retrieveDefaultCompositeBackground () {
@@ -652,8 +654,6 @@ private void createWholeWordsButton() {
652
654
}
653
655
654
656
private void createReplaceTools () {
655
- Color warningColor = JFaceColors .getErrorText (containerControl .getShell ().getDisplay ());
656
-
657
657
replaceTools = new AccessibleToolBar (replaceContainer );
658
658
659
659
replaceTools .createToolItem (SWT .SEPARATOR );
@@ -664,7 +664,7 @@ private void createReplaceTools() {
664
664
.withToolTipText (FindReplaceMessages .FindReplaceOverlay_replaceButton_toolTip )
665
665
.withOperation (() -> {
666
666
if (getFindString ().isEmpty ()) {
667
- showUserFeedback ( warningColor , true );
667
+ applyErrorColor ( replaceBar );
668
668
return ;
669
669
}
670
670
performSingleReplace ();
@@ -675,7 +675,7 @@ private void createReplaceTools() {
675
675
.withToolTipText (FindReplaceMessages .FindReplaceOverlay_replaceAllButton_toolTip )
676
676
.withOperation (() -> {
677
677
if (getFindString ().isEmpty ()) {
678
- showUserFeedback ( warningColor , true );
678
+ applyErrorColor ( replaceBar );
679
679
return ;
680
680
}
681
681
performReplaceAll ();
@@ -703,9 +703,8 @@ private void createSearchBar() {
703
703
searchBar .selectAll ();
704
704
searchBar .addModifyListener (e -> {
705
705
wholeWordSearchButton .setEnabled (findReplaceLogic .isAvailable (SearchOptions .WHOLE_WORD ));
706
-
707
- showUserFeedback (normalTextForegroundColor , true );
708
706
updateIncrementalSearch ();
707
+ decorate ();
709
708
});
710
709
searchBar .addFocusListener (new FocusListener () {
711
710
@ Override
@@ -714,21 +713,18 @@ public void focusGained(FocusEvent e) {
714
713
}
715
714
@ Override
716
715
public void focusLost (FocusEvent e ) {
717
- showUserFeedback ( normalTextForegroundColor , false );
716
+ resetErrorColoring ( );
718
717
}
719
718
});
720
719
searchBar .addFocusListener (targetActionActivationHandling );
721
720
searchBar .setMessage (FindReplaceMessages .FindReplaceOverlay_searchBar_message );
722
721
contentAssistSearchField = createContentAssistField (searchBar , true );
723
- searchBar .addModifyListener (Event -> {
724
- decorate ();
725
- });
726
722
searchBar .setTabList (null );
727
723
}
728
724
729
725
private void updateIncrementalSearch () {
730
726
findReplaceLogic .setFindString (searchBar .getText ());
731
- evaluateFindReplaceStatus ();
727
+ evaluateStatusAfterFind ();
732
728
}
733
729
734
730
private void createReplaceBar () {
@@ -742,12 +738,10 @@ private void createReplaceBar() {
742
738
replaceBar .setMessage (FindReplaceMessages .FindReplaceOverlay_replaceBar_message );
743
739
replaceBar .addModifyListener (e -> {
744
740
findReplaceLogic .setReplaceString (replaceBar .getText ());
741
+ resetErrorColoring ();
745
742
});
746
743
replaceBar .addFocusListener (targetActionActivationHandling );
747
- replaceBar .addFocusListener (FocusListener .focusLostAdapter (e -> {
748
- replaceBar .setForeground (normalTextForegroundColor );
749
- searchBar .setForeground (normalTextForegroundColor );
750
- }));
744
+ replaceBar .addFocusListener (FocusListener .focusLostAdapter (e -> resetErrorColoring ()));
751
745
contentAssistReplaceField = createContentAssistField (replaceBar , false );
752
746
}
753
747
@@ -978,8 +972,13 @@ private String getFindString() {
978
972
}
979
973
980
974
private void performSingleReplace () {
981
- findReplaceLogic .performReplaceAndFind ();
982
- evaluateFindReplaceStatus ();
975
+ if (findReplaceLogic .performSelectAndReplace ()) {
976
+ findReplaceLogic .performSearch ();
977
+ evaluateStatusAfterFind ();
978
+ } else {
979
+ evaluateStatusAfterReplace ();
980
+ }
981
+
983
982
replaceBar .storeHistory ();
984
983
searchBar .storeHistory ();
985
984
}
@@ -989,7 +988,7 @@ private void performSearch(boolean forward) {
989
988
activateInFindReplacerIf (SearchOptions .FORWARD , forward );
990
989
findReplaceLogic .performSearch ();
991
990
activateInFindReplacerIf (SearchOptions .FORWARD , oldForwardSearchSetting );
992
- evaluateFindReplaceStatus ();
991
+ evaluateStatusAfterFind ();
993
992
searchBar .storeHistory ();
994
993
}
995
994
@@ -1008,22 +1007,28 @@ private void updateFromTargetSelection() {
1008
1007
searchBar .setSelection (0 , searchBar .getText ().length ());
1009
1008
}
1010
1009
1011
- private void evaluateFindReplaceStatus () {
1012
- Color warningColor = JFaceColors .getErrorText (containerControl .getShell ().getDisplay ());
1013
- IFindReplaceStatus status = findReplaceLogic .getStatus ();
1010
+ private void evaluateStatusAfterFind () {
1011
+ resetErrorColoring ();
1012
+ if (!findReplaceLogic .getStatus ().wasSuccessful ()) {
1013
+ applyErrorColor (searchBar );
1014
+ }
1015
+ }
1014
1016
1015
- if (!status .wasSuccessful ()) {
1016
- boolean colorReplaceBar = okayToUse (replaceBar ) && replaceBar .isFocusControl ();
1017
- showUserFeedback (warningColor , colorReplaceBar );
1018
- } else {
1019
- showUserFeedback (normalTextForegroundColor , false );
1017
+ private void evaluateStatusAfterReplace () {
1018
+ resetErrorColoring ();
1019
+ if (!findReplaceLogic .getStatus ().wasSuccessful ()) {
1020
+ applyErrorColor (replaceBar );
1020
1021
}
1021
1022
}
1022
1023
1023
- private void showUserFeedback (Color feedbackColor , boolean colorReplaceBar ) {
1024
- searchBar .setForeground (feedbackColor );
1025
- if (colorReplaceBar && okayToUse (replaceBar )) {
1026
- replaceBar .setForeground (feedbackColor );
1024
+ private void applyErrorColor (HistoryTextWrapper inputField ) {
1025
+ inputField .setForeground (errorTextForegroundColor );
1026
+ }
1027
+
1028
+ private void resetErrorColoring () {
1029
+ searchBar .setForeground (normalTextForegroundColor );
1030
+ if (okayToUse (replaceBar )) {
1031
+ replaceBar .setForeground (normalTextForegroundColor );
1027
1032
}
1028
1033
}
1029
1034
0 commit comments