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 @@ -147,6 +147,37 @@ private final class KeyboardShortcuts {
private ControlDecoration searchBarDecoration;
private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField;

private FocusListener targetActionActivationHandling = new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
setTextEditorActionsActivated(false);
}

@Override
public void focusLost(FocusEvent e) {
setTextEditorActionsActivated(true);
}

/*
* Adapted from
* org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#setActionsActivated(
* boolean)
*/
private void setTextEditorActionsActivated(boolean state) {
if (!(targetPart instanceof AbstractTextEditor)) {
return;
}
try {
Method method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", boolean.class); //$NON-NLS-1$
method.setAccessible(true);
method.invoke(targetPart, Boolean.valueOf(state));
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException | NoSuchMethodException ex) {
TextEditorPlugin.getDefault().getLog()
.log(Status.error("cannot (de-)activate actions for text editor", ex)); //$NON-NLS-1$
}
}
};

public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) {
targetPart = part;
targetControl = getTargetControl(parent, part);
Expand Down Expand Up @@ -561,39 +592,16 @@ private void createSearchBar() {
updateIncrementalSearch();
});
searchBar.addFocusListener(new FocusListener() {

@Override
public void focusGained(FocusEvent e) {
findReplaceLogic.resetIncrementalBaseLocation();
setTextEditorActionsActivated(false);
}

@Override
public void focusLost(FocusEvent e) {
showUserFeedback(normalTextForegroundColor, false);
setTextEditorActionsActivated(true);
}

/*
* Adapted from
* org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#setActionsActivated(
* boolean)
*/
private void setTextEditorActionsActivated(boolean state) {
if (!(targetPart instanceof AbstractTextEditor)) {
return;
}
try {
Method method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", boolean.class); //$NON-NLS-1$
method.setAccessible(true);
method.invoke(targetPart, Boolean.valueOf(state));
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException | NoSuchMethodException ex) {
TextEditorPlugin.getDefault().getLog()
.log(Status.error("cannot (de-)activate actions for text editor", ex)); //$NON-NLS-1$
}
}

});
searchBar.addFocusListener(targetActionActivationHandling);
searchBar.setMessage(FindReplaceMessages.FindReplaceOverlay_searchBar_message);
contentAssistSearchField = createContentAssistField(searchBar, true);
searchBar.addModifyListener(Event -> {
Expand All @@ -618,6 +626,7 @@ private void createReplaceBar() {
replaceBar.addModifyListener(e -> {
findReplaceLogic.setReplaceString(replaceBar.getText());
});
replaceBar.addFocusListener(targetActionActivationHandling);
replaceBar.addFocusListener(FocusListener.focusLostAdapter(e -> {
replaceBar.setForeground(normalTextForegroundColor);
searchBar.setForeground(normalTextForegroundColor);
Expand Down
Loading