diff --git a/src/ApplicationServices/Application.ts b/src/ApplicationServices/Application.ts index e0215b97f..20e9441c1 100644 --- a/src/ApplicationServices/Application.ts +++ b/src/ApplicationServices/Application.ts @@ -94,11 +94,11 @@ export class ApplicationService new SnapServices(this); new SnapDrag(this); - xaop.begin(commandMachine, commandMachine.execCommand, () => + xaop.begin(commandMachine, commandMachine.ExecCommand, () => { this.m_Viewer.m_GripScene.visible = false; }) - xaop.begin(commandMachine, commandMachine.commandEnd, () => + xaop.begin(commandMachine, commandMachine.CommandEnd, () => { this.m_Viewer.m_GripScene.visible = true; }) diff --git a/src/DatabaseServices/UndoData.ts b/src/DatabaseServices/UndoData.ts index f8ff52a6f..1509b424b 100644 --- a/src/DatabaseServices/UndoData.ts +++ b/src/DatabaseServices/UndoData.ts @@ -21,7 +21,7 @@ export class UndoData this.m_UndoDataList.push(app.m_Database.dataOut())//初始化空状态 - xaop.end(commandMachine, commandMachine.commandEnd, (name) => + xaop.end(commandMachine, commandMachine.CommandEnd, (name) => { if (name == "u" || name == "redo") { diff --git a/src/Editor/CommandMachine.ts b/src/Editor/CommandMachine.ts index a4397afe9..45a8af985 100644 --- a/src/Editor/CommandMachine.ts +++ b/src/Editor/CommandMachine.ts @@ -9,22 +9,36 @@ export class CommandMachine { m_CommandIng = false; //命令表 - m_CommandList: Map = new Map(); - async execCommand(cmdName: string) + private m_CommandList: Map = new Map(); + async ExecCommand(cmdName: string) { if (this.m_CommandList.has(cmdName)) { let ss = app.m_Editor.m_SelectCtrl.SelectSet; this.m_CommandIng = true; await this.m_CommandList.get(cmdName).exec(ss); - this.commandEnd(cmdName); + this.CommandEnd(cmdName); } } - commandEnd(cmdName: string) + RegisterCommand(cmdName: string, cmd: Command) + { + this.m_CommandList.set(cmdName.toUpperCase(), cmd); + } + CommandEnd(cmdName: string) { this.m_CommandIng = false; } + + get CommandNameList(): Array + { + let cmdList = []; + for (let cmd of this.m_CommandList.keys()) + { + cmdList.push(cmd); + } + return cmdList; + } } diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index 27ddc397e..80dbfc217 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -18,42 +18,42 @@ import { commandMachine } from './CommandMachine'; export function registerCommand() { - commandMachine.m_CommandList.set("l", new DrawLine()) - commandMachine.m_CommandList.set("u", new Undo()) - commandMachine.m_CommandList.set("redo", new Redo()) - commandMachine.m_CommandList.set("ze", new ZoomE()) - commandMachine.m_CommandList.set("rec", new DrawRect()) - commandMachine.m_CommandList.set("c", new DrawCircle()) + commandMachine.RegisterCommand("l", new DrawLine()) + commandMachine.RegisterCommand("u", new Undo()) + commandMachine.RegisterCommand("redo", new Redo()) + commandMachine.RegisterCommand("ze", new ZoomE()) + commandMachine.RegisterCommand("rec", new DrawRect()) + commandMachine.RegisterCommand("c", new DrawCircle()) - commandMachine.m_CommandList.set("t", new DrawTest()) - commandMachine.m_CommandList.set("m", new Command_Move()) - commandMachine.m_CommandList.set("ro", new Command_Rotate()) + commandMachine.RegisterCommand("t", new DrawTest()) + commandMachine.RegisterCommand("m", new Command_Move()) + commandMachine.RegisterCommand("ro", new Command_Rotate()) - commandMachine.m_CommandList.set("sp", new DrawSphere()) + commandMachine.RegisterCommand("sp", new DrawSphere()) - commandMachine.m_CommandList.set("fl", new DrawFloor()) - commandMachine.m_CommandList.set("cc", new Command_SwitchCamera()) - commandMachine.m_CommandList.set("p", new Command_SwitchPass()) + commandMachine.RegisterCommand("fl", new DrawFloor()) + commandMachine.RegisterCommand("cc", new Command_SwitchCamera()) + commandMachine.RegisterCommand("p", new Command_SwitchPass()) - commandMachine.m_CommandList.set("e", new Command_Erase()) + commandMachine.RegisterCommand("e", new Command_Erase()) - commandMachine.m_CommandList.set("br", new Command_DrawBoard()) + commandMachine.RegisterCommand("br", new Command_DrawBoard()) - commandMachine.m_CommandList.set("c0", new DrawCircle0()) + commandMachine.RegisterCommand("c0", new DrawCircle0()) - commandMachine.m_CommandList.set("s", new Stretch()) + commandMachine.RegisterCommand("s", new Stretch()) - commandMachine.m_CommandList.set("fs", new ViewToTop()) + commandMachine.RegisterCommand("fs", new ViewToTop()) - commandMachine.m_CommandList.set("qs", new ViewToFont()) + commandMachine.RegisterCommand("qs", new ViewToFont()) - commandMachine.m_CommandList.set("tt", new Test()) + commandMachine.RegisterCommand("tt", new Test()) - commandMachine.m_CommandList.set("grip", new DrawGripStretch()) + commandMachine.RegisterCommand("grip", new DrawGripStretch()) - commandMachine.m_CommandList.set("fbx", new Fbx()) + commandMachine.RegisterCommand("fbx", new Fbx()) - commandMachine.m_CommandList.set("st", new SaveTarget()) - commandMachine.m_CommandList.set("rt", new RevTarget()) + commandMachine.RegisterCommand("st", new SaveTarget()) + commandMachine.RegisterCommand("rt", new RevTarget()) } diff --git a/src/UI/Components/commandLineInput/InputHint.tsx b/src/UI/Components/commandLineInput/InputHint.tsx index 1fae84c78..458789d35 100644 --- a/src/UI/Components/commandLineInput/InputHint.tsx +++ b/src/UI/Components/commandLineInput/InputHint.tsx @@ -15,7 +15,6 @@ interface ITodoItemState historyCommands: Array,// 历史命令 isShow: React.CSSProperties,// 是否显示历史命令框 isShowSet: React.CSSProperties,//是否显示设置块 - commands: Array, //命令库 searchCommand: Array, //联想命令库 executeCommand: string, //所执行的命令 viceCommand: Array<{ title: string, keyboard: string }>,//副命令 @@ -40,7 +39,6 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS historyCommands: [], isShow: { display: 'none' }, hiUlPos: { bottom: '2rem' }, - commands: ['LINE', 'LINETYPE', 'TR', 'TRANSLATE', 'TEXT1', 'TEXT2', 'TEXT3', 'TEXT4'], searchCommand: [], executeCommand: '', viceCommand: [], @@ -53,7 +51,7 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS public handleOnChange = (e: React.FormEvent) => { // 输入的命令 - let m_inputValue = e.currentTarget.value.toUpperCase(); + let m_inputValue = e.currentTarget.value; this.setState({ command: m_inputValue }); //储存找到的相关命令 @@ -67,14 +65,14 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS // 动态生成正则表达式 let m_searchReg: RegExp = new RegExp(''); // 拼接动态正则表达式 - let m_comTmp: string = '^' + m_inputValue.split('').join('\\w*') + '\\w*$'; + let m_comTmp: string = '^' + m_inputValue.toUpperCase().split('').join('\\w*') + '\\w*$'; m_searchReg = new RegExp(m_comTmp, 'i'); //如果没有确认执行命令,将显示推荐索引的命令 if (!this.state.executeCommand) { - this.state.commands.forEach((value: string) => + this.props.commandStore.CommandList.forEach((value: string) => { if (m_searchReg.test(value)) @@ -122,7 +120,6 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS { executeCommand: e.currentTarget.innerHTML, searchCommand: [], - command: '', historyCommands } ); @@ -130,7 +127,8 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS //绑定键盘命令 public handleSelectCommand = (e: KeyboardEvent) => { - // (this.props.commandStore.elInput as HTMLInputElement).focus(); + // if (document.activeElement.nodeName !== 'INPUT') + // (this.props.commandStore.elInput as HTMLInputElement).focus(); let m_li: HTMLCollection = this.m_recommendUl.children;; let historyCommands = this.state.historyCommands; @@ -193,7 +191,6 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS this.setState({ command: this.m_liHover.innerHTML }); } - //如果有关联命令执行以下逻辑 if (this.state.searchCommand.length > 0) { @@ -217,8 +214,7 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS this.setState( { executeCommand: this.m_liHover.innerHTML, - searchCommand: [], - command: '' + searchCommand: [] } ) return; @@ -254,13 +250,12 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS if (!this.state.executeCommand) { - if (this.state.command && this.state.commands.indexOf(this.state.command.trim()) !== -1) + if (this.state.command && this.props.commandStore.CommandList.indexOf(this.state.command.trim()) !== -1) { this.setState( { executeCommand: this.state.command, - searchCommand: [], - command: '' + searchCommand: [] } ); } @@ -275,13 +270,12 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS if (this.state.command === 'U') { - this.setState({ viceCommand: [], command: '' }); + this.setState({ viceCommand: [] }); return; } this.setState( { - viceCommand: [{ title: '放弃', keyboard: 'U' }], - command: '' + viceCommand: [{ title: '放弃', keyboard: 'U' }] } ); @@ -459,10 +453,9 @@ export default class InputHint extends React.Component<{ commandStore?: CommandS type="text" placeholder="请输入命令" ref={o => { this.props.commandStore.elInput = o; }} - // onKeyPress={this.handleConfirmInput} - onKeyDown={e => { e.preventDefault() }} + // onKeyDown={e => { e.preventDefault() }} onChange={this.handleOnChange} - // value={this.state.command} + value={this.state.command} />
    { - if (IsNumble(e.keyCode) || IsChar(e.keyCode)) - { - this.elInput.value += e.key; - } - else - { - this.keyDownHandle(e.keyCode); - } + this.elInput.focus(); + this.keyDownHandle(e.keyCode); }); } @observable commands: Array = []; @@ -54,9 +48,14 @@ export class CommandStore return document.activeElement.id == "command-input"; } + get CommandList() + { + return commandMachine.CommandNameList; + } + keyDownHandle = (keyCode: number) => { - let inpValue: string = this.elInput.value; + let inpValue: string = this.elInput.value.toUpperCase(); switch (keyCode) { case KeyBoard.BracketLeft: @@ -71,7 +70,7 @@ export class CommandStore case 32: if (inpValue != "") { - commandMachine.execCommand(inpValue); + commandMachine.ExecCommand(inpValue); this.Prompt(inpValue) this.elInput.value = "" }