Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import org.eclipse.ui.internal.findandreplace.FindReplaceMessages;
import org.eclipse.ui.internal.findandreplace.HistoryStore;
import org.eclipse.ui.internal.findandreplace.SearchOptions;
import org.eclipse.ui.internal.findandreplace.status.IFindReplaceStatus;
import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
import org.eclipse.ui.part.MultiPageEditorSite;

Expand Down Expand Up @@ -149,6 +148,8 @@ private final class KeyboardShortcuts {
private Color widgetBackgroundColor;
private Color overlayBackgroundColor;
private Color normalTextForegroundColor;
private Color errorTextForegroundColor;

private boolean positionAtTop = true;
private ControlDecoration searchBarDecoration;
private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField;
Expand Down Expand Up @@ -336,7 +337,7 @@ public Composite getContainerControl() {
private void performReplaceAll() {
BusyIndicator.showWhile(containerControl.getShell() != null ? containerControl.getShell().getDisplay() : Display.getCurrent(),
findReplaceLogic::performReplaceAll);
evaluateFindReplaceStatus();
evaluateStatusAfterReplace();
replaceBar.storeHistory();
searchBar.storeHistory();
}
Expand Down Expand Up @@ -460,7 +461,7 @@ private void createContainerAndSearchControls(Composite parent) {
if (insertedInTargetParent()) {
parent = parent.getParent();
}
retrieveBackgroundColor();
retrieveColors();
createMainContainer(parent);
initializeSearchShortcutHandlers();

Expand All @@ -479,7 +480,7 @@ private void initializeSearchShortcutHandlers() {
* would otherwise inherit non-fitting custom colors from the containing
* StyledText.
*/
private void retrieveBackgroundColor() {
private void retrieveColors() {
if (targetPart instanceof StatusTextEditor textEditor) {
Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget();
widgetBackgroundColor = targetWidget.getBackground();
Expand All @@ -492,6 +493,7 @@ private void retrieveBackgroundColor() {
textBarForRetrievingTheRightColor.dispose();
}
overlayBackgroundColor = retrieveDefaultCompositeBackground();
errorTextForegroundColor = JFaceColors.getErrorText(targetControl.getShell().getDisplay());
}

private Color retrieveDefaultCompositeBackground() {
Expand Down Expand Up @@ -652,8 +654,6 @@ private void createWholeWordsButton() {
}

private void createReplaceTools() {
Color warningColor = JFaceColors.getErrorText(containerControl.getShell().getDisplay());

replaceTools = new AccessibleToolBar(replaceContainer);

replaceTools.createToolItem(SWT.SEPARATOR);
Expand All @@ -664,7 +664,7 @@ private void createReplaceTools() {
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceButton_toolTip)
.withOperation(() -> {
if (getFindString().isEmpty()) {
showUserFeedback(warningColor, true);
applyErrorColor(replaceBar);
return;
}
performSingleReplace();
Expand All @@ -675,7 +675,7 @@ private void createReplaceTools() {
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceAllButton_toolTip)
.withOperation(() -> {
if (getFindString().isEmpty()) {
showUserFeedback(warningColor, true);
applyErrorColor(replaceBar);
return;
}
performReplaceAll();
Expand Down Expand Up @@ -703,9 +703,8 @@ private void createSearchBar() {
searchBar.selectAll();
searchBar.addModifyListener(e -> {
wholeWordSearchButton.setEnabled(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD));

showUserFeedback(normalTextForegroundColor, true);
updateIncrementalSearch();
decorate();
});
searchBar.addFocusListener(new FocusListener() {
@Override
Expand All @@ -714,21 +713,18 @@ public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
showUserFeedback(normalTextForegroundColor, false);
resetErrorColoring();
}
});
searchBar.addFocusListener(targetActionActivationHandling);
searchBar.setMessage(FindReplaceMessages.FindReplaceOverlay_searchBar_message);
contentAssistSearchField = createContentAssistField(searchBar, true);
searchBar.addModifyListener(Event -> {
decorate();
});
searchBar.setTabList(null);
}

private void updateIncrementalSearch() {
findReplaceLogic.setFindString(searchBar.getText());
evaluateFindReplaceStatus();
evaluateStatusAfterFind();
}

private void createReplaceBar() {
Expand All @@ -742,12 +738,10 @@ private void createReplaceBar() {
replaceBar.setMessage(FindReplaceMessages.FindReplaceOverlay_replaceBar_message);
replaceBar.addModifyListener(e -> {
findReplaceLogic.setReplaceString(replaceBar.getText());
resetErrorColoring();
});
replaceBar.addFocusListener(targetActionActivationHandling);
replaceBar.addFocusListener(FocusListener.focusLostAdapter(e -> {
replaceBar.setForeground(normalTextForegroundColor);
searchBar.setForeground(normalTextForegroundColor);
}));
replaceBar.addFocusListener(FocusListener.focusLostAdapter(e -> resetErrorColoring()));
contentAssistReplaceField = createContentAssistField(replaceBar, false);
}

Expand Down Expand Up @@ -978,8 +972,13 @@ private String getFindString() {
}

private void performSingleReplace() {
findReplaceLogic.performReplaceAndFind();
evaluateFindReplaceStatus();
if (findReplaceLogic.performSelectAndReplace()) {
findReplaceLogic.performSearch();
evaluateStatusAfterFind();
} else {
evaluateStatusAfterReplace();
}

replaceBar.storeHistory();
searchBar.storeHistory();
}
Expand All @@ -989,7 +988,7 @@ private void performSearch(boolean forward) {
activateInFindReplacerIf(SearchOptions.FORWARD, forward);
findReplaceLogic.performSearch();
activateInFindReplacerIf(SearchOptions.FORWARD, oldForwardSearchSetting);
evaluateFindReplaceStatus();
evaluateStatusAfterFind();
searchBar.storeHistory();
}

Expand All @@ -1008,22 +1007,28 @@ private void updateFromTargetSelection() {
searchBar.setSelection(0, searchBar.getText().length());
}

private void evaluateFindReplaceStatus() {
Color warningColor = JFaceColors.getErrorText(containerControl.getShell().getDisplay());
IFindReplaceStatus status = findReplaceLogic.getStatus();
private void evaluateStatusAfterFind() {
resetErrorColoring();
if (!findReplaceLogic.getStatus().wasSuccessful()) {
applyErrorColor(searchBar);
}
}

if (!status.wasSuccessful()) {
boolean colorReplaceBar = okayToUse(replaceBar) && replaceBar.isFocusControl();
showUserFeedback(warningColor, colorReplaceBar);
} else {
showUserFeedback(normalTextForegroundColor, false);
private void evaluateStatusAfterReplace() {
resetErrorColoring();
if (!findReplaceLogic.getStatus().wasSuccessful()) {
applyErrorColor(replaceBar);
}
}

private void showUserFeedback(Color feedbackColor, boolean colorReplaceBar) {
searchBar.setForeground(feedbackColor);
if (colorReplaceBar && okayToUse(replaceBar)) {
replaceBar.setForeground(feedbackColor);
private void applyErrorColor(HistoryTextWrapper inputField) {
inputField.setForeground(errorTextForegroundColor);
}

private void resetErrorColoring() {
searchBar.setForeground(normalTextForegroundColor);
if (okayToUse(replaceBar)) {
replaceBar.setForeground(normalTextForegroundColor);
}
}

Expand Down
Loading