Skip to content

Commit 5c74619

Browse files
committed
Find/replace overlay: improve expressiveness of IFindReplaceUIAccess
Improves the design/expressiveness of the IFindReplaceUIAccess to reduce dependency on implementation details (like using shells as the container for the dialog and the overlay).
1 parent bc672de commit 5c74619

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected void reopenFindReplaceUIForTextViewer() {
8181
protected final void ensureHasFocusOnGTK() {
8282
if (Util.isGtk()) {
8383
runEventQueue();
84-
if (dialog.getActiveShell() == null) {
84+
if (!dialog.hasFocus()) {
8585
String screenshotPath= ScreenshotTest.takeScreenshot(FindReplaceUITest.class, testName.getMethodName(), System.out);
8686
fail("this test does not work on GTK unless the runtime workbench has focus. Screenshot: " + screenshotPath);
8787
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*******************************************************************************/
1111
package org.eclipse.ui.internal.findandreplace;
1212

13-
import org.eclipse.swt.widgets.Shell;
1413
import org.eclipse.swt.widgets.Widget;
1514

1615
import org.eclipse.jface.text.IFindReplaceTarget;
@@ -26,6 +25,8 @@ public interface IFindReplaceUIAccess {
2625

2726
void close();
2827

28+
boolean isShown();
29+
2930
void unselect(SearchOptions option);
3031

3132
void select(SearchOptions option);
@@ -42,7 +43,7 @@ public interface IFindReplaceUIAccess {
4243

4344
void setReplaceText(String text);
4445

45-
Shell getActiveShell();
46+
boolean hasFocus();
4647

4748
Widget getButtonForSearchOption(SearchOptions option);
4849

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import static org.hamcrest.MatcherAssert.assertThat;
1717
import static org.hamcrest.Matchers.is;
1818
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertNull;
19+
import static org.junit.Assert.assertFalse;
2020

2121
import org.junit.Test;
2222

@@ -174,7 +174,7 @@ public void testDisableOverlayViaPreference() {
174174
boolean useOverlayPreference= preferences.getBoolean(USE_FIND_REPLACE_OVERLAY, true);
175175
try {
176176
preferences.putBoolean(USE_FIND_REPLACE_OVERLAY, false);
177-
assertNull("dialog should be closed after changing preference", getDialog().getActiveShell());
177+
assertFalse("dialog should be closed after changing preference", getDialog().isShown());
178178
} finally {
179179
preferences.putBoolean(USE_FIND_REPLACE_OVERLAY, useOverlayPreference);
180180
reopenFindReplaceUIForTextViewer();

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.eclipse.swt.SWT;
2828
import org.eclipse.swt.widgets.Button;
29+
import org.eclipse.swt.widgets.Control;
2930
import org.eclipse.swt.widgets.Event;
3031
import org.eclipse.swt.widgets.Shell;
3132
import org.eclipse.swt.widgets.ToolItem;
@@ -321,8 +322,16 @@ public void assertEnabled(SearchOptions option) {
321322
}
322323

323324
@Override
324-
public Shell getActiveShell() {
325-
return shellRetriever.get();
325+
public boolean isShown() {
326+
return shellRetriever.get() != null && shellRetriever.get().isVisible();
327+
}
328+
329+
@Override
330+
public boolean hasFocus() {
331+
Shell overlayShell= shellRetriever.get();
332+
Control focusControl= overlayShell.getDisplay().getFocusControl();
333+
Shell focusControlShell= focusControl != null ? focusControl.getShell() : null;
334+
return focusControlShell == overlayShell;
326335
}
327336

328337
}

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/DialogAccess.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ public void close() {
165165
}
166166

167167
@Override
168-
public Shell getActiveShell() {
169-
return shellRetriever.get();
168+
public boolean hasFocus() {
169+
return shellRetriever.get() != null;
170170
}
171171

172172
@Override
@@ -316,4 +316,9 @@ private Set<SearchOptions> getSelectedOptions() {
316316
.collect(Collectors.toSet());
317317
}
318318

319+
@Override
320+
public boolean isShown() {
321+
return shellRetriever.get() != null;
322+
}
323+
319324
}

0 commit comments

Comments
 (0)