Skip to content

Commit

Permalink
Provide text action bar contributor for text editors in type editor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mx990 authored and azoitl committed Jan 21, 2025
1 parent abef213 commit 4039834
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
point="org.eclipse.ui.editors">
<editor
class="org.eclipse.fordiac.ide.fbtypeeditor.editors.FBTypeEditor"
contributorClass="org.eclipse.fordiac.ide.gef.editors.GraphicalMultipageEditorContributor"
contributorClass="org.eclipse.fordiac.ide.typeeditor.TypeEditorContributor"
extensions="fbt, fct, adp"
icon="fordiacimage://ICON_FB_TYPE"
id="org.eclipse.fordiac.ide.fbtypeeditor.editors.FBTypeEditor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.Adapters;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.AlignmentRetargetAction;
Expand All @@ -37,16 +38,14 @@ public class GraphicalMultipageEditorContributor extends MultiPageEditorActionBa

@Override
public void setActiveEditor(final IEditorPart editor) {
setGlobalActionHandler(editor.getAdapter(ActionRegistry.class));
setGlobalActionHandler(Adapters.adapt(editor, ActionRegistry.class));
super.setActiveEditor(editor);

}

@Override
public void setActivePage(final IEditorPart activeEditor) {
if (null != activeEditor) {
setGlobalActionHandler(activeEditor.getAdapter(ActionRegistry.class));
}
setGlobalActionHandler(Adapters.adapt(activeEditor, ActionRegistry.class));
}

private void setGlobalActionHandler(final ActionRegistry editorRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
extensions="sub"
default="true"
icon="fordiacimage://ICON_SUB_APP_TYPE"
contributorClass="org.eclipse.fordiac.ide.gef.editors.GraphicalMultipageEditorContributor"
contributorClass="org.eclipse.fordiac.ide.typeeditor.TypeEditorContributor"
class="org.eclipse.fordiac.ide.subapptypeeditor.SubAppTypeEditor"
id="org.eclipse.fordiac.ide.subapptypeeditor.SubAppTypeEditor"
matchingStrategy="org.eclipse.fordiac.ide.ui.editors.FordiacEditorMatchingStrategy"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
point="org.eclipse.ui.editors">
<editor
class="org.eclipse.fordiac.ide.systemmanagement.ui.editors.AutomationSystemEditor"
contributorClass="org.eclipse.fordiac.ide.gef.editors.GraphicalMultipageEditorContributor"
contributorClass="org.eclipse.fordiac.ide.typeeditor.TypeEditorContributor"
default="true"
extensions="sys"
icon="fordiacimage://ICON_SYSTEM_PERSPECTIVE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Import-Package: org.eclipse.core.commands.common,
org.eclipse.emf.ecore.resource,
org.eclipse.fordiac.ide.application.editors,
org.eclipse.fordiac.ide.gef.annotation,
org.eclipse.fordiac.ide.gef.editors,
org.eclipse.fordiac.ide.gef.validation,
org.eclipse.fordiac.ide.model.edit,
org.eclipse.fordiac.ide.model.libraryElement,
Expand All @@ -30,6 +31,7 @@ Import-Package: org.eclipse.core.commands.common,
org.eclipse.fordiac.ide.ui.widget,
org.eclipse.gef,
org.eclipse.gef.commands,
org.eclipse.jface.action,
org.eclipse.jface.dialogs,
org.eclipse.jface.layout,
org.eclipse.jface.resource,
Expand All @@ -42,6 +44,7 @@ Import-Package: org.eclipse.core.commands.common,
org.eclipse.swt.widgets,
org.eclipse.ui,
org.eclipse.ui.actions,
org.eclipse.ui.editors.text,
org.eclipse.ui.forms.editor,
org.eclipse.ui.ide,
org.eclipse.ui.part,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public void createPartControl(final Composite parent) {

@Override
protected IEditorSite createSite(final IEditorPart editor) {
if (editor instanceof ITextEditor) {
return new TypeTextMultiPageEditorSite(this, editor);
}
return new TypeMultiPageEditorSite(this, editor);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*******************************************************************************
* 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 java.util.Map;

import org.eclipse.fordiac.ide.gef.editors.GraphicalMultipageEditorContributor;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.SubActionBars;
import org.eclipse.ui.editors.text.TextEditorActionContributor;
import org.eclipse.ui.texteditor.ITextEditor;

public class TypeEditorContributor extends GraphicalMultipageEditorContributor {
private final TextEditorActionContributor textContributor = createTextContributor();
private SubActionBars textActionBars;

@Override
public void init(final IActionBars bars) {
super.init(bars);
textActionBars = new SubActionBars(bars);
textContributor.init(textActionBars);
}

@Override
public void dispose() {
textActionBars.dispose();
textContributor.dispose();
super.dispose();
}

@Override
public void setActivePage(final IEditorPart newEditor) {
if (newEditor instanceof final ITextEditor newTextEditor) {
super.setActivePage(null);
textContributor.setActiveEditor(newTextEditor);
textActionBars.activate();
forwardGlobalActionHandlers(true);
} else {
forwardGlobalActionHandlers(false);
textActionBars.deactivate();
textContributor.setActiveEditor(null);
super.setActivePage(newEditor);
}
getActionBars().updateActionBars();
}

protected void forwardGlobalActionHandlers(final boolean active) {
final Map<String, IAction> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 4039834

Please sign in to comment.