feat: rename, deletion, and validation support

Closes #1599
Closes #1825
Closes #649
Closes #1847
Closes #1882

Co-authored-by: Akos Kitta <a.kitta@arduino.cc>
Co-authored-by: per1234 <accounts@perglass.com>

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta
2023-01-17 14:03:07 +01:00
committed by Akos Kitta
parent 4f07515ee8
commit d68bc4abdb
71 changed files with 2905 additions and 874 deletions

View File

@@ -0,0 +1,60 @@
import { webFrame } from '@theia/core/electron-shared/electron/';
import {
ContextMenuAccess,
coordinateFromAnchor,
RenderContextMenuOptions,
} from '@theia/core/lib/browser/context-menu-renderer';
import {
ElectronContextMenuAccess,
ElectronContextMenuRenderer as TheiaElectronContextMenuRenderer,
} from '@theia/core/lib/electron-browser/menu/electron-context-menu-renderer';
import { injectable } from '@theia/core/shared/inversify';
@injectable()
export class ElectronContextMenuRenderer extends TheiaElectronContextMenuRenderer {
protected override doRender(
options: RenderContextMenuOptions
): ContextMenuAccess {
if (this.useNativeStyle) {
const { menuPath, anchor, args, onHide, context } = options;
const menu = this['electronMenuFactory'].createElectronContextMenu(
menuPath,
args,
context,
this.showDisabled(options)
);
const { x, y } = coordinateFromAnchor(anchor);
const zoom = webFrame.getZoomFactor();
// TODO: Remove the offset once Electron fixes https://github.com/electron/electron/issues/31641
const offset = process.platform === 'win32' ? 0 : 2;
// x and y values must be Ints or else there is a conversion error
menu.popup({
x: Math.round(x * zoom) + offset,
y: Math.round(y * zoom) + offset,
});
// native context menu stops the event loop, so there is no keyboard events
this.context.resetAltPressed();
if (onHide) {
menu.once('menu-will-close', () => onHide());
}
return new ElectronContextMenuAccess(menu);
} else {
return super.doRender(options);
}
}
/**
* Theia does not allow selectively control whether disabled menu items are visible or not. This is a workaround.
* Attach the `showDisabled: true` to the `RenderContextMenuOptions` object, and you can control it.
* https://github.com/eclipse-theia/theia/blob/d59d5279b93e5050c2cbdd4b6726cab40187c50e/packages/core/src/electron-browser/menu/electron-main-menu-factory.ts#L134.
*/
private showDisabled(options: RenderContextMenuOptions): boolean {
if ('showDisabled' in options) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const object = options as any;
const showDisabled = object['showDisabled'] as unknown;
return typeof showDisabled === 'boolean' && Boolean(showDisabled);
}
return false;
}
}

View File

@@ -74,11 +74,12 @@ export class ElectronMainMenuFactory extends TheiaElectronMainMenuFactory {
menuPath: MenuPath,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args?: any[],
context?: HTMLElement
context?: HTMLElement,
showDisabled?: boolean
): Electron.Menu {
const menuModel = this.menuProvider.getMenu(menuPath);
const template = this.fillMenuTemplate([], menuModel, args, {
showDisabled: false,
showDisabled,
context,
rootMenuPath: menuPath,
});

View File

@@ -1,13 +1,17 @@
import { ContainerModule } from '@theia/core/shared/inversify';
import { ContextMenuRenderer } from '@theia/core/lib/browser/context-menu-renderer';
import { ElectronMainMenuFactory as TheiaElectronMainMenuFactory } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory';
import { ElectronMenuContribution as TheiaElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
import { ContainerModule } from '@theia/core/shared/inversify';
import { MainMenuManager } from '../../../common/main-menu-manager';
import { ElectronContextMenuRenderer } from './electron-context-menu-renderer';
import { ElectronMainMenuFactory } from './electron-main-menu-factory';
import { ElectronMenuContribution } from './electron-menu-contribution';
export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ElectronMenuContribution).toSelf().inSingletonScope();
bind(MainMenuManager).toService(ElectronMenuContribution);
bind(ElectronContextMenuRenderer).toSelf().inSingletonScope();
rebind(ContextMenuRenderer).toService(ElectronContextMenuRenderer);
rebind(TheiaElectronMenuContribution).toService(ElectronMenuContribution);
bind(ElectronMainMenuFactory).toSelf().inSingletonScope();
rebind(TheiaElectronMainMenuFactory).toService(ElectronMainMenuFactory);