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 Oct 1, 2024
1 parent 175f65e commit 21c0c67
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.swt.widgets.ToolItem;

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

class AccessibleToolItem {
private final ToolItem toolItem;
Expand All @@ -30,6 +31,7 @@ class AccessibleToolItem {

AccessibleToolItem(Composite parent, int styleBits) {
ToolBar toolbar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.CENTER, SWT.CENTER).applyTo(toolbar);
toolItem = new ToolItem(toolbar, styleBits);
addToolItemTraverseListener(toolbar);
}
Expand Down
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,7 @@
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.MouseListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
Expand All @@ -37,7 +35,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 @@ -119,8 +116,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 @@ -496,7 +493,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 @@ -734,15 +731,16 @@ 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.FILL, GridData.FILL)
.applyTo(replaceToggleTools);
replaceToggleTools.addMouseListener(MouseListener.mouseDownAdapter(__ -> toggleReplace()));

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 @@ -788,7 +786,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 @@ -801,8 +799,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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.stream.Collectors;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -54,7 +53,7 @@ class OverlayAccess implements IFindReplaceUIAccess {

private final ToolItem searchBackward;

private final Button openReplaceDialog;
private final ToolItem openReplaceDialog;

private HistoryTextWrapper replace;

Expand All @@ -78,7 +77,7 @@ class OverlayAccess implements IFindReplaceUIAccess {
inSelection= widgetExtractor.findToolItem("searchInSelection");
searchForward= widgetExtractor.findToolItem("searchForward");
searchBackward= widgetExtractor.findToolItem("searchBackward");
openReplaceDialog= widgetExtractor.findButton("replaceToggle");
openReplaceDialog= widgetExtractor.findToolItem("replaceToggle");
extractReplaceWidgets();
}

Expand Down

0 comments on commit 21c0c67

Please sign in to comment.