diff --git a/bundles/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF index cf12407210d..7d6d5ae6b7b 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF @@ -33,6 +33,9 @@ Require-Bundle: org.eclipse.jface.text;bundle-version="[3.19.0,4.0.0)", org.eclipse.swt;bundle-version="[3.107.0,4.0.0)", org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", - org.eclipse.jface.notifications + org.eclipse.jface.notifications, + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.core.contexts, + org.eclipse.e4.ui.workbench Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: org.eclipse.ui.workbench.texteditor 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 7e131500202..e8e5278f38f 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 @@ -20,6 +20,13 @@ import org.osgi.framework.FrameworkUtil; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.advanced.MArea; +import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + import org.eclipse.swt.SWT; import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.custom.StyledText; @@ -37,6 +44,7 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGBA; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; @@ -50,7 +58,6 @@ import org.eclipse.swt.widgets.Widget; import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IPageChangedListener; import org.eclipse.jface.dialogs.PageChangedEvent; @@ -68,6 +75,7 @@ import org.eclipse.ui.IPartListener2; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartReference; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; import org.eclipse.ui.internal.findandreplace.FindReplaceLogic; @@ -81,7 +89,7 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.StatusTextEditor; -public class FindReplaceOverlay extends Dialog { +public class FindReplaceOverlay { private final class KeyboardShortcuts { private static final List SEARCH_FORWARD = List.of( // KeyStroke.getInstance(SWT.CR), KeyStroke.getInstance(SWT.KEYPAD_CR)); @@ -150,21 +158,12 @@ private final class KeyboardShortcuts { private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField; public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) { - super(parent); createFindReplaceLogic(target); - - setShellStyle(SWT.MODELESS); - setBlockOnOpen(false); targetPart = part; targetPartVisibilityHandler = new TargetPartVisibilityHandler(targetPart, this::getShell, this::close, this::updatePlacementAndVisibility); } - @Override - protected boolean isResizable() { - return false; - } - private void createFindReplaceLogic(IFindReplaceTarget target) { findReplaceLogic = new FindReplaceLogic(); boolean isTargetEditable = false; @@ -207,7 +206,7 @@ public void controlResized(ControlEvent e) { private PaintListener widgetMovementListener = __ -> asyncUpdatePlacementAndVisibility(); private void asyncUpdatePlacementAndVisibility() { - Shell shell = getShell(); + Composite shell = getShell(); if (shell != null) { shell.getDisplay().asyncExec(this::updatePlacementAndVisibility); } @@ -228,14 +227,15 @@ public void shellDeactivated(ShellEvent e) { private static class TargetPartVisibilityHandler implements IPartListener2, IPageChangedListener { private final IWorkbenchPart targetPart; private final IWorkbenchPart topLevelPart; - private final Supplier shellProvider; + private final Supplier shellProvider; private final Runnable closeCallback; private final Runnable placementUpdateCallback; private boolean isTopLevelVisible = true; private boolean isNestedLevelVisible = true; - TargetPartVisibilityHandler(IWorkbenchPart targetPart, Supplier shellProvider, Runnable closeCallback, + TargetPartVisibilityHandler(IWorkbenchPart targetPart, Supplier shellProvider, + Runnable closeCallback, Runnable placementUpdateCallback) { this.targetPart = targetPart; this.shellProvider = shellProvider; @@ -318,9 +318,6 @@ public boolean isTargetVisible() { } private KeyListener closeOnTargetEscapeListener = KeyListener.keyPressedAdapter(c -> { - if (c.keyCode == SWT.ESC) { - this.close(); - } }); /** @@ -335,11 +332,11 @@ private static IDialogSettings getDialogSettings() { return settings; } - @Override public boolean close() { if (!overlayOpen) { return true; } + overlayPart.dispose(); if (targetPart != null) { targetPart.setFocus(); } @@ -350,14 +347,61 @@ public boolean close() { replaceBarOpen = false; unbindListeners(); container.dispose(); - return super.close(); + return overlayOpen; + } + + MPartStack pipStack = null; + Composite pipComp = null; + Composite overlayPart; + + private void openOverlayPart() { + IWorkbenchWindow window = targetPart.getSite().getWorkbenchWindow(); + MApplication theApp = window.getService(MApplication.class); + MWindow win1 = theApp.getChildren().get(0); + EPartService ps = win1.getContext().get(EPartService.class); + EModelService ms = win1.getContext().get(EModelService.class); + + if (pipStack == null) { + // Find the MArea + List areas = ms.findElements(win1, null, MArea.class, null); + if (areas.size() > 0) { + MArea area = areas.get(0); + List areaStacks = ms.findElements(area, null, MPartStack.class, null); + if (areaStacks.size() == 1) { + pipStack = ms.createModelElement(MPartStack.class); + Composite areaComp = (Composite) area.getWidget(); + overlayPart = areaComp; + Rectangle ar = areaComp.getBounds(); + + pipComp = new Composite(areaComp, SWT.BORDER); + pipComp.setSize((ar.width / 2) - 20, (ar.height / 2) - 20); + pipComp.setLocation((ar.width / 2) - 25, (ar.height / 2) - 25); + pipComp.moveAbove(null); + pipComp.setLayout(new FillLayout()); + + pipStack.setVisible(true); + Control stackCtrl = (Control) pipStack.getWidget(); + stackCtrl.setParent(pipComp); + pipComp.layout(true); + } + } + } else { + pipStack.setVisible(true); + pipComp.dispose(); + pipStack = null; + pipComp = null; + } + } + + private Composite getShell() { + return overlayPart; } - @Override public int open() { int returnCode = Window.OK; if (!overlayOpen) { - returnCode = super.open(); + openOverlayPart(); + createContents(overlayPart); bindListeners(); restoreOverlaySettings(); } @@ -366,7 +410,7 @@ public int open() { updateFromTargetSelection(); searchBar.forceFocus(); - getShell().layout(); + overlayPart.layout(); updatePlacementAndVisibility(); updateContentAssistAvailability(); @@ -412,7 +456,7 @@ private void applyOverlayColors(Color color, boolean tryToColorReplaceBar) { } private void unbindListeners() { - getShell().removeShellListener(overlayDeactivationListener); +// getShell().removeShellListener(overlayDeactivationListener); if (targetPart != null && targetPart instanceof StatusTextEditor textEditor) { Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget(); if (targetWidget != null) { @@ -425,7 +469,7 @@ private void unbindListeners() { } private void bindListeners() { - getShell().addShellListener(overlayDeactivationListener); +// getShell().addShellListener(overlayDeactivationListener); if (targetPart instanceof StatusTextEditor textEditor) { Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget(); @@ -436,13 +480,14 @@ private void bindListeners() { } } - @Override public Control createContents(Composite parent) { PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(), IAbstractTextEditorHelpContextIds.FIND_REPLACE_OVERLAY); backgroundToUse = new Color(getShell().getDisplay(), new RGBA(0, 0, 0, 0)); - return createDialog(parent); + final Control dialog = createDialog(parent); + + return dialog; } private Control createDialog(final Composite parent) { @@ -458,7 +503,7 @@ private Control createDialog(final Composite parent) { container.layout(); - applyDialogFont(container); +// applyDialogFont(container); return container; } @@ -488,7 +533,6 @@ private void retrieveBackgroundColor() { } } - private void createSearchTools() { searchTools = new AccessibleToolBar(searchContainer); GridDataFactory.fillDefaults().grab(false, true).align(GridData.END, GridData.END).applyTo(searchTools); @@ -505,14 +549,12 @@ private void createSearchTools() { searchUpButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.PUSH) .withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_FIND_PREV)) .withToolTipText(FindReplaceMessages.FindReplaceOverlay_upSearchButton_toolTip) - .withOperation(() -> performSearch(false)) - .withShortcuts(KeyboardShortcuts.SEARCH_BACKWARD).build(); + .withOperation(() -> performSearch(false)).withShortcuts(KeyboardShortcuts.SEARCH_BACKWARD).build(); searchDownButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.PUSH) .withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_FIND_NEXT)) .withToolTipText(FindReplaceMessages.FindReplaceOverlay_downSearchButton_toolTip) - .withOperation(() -> performSearch(true)) - .withShortcuts(KeyboardShortcuts.SEARCH_FORWARD).build(); + .withOperation(() -> performSearch(true)).withShortcuts(KeyboardShortcuts.SEARCH_FORWARD).build(); searchDownButton.setSelection(true); // by default, search down searchAllButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.PUSH) @@ -528,8 +570,7 @@ private void createCloseTools() { closeButton = new AccessibleToolItemBuilder(closeTools).withStyleBits(SWT.PUSH) .withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_CLOSE)) .withToolTipText(FindReplaceMessages.FindReplaceOverlay_closeButton_toolTip) // - .withOperation(this::close) - .withShortcuts(KeyboardShortcuts.CLOSE).build(); + .withOperation(this::close).withShortcuts(KeyboardShortcuts.CLOSE).build(); } private void createAreaSearchButton() { @@ -539,16 +580,14 @@ private void createAreaSearchButton() { .withOperation(() -> { activateInFindReplacerIf(SearchOptions.GLOBAL, !searchInSelectionButton.getSelection()); updateIncrementalSearch(); - }) - .withShortcuts(KeyboardShortcuts.OPTION_SEARCH_IN_SELECTION).build(); + }).withShortcuts(KeyboardShortcuts.OPTION_SEARCH_IN_SELECTION).build(); searchInSelectionButton.setSelection(findReplaceLogic.isActive(SearchOptions.WHOLE_WORD)); } private void createRegexSearchButton() { regexSearchButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.CHECK) .withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_FIND_REGEX)) - .withToolTipText(FindReplaceMessages.FindReplaceOverlay_regexSearchButton_toolTip) - .withOperation(() -> { + .withToolTipText(FindReplaceMessages.FindReplaceOverlay_regexSearchButton_toolTip).withOperation(() -> { activateInFindReplacerIf(SearchOptions.REGEX, regexSearchButton.getSelection()); wholeWordSearchButton.setEnabled(findReplaceLogic.isWholeWordSearchAvailable(getFindString())); updateIncrementalSearch(); @@ -571,8 +610,7 @@ private void createCaseSensitiveButton() { private void createWholeWordsButton() { wholeWordSearchButton = new AccessibleToolItemBuilder(searchTools).withStyleBits(SWT.CHECK) .withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_WHOLE_WORD)) - .withToolTipText(FindReplaceMessages.FindReplaceOverlay_wholeWordsButton_toolTip) - .withOperation(() -> { + .withToolTipText(FindReplaceMessages.FindReplaceOverlay_wholeWordsButton_toolTip).withOperation(() -> { activateInFindReplacerIf(SearchOptions.WHOLE_WORD, wholeWordSearchButton.getSelection()); updateIncrementalSearch(); }).withShortcuts(KeyboardShortcuts.OPTION_WHOLE_WORD).build(); @@ -589,8 +627,7 @@ private void createReplaceTools() { 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)) - .withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceButton_toolTip) - .withOperation(() -> { + .withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceButton_toolTip).withOperation(() -> { if (getFindString().isEmpty()) { showUserFeedback(warningColor, true); return; @@ -600,8 +637,7 @@ private void createReplaceTools() { replaceAllButton = new AccessibleToolItemBuilder(replaceTools).withStyleBits(SWT.PUSH) .withImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.KEY_REPLACE_ALL)) - .withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceAllButton_toolTip) - .withOperation(() -> { + .withToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceAllButton_toolTip).withOperation(() -> { if (getFindString().isEmpty()) { showUserFeedback(warningColor, true); return; @@ -840,39 +876,39 @@ private void repositionTextSelection() { } private void updatePlacementAndVisibility() { - if (!targetPartVisibilityHandler.isTargetVisible()) { - getShell().setVisible(false); - return; - } - if (isInvalidTargetShell()) { - getShell().getDisplay().asyncExec(() -> { - if (isInvalidTargetShell()) { - close(); - setParentShell(targetPart.getSite().getShell()); - open(); - targetPart.setFocus(); - } - }); - return; - } - getShell().requestLayout(); - if (!(targetPart instanceof StatusTextEditor textEditor)) { - return; - } - - Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget(); - if (!okayToUse(targetWidget)) { - this.close(); - return; - } - - Rectangle targetControlBounds = calculateAbsoluteControlBounds(targetWidget); - Rectangle overlayBounds = calculateDesiredOverlayBounds(targetControlBounds); - updatePosition(overlayBounds); - configureDisplayedWidgetsForWidth(overlayBounds.width); - updateVisibility(targetControlBounds, overlayBounds); - - repositionTextSelection(); +// if (!targetPartVisibilityHandler.isTargetVisible()) { +// getShell().setVisible(false); +// return; +// } +// if (isInvalidTargetShell()) { +// getShell().getDisplay().asyncExec(() -> { +// if (isInvalidTargetShell()) { +// close(); +//// setParentShell(targetPart.getSite().getShell()); +// open(); +// targetPart.setFocus(); +// } +// }); +// return; +// } +// getShell().requestLayout(); +// if (!(targetPart instanceof StatusTextEditor textEditor)) { +// return; +// } +// +// Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget(); +// if (!okayToUse(targetWidget)) { +// this.close(); +// return; +// } +// +// Rectangle targetControlBounds = calculateAbsoluteControlBounds(targetWidget); +// Rectangle overlayBounds = calculateDesiredOverlayBounds(targetControlBounds); +// updatePosition(overlayBounds); +// configureDisplayedWidgetsForWidth(overlayBounds.width); +// updateVisibility(targetControlBounds, overlayBounds); +// +// repositionTextSelection(); } private boolean isInvalidTargetPart() { @@ -934,9 +970,9 @@ private void updateVisibility(Rectangle targetControlBounds, Rectangle overlayBo } else { shallBeVisible = overlayBounds.y >= targetControlBounds.y; } - Shell shell = getShell(); - if (shallBeVisible != shell.isVisible()) { - shell.setVisible(shallBeVisible); + Composite part = getShell(); + if (shallBeVisible != part.isVisible()) { + part.setVisible(shallBeVisible); } } diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java index e6ba4778444..83ce4b29f48 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java @@ -16,8 +16,11 @@ import java.util.ResourceBundle; +import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; + import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; import org.eclipse.core.runtime.Assert; @@ -411,6 +414,8 @@ private void showDialog() { dialog.open(); } + MPartStack pipStack = null; + Composite pipComp = null; private void showOverlayInEditor() { if (overlay == null) { Shell shellToUse = null; @@ -429,7 +434,7 @@ private void showOverlayInEditor() { overlay.setPositionToTop(shouldPositionOverlayOnTop()); hookDialogPreferenceListener(); - overlay.getShell().addDisposeListener(__ -> removeDialogPreferenceListener()); +// overlay.getShell().addDisposeListener(__ -> removeDialogPreferenceListener()); } @Override