Skip to content

Commit

Permalink
Fix context menu for Edge in Windows (#77)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
planger authored Apr 26, 2023
1 parent 52353f6 commit cf2cdd3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
allPopups="false"
locationURI="popup:org.eclipse.glsp.workflow.editor">
<separator
name="org.eclipse.glsp.integration.workflow.editor.edit_start">
name="org.eclipse.glsp.integration.workflow.editor.edit_start" visible="true">
</separator>
<command
commandId="org.eclipse.ui.edit.copy"
Expand All @@ -43,6 +43,13 @@
<separator
name="org.eclipse.glsp.integration.workflow.editor.edit_end">
</separator>
<separator
name="org.eclipse.glsp.integration.workflow.editor.navigate_start" visible="true">
</separator>
<command
commandId="org.eclipse.glsp.ide.workflow.editor.navigate.next-node"
style="push">
</command>
<dynamic
class="org.eclipse.glsp.ide.editor.ui.GLSPDynamicContribution"
id="org.eclipse.glsp.ide.editor.actionprovider">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/********************************************************************************
* Copyright (c) 2023 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
package org.eclipse.glsp.ide.editor.ui;

import java.util.Optional;

import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;

public class BrowserContextMenuInstaller implements BrowserFunctionInstaller {

private static final String FUNCTION_NAME = "requestContextMenu";
private static final String FUNCTION_INSTALLER = "document.addEventListener(\"contextmenu\", e => { requestContextMenu(); e.preventDefault(); });";

@Override
public Optional<BrowserFunction> install(final Browser browser) {
BrowserFunction browserFunction = new BrowserFunction(browser, FUNCTION_NAME) {
@Override
public Object function(final Object[] arguments) {
browser.getDisplay().asyncExec(() -> requestContextMenu(browser));
return null;
}
};
browser.execute(FUNCTION_INSTALLER);
return Optional.of(browserFunction);
}

protected void requestContextMenu(final Browser browser) {
if (browser.isDisposed()) {
return;
}
browser.getMenu().setEnabled(true);
browser.getMenu().setVisible(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,8 @@ protected void syncMarkers(final GModelState modelState) {
.ifPresent(toDispose::add);
}

@SuppressWarnings("deprecation")
protected Browser createBrowser(final Composite parent) {
Browser browser = new FocusAwareBrowser(parent, SWT.NO_SCROLL | SWT.EDGE | SWT.CHROMIUM);
Browser browser = new FocusAwareBrowser(parent, SWT.NO_SCROLL | SWT.EDGE);
browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
toDispose.add(browser::dispose);
return browser;
Expand Down Expand Up @@ -405,6 +404,7 @@ protected void installBrowserFunctions() {
// browser functions are automatically disposed with the browser
new BrowserKeyBindingForwarderInstaller(getSite()).install(browser);
new BrowserFocusControlInstaller().install(browser);
new BrowserContextMenuInstaller().install(browser);
}

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

0 comments on commit cf2cdd3

Please sign in to comment.