Skip to content

Commit

Permalink
GH-22: Declared menu registry based on the VSCode's actions module.
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <kittaakos@gmail.com>
  • Loading branch information
kittaakos committed Apr 5, 2017
1 parent 6c8c767 commit 6b6d989
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
8 changes: 5 additions & 3 deletions examples/src/electron/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
'vs/language/typescript/src/monaco.contribution',
'vs/language/html/monaco.contribution',
'vs/language/json/monaco.contribution',
'vs/platform/commands/common/commands'
], (basic, css, ts, html, json, commands) => {
'vs/platform/commands/common/commands',
'vs/platform/actions/common/actions'
], (basic, css, ts, html, json, commands, actions) => {
const global = self;
global.monaco.commands.CommandsRegistry = commands.CommandsRegistry;
global.monaco.commands = commands;
global.monaco.actions = actions;
require("./bundle.js");
});
});
Expand Down
8 changes: 5 additions & 3 deletions examples/src/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ window.onload = () => {
'vs/language/typescript/src/monaco.contribution',
'vs/language/html/monaco.contribution',
'vs/language/json/monaco.contribution',
'vs/platform/commands/common/commands'
], (basic: any, css: any, ts: any, html: any, json: any, commands: any) => {
'vs/platform/commands/common/commands',
'vs/platform/actions/common/actions'
], (basic: any, css: any, ts: any, html: any, json: any, commands: any, actions: any) => {
const global: any = self;
global.monaco.commands.CommandsRegistry = commands.CommandsRegistry;
global.monaco.commands = commands;
global.monaco.actions = actions;
require('./main');
});
});
Expand Down
11 changes: 5 additions & 6 deletions src/editor/browser/editor-contextmenu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { injectable } from "inversify";
import IContextMenuService = monaco.editor.IContextMenuService;
import CommandsRegistry = monaco.commands.CommandsRegistry;
import MenuRegistry = monaco.actions.MenuRegistry;
import MenuId = monaco.actions.MenuId;

export const EditorContextMenuService = Symbol("EditorContextMenuService");

Expand All @@ -14,12 +16,9 @@ export class BrowserContextMenuService implements EditorContextMenuService {
showContextMenu(delegate: any): void {
const ids = Object.keys(CommandsRegistry.getCommands());
console.log(ids.length);
// for (let id of ids) {
// const command = CommandsRegistry.getCommand(id);
// console.log();
// console.log(id);
// console.log(command);
// }

const menuItems = MenuRegistry.getMenuItems(MenuId.EditorContext);
console.log(JSON.stringify(menuItems));
}

}
36 changes: 36 additions & 0 deletions typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,40 @@ declare module monaco.commands {
*/
export const CommandsRegistry: ICommandRegistry;

}

declare module monaco.actions {

export class MenuId {

public static readonly EditorContext: MenuId;
}

export interface ILocalizedString {
value: string;
original: string;
}

export interface ICommandAction {
id: string;
title: string | ILocalizedString;
category?: string | ILocalizedString;
iconClass?: string;
}

export interface IMenuItem {
command: ICommandAction;
alt?: ICommandAction;
when?: any;
group?: 'navigation' | string;
order?: number;
}

export interface IMenuRegistry {
getCommand(id: string): ICommandAction;
getMenuItems(loc: MenuId): IMenuItem[];
}

export const MenuRegistry: IMenuRegistry;

}

0 comments on commit 6b6d989

Please sign in to comment.