Skip to content

Commit cf2cdd3

Browse files
authored
Fix context menu for Edge in Windows (#77)
* Add browser function that fires on context menu request * Add example for custom context menu in workflow diagram Fixes eclipse-glsp/glsp#978 Fixes eclipse-glsp/glsp#969 Contributed on behalf of STMicroelectronics
1 parent 52353f6 commit cf2cdd3

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

server/example/org.eclipse.glsp.ide.workflow.editor/plugin.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
allPopups="false"
2727
locationURI="popup:org.eclipse.glsp.workflow.editor">
2828
<separator
29-
name="org.eclipse.glsp.integration.workflow.editor.edit_start">
29+
name="org.eclipse.glsp.integration.workflow.editor.edit_start" visible="true">
3030
</separator>
3131
<command
3232
commandId="org.eclipse.ui.edit.copy"
@@ -43,6 +43,13 @@
4343
<separator
4444
name="org.eclipse.glsp.integration.workflow.editor.edit_end">
4545
</separator>
46+
<separator
47+
name="org.eclipse.glsp.integration.workflow.editor.navigate_start" visible="true">
48+
</separator>
49+
<command
50+
commandId="org.eclipse.glsp.ide.workflow.editor.navigate.next-node"
51+
style="push">
52+
</command>
4653
<dynamic
4754
class="org.eclipse.glsp.ide.editor.ui.GLSPDynamicContribution"
4855
id="org.eclipse.glsp.ide.editor.actionprovider">
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/********************************************************************************
2+
* Copyright (c) 2023 EclipseSource and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* https://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the Eclipse
10+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
11+
* with the GNU Classpath Exception which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
********************************************************************************/
16+
package org.eclipse.glsp.ide.editor.ui;
17+
18+
import java.util.Optional;
19+
20+
import org.eclipse.swt.browser.Browser;
21+
import org.eclipse.swt.browser.BrowserFunction;
22+
23+
public class BrowserContextMenuInstaller implements BrowserFunctionInstaller {
24+
25+
private static final String FUNCTION_NAME = "requestContextMenu";
26+
private static final String FUNCTION_INSTALLER = "document.addEventListener(\"contextmenu\", e => { requestContextMenu(); e.preventDefault(); });";
27+
28+
@Override
29+
public Optional<BrowserFunction> install(final Browser browser) {
30+
BrowserFunction browserFunction = new BrowserFunction(browser, FUNCTION_NAME) {
31+
@Override
32+
public Object function(final Object[] arguments) {
33+
browser.getDisplay().asyncExec(() -> requestContextMenu(browser));
34+
return null;
35+
}
36+
};
37+
browser.execute(FUNCTION_INSTALLER);
38+
return Optional.of(browserFunction);
39+
}
40+
41+
protected void requestContextMenu(final Browser browser) {
42+
if (browser.isDisposed()) {
43+
return;
44+
}
45+
browser.getMenu().setEnabled(true);
46+
browser.getMenu().setVisible(true);
47+
}
48+
}

server/plugins/org.eclipse.glsp.ide.editor/src/org/eclipse/glsp/ide/editor/ui/GLSPDiagramEditor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,8 @@ protected void syncMarkers(final GModelState modelState) {
361361
.ifPresent(toDispose::add);
362362
}
363363

364-
@SuppressWarnings("deprecation")
365364
protected Browser createBrowser(final Composite parent) {
366-
Browser browser = new FocusAwareBrowser(parent, SWT.NO_SCROLL | SWT.EDGE | SWT.CHROMIUM);
365+
Browser browser = new FocusAwareBrowser(parent, SWT.NO_SCROLL | SWT.EDGE);
367366
browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
368367
toDispose.add(browser::dispose);
369368
return browser;
@@ -405,6 +404,7 @@ protected void installBrowserFunctions() {
405404
// browser functions are automatically disposed with the browser
406405
new BrowserKeyBindingForwarderInstaller(getSite()).install(browser);
407406
new BrowserFocusControlInstaller().install(browser);
407+
new BrowserContextMenuInstaller().install(browser);
408408
}
409409

410410
protected String getBaseUrl() { return "diagram.html"; }

0 commit comments

Comments
 (0)