Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.9.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.22.0,4.0.0)";resolution:=optional,
org.eclipse.ui.editors;bundle-version="[3.20.0,4.0.0)";resolution:=optional,
org.eclipse.text;bundle-version="[3.14.0,4.0.0)";resolution:=optional,
org.eclipse.terminal.view.core;bundle-version="[1.0.0,2.0.0)"
org.eclipse.terminal.view.core;bundle-version="[1.0.0,2.0.0)",
org.eclipse.e4.core.contexts;bundle-version="[1.10.0,2.0.0)",
org.eclipse.e4.core.di;bundle-version="[1.9.0,2.0.0)",
org.eclipse.e4.ui.di;bundle-version="[1.5.0,2.0.0)",
org.eclipse.e4.ui.model.workbench;bundle-version="[2.4.0,3.0.0)",
org.eclipse.e4.ui.workbench;bundle-version="[1.15.0,2.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Expand All @@ -32,7 +37,9 @@ Export-Package: org.eclipse.terminal.view.ui;version="1.0.100",
org.eclipse.terminal.view.ui.launcher;version="1.0.100",
org.eclipse.terminal.view.ui.streams;version="1.0.100"
Automatic-Module-Name: org.eclipse.terminal.view.ui
Import-Package: org.eclipse.terminal.connector;version="[1.0.0,2.0.0)",
Import-Package: jakarta.annotation;version="[2.1.0,3.0.0)",
jakarta.inject;version="[2.0.0,3.0.0)",
org.eclipse.terminal.connector;version="[1.0.0,2.0.0)",
org.eclipse.terminal.connector.provider;version="[1.0.0,2.0.0)",
org.eclipse.terminal.control;version="[1.0.0,2.0.0)",
org.eclipse.terminal.model;version="[1.0.0,2.0.0)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bin.includes = META-INF/,\
about.html,\
icons/,\
contexts.xml,\
OSGI-INF/
OSGI-INF/,\
fragment.e4xmi
src.includes = schema/,\
about.html
17 changes: 17 additions & 0 deletions terminal/bundles/org.eclipse.terminal.view.ui/fragment.e4xmi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_fragment">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_commands_fragment" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_command_launch" elementId="org.eclipse.terminal.view.ui.command.launch" commandName="Launch Terminal" description="Launch Terminal"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n was lost

<elements xsi:type="commands:Command" xmi:id="_command_launchConsole" elementId="org.eclipse.terminal.view.ui.command.launchConsole" commandName="Launch Terminal" description="Launch Terminal"/>
<elements xsi:type="commands:Command" xmi:id="_command_launchToolbar" elementId="org.eclipse.terminal.view.ui.command.launchToolbar" commandName="Open a Terminal" description="Open a Terminal"/>
<elements xsi:type="commands:Command" xmi:id="_command_disconnect" elementId="org.eclipse.terminal.view.ui.command.disconnect" commandName="Disconnect" description="Disconnect Terminal"/>
<elements xsi:type="commands:Command" xmi:id="_command_newview" elementId="org.eclipse.terminal.view.ui.command.newview" commandName="New Terminal View" description="New Terminal View"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_handlers_fragment" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_handler_launch" elementId="org.eclipse.terminal.view.ui.handler.launch" contributionURI="bundleclass://org.eclipse.terminal.view.ui/org.eclipse.terminal.view.ui.internal.handler.LaunchTerminalCommandHandler" command="_command_launch"/>
<elements xsi:type="commands:Handler" xmi:id="_handler_launchConsole" elementId="org.eclipse.terminal.view.ui.handler.launchConsole" contributionURI="bundleclass://org.eclipse.terminal.view.ui/org.eclipse.terminal.view.ui.internal.handler.LaunchTerminalCommandHandler" command="_command_launchConsole"/>
<elements xsi:type="commands:Handler" xmi:id="_handler_launchToolbar" elementId="org.eclipse.terminal.view.ui.handler.launchToolbar" contributionURI="bundleclass://org.eclipse.terminal.view.ui/org.eclipse.terminal.view.ui.internal.handler.LaunchTerminalCommandHandler" command="_command_launchToolbar"/>
<elements xsi:type="commands:Handler" xmi:id="_handler_disconnect" elementId="org.eclipse.terminal.view.ui.handler.disconnect" contributionURI="bundleclass://org.eclipse.terminal.view.ui/org.eclipse.terminal.view.ui.internal.handler.DisconnectTerminalCommandHandler" command="_command_disconnect"/>
<elements xsi:type="commands:Handler" xmi:id="_handler_newview" elementId="org.eclipse.terminal.view.ui.handler.newview" contributionURI="bundleclass://org.eclipse.terminal.view.ui/org.eclipse.terminal.view.ui.internal.handler.NewTerminalViewHandler" command="_command_newview"/>
</fragments>
</fragment:ModelFragments>
100 changes: 9 additions & 91 deletions terminal/bundles/org.eclipse.terminal.view.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

