Repository navigation
Find/Replace overlay: offer it in any part that can host it #4509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,20 +14,26 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package org.eclipse.ui.internal.findandreplace.overlay; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.eclipse.ui.internal.findandreplace.FindReplaceTestUtil.waitForFocus; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.eclipse.ui.internal.findandreplace.overlay.OverlayAccess.RESTRICT_FIND_REPLACE_OVERLAY_TO_TEXT_EDITORS_PREFERENCE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.mockito.Mockito.when; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Arrays; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.ResourceBundle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.mockito.Mockito; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.swt.SWT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.swt.graphics.Point; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.swt.graphics.Rectangle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.swt.widgets.Display; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.swt.widgets.Shell; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.core.runtime.preferences.IEclipsePreferences; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.core.runtime.preferences.InstanceScope; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -89,6 +95,22 @@ private static IWorkbenchPart createHostPart(TextViewer viewer) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return part; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testOverlayCanOnlyBeOpenedInPartExposingTextViewerWidget() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| openTextViewer("line"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertTrue(FindReplaceOverlay.canOpenInPart(createHostPart(getTextViewer()))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertFalse(FindReplaceOverlay.canOpenInPart(Mockito.mock(IWorkbenchPart.class))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertFalse(FindReplaceOverlay.canOpenInPart(null)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testOverlayRejectsPartItCannotBeOpenedIn() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IWorkbenchPart partWithoutTextViewer= Mockito.mock(IWorkbenchPart.class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThrows(IllegalArgumentException.class, () -> new FindReplaceOverlay(partWithoutTextViewer, null)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testShortcutHintReflectsFocusedInputField() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initializeTextViewerWithFindReplaceUI("line"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -242,6 +264,52 @@ public void testDisableOverlayViaPreference() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testOverlayIsOpenedByActionForPartExposingTextViewer() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The part hosting the viewer is no text editor, so this also covers that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // action goes by what the part exposes rather than by its type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initializeTextViewerWithFindReplaceUI(""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getDialog().close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertFalse(getDialog().isShown()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getFindReplaceAction().run(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertTrue(getDialog().isShown(), "the action should have opened the overlay"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a test case missing here: ensuring that the dialog (instead of the overlay) is opened for generic text viewers if
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to only add minimal tests for this fallback functionality, as it is supposed to be temporary and will eventually be removed anyway. But you are of course right that as long as the functionality is there, it's behavior should be tested. What is particularly helpful with this test is that it will start failing once the fallback is removed, so that the developer becomes aware that tests have to be removed as well. The other test would have simply keps succeeding. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * User can restrict the overlay to text editors in case they have trouble with it elsewhere, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * we need to ensure that for an editor that is not a StatusTextEditor, the dialog is opened. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * <p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The preference is meant as a temporary fallback for the overlay's generalization to parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * other than text editors. Remove this test together with it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testOverlayIsNotOpenedForNonTextEditorWhenRestrictedToTextEditors() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IEclipsePreferences preferences= InstanceScope.INSTANCE.getNode(INSTANCE_SCOPE_NODE_NAME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean wasRestricted= preferences.getBoolean(RESTRICT_FIND_REPLACE_OVERLAY_TO_TEXT_EDITORS_PREFERENCE, false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Display display= Display.getCurrent(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Set<Shell> shellsBeforeAction= Set.of(display.getShells()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| preferences.putBoolean(RESTRICT_FIND_REPLACE_OVERLAY_TO_TEXT_EDITORS_PREFERENCE, true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initializeTextViewerWithFindReplaceUI(""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getDialog().close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertFalse(getDialog().isShown()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getFindReplaceAction().run(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertFalse(getDialog().isShown(), "the action should have opened the dialog (so no overlay should be shown)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertTrue(Arrays.stream(display.getShells()).anyMatch(shell -> !shellsBeforeAction.contains(shell) && shell.isVisible()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "the action should have opened the dialog"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The dialog is unknown to the overlay test infrastructure, so close every shell the action opened | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (Shell shell : display.getShells()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!shellsBeforeAction.contains(shell)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shell.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| preferences.putBoolean(RESTRICT_FIND_REPLACE_OVERLAY_TO_TEXT_EDITORS_PREFERENCE, wasRestricted); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testSearchTermStoredInHistoryAfterSearchForward() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // After a forward search, the term must be retrievable from history so that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.