diff --git a/src/Add-on/Command_CommandPanel.ts b/src/Add-on/Command_CommandPanel.ts index ea49582ae..5a34e23c9 100644 --- a/src/Add-on/Command_CommandPanel.ts +++ b/src/Add-on/Command_CommandPanel.ts @@ -9,5 +9,6 @@ export class Command_CommandPanel implements Command { let store = app.Editor.CommandStore; app.Editor.ModalManage.RenderModal(CommandPanel, { store }, { position: ModalPosition.Top }); + window.event.preventDefault(); } } diff --git a/src/ApplicationServices/Application.ts b/src/ApplicationServices/Application.ts index eec6c0348..fa31fb950 100644 --- a/src/ApplicationServices/Application.ts +++ b/src/ApplicationServices/Application.ts @@ -30,10 +30,8 @@ import { Viewer } from '../GraphicsSystem/Viewer'; import { CommandReactor } from '../Reactor/CommandReactor'; import { RelevanceCuttingReactor } from '../Reactor/RelevanceCuttingReactor'; import { SyncDataReactor } from '../Reactor/SyncDataReactor'; -import { RightTabId } from '../UI/Components/RightPanel/RightPanel'; import { AppToaster } from '../UI/Components/Toaster'; import { DownPanelStore } from '../UI/Store/DownPanelStore'; -import { RightPanelStore } from '../UI/Store/RightPanelStore/RightPanelStore'; import { HostApplicationServices } from './HostApplicationServices'; import { WebSocketClientServer } from './WebSocketClientServer'; @@ -51,7 +49,6 @@ export class ApplicationService _drillingReactor: DrillingReactor; // _autoCuttingReactor: AutoCuttingReactor; _hardwareCuttingReactor: HardwareCuttingReactor; - Saved = true; MoveTool: BoardMoveTool; WebSocket: WebSocketClientServer = new WebSocketClientServer("ws://localhost:9002/loadmesh"); @@ -64,7 +61,6 @@ export class ApplicationService HostApplicationServices.Application = this; //数据 this.Database = new Database(true, true); - let container = document.getElementById("Webgl"); //渲染器 this.Viewer = new Viewer(container); @@ -189,11 +185,6 @@ export class ApplicationService window["app"] = this; - hotkeys('f1', e => - { - commandMachine.ExecCommand("COMANP"); - e.preventDefault(); - }); hotkeys('f3', e => { let store = DownPanelStore.GetInstance(); @@ -205,45 +196,6 @@ export class ApplicationService let s = DownPanelStore.GetInstance(); s.useOrtho = !s.useOrtho; }); - hotkeys('delete', e => { commandMachine.ExecCommand(CommandNames.Erase); }); - - hotkeys('ctrl+1', e => { DownPanelStore.GetInstance().TogglePropertiesPanel(); }); - hotkeys('ctrl+2', e => { RightPanelStore.GetInstance().m_IsShow = !RightPanelStore.GetInstance().m_IsShow; }); - - hotkeys('alt+d', e => { commandMachine.ExecCommand(CommandNames.EditDrilEdgeData); }); - hotkeys('alt+s', e => { commandMachine.ExecCommand(CommandNames.EditSealEdgeData); }); - hotkeys('alt+f', e => { commandMachine.ExecCommand(CommandNames.ZoomObject); }); - - hotkeys('ctrl+z', e => - { - app.Database.hm.Undo(); - app.Viewer.GripScene.UpdateAll(); - }); - hotkeys('ctrl+y', e => - { - app.Database.hm.Redo(); - app.Viewer.GripScene.UpdateAll(); - }); - hotkeys('ctrl+b', e => - { - let store = DownPanelStore.GetInstance(); - store.isLayout = !store.isLayout; - }); - hotkeys('ctrl+m', e => - { - let rightStore = RightPanelStore.GetInstance(); - if (rightStore.m_TabId === RightTabId.TemplateParam && rightStore.m_IsShow) - rightStore.m_IsShow = false; - else - { - rightStore.m_TabId = RightTabId.TemplateParam; - rightStore.m_IsShow = true; - } - }); - hotkeys('ctrl+c', e => { commandMachine.ExecCommand(CommandNames.CopyClip); }); - hotkeys('ctrl+shift+c', e => { commandMachine.ExecCommand(CommandNames.CopyBase); }); - hotkeys('ctrl+v', e => { commandMachine.ExecCommand(CommandNames.PasteClip); }); - hotkeys('ctrl+s', e => { commandMachine.ExecCommand(CommandNames.Save); }); hotkeys('ctrl+p', e => { if (this.Viewer.isLayout) @@ -253,7 +205,6 @@ export class ApplicationService e.preventDefault(); e.stopPropagation(); }); - hotkeys('ctrl+a', e => { commandMachine.ExecCommand(CommandNames.SelectAll); }); hotkeys('ctrl+alt+e', e => { diff --git a/src/Common/CommandNames.ts b/src/Common/CommandNames.ts index 6120cec8b..248ab019e 100644 --- a/src/Common/CommandNames.ts +++ b/src/Common/CommandNames.ts @@ -119,6 +119,11 @@ export enum CommandNames Lattice = "LATTICE", Array = "ARRAY", ComanPanel = "COMMANDPANEL", + Comanp = "COMANP", + PropertiesBar = "PROPERTIESBAR", + ModuleBar = "MODULEBAR", + ChangeLayout = "CHANGELAYOUT", + RightPanel = "RIGHTPANEL", Config = "CONFIG", Esc = "ESC", Wireframe = "WIREFRAME", diff --git a/src/Common/HotKeyList.ts b/src/Common/HotKeyList.ts new file mode 100644 index 000000000..cf564f2cd --- /dev/null +++ b/src/Common/HotKeyList.ts @@ -0,0 +1,22 @@ +export enum HotkeyList +{ + C1 = "Control+1", + C2 = "Control+2", + CA = "Control+A", + CB = "Control+B", + CC = "Control+C", + CY = "Control+Y", + CV = "Control+V", + CM = "Control+M", + CS = "Control+S", + CZ = "Control+Z", + CP = "Control+P", + CAE = "Control+Alt+E", + CAP = "Control+Alt+P", + CSC = "Control+Shift+C", + AD = "Alt+D", + AS = "Alt+S", + AF = "Alt+F", + D = "Delete", + F1 = "F1" +} diff --git a/src/DatabaseServices/CommandServer.ts b/src/DatabaseServices/CommandServer.ts index 947a1ad23..a151d1200 100644 --- a/src/DatabaseServices/CommandServer.ts +++ b/src/DatabaseServices/CommandServer.ts @@ -18,10 +18,10 @@ export class CommandServer extends Singleton private _customCommand: { [key: string]: ICommand; } = {}; private _needUpload = false; CommandListMap = new Map(); + HotKeyListMap = new Map(); AddCustonCommand(icommand: ICommand) { this.CommandListMap.set(icommand.customize || icommand.defaultCustom, icommand.command); - if (icommand.command !== icommand.customize && icommand.customize !== icommand.defaultCustom) { this._needUpload = true; @@ -44,7 +44,6 @@ export class CommandServer extends Singleton async Upload() { if (!this._needUpload) return; - let dbStore = await IndexedDbStore.CADStore(); let data = await PostJson(ConfigUrls.Edit, { key: CommandServer.name, value: JSON.stringify(this._customCommand) }); if (data.err_code === RequestStatus.Ok) @@ -68,10 +67,10 @@ export class CommandServer extends Singleton { cmd.customize = cusCmd.customize; cmd.customizeed = cusCmd.customize; + cmd.hotkeysCustomize = cusCmd.hotkeysCustomize; } } } - return CommandList; } async SaveOldDataToServer() diff --git a/src/Editor/CommandMachine.ts b/src/Editor/CommandMachine.ts index c4bedbc46..52a7459a8 100644 --- a/src/Editor/CommandMachine.ts +++ b/src/Editor/CommandMachine.ts @@ -1,4 +1,5 @@ import { Intent } from '@blueprintjs/core'; +import hotkeys from 'hotkeys-js'; import { app } from '../ApplicationServices/Application'; import { arrayLast, arrayRemoveOnce } from '../Common/ArrayExt'; import { ReportError } from '../Common/ErrorMonitoring'; @@ -23,6 +24,7 @@ export interface Command //命令状态机. class CommandMachine { + HotKeyList: Map = new Map(); //命令表 CommandMap: Map = new Map(); LastCmd: string; @@ -30,6 +32,7 @@ class CommandMachine async ExecCommand(cmdName: string) { const server = CommandServer.GetInstance() as CommandServer; + this.HotKeyList = server.HotKeyListMap; if (server.CommandListMap.has(cmdName)) cmdName = server.CommandListMap.get(cmdName); @@ -97,6 +100,51 @@ class CommandMachine this.CommandMap.set(newName, oldCmd); } } + RegisterCustomHotKey(oldKey: string, newkey: string) + { + if (oldKey !== newkey) + { + let oldHotKeyValue = this.HotKeyList.get(oldKey); + hotkeys(newkey, "custom", (e) => + { + e.preventDefault(); + commandMachine.ExecCommand(oldHotKeyValue); + }); + this.HotKeyList.set(newkey, oldHotKeyValue); + this.RemoveCommandHotKey(oldKey); + } + } + RemoveCommandHotKey(oldKey: string) + { + if (!oldKey) return; + hotkeys.unbind(oldKey); + this.HotKeyList.delete(oldKey); + } + RegisterCustomDefaultHotKey(Key: string, command: string) + { + hotkeys(Key, "custom", (e) => + { + e.preventDefault(); + commandMachine.ExecCommand(command); + }); + this.HotKeyList.set(Key, command); + } + RegisterHotKey(oldKey: string, newkey: string) + { + let oldHotKeyValue = this.HotKeyList.get(oldKey); + this.HotKeyList.set(newkey, oldHotKeyValue); + this.RemoveCommandDefaultHotKey(oldKey); + hotkeys(newkey, "custom", (e) => + { + e.preventDefault(); + commandMachine.ExecCommand(oldHotKeyValue); + }); + } + RemoveCommandDefaultHotKey(oldKey: string) + { + if (!oldKey) return; + hotkeys.unbind(oldKey); + } /** * 意味着命令开始,系统将会帮你初始化一些事情. * @param cmdName diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index 457324eb7..32744cef6 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -232,7 +232,8 @@ import { BuyMaterial } from './../Add-on/BuyMaterial'; import { Interfere } from './../Add-on/interfere'; import { ShowKinfeManageModal } from './../Add-on/showModal/ShowKnifeManageModal'; import { commandMachine } from './CommandMachine'; - +import hotkeys from "hotkeys-js"; +import { Command_ChangeLayout, Command_ModuleBar, Command_PropertiesBar, Command_RightPanel } from "../UI/Components/CommandPanel/SystemCommand/UICpmmand"; export function registerCommand() { commandMachine.RegisterCommand(CommandNames.Puge, new Command_Purge()); @@ -479,8 +480,12 @@ export function registerCommand() commandMachine.RegisterCommand(CommandNames.CopyBase, new CopyClip(true)); commandMachine.RegisterCommand(CommandNames.PasteClip, new PasteClip()); - //命令面板 + //UI命令 commandMachine.RegisterCommand("comanp", new Command_CommandPanel()); + commandMachine.RegisterCommand(CommandNames.PropertiesBar, new Command_PropertiesBar()); + commandMachine.RegisterCommand(CommandNames.ModuleBar, new Command_ModuleBar()); + commandMachine.RegisterCommand(CommandNames.ChangeLayout, new Command_ChangeLayout()); + commandMachine.RegisterCommand(CommandNames.RightPanel, new Command_RightPanel()); //选项 commandMachine.RegisterCommand(CommandNames.Config, new Command_Options()); @@ -675,7 +680,26 @@ export async function RegistCustomCommand() commandMachine.RegisterCustomCommand(i.command, customize); cserver.CommandListMap.set(customize, i.command); } + + let hotkey = i.hotkeysCustomize || i.defaultHotkeys || i.systemHotkeys; + if (i.hotkeysCustomize === " ") + { + hotkey = undefined; + } + if (hotkey && i.command) + { + hotkeys(hotkey, "custom", () => + { + commandMachine.ExecCommand(i.command); + }); + cserver.HotKeyListMap.set(hotkey, i.command); + } + else + { + cserver.HotKeyListMap.set("cmd" + i.command, i.command); + } } + hotkeys.setScope("custom"); } export function RemoveCustonCommand() @@ -689,4 +713,5 @@ export function RemoveCustonCommand() i.customize = i.defaultCustom; } } + hotkeys.deleteScope('custom'); } diff --git a/src/UI/Components/CommandPanel/CommandItem.tsx b/src/UI/Components/CommandPanel/CommandItem.tsx index 5ec0d8e98..6d1f1255b 100644 --- a/src/UI/Components/CommandPanel/CommandItem.tsx +++ b/src/UI/Components/CommandPanel/CommandItem.tsx @@ -9,6 +9,7 @@ import { CommandServer } from "../../../DatabaseServices/CommandServer"; import { commandMachine } from "../../../Editor/CommandMachine"; import { ICommand, CommandList } from "./CommandList"; import { ICON_CDN } from "../../IconEnum"; +import { InputHotKeys } from "./InputHotKeys"; enum TipType { @@ -17,7 +18,8 @@ enum TipType StrIllegal = 2, //非法字符 IsExist = 4, //重复 } -interface CommandItemProps + +export interface CommandItemProps { commandData: ICommand; } @@ -26,6 +28,7 @@ interface CommandItemProps * 命令面板列表项 * TODO:相应项根据命令数据改为变量名接收传入值 */ + @observer export class CommandItem extends React.Component{ @observable private flag: TipType = TipType.OK; @@ -64,6 +67,8 @@ export class CommandItem extends React.Component{ if (this.isReset || document.activeElement === this.m_InputEl) return; const command = this.props.commandData; + if (!command.typeId) + return; app.Editor.ModalManage.Destory(); commandMachine.ExecCommand(command.command); }; @@ -168,87 +173,103 @@ export class CommandItem extends React.Component{
  • {store.commandData.type}
  • - - { this.m_InputEl = el; }} - placeholder={store.commandData.defaultCustom} - defaultValue={store.commandData.customize || store.commandData.defaultCustom} - - onCompositionStart={() => this.isCNInput = true} - onCompositionEnd={(e) => - { - this.isCNInput = false; - this.handleOnChange(); - }} - onFocus={e => - { - e.target.setSelectionRange(0, e.target.value.length); - }} - onClick={(e) => e.stopPropagation()} - onChange={this.handleOnChange} - onBlur={this.handleOnBlur} - /> - -
  • -
  • - - { - this.isReset = false; - this.m_InputEl.focus(); - }} - content={ -
    - { - if (e.keyCode === KeyBoard.Escape) +
    +
    + + { this.m_InputEl = el; }} + placeholder={store.commandData.defaultCustom} + defaultValue={store.commandData.customize || store.commandData.defaultCustom} + style={{ backgroundColor: this.props.commandData.typeId ? "#FFFFFF" : "#DDDDDD" }} + disabled={this.props.commandData.typeId ? false : true} + onCompositionStart={() => this.isCNInput = true} + onCompositionEnd={(e) => { - (e.currentTarget.lastElementChild.firstElementChild as HTMLButtonElement).click(); - this.m_commandItemEl.parentElement.focus(); - } - - else if (e.keyCode === KeyBoard.Enter || e.keyCode === KeyBoard.Space) - (e.currentTarget.lastElementChild.lastElementChild as HTMLButtonElement).click(); - e.stopPropagation(); + this.isCNInput = false; + this.handleOnChange(); + }} + onFocus={e => + { + e.target.setSelectionRange(0, e.target.value.length); + }} + onClick={(e) => e.stopPropagation()} + onChange={this.handleOnChange} + onBlur={this.handleOnBlur} + /> + +
    +
    + + { + this.isReset = false; + this.m_InputEl.focus(); }} - > -

    确定重置自定义吗?

    -
    -
    +
    + } + target={
    -
    - } - target={ -
  • +
  • +