Skip to content

Commit

Permalink
Find/replace overlay: improve expressiveness of IFindReplaceUIAccess
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
HeikoKlare committed Sep 8, 2024
1 parent bc672de commit f23f35b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void reopenFindReplaceUIForTextViewer() {
protected final void ensureHasFocusOnGTK() {
if (Util.isGtk()) {
runEventQueue();
if (dialog.getActiveShell() == null) {
if (!dialog.hasFocus()) {
String screenshotPath= ScreenshotTest.takeScreenshot(FindReplaceUITest.class, testName.getMethodName(), System.out);
fail("this test does not work on GTK unless the runtime workbench has focus. Screenshot: " + screenshotPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.ui.internal.findandreplace;

import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;

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

void close();

boolean isShown();

void unselect(SearchOptions option);

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

void setReplaceText(String text);

Shell getActiveShell();
boolean hasFocus();

Widget getButtonForSearchOption(SearchOptions option);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertFalse;

import org.junit.Test;

Expand Down Expand Up @@ -174,7 +174,7 @@ public void testDisableOverlayViaPreference() {
boolean useOverlayPreference= preferences.getBoolean(USE_FIND_REPLACE_OVERLAY, true);
try {
preferences.putBoolean(USE_FIND_REPLACE_OVERLAY, false);
assertNull("dialog should be closed after changing preference", getDialog().getActiveShell());
assertFalse("dialog should be closed after changing preference", getDialog().isShown());
} finally {
preferences.putBoolean(USE_FIND_REPLACE_OVERLAY, useOverlayPreference);
reopenFindReplaceUIForTextViewer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

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;
import org.eclipse.swt.widgets.ToolItem;
Expand Down Expand Up @@ -321,8 +322,16 @@ public void assertEnabled(SearchOptions option) {
}

@Override
public Shell getActiveShell() {
return shellRetriever.get();
public boolean isShown() {
return shellRetriever.get() != null && shellRetriever.get().isVisible();
}

@Override
public boolean hasFocus() {
Shell overlayShell= shellRetriever.get();
Control focusControl= overlayShell.getDisplay().getFocusControl();
Shell focusControlShell= focusControl != null ? focusControl.getShell() : null;
return focusControlShell == overlayShell;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ public void close() {
}

@Override
public Shell getActiveShell() {
return shellRetriever.get();
public boolean hasFocus() {
return shellRetriever.get() != null;
}

@Override
Expand Down Expand Up @@ -316,4 +316,9 @@ private Set<SearchOptions> getSelectedOptions() {
.collect(Collectors.toSet());
}

@Override
public boolean isShown() {
return shellRetriever.get() != null;
}

}

0 comments on commit f23f35b

Please sign in to comment.