-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
9 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
....fordiac.ide.typeeditor/src/org/eclipse/fordiac/ide/typeeditor/TypeEditorContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ac.ide.typeeditor/src/org/eclipse/fordiac/ide/typeeditor/TypeTextMultiPageEditorSite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |