整合代码

pull/7/head
zoe 7 years ago
parent 43e2ad5e2a
commit 767eabea82

@ -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;
})

@ -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")
{

@ -9,22 +9,36 @@ export class CommandMachine
{
m_CommandIng = false;
//命令表
m_CommandList: Map<string, Command> = new Map<string, Command>();
async execCommand(cmdName: string)
private m_CommandList: Map<string, Command> = new Map<string, Command>();
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<string>
{
let cmdList = [];
for (let cmd of this.m_CommandList.keys())
{
cmdList.push(cmd);
}
return cmdList;
}
}

@ -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())
}

@ -15,7 +15,6 @@ interface ITodoItemState
historyCommands: Array<string>,// 历史命令
isShow: React.CSSProperties,// 是否显示历史命令框
isShowSet: React.CSSProperties,//是否显示设置块
commands: Array<string>, //命令库
searchCommand: Array<string>, //联想命令库
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<HTMLInputElement>) =>
{
// 输入的命令
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}
/>
<ul
className="history-command"

@ -1,11 +1,11 @@
import { observable, runInAction, autorun } from 'mobx';
import { app } from '../../ApplicationServices/Application';
import { observable } from 'mobx';
import * as xaop from 'xaop';
import { app } from '../../ApplicationServices/Application';
import { KeyBoard } from '../../Common/KeyEnum';
import { commandMachine } from '../../Editor/CommandMachine';
import { Editor } from '../../Editor/Editor';
import { IsNumble, IsChar } from '../../Common/Utils';
import { KeyBoardControls } from '../../Editor/KeyBoardControls';
import { commandMachine } from '../../Editor/CommandMachine';
import { KeyBoard } from '../../Common/KeyEnum';
export interface CommandMsg
{
@ -18,14 +18,8 @@ export class CommandStore
{
xaop.begin(ed.m_KeyCtrl, KeyBoardControls.prototype.OnKeyDown, (e: KeyboardEvent) =>
{
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<CommandMsg> = [];
@ -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 = ""
}

Loading…
Cancel
Save