<plugin>

<!-- E4 model fragment -->
<extension
id="fragment"
point="org.eclipse.e4.workbench.model">
<fragment
uri="fragment.e4xmi">
</fragment>
</extension>

<!-- Extension points -->
<extension-point id="launcherDelegates" name="%ExtensionPoint.launcherDelegates.name" schema="schema/launcherDelegates.exsd"/>

Expand Down Expand Up @@ -309,104 +318,13 @@
</menuContribution>

</extension>
<extension point="org.eclipse.ui.commands">
<category
id="org.eclipse.terminal.view.ui.commands.category"
name="%command.category.name">
</category>

<command
categoryId="org.eclipse.terminal.view.ui.commands.category"
helpContextId="org.eclipse.terminal.view.ui.command_Launch"
id="org.eclipse.terminal.view.ui.command.launch"
name="%command.launch.selection.name">
</command>
<command
categoryId="org.eclipse.terminal.view.ui.commands.category"
helpContextId="org.eclipse.terminal.view.ui.command_Launch"
id="org.eclipse.terminal.view.ui.command.launchConsole"
name="%command.launch.selection.name">
</command>
<command
categoryId="org.eclipse.terminal.view.ui.commands.category"
helpContextId="org.eclipse.terminal.view.ui.command_Launch"
id="org.eclipse.terminal.view.ui.command.launchToolbar"
name="%command.launch.name">
</command>
<command
categoryId="org.eclipse.terminal.view.ui.commands.category"
helpContextId="org.eclipse.terminal.view.ui.command_Disconnect"
id="org.eclipse.terminal.view.ui.command.disconnect"
name="%command.disconnect.name">
</command>
<command
categoryId="org.eclipse.terminal.view.ui.commands.category"
helpContextId="org.eclipse.terminal.view.ui.command_NewView"
id="org.eclipse.terminal.view.ui.command.newview"
name="%command.newview.name">
</command>
</extension>
<extension point="org.eclipse.ui.bindings">
<key
commandId="org.eclipse.terminal.view.ui.command.launchToolbar"
contextId="org.eclipse.ui.contexts.window"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+SHIFT+M3+T"/> <!-- Bug 435111: Don't use M1 since COMMAND+Option T already taken on Mac -->
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.terminal.view.ui.internal.handler.LaunchTerminalCommandHandler"
commandId="org.eclipse.terminal.view.ui.command.launch">
</handler>
<handler
class="org.eclipse.terminal.view.ui.internal.handler.LaunchTerminalCommandHandler"
commandId="org.eclipse.terminal.view.ui.command.launchToolbar">
</handler>
<handler
class="org.eclipse.terminal.view.ui.internal.handler.LaunchTerminalCommandHandler"
commandId="org.eclipse.terminal.view.ui.command.launchConsole">
</handler>
<handler
class="org.eclipse.terminal.view.ui.internal.handler.DisconnectTerminalCommandHandler"
commandId="org.eclipse.terminal.view.ui.command.disconnect">
<enabledWhen>
<with variable="activePart">
<instanceof value="org.eclipse.terminal.view.ui.ITerminalsView"/>
<test property="org.eclipse.terminal.view.ui.canDisconnect" value="true"/>
</with>
</enabledWhen>
Comment on lines -372 to -377
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it looks like this should become a core expression instead of doing it "in code" @mickaelistria wdyt?

@vogella @opcoach @ruspl-afed it seems handler in E4 can currently only use annotated code based enablement, should we allow core expressions as well? If yes please add an issue so we can track missing E4 features!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted a task now to support core expressions for handlers:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laeubi In e4 the handler can be assigned to the part directly, instead of "enabling it" whenever the part gets selected. If you look at the part in the model editor you see that the handler can be assigned directly to it. When Paul did redesign the handlers he wanted to get aways from the "all handlers are on the same level and you need to have additonal logic to make them available for only one part".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I think it would be better to have an issue for discussion instead of lots of different PR with questions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vogella PR are issues ... just in case anyways before the PR one can hardly know what issues arise.

Can you provide an example how this should be handled to the migration docs for reference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

@laeubi laeubi Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vogella thanks, I'm lloking into it, I assume the

<test property="org.eclipse.terminal.view.ui.canDisconnect" value="true"/>

would then be need to be implemented in code additionally so one can only "save" the check for the part itself?

Also it means it can only be accomplished when migrating the part first...

