Skip to content

Commit ecfde49

Browse files
committed
Add close button to find/replace overlay #1991
The find/replace overlay can currently only be closed via pressing Escape or using the shortcut CTRL+F when the overlay has input focus. This change adds a close button to the overlay for providing an easy and comprehensible way of closing the overlay. Contributes to #1991
1 parent 80c6da9 commit ecfde49

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed
339 Bytes
Loading
518 Bytes
Loading

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ private FindReplaceMessages() {
6060
public static String FindReplace_SelectAllButton_label;
6161
public static String FindReplace_CloseButton_label;
6262

63+
public static String FindReplaceOverlay_closeButton_toolTip;
6364
public static String FindReplaceOverlay_downSearchButton_toolTip;
6465
public static String FindReplaceOverlay_upSearchButton_toolTip;
6566
public static String FindReplaceOverlay_searchAllButton_toolTip;

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceMessages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ FindReplace_ReplaceAllButton_label=Replace &All
4545
FindReplace_SelectAllButton_label=&Select All
4646
FindReplace_CloseButton_label=Close
4747

48-
# Messages for the "new" Find-Replace-Overlay
48+
# Messages for the find/replace overlay
49+
FindReplaceOverlay_closeButton_toolTip=Close (Esc)
4950
FindReplaceOverlay_upSearchButton_toolTip=Search backward (Shift + Enter)
5051
FindReplaceOverlay_downSearchButton_toolTip=Search forward (Enter)
5152
FindReplaceOverlay_searchAllButton_toolTip=Search all (Ctrl + Enter)

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.eclipse.swt.graphics.RGBA;
3535
import org.eclipse.swt.graphics.Rectangle;
3636
import org.eclipse.swt.layout.GridData;
37-
import org.eclipse.swt.layout.GridLayout;
3837
import org.eclipse.swt.widgets.Button;
3938
import org.eclipse.swt.widgets.Composite;
4039
import org.eclipse.swt.widgets.Control;
@@ -92,14 +91,15 @@ public class FindReplaceOverlay extends Dialog {
9291
private Composite searchBarContainer;
9392
private Text searchBar;
9493
private AccessibleToolBar searchTools;
95-
9694
private ToolItem searchInSelectionButton;
9795
private ToolItem wholeWordSearchButton;
9896
private ToolItem caseSensitiveSearchButton;
9997
private ToolItem regexSearchButton;
10098
private ToolItem searchUpButton;
10199
private ToolItem searchDownButton;
102100
private ToolItem searchAllButton;
101+
private AccessibleToolBar closeTools;
102+
private ToolItem closeButton;
103103

104104
private Composite replaceContainer;
105105
private Composite replaceBarContainer;
@@ -378,6 +378,9 @@ private void restoreOverlaySettings() {
378378
}
379379

380380
private void applyOverlayColors(Color color, boolean tryToColorReplaceBar) {
381+
closeTools.setBackground(color);
382+
closeButton.setBackground(color);
383+
381384
searchTools.setBackground(color);
382385
searchInSelectionButton.setBackground(color);
383386
wholeWordSearchButton.setBackground(color);
@@ -441,6 +444,7 @@ private Control createDialog(final Composite parent) {
441444
createFindContainer();
442445
createSearchBar();
443446
createSearchTools();
447+
createCloseTools();
444448

445449
container.layout();
446450

@@ -464,7 +468,7 @@ private void retrieveBackgroundColor() {
464468

465469
private void createSearchTools() {
466470
searchTools = new AccessibleToolBar(searchContainer);
467-
GridDataFactory.fillDefaults().grab(false, true).align(GridData.CENTER, GridData.END).applyTo(searchTools);
471+
GridDataFactory.fillDefaults().grab(false, true).align(GridData.END, GridData.END).applyTo(searchTools);
468472

469473
createCaseSensitiveButton();
470474
createRegexSearchButton();
@@ -499,6 +503,16 @@ private void createSearchTools() {
499503
})).build();
500504
}
501505

506+
private void createCloseTools() {
507+
closeTools = new AccessibleToolBar(searchContainer);
508+
GridDataFactory.fillDefaults().grab(false, true).align(GridData.END, GridData.END).applyTo(closeTools);
509+
510+
closeButton = new AccessibleToolItemBuilder(closeTools).withStyleBits(SWT.PUSH)
511+
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_CLOSE))
512+
.withToolTipText(FindReplaceMessages.FindReplaceOverlay_closeButton_toolTip)
513+
.withSelectionListener(SelectionListener.widgetSelectedAdapter(e -> close())).build();
514+
}
515+
502516
private void createAreaSearchButton() {
503517
searchInSelectionButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.CHECK)
504518
.withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_SEARCH_IN_AREA))
@@ -633,7 +647,7 @@ private void createReplaceBar() {
633647
private void createFindContainer() {
634648
searchContainer = new Composite(contentGroup, SWT.NONE);
635649
GridDataFactory.fillDefaults().grab(true, true).align(GridData.FILL, GridData.FILL).applyTo(searchContainer);
636-
GridLayoutFactory.fillDefaults().numColumns(2).extendedMargins(4, 4, 2, 8).equalWidth(false)
650+
GridLayoutFactory.fillDefaults().numColumns(3).extendedMargins(4, 4, 2, 8).equalWidth(false)
637651
.applyTo(searchContainer);
638652
searchContainer.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
639653
searchBarContainer = new Composite(searchContainer, SWT.NONE);
@@ -713,12 +727,6 @@ private void createReplaceDialog() {
713727
private void enableSearchTools(boolean enable) {
714728
((GridData) searchTools.getLayoutData()).exclude = !enable;
715729
searchTools.setVisible(enable);
716-
717-
if (enable) {
718-
((GridLayout) searchTools.getParent().getLayout()).numColumns = 2;
719-
} else {
720-
((GridLayout) searchTools.getParent().getLayout()).numColumns = 1;
721-
}
722730
}
723731

724732
private void enableReplaceToggle(boolean enable) {
@@ -735,20 +743,14 @@ private void enableReplaceTools(boolean enable) {
735743
}
736744
((GridData) replaceTools.getLayoutData()).exclude = !enable;
737745
replaceTools.setVisible(enable);
738-
739-
if (enable) {
740-
((GridLayout) replaceTools.getParent().getLayout()).numColumns = 2;
741-
} else {
742-
((GridLayout) replaceTools.getParent().getLayout()).numColumns = 1;
743-
}
744746
}
745747

746748
private int getIdealDialogWidth(Rectangle targetBounds) {
747749
int replaceToggleWidth = 0;
748750
if (okayToUse(replaceToggle)) {
749751
replaceToggleWidth = replaceToggle.getBounds().width;
750752
}
751-
int toolBarWidth = searchTools.getSize().x;
753+
int toolBarWidth = searchTools.getSize().x + closeTools.getSize().x;
752754
GC gc = new GC(searchBar);
753755
gc.setFont(searchBar.getFont());
754756
int idealWidth = gc.stringExtent(IDEAL_WIDTH_TEXT).x; // $NON-NLS-1$

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
class FindReplaceOverlayImages {
3636
private static final String PREFIX_ELCL = TextEditorPlugin.PLUGIN_ID + ".elcl."; //$NON-NLS-1$
3737

38+
static final String KEY_CLOSE = PREFIX_ELCL + "close"; //$NON-NLS-1$
3839
static final String KEY_FIND_NEXT = PREFIX_ELCL + "select_next"; //$NON-NLS-1$
3940
static final String KEY_FIND_PREV = PREFIX_ELCL + "select_prev"; //$NON-NLS-1$
4041
static final String KEY_FIND_REGEX = PREFIX_ELCL + "regex"; //$NON-NLS-1$
@@ -60,6 +61,7 @@ class FindReplaceOverlayImages {
6061
* Declare all images
6162
*/
6263
private static void declareImages() {
64+
declareRegistryImage(KEY_CLOSE, ELCL + "close.png"); //$NON-NLS-1$
6365
declareRegistryImage(KEY_FIND_NEXT, ELCL + "select_next.png"); //$NON-NLS-1$
6466
declareRegistryImage(KEY_FIND_PREV, ELCL + "select_prev.png"); //$NON-NLS-1$
6567
declareRegistryImage(KEY_FIND_REGEX, ELCL + "regex.png"); //$NON-NLS-1$

0 commit comments

Comments
 (0)