From 4039834bac5cc597b9e90a1e59557f5b0009fff3 Mon Sep 17 00:00:00 2001 From: Martin Jobst Date: Tue, 21 Jan 2025 10:01:31 +0100 Subject: [PATCH] Provide text action bar contributor for text editors in type editor The text editors inside a multi-page type editor need to have a proper text action contributor to properly support switching of actions between pages and also for the new search overlay. This provides a text action bar contributor for text editors inside a type editor. --- .../plugin.xml | 2 +- .../GraphicalMultipageEditorContributor.java | 7 +- .../plugin.xml | 2 +- .../META-INF/MANIFEST.MF | 3 +- .../plugin.xml | 2 +- .../META-INF/MANIFEST.MF | 3 + .../ide/typeeditor/AbstractTypeEditor.java | 3 + .../ide/typeeditor/TypeEditorContributor.java | 77 +++++++++++++++++++ .../TypeTextMultiPageEditorSite.java | 33 ++++++++ 9 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 plugins/org.eclipse.fordiac.ide.typeeditor/src/org/eclipse/fordiac/ide/typeeditor/TypeEditorContributor.java create mode 100644 plugins/org.eclipse.fordiac.ide.typeeditor/src/org/eclipse/fordiac/ide/typeeditor/TypeTextMultiPageEditorSite.java diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml index 71e3972542..f30124a871 100644 --- a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml @@ -14,7 +14,7 @@ point="org.eclipse.ui.editors"> diff --git a/plugins/org.eclipse.fordiac.ide.systemmanagement.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.systemmanagement.ui/META-INF/MANIFEST.MF index da0d267245..707d659e17 100644 --- a/plugins/org.eclipse.fordiac.ide.systemmanagement.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.systemmanagement.ui/META-INF/MANIFEST.MF @@ -35,7 +35,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.fordiac.ide.subapptypeeditor, org.eclipse.fordiac.ide.fbtypeeditor.network, org.eclipse.fordiac.ide.library.model, - org.eclipse.fordiac.ide.library.ui + org.eclipse.fordiac.ide.library.ui, + org.eclipse.fordiac.ide.typeeditor Bundle-Vendor: %Bundle-Vendor Bundle-Version: 3.0.0.qualifier Bundle-ManifestVersion: 2 diff --git a/plugins/org.eclipse.fordiac.ide.systemmanagement.ui/plugin.xml b/plugins/org.eclipse.fordiac.ide.systemmanagement.ui/plugin.xml index 8e190aec78..f328f0af1f 100644 --- a/plugins/org.eclipse.fordiac.ide.systemmanagement.ui/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.systemmanagement.ui/plugin.xml @@ -68,7 +68,7 @@ point="org.eclipse.ui.editors"> handlers = textActionBars.getGlobalActionHandlers(); + if (handlers != null) { + for (final var action : handlers.entrySet()) { + getActionBars().setGlobalActionHandler(action.getKey(), active ? action.getValue() : null); + } + } + } + + @SuppressWarnings("static-method") // subclasses may override + protected TextEditorActionContributor createTextContributor() { + return new TextEditorActionContributor(); + } + + public IEditorActionBarContributor getTextContributor() { + return textContributor; + } +} diff --git a/plugins/org.eclipse.fordiac.ide.typeeditor/src/org/eclipse/fordiac/ide/typeeditor/TypeTextMultiPageEditorSite.java b/plugins/org.eclipse.fordiac.ide.typeeditor/src/org/eclipse/fordiac/ide/typeeditor/TypeTextMultiPageEditorSite.java new file mode 100644 index 0000000000..649a964a90 --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typeeditor/src/org/eclipse/fordiac/ide/typeeditor/TypeTextMultiPageEditorSite.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2025 Martin Erich Jobst + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Jobst - initial API and implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.fordiac.ide.typeeditor; + +import org.eclipse.ui.IEditorActionBarContributor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.part.MultiPageEditorPart; + +public class TypeTextMultiPageEditorSite extends TypeMultiPageEditorSite { + + public TypeTextMultiPageEditorSite(final MultiPageEditorPart multiPageEditor, final IEditorPart editor) { + super(multiPageEditor, editor); + } + + @Override + public IEditorActionBarContributor getActionBarContributor() { + if (getMultiPageEditor().getEditorSite() + .getActionBarContributor() instanceof final TypeEditorContributor typeEditorContributor) { + return typeEditorContributor.getTextContributor(); + } + return null; + } +}