Skip to content

Commit

Permalink
Find/replace overlay: improve replace toggle button appearance
Browse files Browse the repository at this point in the history
The button to toggle whether the replace bar in a find/replace overlay
is shown currently appears to be a rather heavyweight button with a
border. With this change, the button is replace with a lightweight
toolbar item like used for all other buttons in the overlay. This
improves the appearance as well as the implementation as the same
implementation patterns can now be applied to all buttons in the
overlay.
  • Loading branch information
HeikoKlare committed Sep 28, 2024
1 parent f35ef3a commit 4d28260
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*******************************************************************************/
package org.eclipse.ui.internal.findandreplace.overlay;

import static org.eclipse.ui.internal.findandreplace.overlay.FindReplaceShortcutUtil.registerActionShortcutsAtControl;

import java.util.List;
import java.util.function.Consumer;

Expand All @@ -28,7 +26,6 @@
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
Expand All @@ -37,7 +34,6 @@
import org.eclipse.swt.graphics.RGBA;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
Expand Down Expand Up @@ -117,8 +113,8 @@ private final class KeyboardShortcuts {
private boolean replaceBarOpen;

private Composite container;
private Button replaceToggle;
private FindReplaceOverlayAction replaceToggleShortcut;
private AccessibleToolBar replaceToggleTools;
private ToolItem replaceToggle;

private Composite contentGroup;

Expand Down Expand Up @@ -474,7 +470,7 @@ private Control createDialog(final Composite parent) {
private void initializeSearchShortcutHandlers() {
searchTools.registerActionShortcutsAtControl(searchBar);
closeTools.registerActionShortcutsAtControl(searchBar);
registerActionShortcutsAtControl(replaceToggleShortcut, searchBar);
replaceToggleTools.registerActionShortcutsAtControl(searchBar);
}

/**
Expand Down Expand Up @@ -712,15 +708,15 @@ private void createMainContainer(final Composite parent) {
}

private void createReplaceToggle() {
replaceToggleShortcut = new FindReplaceOverlayAction(this::toggleReplace);
replaceToggleShortcut.addShortcuts(KeyboardShortcuts.TOGGLE_REPLACE);
replaceToggle = new Button(container, SWT.FLAT | SWT.PUSH);
GridDataFactory.fillDefaults().grab(false, true).align(GridData.BEGINNING, GridData.FILL)
.applyTo(replaceToggle);
replaceToggle.setToolTipText(replaceToggleShortcut
.addShortcutHintToTooltipText(FindReplaceMessages.FindReplaceOverlay_replaceToggle_toolTip));
replaceToggle.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_OPEN_REPLACE_AREA));
replaceToggle.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> toggleReplace()));
replaceToggleTools = new AccessibleToolBar(container);
GridDataFactory.fillDefaults().grab(false, true).align(GridData.CENTER, GridData.CENTER)
.applyTo(replaceToggleTools);

replaceToggle = new AccessibleToolItemBuilder(replaceToggleTools)
.withShortcuts(KeyboardShortcuts.TOGGLE_REPLACE)
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_OPEN_REPLACE_AREA))
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceToggle_toolTip)
.withOperation(this::toggleReplace).build();
}

private void toggleReplace() {
Expand Down Expand Up @@ -765,7 +761,7 @@ private void createReplaceDialog() {
private void initializeReplaceShortcutHandlers() {
replaceTools.registerActionShortcutsAtControl(replaceBar);
closeTools.registerActionShortcutsAtControl(replaceBar);
registerActionShortcutsAtControl(replaceToggleShortcut, replaceBar);
replaceToggleTools.registerActionShortcutsAtControl(replaceBar);
}

private void enableSearchTools(boolean enable) {
Expand All @@ -778,8 +774,8 @@ private void enableReplaceToggle(boolean enable) {
return;
}
boolean visible = enable && findReplaceLogic.getTarget().isEditable();
((GridData) replaceToggle.getLayoutData()).exclude = !visible;
replaceToggle.setVisible(visible);
((GridData) replaceToggleTools.getLayoutData()).exclude = !visible;
replaceToggleTools.setVisible(visible);
}

private void enableReplaceTools(boolean enable) {
Expand Down

0 comments on commit 4d28260

Please sign in to comment.