Also I'm a bit confused how to distinguish the case where <enabledWhen> versus <activeWhen>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the replacement for is the CanExecute and you should be able to inject properties into this method. You can check via the context spy.

</handler>

<handler
class="org.eclipse.terminal.view.ui.internal.handler.MaximizeViewHandler"
commandId="org.eclipse.terminal.maximize">
<activeWhen>
<with variable="activePartId">
<equals value="org.eclipse.terminal.view.ui.TerminalsView"/>
</with>
</activeWhen>
</handler>

<handler
class="org.eclipse.terminal.view.ui.internal.handler.QuickAccessHandler"
commandId="org.eclipse.terminal.quickaccess">
<activeWhen>
<with variable="activePartId">
<equals value="org.eclipse.terminal.view.ui.TerminalsView"/>
</with>
</activeWhen>
</handler>

<handler
class="org.eclipse.terminal.view.ui.internal.handler.NewTerminalViewHandler"
commandId="org.eclipse.terminal.view.ui.command.newview">
<activeWhen>
<with variable="activePartId">
<equals value="org.eclipse.terminal.view.ui.TerminalsView"/>
</with>
</activeWhen>
</handler>
</extension>
<extension point="org.eclipse.help.contexts">
<contexts
file="contexts.xml">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public abstract class AbstractTriggerCommandHandler extends AbstractHandler {
* @param selection The selection to pass on to the command or <code>null</code>.
*/
protected void triggerCommand(String commandId, ISelection selection) {
triggerCommandStatic(commandId, selection);
}

/**
* Static method to trigger a command to be executed. Can be used from E4 handlers.
*
* @param commandId The command id. Must not be <code>null</code>.
* @param selection The selection to pass on to the command or <code>null</code>.
*/
protected static void triggerCommandStatic(String commandId, ISelection selection) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@opcoach @vogella @ruspl-afed we need a link to some documentation what is the correct E4 way to trigger commands so we can instruct copilote here to not use PlatformUI!

At best this would be done by an enhancement to the https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/docs/Eclipse4_Migration.md file so it is discoverable by copilote in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot the migration doc was enhanced to support how to programmatically call commands in E4:

https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/docs/Eclipse4_Migration.md#migrate-programmatic-command-execution

please adjust the code to use the E4 Command service instead of ICommandService static singelton from PlatformUI!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use E4 command services. QuickAccessHandler, MaximizeViewHandler, and NewTerminalViewHandler now inject ECommandService and EHandlerService instead of accessing ICommandService through PlatformUI singleton.

Commit: The changes will be in the next commit.

Assert.isNotNull(commandId);

ICommandService service = PlatformUI.getWorkbench().getService(ICommandService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,38 @@
*******************************************************************************/
package org.eclipse.terminal.view.ui.internal.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import jakarta.inject.Named;

import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.terminal.control.ITerminalViewControl;
import org.eclipse.terminal.view.ui.ITerminalsView;
import org.eclipse.terminal.view.ui.internal.tabs.TabFolderManager;
import org.eclipse.ui.handlers.HandlerUtil;

/**
* Disconnect terminal connection command handler implementation.
*/
public class DisconnectTerminalCommandHandler extends AbstractHandler {
public class DisconnectTerminalCommandHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection,
@Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
CTabItem item = null;

ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof CTabItem && ((CTabItem) element).getData() instanceof ITerminalViewControl) {
item = (CTabItem) element;
}
}

if (item == null && HandlerUtil.getActivePart(event) instanceof ITerminalsView) {
ITerminalsView view = (ITerminalsView) HandlerUtil.getActivePart(event);
if (item == null && activePart != null && activePart.getObject() instanceof ITerminalsView) {
ITerminalsView view = (ITerminalsView) activePart.getObject();
TabFolderManager mgr = view.getAdapter(TabFolderManager.class);
if (mgr != null && mgr.getActiveTabItem() != null) {
item = mgr.getActiveTabItem();
Expand All @@ -53,8 +55,22 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
terminal.disconnectTerminal();
}
}
}

return null;
@CanExecute
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
if (activePart != null && activePart.getObject() instanceof ITerminalsView) {
ITerminalsView view = (ITerminalsView) activePart.getObject();
TabFolderManager mgr = view.getAdapter(TabFolderManager.class);
if (mgr != null && mgr.getActiveTabItem() != null) {
CTabItem item = mgr.getActiveTabItem();
if (item != null && item.getData() instanceof ITerminalViewControl) {
ITerminalViewControl terminal = (ITerminalViewControl) item.getData();
return terminal != null && !terminal.isDisposed();
}
}
}
return false;
}

}
Loading