Skip to content

Commit 982ef62

Browse files
committed
Find/replace overlay: improve replace toggle button appearance
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.
1 parent f9b743f commit 982ef62

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/AccessibleToolItem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.eclipse.swt.widgets.ToolItem;
2323

2424
import org.eclipse.jface.bindings.keys.KeyStroke;
25+
import org.eclipse.jface.layout.GridDataFactory;
2526

2627
class AccessibleToolItem {
2728
private final ToolItem toolItem;
@@ -30,6 +31,7 @@ class AccessibleToolItem {
3031

3132
AccessibleToolItem(Composite parent, int styleBits) {
3233
ToolBar toolbar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL);
34+
GridDataFactory.fillDefaults().grab(true, true).align(SWT.CENTER, SWT.CENTER).applyTo(toolbar);
3335
toolItem = new ToolItem(toolbar, styleBits);
3436
addToolItemTraverseListener(toolbar);
3537
}

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.internal.findandreplace.overlay;
1515

16-
import static org.eclipse.ui.internal.findandreplace.overlay.FindReplaceShortcutUtil.registerActionShortcutsAtControl;
17-
1816
import java.util.List;
1917
import java.util.function.Consumer;
2018

@@ -28,7 +26,7 @@
2826
import org.eclipse.swt.events.FocusEvent;
2927
import org.eclipse.swt.events.FocusListener;
3028
import org.eclipse.swt.events.KeyListener;
31-
import org.eclipse.swt.events.SelectionListener;
29+
import org.eclipse.swt.events.MouseListener;
3230
import org.eclipse.swt.events.ShellAdapter;
3331
import org.eclipse.swt.events.ShellEvent;
3432
import org.eclipse.swt.graphics.Color;
@@ -37,7 +35,6 @@
3735
import org.eclipse.swt.graphics.RGBA;
3836
import org.eclipse.swt.graphics.Rectangle;
3937
import org.eclipse.swt.layout.GridData;
40-
import org.eclipse.swt.widgets.Button;
4138
import org.eclipse.swt.widgets.Composite;
4239
import org.eclipse.swt.widgets.Control;
4340
import org.eclipse.swt.widgets.Display;
@@ -117,8 +114,8 @@ private final class KeyboardShortcuts {
117114
private boolean replaceBarOpen;
118115

119116
private Composite container;
120-
private Button replaceToggle;
121-
private FindReplaceOverlayAction replaceToggleShortcut;
117+
private AccessibleToolBar replaceToggleTools;
118+
private ToolItem replaceToggle;
122119

123120
private Composite contentGroup;
124121

@@ -474,7 +471,7 @@ private Control createDialog(final Composite parent) {
474471
private void initializeSearchShortcutHandlers() {
475472
searchTools.registerActionShortcutsAtControl(searchBar);
476473
closeTools.registerActionShortcutsAtControl(searchBar);
477-
registerActionShortcutsAtControl(replaceToggleShortcut, searchBar);
474+
replaceToggleTools.registerActionShortcutsAtControl(searchBar);
478475
}
479476

480477
/**
@@ -712,15 +709,16 @@ private void createMainContainer(final Composite parent) {
712709
}
713710

714711
private void createReplaceToggle() {
715-
replaceToggleShortcut = new FindReplaceOverlayAction(this::toggleReplace);
716-
replaceToggleShortcut.addShortcuts(KeyboardShortcuts.TOGGLE_REPLACE);
717-
replaceToggle = new Button(container, SWT.FLAT | SWT.PUSH);
718-
GridDataFactory.fillDefaults().grab(false, true).align(GridData.BEGINNING, GridData.FILL)
719-
.applyTo(replaceToggle);
720-
replaceToggle.setToolTipText(replaceToggleShortcut
721-
.addShortcutHintToTooltipText(FindReplaceMessages.FindReplaceOverlay_replaceToggle_toolTip));
722-
replaceToggle.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_OPEN_REPLACE_AREA));
723-
replaceToggle.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> toggleReplace()));
712+
replaceToggleTools = new AccessibleToolBar(container);
713+
GridDataFactory.fillDefaults().grab(false, true).align(GridData.FILL, GridData.FILL)
714+
.applyTo(replaceToggleTools);
715+
replaceToggleTools.addMouseListener(MouseListener.mouseDownAdapter(__ -> toggleReplace()));
716+
717+
replaceToggle = new AccessibleToolItemBuilder(replaceToggleTools)
718+
.withShortcuts(KeyboardShortcuts.TOGGLE_REPLACE)
719+
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_OPEN_REPLACE_AREA))
720+
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceToggle_toolTip)
721+
.withOperation(this::toggleReplace).build();
724722
}
725723

726724
private void toggleReplace() {
@@ -765,7 +763,7 @@ private void createReplaceDialog() {
765763
private void initializeReplaceShortcutHandlers() {
766764
replaceTools.registerActionShortcutsAtControl(replaceBar);
767765
closeTools.registerActionShortcutsAtControl(replaceBar);
768-
registerActionShortcutsAtControl(replaceToggleShortcut, replaceBar);
766+
replaceToggleTools.registerActionShortcutsAtControl(replaceBar);
769767
}
770768

771769
private void enableSearchTools(boolean enable) {
@@ -778,8 +776,8 @@ private void enableReplaceToggle(boolean enable) {
778776
return;
779777
}
780778
boolean visible = enable && findReplaceLogic.getTarget().isEditable();
781-
((GridData) replaceToggle.getLayoutData()).exclude = !visible;
782-
replaceToggle.setVisible(visible);
779+
((GridData) replaceToggleTools.getLayoutData()).exclude = !visible;
780+
replaceToggleTools.setVisible(visible);
783781
}
784782

785783
private void enableReplaceTools(boolean enable) {

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.stream.Collectors;
2626

2727
import org.eclipse.swt.SWT;
28-
import org.eclipse.swt.widgets.Button;
2928
import org.eclipse.swt.widgets.Control;
3029
import org.eclipse.swt.widgets.Event;
3130
import org.eclipse.swt.widgets.Shell;
@@ -56,7 +55,7 @@ class OverlayAccess implements IFindReplaceUIAccess {
5655

5756
private final ToolItem searchBackward;
5857

59-
private final Button openReplaceDialog;
58+
private final ToolItem openReplaceDialog;
6059

6160
private HistoryTextWrapper replace;
6261

@@ -81,7 +80,7 @@ class OverlayAccess implements IFindReplaceUIAccess {
8180
searchForward= (ToolItem) findReplaceOverlayAccessor.get("searchDownButton");
8281
searchBackward= (ToolItem) findReplaceOverlayAccessor.get("searchUpButton");
8382
closeOperation= () -> findReplaceOverlayAccessor.invoke("close", null);
84-
openReplaceDialog= (Button) findReplaceOverlayAccessor.get("replaceToggle");
83+
openReplaceDialog= (ToolItem) findReplaceOverlayAccessor.get("replaceToggle");
8584
replaceButton= (ToolItem) findReplaceOverlayAccessor.get("replaceButton");
8685
replaceAllButton= (ToolItem) findReplaceOverlayAccessor.get("replaceAllButton");
8786
inSelection= (ToolItem) findReplaceOverlayAccessor.get("searchInSelectionButton");

0 commit comments

Comments
 (0)