-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
3 changed files
with
58 additions
and
3 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
48 changes: 48 additions & 0 deletions
48
...lipse.glsp.ide.editor/src/org/eclipse/glsp/ide/editor/ui/BrowserContextMenuInstaller.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,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); | ||
} | ||
} |
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