import { inject, injectable, postConstruct } from 'inversify'; import { Command, CommandContribution, CommandRegistry } from '@gedit/command'; import { nls } from '@gedit/nls'; import { MenuContribution, MenuModelRegistry, MenuPath, SelectionService } from '@gedit/application-common'; import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegistry, OpenerService, TabBarToolbarContribution, TabBarToolbarRegistry, } from '@gedit/application/lib/browser'; import { NavigatorResourceProvider } from './navigator-resource-provider'; import { NavigatorService } from './navigator-service'; /** * 导航栏注册的命令 */ export namespace NavigatorCommands { const NAVIGATOR_CATEGORY = 'Navigator2d'; export const REVEAL_IN_HIERACHY: Command = { id: 'navigagtor2d.reveal', category: NAVIGATOR_CATEGORY, label: nls.localize('navigagtor2d.reveal', 'Reveal in Navigator') }; /** * 刷新 */ export const REFRESH_NAVIGATOR: Command = { id: 'navigator2d.refresh', category: 'File', label: 'Refresh in Explorer', iconClass: 'refresh' }; /** * 折叠所有 */ export const COLLAPSE_ALL: Command = { id: 'navigator2d.collapse.all', category: 'File', label: 'Collapse Folders in Explorer', iconClass: 'theia-collapse-all-icon' }; } /** * 导航栏工具栏点击更多的操作命令 */ export namespace NavigatorMoreToolbarGroups { export const NEW_OPEN = '1_navigator2d_new_open'; } export const NAVIGATOR_CONTEXT_MENU: MenuPath = ['navigator2d-context-menu']; /** * 导航栏右键菜单 */ export namespace NavigatorContextMenu { export const NAVIGATION = [...NAVIGATOR_CONTEXT_MENU, 'navigation']; export const CLIPBOARD = [...NAVIGATOR_CONTEXT_MENU, '5_cutcopypaste']; export const MODIFICATION = [...NAVIGATOR_CONTEXT_MENU, '7_modification']; } @injectable() export class NavigatorContribution implements FrontendApplicationContribution, CommandContribution, KeybindingContribution, MenuContribution, TabBarToolbarContribution { @inject(NavigatorService) navigatorService: NavigatorService; @inject(SelectionService) selectionService: SelectionService; @inject(OpenerService) protected readonly openerService: OpenerService; @inject(NavigatorResourceProvider) resourceProivder: NavigatorResourceProvider; @inject(CommandRegistry) protected readonly commandRegistry: CommandRegistry; @inject(TabBarToolbarRegistry) protected readonly tabbarToolbarRegistry: TabBarToolbarRegistry; @postConstruct() protected async init(): Promise { // DEPRECATED // this.selectionService.onSelectionChanged((selected: object) => this.navigatorService.selectTreeNode(selected)); } onStart(): void { } /** * 注册命令 * @param commands */ registerCommands(commands: CommandRegistry): void { // TODO创建场景和创建组件命令移动到mindmap管理 // commands.registerCommand(NavigatorCommands.ADD_SCENE, { // isEnabled: () => !!this.treeModel.getRootNode(), // execute: async () => { // const dialog = new NavigatorInputDialog({ // title: '新建场景', // parentUri: this.treeModel.getRootNode()!.uri // }) // dialog.open().then(async name => { // if (name) { // const uri = await this.resourceProivder.createSceneNode(name) // if (uri) { // await this.openerService.open(uri) // await this.selectFileNode(uri) // } // } // }) // } // }) // commands.registerCommand(NavigatorCommands.ADD_COMPONENT, { // isEnabled: () => !!this.treeModel.getRootNode(), // execute: async () => { // const dialog = new NavigatorInputDialog({ // title: '新建组件', // parentUri: this.treeModel.getRootNode()!.uri // }) // dialog.open().then(async name => { // if (name) { // const uri = await this.resourceProivder.createComponentNode(name) // if (uri) { // await this.openerService.open(uri) // await this.selectFileNode(uri) // } // } // }) // } // }) // commands.registerCommand(NavigatorCommands.REFRESH_NAVIGATOR, { // execute: widget => this.withWidget(widget, () => true), // isEnabled: widget => this.withWidget(widget, () => true), // isVisible: widget => this.withWidget(widget, () => true), // }); } /** * 注册菜单 * @param menus */ registerMenus(menus: MenuModelRegistry): void { // menus.registerMenuAction(NavigatorContextMenu.NAVIGATION, { // commandId: NavigatorCommands.ADD_SCENE.id, // label: NavigatorCommands.ADD_SCENE.label, // }); // menus.registerMenuAction(NavigatorContextMenu.NAVIGATION, { // commandId: NavigatorCommands.ADD_COMPONENT.id, // label: NavigatorCommands.ADD_COMPONENT.label, // }); // menus.registerMenuAction(NavigatorContextMenu.CLIPBOARD, { // commandId: CommonCommands.COPY.id, // order: 'a' // }) // menus.registerMenuAction(NavigatorContextMenu.CLIPBOARD, { // commandId: CommonCommands.PASTE.id, // order: 'b' // }) // menus.registerMenuAction(NavigatorContextMenu.MODIFICATION, { // commandId: WorkspaceCommands.FILE_RENAME.id // }) // menus.registerMenuAction(NavigatorContextMenu.MODIFICATION, { // commandId: WorkspaceCommands.FILE_DELETE.id // }) // menus.registerMenuAction(NavigatorContextMenu.MODIFICATION, { // commandId: WorkspaceCommands.FILE_DUPLICATE.id // }) } /** * 注册快捷键 * @param keybindings */ registerKeybindings(keybindings: KeybindingRegistry): void { } /** * 注册快捷菜单 */ registerToolbarItems(toolbars: TabBarToolbarRegistry): void { /* toolbars.registerItem({ id: NavigatorCommands.REFRESH_NAVIGATOR.id, command: NavigatorCommands.REFRESH_NAVIGATOR.id, tooltip: nls.localize('view.refresh', 'Refresh Explorer'), priority: 0, }) this.registerMoreToolbarItem({ id: NavigatorCommands.ADD_SCENE.id, command: NavigatorCommands.ADD_SCENE.id, tooltip: NavigatorCommands.ADD_SCENE.label, group: NavigatorMoreToolbarGroups.NEW_OPEN, }) this.registerMoreToolbarItem({ id: NavigatorCommands.ADD_COMPONENT.id, command: NavigatorCommands.ADD_COMPONENT.id, tooltip: NavigatorCommands.ADD_COMPONENT.label, group: NavigatorMoreToolbarGroups.NEW_OPEN, }) */ } /** * Register commands to the `More Actions...` navigator toolbar item. */ // public registerMoreToolbarItem = (item: Mutable) => { // const commandId = item.command; // const id = 'navigator2d.tabbar.toolbar.' + commandId; // const command = this.commandRegistry.getCommand(commandId); // this.commandRegistry.registerCommand({id, iconClass: command && command.iconClass}, { // execute: (w, ...args) => w instanceof NavigatorViewContainer // && this.commandRegistry.executeCommand(commandId, ...args), // isEnabled: (w, ...args) => w instanceof NavigatorViewContainer // && this.commandRegistry.isEnabled(commandId, ...args), // isVisible: (w, ...args) => w instanceof NavigatorViewContainer // && this.commandRegistry.isVisible(commandId, ...args), // isToggled: (w, ...args) => w instanceof NavigatorViewContainer // && this.commandRegistry.isToggled(commandId, ...args), // }); // item.command = id; // this.tabbarToolbarRegistry.registerItem(item); // }; // // protected withWidget(widget: Widget, cb: (navigator: NavigatorViewContainer) => boolean): boolean { // if (widget && widget instanceof NavigatorViewContainer && widget.id === NAVIGATOR_VIEW_CONTAINER_ID) { // return cb(widget); // } // return false; // } }