mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2 (#8911)
* Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2 * update distro * fix layering * update distro * fix tests
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { SyncDescriptor0, createSyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { IConstructorSignature2, createDecorator, BrandedService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IKeybindings, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { IConstructorSignature2, createDecorator, BrandedService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IKeybindings, KeybindingsRegistry, IKeybindingRule } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ICommandService, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
|
||||
@@ -70,6 +70,8 @@ export const enum MenuId {
|
||||
EditorTitleContext,
|
||||
EmptyEditorGroupContext,
|
||||
ExplorerContext,
|
||||
ExtensionContext,
|
||||
GlobalActivity,
|
||||
MenubarAppearanceMenu,
|
||||
MenubarDebugMenu,
|
||||
MenubarEditMenu,
|
||||
@@ -111,7 +113,8 @@ export const enum MenuId {
|
||||
CommentThreadActions,
|
||||
CommentTitle,
|
||||
CommentActions,
|
||||
GlobalActivity
|
||||
BulkEditTitle,
|
||||
BulkEditContext,
|
||||
}
|
||||
|
||||
export interface IMenuActionOptions {
|
||||
@@ -347,62 +350,50 @@ export class SyncActionDescriptor {
|
||||
}
|
||||
}
|
||||
|
||||
//#region --- IAction2
|
||||
|
||||
export interface IActionDescriptor {
|
||||
id: string;
|
||||
handler: ICommandHandler;
|
||||
type OneOrN<T> = T | T[];
|
||||
|
||||
// ICommandUI
|
||||
title?: ILocalizedString;
|
||||
category?: string;
|
||||
export interface IAction2Options extends ICommandAction {
|
||||
f1?: boolean;
|
||||
|
||||
//
|
||||
menu?: {
|
||||
menuId: MenuId,
|
||||
when?: ContextKeyExpr;
|
||||
group?: string;
|
||||
};
|
||||
|
||||
//
|
||||
keybinding?: {
|
||||
when?: ContextKeyExpr;
|
||||
weight?: number;
|
||||
keys: IKeybindings;
|
||||
};
|
||||
menu?: OneOrN<{ id: MenuId } & Omit<IMenuItem, 'command'>>;
|
||||
keybinding?: Omit<IKeybindingRule, 'id'>;
|
||||
}
|
||||
|
||||
export abstract class Action2 {
|
||||
constructor(readonly desc: Readonly<IAction2Options>) { }
|
||||
abstract run(accessor: ServicesAccessor, ...args: any[]): any;
|
||||
}
|
||||
|
||||
export function registerAction(desc: IActionDescriptor) {
|
||||
export function registerAction2(ctor: { new(): Action2 }): IDisposable {
|
||||
const disposables = new DisposableStore();
|
||||
const action = new ctor();
|
||||
disposables.add(CommandsRegistry.registerCommand({
|
||||
id: action.desc.id,
|
||||
handler: (accessor, ...args) => action.run(accessor, ...args),
|
||||
description: undefined,
|
||||
}));
|
||||
|
||||
const { id, handler, title, category, menu, keybinding } = desc;
|
||||
|
||||
// 1) register as command
|
||||
CommandsRegistry.registerCommand(id, handler);
|
||||
|
||||
// 2) menus
|
||||
if (menu && title) {
|
||||
let command = { id, title, category };
|
||||
let { menuId, when, group } = menu;
|
||||
MenuRegistry.appendMenuItem(menuId, {
|
||||
command,
|
||||
when,
|
||||
group
|
||||
});
|
||||
if (Array.isArray(action.desc.menu)) {
|
||||
for (let item of action.desc.menu) {
|
||||
disposables.add(MenuRegistry.appendMenuItem(item.id, { command: action.desc, ...item }));
|
||||
}
|
||||
} else if (action.desc.menu) {
|
||||
disposables.add(MenuRegistry.appendMenuItem(action.desc.menu.id, { command: action.desc, ...action.desc.menu }));
|
||||
}
|
||||
|
||||
// 3) keybindings
|
||||
if (keybinding) {
|
||||
let { when, weight, keys } = keybinding;
|
||||
if (action.desc.f1) {
|
||||
disposables.add(MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: action.desc, ...action.desc }));
|
||||
}
|
||||
|
||||
if (action.desc.keybinding) {
|
||||
KeybindingsRegistry.registerKeybindingRule({
|
||||
id,
|
||||
when,
|
||||
weight: weight || 0,
|
||||
primary: keys.primary,
|
||||
secondary: keys.secondary,
|
||||
linux: keys.linux,
|
||||
mac: keys.mac,
|
||||
win: keys.win
|
||||
...action.desc.keybinding,
|
||||
id: action.desc.id,
|
||||
when: ContextKeyExpr.and(action.desc.precondition, action.desc.keybinding.when)
|
||||
});
|
||||
}
|
||||
|
||||
return disposables;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
Reference in New Issue
Block a user