Skip to content
Open
Show file tree
Hide file tree
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 @@ -23,7 +23,8 @@
class AccessibleToolItem {
private final ToolItem toolItem;

private FindReplaceOverlayAction action;
private String baseToolTipText;


AccessibleToolItem(Composite parent, int styleBits) {
ToolBar toolbar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL);
Expand All @@ -44,13 +45,22 @@ void setImage(Image image) {
}

void setToolTipText(String text) {
toolItem.setToolTipText(action != null ? action.addShortcutHintToTooltipText(text) : text);
this.baseToolTipText = text;
toolItem.setToolTipText(text);
}

void setAction(FindReplaceOverlayAction newAction) {
this.action = newAction;
void setAction(FindReplaceOverlayAction action) {
setToolTipText(toolItem.getToolTipText());
toolItem.addSelectionListener(SelectionListener.widgetSelectedAdapter(__ -> action.execute()));
action.addShortcutHintListener(hint -> {
if (!toolItem.isDisposed()) {
String tooltipWithHint = baseToolTipText;
if (!hint.isEmpty()) {
tooltipWithHint += " (" + hint + ")"; //$NON-NLS-1$//$NON-NLS-2$
}
toolItem.setToolTipText(tooltipWithHint);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.ui.internal.findandreplace.overlay;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -136,10 +135,6 @@ private static final class KeyboardShortcuts {
private ToolItem replaceButton;
private ToolItem replaceAllButton;

private final List<FindReplaceOverlayAction> commonActions = new ArrayList<>();
private final List<FindReplaceOverlayAction> searchActions = new ArrayList<>();
private final List<FindReplaceOverlayAction> replaceActions = new ArrayList<>();

private Color widgetBackgroundColor;
private Color overlayBackgroundColor;
private Color normalTextForegroundColor;
Expand All @@ -154,12 +149,16 @@ private static final class KeyboardShortcuts {
private final FocusListener targetActionActivationHandling = new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
commandSupport.overlayActivated();
if (e.widget == searchBar.getTextBar()) {
commandSupport.searchBarActivated();
} else if (replaceBar != null && e.widget == replaceBar.getTextBar()) {
commandSupport.replaceBarActivated();
}
}

@Override
public void focusLost(FocusEvent e) {
commandSupport.overlayDeactivated();
commandSupport.searchOrReplaceBarDeactivated();
}
};

Expand Down Expand Up @@ -415,14 +414,8 @@ private void createContainerAndSearchControls(Composite parent) {
}

private void initializeSearchShortcutHandlers() {
registerActionShortcutsAtControl(commonActions, searchBar);
registerActionShortcutsAtControl(searchActions, searchBar);
}

private void registerActionShortcutsAtControl(List<FindReplaceOverlayAction> actions, Control control) {
for (FindReplaceOverlayAction action : actions) {
FindReplaceShortcutUtil.registerActionShortcutsAtControl(action, control);
}
commandSupport.registerCommonActionShortcutsAtControl(searchBar);
commandSupport.registerSearchActionShortcutsAtControl(searchBar);
}

/**
Expand Down Expand Up @@ -498,7 +491,7 @@ private void createReplaceToggle() {

FindReplaceOverlayAction replaceToggleAction = new FindReplaceOverlayAction(() -> setReplaceVisible(!replaceBarOpen));
replaceToggleAction.addShortcuts(KeyboardShortcuts.TOGGLE_REPLACE);
commonActions.add(replaceToggleAction);
commandSupport.registerCommonAction(replaceToggleAction);

replaceToggle = new AccessibleToolItemBuilder(replaceToggleTools)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_OPEN_REPLACE_AREA))
Expand Down Expand Up @@ -530,15 +523,15 @@ private void createSearchTools() {

FindReplaceOverlayAction searchBackwardAction = new FindReplaceOverlayAction(() -> performSearch(false));
searchBackwardAction.addShortcuts(KeyboardShortcuts.SEARCH_BACKWARD);
searchActions.add(searchBackwardAction);
commandSupport.registerSearchAction(searchBackwardAction);
searchBackwardButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.PUSH)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_FIND_PREV))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_upSearchButton_toolTip)
.withAction(searchBackwardAction).build();

FindReplaceOverlayAction searchForwardAction = new FindReplaceOverlayAction(() -> performSearch(true));
searchForwardAction.addShortcuts(KeyboardShortcuts.SEARCH_FORWARD);
searchActions.add(searchForwardAction);
commandSupport.registerSearchAction(searchForwardAction);
searchForwardButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.PUSH)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_FIND_NEXT))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_downSearchButton_toolTip)
Expand All @@ -547,7 +540,7 @@ private void createSearchTools() {

FindReplaceOverlayAction selectAllAction = new FindReplaceOverlayAction(this::performSelectAll);
selectAllAction.addShortcuts(KeyboardShortcuts.SEARCH_ALL);
searchActions.add(selectAllAction);
commandSupport.registerSearchAction(selectAllAction);
selectAllButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.PUSH)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_SEARCH_ALL))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_searchAllButton_toolTip)
Expand All @@ -560,7 +553,7 @@ private void createCloseTools() {

FindReplaceOverlayAction closeAction = new FindReplaceOverlayAction(this::close);
closeAction.addShortcuts(KeyboardShortcuts.CLOSE);
commonActions.add(closeAction);
commandSupport.registerCommonAction(closeAction);

// Close button
new AccessibleToolItemBuilder(closeTools).withStyleBits(SWT.PUSH)
Expand All @@ -573,7 +566,7 @@ private void createAreaSearchButton() {
FindReplaceOverlaySearchOptionAction searchInSelectionAction = new FindReplaceOverlaySearchOptionAction(SearchOptions.GLOBAL, findReplaceLogic);
searchInSelectionAction.addExecutionListener(this::updateIncrementalSearch);
searchInSelectionAction.addShortcuts(KeyboardShortcuts.OPTION_SEARCH_IN_SELECTION);
commonActions.add(searchInSelectionAction);
commandSupport.registerCommonAction(searchInSelectionAction);
searchInSelectionButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.CHECK)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_SEARCH_IN_AREA))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_searchInSelectionButton_toolTip)
Expand All @@ -585,7 +578,7 @@ private void createRegexSearchButton() {
findReplaceLogic);
regexAction.addExecutionListener(this::updateIncrementalSearch);
regexAction.addShortcuts(KeyboardShortcuts.OPTION_REGEX);
commonActions.add(regexAction);
commandSupport.registerCommonAction(regexAction);
regexSearchButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.CHECK)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_FIND_REGEX))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_regexSearchButton_toolTip)
Expand All @@ -601,7 +594,7 @@ private void createCaseSensitiveButton() {
SearchOptions.CASE_SENSITIVE, findReplaceLogic);
caseSensitiveAction.addExecutionListener(this::updateIncrementalSearch);
caseSensitiveAction.addShortcuts(KeyboardShortcuts.OPTION_CASE_SENSITIVE);
commonActions.add(caseSensitiveAction);
commandSupport.registerCommonAction(caseSensitiveAction);
caseSensitiveSearchButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.CHECK)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_CASE_SENSITIVE))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_caseSensitiveButton_toolTip)
Expand All @@ -613,7 +606,7 @@ private void createWholeWordsButton() {
SearchOptions.WHOLE_WORD, findReplaceLogic);
wholeWordAction.addExecutionListener(this::updateIncrementalSearch);
wholeWordAction.addShortcuts(KeyboardShortcuts.OPTION_WHOLE_WORD);
commonActions.add(wholeWordAction);
commandSupport.registerCommonAction(wholeWordAction);
wholeWordSearchButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.CHECK)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_WHOLE_WORD))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_wholeWordsButton_toolTip)
Expand All @@ -634,7 +627,7 @@ private void createReplaceTools() {
performSingleReplace();
});
replaceAction.addShortcuts(KeyboardShortcuts.SEARCH_FORWARD);
replaceActions.add(replaceAction);
commandSupport.registerReplaceAction(replaceAction);
replaceButton = new AccessibleToolItemBuilder(replaceTools).withStyleBits(SWT.PUSH)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_REPLACE))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceButton_toolTip)
Expand All @@ -648,7 +641,7 @@ private void createReplaceTools() {
performReplaceAll();
});
replaceAllAction.addShortcuts(KeyboardShortcuts.SEARCH_ALL);
replaceActions.add(replaceAllAction);
commandSupport.registerReplaceAction(replaceAllAction);
replaceAllButton = new AccessibleToolItemBuilder(replaceTools).withStyleBits(SWT.PUSH)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_REPLACE_ALL))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceAllButton_toolTip)
Expand Down Expand Up @@ -754,6 +747,7 @@ private void hideReplace() {
return;
}
customFocusOrder.dispose();
commandSupport.unregisterReplaceActions();
searchBar.forceFocus();
contentAssistReplaceField = null;
replaceBarOpen = false;
Expand All @@ -776,8 +770,8 @@ private void createReplaceDialog() {
}

private void initializeReplaceShortcutHandlers() {
registerActionShortcutsAtControl(commonActions, replaceBar);
registerActionShortcutsAtControl(replaceActions, replaceBar);
commandSupport.registerCommonActionShortcutsAtControl(replaceBar);
commandSupport.registerReplaceActionShortcutsAtControl(replaceBar);
}

private void enableSearchTools(boolean enable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

import org.eclipse.jface.bindings.keys.KeyStroke;

Expand All @@ -21,6 +22,8 @@ class FindReplaceOverlayAction {

private final List<Runnable> executionListeners = new ArrayList<>();

private final List<Consumer<String>> shortcutHintListeners = new ArrayList<>();

private final List<KeyStroke> shortcuts = new ArrayList<>();

FindReplaceOverlayAction(Runnable operation) {
Expand Down Expand Up @@ -48,13 +51,6 @@ boolean executeIfMatching(KeyStroke keystroke) {
return false;
}

String addShortcutHintToTooltipText(String originalTooltipText) {
if (shortcuts.isEmpty()) {
return originalTooltipText;
}
return originalTooltipText + " (" + shortcuts.get(0).format() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}

void addExecutionListener(Runnable listener) {
executionListeners.add(listener);
}
Expand All @@ -65,4 +61,23 @@ void notifyExecutionListeners() {
}
}

void addShortcutHintListener(Consumer<String> listener) {
shortcutHintListeners.add(listener);
}

void activateKeyBinding() {
shortcutHintListeners.forEach(listener -> listener.accept(getShortcutHint()));
}

private String getShortcutHint() {
if (shortcuts.isEmpty()) {
return ""; //$NON-NLS-1$
}
return shortcuts.get(0).format(); // $NON-NLS-1$
}

void deactivateKeyBinding() {
shortcutHintListeners.forEach(listener -> listener.accept("")); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
package org.eclipse.ui.internal.findandreplace.overlay;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.widgets.Control;

import org.eclipse.core.runtime.ILog;

import org.eclipse.jface.action.IAction;
Expand All @@ -37,15 +40,61 @@ class FindReplaceOverlayCommandSupport {
private final IWorkbenchPart targetPart;
private DeactivateGlobalActionHandlers globalActionHandlerDeaction;

private List<FindReplaceOverlayAction> commonActions = new ArrayList<>();
private List<FindReplaceOverlayAction> searchActions = new ArrayList<>();
private List<FindReplaceOverlayAction> replaceActions = new ArrayList<>();

FindReplaceOverlayCommandSupport(IWorkbenchPart targetPart) {
this.targetPart = targetPart;
}

void overlayActivated() {
void registerCommonAction(FindReplaceOverlayAction action) {
this.commonActions.add(action);
}

void registerSearchAction(FindReplaceOverlayAction action) {
this.searchActions.add(action);
}

void registerReplaceAction(FindReplaceOverlayAction action) {
this.replaceActions.add(action);
}

void unregisterReplaceActions() {
this.replaceActions.clear();
}

void registerCommonActionShortcutsAtControl(Control control) {
commonActions.forEach(action -> FindReplaceShortcutUtil.registerActionShortcutsAtControl(action, control));
}

void registerSearchActionShortcutsAtControl(Control control) {
searchActions.forEach(action -> FindReplaceShortcutUtil.registerActionShortcutsAtControl(action, control));
}

void registerReplaceActionShortcutsAtControl(Control control) {
replaceActions.forEach(action -> FindReplaceShortcutUtil.registerActionShortcutsAtControl(action, control));
}

void searchBarActivated() {
searchOrReplaceBarActivated();
searchActions.forEach(FindReplaceOverlayAction::activateKeyBinding);
}

void replaceBarActivated() {
searchOrReplaceBarActivated();
replaceActions.forEach(FindReplaceOverlayAction::activateKeyBinding);
}

private void searchOrReplaceBarActivated() {
setTextEditorActionsActivated(false);
commonActions.forEach(FindReplaceOverlayAction::activateKeyBinding);
}

void overlayDeactivated() {
void searchOrReplaceBarDeactivated() {
commonActions.forEach(FindReplaceOverlayAction::deactivateKeyBinding);
searchActions.forEach(FindReplaceOverlayAction::deactivateKeyBinding);
replaceActions.forEach(FindReplaceOverlayAction::deactivateKeyBinding);
setTextEditorActionsActivated(true);
}

Expand Down
Loading