From 9ff464d8c7f049d28d2fd8e12ff026051b2420f1 Mon Sep 17 00:00:00 2001 From: Maximilian Wittmer Date: Wed, 29 May 2024 21:39:00 +0200 Subject: [PATCH] Find/Replace Overlay: Add a search history Add a search history for the Find/Replace overlay, displayed as a dropdown below the find/replace inputs. fixes #1907 --- .../icons/full/elcl16/open_history.png | Bin 0 -> 331 bytes .../icons/full/elcl16/open_history@2x.png | Bin 0 -> 556 bytes .../findandreplace/FindReplaceMessages.java | 3 + .../FindReplaceMessages.properties | 4 +- .../internal/findandreplace/HistoryStore.java | 7 + .../overlay/FindReplaceOverlay.java | 31 ++- .../overlay/FindReplaceOverlayImages.java | 3 +- .../overlay/HistoryTextWrapper.java | 202 ++++++++++++++++++ .../overlay/SearchHistoryMenu.java | 140 ++++++++++++ .../findandreplace/overlay/OverlayAccess.java | 11 +- 10 files changed, 385 insertions(+), 16 deletions(-) create mode 100644 bundles/org.eclipse.ui.workbench.texteditor/icons/full/elcl16/open_history.png create mode 100644 bundles/org.eclipse.ui.workbench.texteditor/icons/full/elcl16/open_history@2x.png create mode 100644 bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/HistoryTextWrapper.java create mode 100644 bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/SearchHistoryMenu.java diff --git a/bundles/org.eclipse.ui.workbench.texteditor/icons/full/elcl16/open_history.png b/bundles/org.eclipse.ui.workbench.texteditor/icons/full/elcl16/open_history.png new file mode 100644 index 0000000000000000000000000000000000000000..d3620887168e3a03a05bd5726901fa7b8df13caa GIT binary patch literal 331 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5he4R}c>anMprB-l zYeY$Kep*R+Vo@qXd3m{BW?pu2a$-TMUVc&f>~}U&Kt(q^T^vI!dhbrM%{uHL(0YH3 z&d!kO*VbmuSD1do%(WwU7iU~^q-)1jt~-(9Cseu9sdgIXk`M%_S4tJ4}1N8w=ia3*2IGYzr5|mTNM{Kkg2C zb=C5F8LwW~qez!+XZDyJ+rr?mJiX-HUV)2qX8KM`y<6{l?|10^?}d|8=0|1Qy*tms z5HRiOoSEicEBg(2>UXbO%}^7a{eAiEZYG8kpZ{obGbP0l+XkKX>*9P literal 0 HcmV?d00001 diff --git a/bundles/org.eclipse.ui.workbench.texteditor/icons/full/elcl16/open_history@2x.png b/bundles/org.eclipse.ui.workbench.texteditor/icons/full/elcl16/open_history@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..d047a63ba0910c9a30b49f09830084623b37fe37 GIT binary patch literal 556 zcmV+{0@MA8P)6fqdZ-%A!7K~S&~8!N$1*V?nYUQj^<8?VwvSA@w7A)91p#q9*EgR>LF zf1t(LS&705hqc`mHns}7lf>oe-F>dwy{fpC{vMi5xI-N}b*GaB4DQ^q_09xzsRaLD5*bqXz+qu~Q0PlS_gfLDi z9TGxxl~Ny?<~AC^w7mCMQcCLpUXdK9lpdy(9>*B(X|1chWGw^$0M^gggm3j-`m2k$d#0a}0-pauBv0R8~F4z6_kX$XD*0000disable it now. FindReplaceOverlayFirstTimePopup_FindReplaceOverlayFirstTimePopup_title=New Find/Replace Overlay +SearchHistoryMenu_SEARCH_HISTORY_EMPTY_STRING=perform search for search history diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java index 5d091011028..2d5e063a745 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java @@ -109,4 +109,11 @@ private void writeHistory() { settingsManager.put(sectionName, names); } + public int indexOf(String entry) { + return history.indexOf(entry); + } + + public int size() { + return history.size(); + } } diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java index 525489111cc..026f0441390 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java @@ -67,6 +67,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.findandreplace.FindReplaceLogic; import org.eclipse.ui.internal.findandreplace.FindReplaceMessages; +import org.eclipse.ui.internal.findandreplace.HistoryStore; import org.eclipse.ui.internal.findandreplace.SearchOptions; import org.eclipse.ui.internal.findandreplace.status.IFindReplaceStatus; @@ -104,6 +105,7 @@ private final class KeyboardShortcuts { private static final double BIG_WIDTH_RATIO_EDITOR_TO_OVERLAY = 0.7; private static final String MINIMAL_WIDTH_TEXT = "THIS TEXT IS SHORT "; //$NON-NLS-1$ private static final String IDEAL_WIDTH_TEXT = "THIS TEXT HAS A REASONABLE LENGTH FOR SEARCHING"; //$NON-NLS-1$ + private static final int HISTORY_SIZE = 15; private final Map searchKeyStrokeHandlers = new HashMap<>(); private final Map replaceKeyStrokeHandlers = new HashMap<>(); @@ -120,7 +122,7 @@ private final class KeyboardShortcuts { private Composite searchContainer; private Composite searchBarContainer; - private Text searchBar; + private HistoryTextWrapper searchBar; private AccessibleToolBar searchTools; private ToolItem searchInSelectionButton; private ToolItem wholeWordSearchButton; @@ -134,7 +136,7 @@ private final class KeyboardShortcuts { private Composite replaceContainer; private Composite replaceBarContainer; - private Text replaceBar; + private HistoryTextWrapper replaceBar; private AccessibleToolBar replaceTools; private ToolItem replaceButton; private ToolItem replaceAllButton; @@ -151,7 +153,6 @@ public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget setShellStyle(SWT.MODELESS); setBlockOnOpen(false); targetPart = part; - } @Override @@ -176,12 +177,14 @@ private void performReplaceAll() { BusyIndicator.showWhile(getShell() != null ? getShell().getDisplay() : Display.getCurrent(), () -> findReplaceLogic.performReplaceAll(getFindString(), getReplaceString())); evaluateFindReplaceStatus(); + replaceBar.storeHistory(); + searchBar.storeHistory(); } private void performSelectAll() { BusyIndicator.showWhile(getShell() != null ? getShell().getDisplay() : Display.getCurrent(), () -> findReplaceLogic.performSelectAll(getFindString())); - evaluateFindReplaceStatus(); + searchBar.storeHistory(); } private void toggleToolItem(ToolItem toolItem) { @@ -372,6 +375,7 @@ private void applyOverlayColors(Color color, boolean tryToColorReplaceBar) { replaceContainer.setBackground(color); replaceBar.setBackground(color); replaceBarContainer.setBackground(color); + replaceTools.setBackground(color); replaceAllButton.setBackground(color); replaceButton.setBackground(color); } @@ -441,17 +445,19 @@ private void retrieveBackgroundColor() { textBarForRetrievingTheRightColor.dispose(); } + private void createSearchTools() { searchTools = new AccessibleToolBar(searchContainer); GridDataFactory.fillDefaults().grab(false, true).align(GridData.END, GridData.END).applyTo(searchTools); + searchTools.createToolItem(SWT.SEPARATOR); + createCaseSensitiveButton(); createRegexSearchButton(); createWholeWordsButton(); createAreaSearchButton(); - @SuppressWarnings("unused") - ToolItem separator = searchTools.createToolItem(SWT.SEPARATOR); + searchTools.createToolItem(SWT.SEPARATOR); Runnable searchUpOperation = () -> performSearch(false); searchUpButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.PUSH) @@ -564,6 +570,9 @@ private void createReplaceTools() { Color warningColor = JFaceColors.getErrorText(getShell().getDisplay()); replaceTools = new AccessibleToolBar(replaceContainer); + + replaceTools.createToolItem(SWT.SEPARATOR); + GridDataFactory.fillDefaults().grab(false, true).align(GridData.CENTER, GridData.END).applyTo(replaceTools); replaceButton = new AccessibleToolItemBuilder(replaceTools).withStyleBits(SWT.PUSH) .withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_REPLACE)) @@ -593,7 +602,9 @@ private void createReplaceTools() { } private void createSearchBar() { - searchBar = new Text(searchBarContainer, SWT.SINGLE); + HistoryStore searchHistory = new HistoryStore(getDialogSettings(), "searchhistory", //$NON-NLS-1$ + HISTORY_SIZE); + searchBar = new HistoryTextWrapper(searchHistory, searchBarContainer, SWT.SINGLE); GridDataFactory.fillDefaults().grab(true, false).align(GridData.FILL, GridData.END).applyTo(searchBar); searchBar.forceFocus(); searchBar.selectAll(); @@ -656,7 +667,8 @@ private void updateIncrementalSearch() { } private void createReplaceBar() { - replaceBar = new Text(replaceBarContainer, SWT.SINGLE); + HistoryStore replaceHistory = new HistoryStore(getDialogSettings(), "replacehistory", HISTORY_SIZE); //$NON-NLS-1$ + replaceBar = new HistoryTextWrapper(replaceHistory, replaceBarContainer, SWT.SINGLE); GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.END).applyTo(replaceBar); replaceBar.setMessage(FindReplaceMessages.FindReplaceOverlay_replaceBar_message); replaceBar.addFocusListener(FocusListener.focusLostAdapter(e -> { @@ -922,6 +934,8 @@ private String getReplaceString() { private void performSingleReplace() { findReplaceLogic.performReplaceAndFind(getFindString(), getReplaceString()); evaluateFindReplaceStatus(); + replaceBar.storeHistory(); + searchBar.storeHistory(); } private void performSearch(boolean forward) { @@ -932,6 +946,7 @@ private void performSearch(boolean forward) { activateInFindReplacerIf(SearchOptions.FORWARD, oldForwardSearchSetting); findReplaceLogic.activate(SearchOptions.INCREMENTAL); evaluateFindReplaceStatus(); + searchBar.storeHistory(); } private void updateFromTargetSelection() { diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayImages.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayImages.java index 10b8dd71845..e94c58d5868 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayImages.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayImages.java @@ -34,7 +34,6 @@ */ class FindReplaceOverlayImages { private static final String PREFIX_ELCL = TextEditorPlugin.PLUGIN_ID + ".elcl."; //$NON-NLS-1$ - static final String KEY_CLOSE = PREFIX_ELCL + "close"; //$NON-NLS-1$ static final String KEY_FIND_NEXT = PREFIX_ELCL + "select_next"; //$NON-NLS-1$ static final String KEY_FIND_PREV = PREFIX_ELCL + "select_prev"; //$NON-NLS-1$ @@ -47,6 +46,7 @@ class FindReplaceOverlayImages { static final String KEY_SEARCH_IN_AREA = PREFIX_ELCL + "search_in_selection"; //$NON-NLS-1$ static final String KEY_OPEN_REPLACE_AREA = PREFIX_ELCL + "open_replace"; //$NON-NLS-1$ static final String KEY_CLOSE_REPLACE_AREA = PREFIX_ELCL + "close_replace"; //$NON-NLS-1$ + static final String KEY_OPEN_HISTORY = "open_history"; //$NON-NLS-1$ /** * The image registry containing {@link Image images}. @@ -73,6 +73,7 @@ private static void declareImages() { declareRegistryImage(KEY_SEARCH_IN_AREA, ELCL + "search_in_area.png"); //$NON-NLS-1$ declareRegistryImage(KEY_OPEN_REPLACE_AREA, ELCL + "open_replace.png"); //$NON-NLS-1$ declareRegistryImage(KEY_CLOSE_REPLACE_AREA, ELCL + "close_replace.png"); //$NON-NLS-1$ + declareRegistryImage(KEY_OPEN_HISTORY, ELCL + "open_history.png"); //$NON-NLS-1$ } /** diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/HistoryTextWrapper.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/HistoryTextWrapper.java new file mode 100644 index 00000000000..abaa76620c8 --- /dev/null +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/HistoryTextWrapper.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2024 Vector Informatik GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Vector Informatik GmbH - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.findandreplace.overlay; + +import java.util.function.Consumer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.Widget; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; + +import org.eclipse.ui.internal.findandreplace.FindReplaceMessages; +import org.eclipse.ui.internal.findandreplace.HistoryStore; + +/** + * Wrap a Text Bar and a ToolItem to add an input history. The text is only + * stored to history when requested by the Client code, the history is stored in + * a {@code HistoryStore} provided by the client. The history bar behaves like a + * normal {@code Text}. + */ +class HistoryTextWrapper extends Composite { + final private Text textBar; + final private AccessibleToolBar tools; + final private ToolItem dropDown; + final private HistoryStore history; + private SearchHistoryMenu menu; + + public HistoryTextWrapper(HistoryStore history, Composite parent, int style) { + super(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(this); + + this.history = history; + + textBar = new Text(this, style); + GridDataFactory.fillDefaults().grab(true, true).align(GridData.FILL, GridData.CENTER).applyTo(textBar); + tools = new AccessibleToolBar(this); + dropDown = new AccessibleToolItemBuilder(tools).withStyleBits(SWT.PUSH) + .withToolTipText(FindReplaceMessages.FindReplaceOverlay_searchHistory_toolTip) + .withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_OPEN_HISTORY)) + .withSelectionListener(SelectionListener.widgetSelectedAdapter(e -> createHistoryMenuDropdown())) + .build(); + + listenForKeyboardHistoryNavigation(); + } + + private void listenForKeyboardHistoryNavigation() { + addKeyListener(KeyListener.keyPressedAdapter(e -> { + if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN) { + int stepDirection = e.keyCode == SWT.ARROW_UP ? 1 : -1; + navigateInHistory(stepDirection); + } + })); + } + + private void createHistoryMenuDropdown() { + if (menu != null && okayToUse(menu.getShell()) || !dropDown.isEnabled()) { + return; + } + + dropDown.setEnabled(false); + Consumer textUpdaterOnHistoryEntrySelection = selectedHistoryItem -> { + if (selectedHistoryItem != null) { + textBar.setText(selectedHistoryItem); + } + }; + menu = new SearchHistoryMenu(getShell(), history, textUpdaterOnHistoryEntrySelection); + + Point barPosition = textBar.toDisplay(0, 0); + Rectangle dropDownBounds = dropDown.getBounds(); + menu.setPosition(barPosition.x, barPosition.y + dropDownBounds.height, + textBar.getSize().x + dropDownBounds.width); + menu.open(); + + menu.getShell().addDisposeListener( + __ -> getShell().getDisplay().timerExec(100, HistoryTextWrapper.this::enableDropDown)); + } + + private void enableDropDown() { + dropDown.setEnabled(true); + } + + private void navigateInHistory(int navigationOffset) { + if (history.size() == 0) { + return; + } + + int offset = history.indexOf(textBar.getText()); + + offset += navigationOffset; + offset = offset % history.size(); + + if (offset + navigationOffset < 0) { + offset = history.size() - 1; + } + + textBar.setText(history.get(offset)); + } + + public void storeHistory() { + String string = textBar.getText(); + history.remove(string); // ensure findString is now on the newest index of the history + history.add(string); + } + + private static boolean okayToUse(final Widget widget) { + return widget != null && !widget.isDisposed(); + } + + public void selectAll() { + textBar.selectAll(); + } + + public void addModifyListener(final ModifyListener listener) { + textBar.addModifyListener(listener); + } + + @Override + public void addFocusListener(final FocusListener listener) { + textBar.addFocusListener(listener); + } + + @Override + public void addKeyListener(final KeyListener listener) { + textBar.addKeyListener(listener); + } + + public void setMessage(final String message) { + textBar.setMessage(message); + } + + public void setSelection(int i, int j) { + textBar.setSelection(i, j); + } + + @Override + public boolean isFocusControl() { + return textBar.isFocusControl(); + } + + public String getText() { + return textBar.getText(); + } + + public void setText(String str) { + textBar.setText(str); + } + + @Override + public void setBackground(Color color) { + super.setBackground(color); + + textBar.setBackground(color); + tools.setBackground(color); + } + + @Override + public void setForeground(Color color) { + super.setForeground(color); + + textBar.setForeground(color); + tools.setForeground(color); + } + + @Override + public boolean forceFocus() { + return textBar.forceFocus(); + } + + @Override + public void notifyListeners(int eventType, Event event) { + textBar.notifyListeners(eventType, event); + } + + public Text getTextBar() { + return textBar; + } + +} diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/SearchHistoryMenu.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/SearchHistoryMenu.java new file mode 100644 index 00000000000..4360d900f91 --- /dev/null +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/SearchHistoryMenu.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2024 Vector Informatik GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Vector Informatik GmbH - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.findandreplace.overlay; + +import java.util.function.Consumer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.events.ShellListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.layout.GridDataFactory; + +import org.eclipse.ui.internal.findandreplace.FindReplaceMessages; +import org.eclipse.ui.internal.findandreplace.HistoryStore; + +/** + * Menu dropdown for the search history in the find/replace overlay + */ +class SearchHistoryMenu extends Dialog { + private final Consumer historyEntrySelectedCallback; + private final HistoryStore history; + private final ShellListener shellFocusListener = new ShellAdapter() { + @Override + public void shellDeactivated(ShellEvent e) { + if (!getShell().isDisposed()) { + getShell().getDisplay().asyncExec(SearchHistoryMenu.this::close); + } + } + }; + private Point location; + private int width; + private Table table; + private TableColumn column; + + public SearchHistoryMenu(Shell parent, HistoryStore history, Consumer historyEntrySelectedCallback) { + super(parent); + setShellStyle(SWT.NONE); + setBlockOnOpen(false); + + this.historyEntrySelectedCallback = historyEntrySelectedCallback; + this.history = history; + } + + public void setPosition(int x, int y, int width) { + location = new Point(x, y); + this.width = width; + } + + @Override + public Control createContents(Composite parent) { + table = new Table(parent, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(table); + column = new TableColumn(table, SWT.NONE); + + if (history.size() == 0) { + TableItem item = new TableItem(table, SWT.NONE); + item.setText(FindReplaceMessages.SearchHistoryMenu_SEARCH_HISTORY_EMPTY_STRING); + table.setEnabled(false); + } else { + for (String entry : history.get()) { + TableItem item = new TableItem(table, SWT.NONE); + item.setText(entry); + } + } + + attachTableListeners(); + getShell().pack(); + getShell().layout(); + return table; + } + + private void attachTableListeners() { + table.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { + TableItem[] selection = table.getSelection(); + if (selection.length == 0) { + historyEntrySelectedCallback.accept(null); + return; + } + String text = selection[0].getText(); + if (text != null) { + historyEntrySelectedCallback.accept(text); + } + historyEntrySelectedCallback.accept(null); + })); + table.addMouseListener(MouseListener.mouseDownAdapter(e -> { + table.notifyListeners(SWT.Selection, null); + close(); + })); + table.addKeyListener(KeyListener.keyPressedAdapter(e -> { + if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { + close(); + } + })); + } + + private void positionShell() { + if (location != null && table.getItemCount() != 0) { + getShell().setBounds(location.x, location.y, width, + Math.min(table.getItemHeight() * 7, table.getItemHeight() * table.getItemCount() + 2)); + } + int columnWidth = table.getSize().x; + if (table.getVerticalBar() != null && table.getVerticalBar().isVisible()) { + columnWidth = table.getSize().x - table.getVerticalBar().getSize().x; + } + column.setWidth(columnWidth); + } + + @Override + public int open() { + int code = super.open(); + + getShell().addShellListener(shellFocusListener); + positionShell(); + + return code; + } +} diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java index 64b764933eb..b4414570143 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java @@ -27,7 +27,6 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.text.tests.Accessor; @@ -44,9 +43,9 @@ class OverlayAccess implements IFindReplaceUIAccess { FindReplaceLogic findReplaceLogic; - Text find; + HistoryTextWrapper find; - Text replace; + HistoryTextWrapper replace; ToolItem inSelection; @@ -75,8 +74,8 @@ class OverlayAccess implements IFindReplaceUIAccess { OverlayAccess(Accessor findReplaceOverlayAccessor) { dialogAccessor= findReplaceOverlayAccessor; findReplaceLogic= (FindReplaceLogic) findReplaceOverlayAccessor.get("findReplaceLogic"); - find= (Text) findReplaceOverlayAccessor.get("searchBar"); - replace= (Text) findReplaceOverlayAccessor.get("replaceBar"); + find= (HistoryTextWrapper) findReplaceOverlayAccessor.get("searchBar"); + replace= (HistoryTextWrapper) findReplaceOverlayAccessor.get("replaceBar"); caseSensitive= (ToolItem) findReplaceOverlayAccessor.get("caseSensitiveSearchButton"); wholeWord= (ToolItem) findReplaceOverlayAccessor.get("wholeWordSearchButton"); regEx= (ToolItem) findReplaceOverlayAccessor.get("regexSearchButton"); @@ -253,7 +252,7 @@ public boolean isReplaceDialogOpen() { public void openReplaceDialog() { if (!isReplaceDialogOpen() && Objects.nonNull(openReplaceDialog)) { openReplaceDialog.notifyListeners(SWT.Selection, null); - replace= (Text) dialogAccessor.get("replaceBar"); + replace= (HistoryTextWrapper) dialogAccessor.get("replaceBar"); replaceButton= (ToolItem) dialogAccessor.get("replaceButton"); replaceAllButton= (ToolItem) dialogAccessor.get("replaceAllButton"); }