!1674 优化:默认命令和快捷键组合与用户自定义的命令和快捷键组合重复将不使用

pull/1676/MERGE
林三 3 years ago committed by ChenX
parent b26a64b3e6
commit da10ab135b

@ -8,10 +8,10 @@ export class Command_ResetCustomCommand implements Command
{
async exec()
{
let cmd = CommandServer.GetInstance() as CommandServer;
let status = await AppConfirm.show({ message: "重置所有的快捷键?" });
if (status)
{
let cmd = CommandServer.GetInstance();
await cmd.Reset();
AppToaster.show({
message: "成功重置快捷键,请重启WebCAD!",

@ -1,99 +1,189 @@
import { Intent } from "@blueprintjs/core";
import { toJS } from "mobx";
import hotkeys from "hotkeys-js-ext";
import { ConfigUrls } from "../Common/HostUrl";
import { PostJson, RequestStatus } from "../Common/Request";
import { Singleton } from "../Common/Singleton";
import { GetIndexDBID } from "../Common/Utils";
import { Command } from "../Editor/CommandMachine";
import { commandMachine } from "../Editor/CommandMachine";
import { IndexedDbStore, StoreName } from "../IndexedDb/IndexedDbStore";
import { CommandList, ICommand } from "../UI/Components/CommandPanel/CommandList";
import { AppToaster } from "../UI/Components/Toaster";
import { userConfigStore } from "../UI/Store/UserConfigStore";
/**
* CAD,CRUD
*/
export class CommandServer extends Singleton
export class CommandServer
{
private _customCommand: { [key: string]: ICommand; } = {};
private _needUpload = false;
CommandListMap = new Map<string, string>();
HotKeyListMap = new Map<string, string>();
AddCustonCommand(icommand: ICommand)
//记录需要上传的数据
private _NeedUpload = false;
private _CustomCommand: { [key: string]: ICommand; } = {};
//记录自定义命令映射
private _CustomCommandMap = new Map<string, string>();//<用户自定义命令|默认自定义命令,原始命令>
private _CommandCustomMap = new Map<string, string>();//<原始命令,用户自定义命令|默认自定义命令>
//记录组合键映射
private _CommandHotKeyMap = new Map<string, string>(); //<原始命令,组合键>
private _HotKeyCommandMap = new Map<string, string>(); //<组合键,原始命令>
private constructor() { }
private static _SingleInstance: CommandServer;
static GetInstance(): CommandServer
{
this.CommandListMap.set(icommand.customize || icommand.defaultCustom, icommand.command);
if (icommand.command !== icommand.customize && icommand.customize !== icommand.defaultCustom)
if (this._SingleInstance) return this._SingleInstance;
this._SingleInstance = new CommandServer;
return this._SingleInstance;
}
get CustomCommandMap() { return this._CustomCommandMap; }
get HotKeyCommandMap() { return this._HotKeyCommandMap; }
//UI只需要调用这个方法
ChangeCustonCommand(icommand: ICommand)
{
this._NeedUpload = true;
delete this._CustomCommand[icommand.command];
//删除原先注册的命令
this.DeleteCustomCommand(icommand.command);
//注册新的命令
let newCmd = icommand.customize || icommand.defaultCustom;
if (!this._CustomCommandMap.has(newCmd)) //避免覆盖已经设置的命令
this.RegistCustomCommand(newCmd, icommand.command);
//删除原先注册的组合键
this.DeleteHotkey(icommand.command);
//注册新的组合键
let newHotkey = icommand.hotkeysCustomize ?? icommand.defaultHotkeys;
if (!this._HotKeyCommandMap.has(newHotkey))
this.RegistHotkey(newHotkey, icommand.command);
//设置要上传的命令信息
if (
(icommand.customize !== undefined && icommand.customize !== icommand.command && icommand.customize !== icommand.defaultCustom)//"" 或者其他自定义
|| (icommand.hotkeysCustomize !== undefined && icommand.hotkeysCustomize !== icommand.defaultHotkeys))//必须自定义快捷键 并且不是原先的默认快捷键
{
this._needUpload = true;
this._customCommand[icommand.command] = toJS(icommand);
this._NeedUpload = true;
this._CustomCommand[icommand.command] = {
customize: icommand.customize,
hotkeysCustomize: icommand.hotkeysCustomize
} as ICommand;
}
}
GetCommandCanUseDefaultCustomCmd(cmd: ICommand)
{
if (!cmd.defaultCustom) return false;
let command = this._CustomCommandMap.get(cmd.defaultCustom);
return !command || command === cmd.command;//如果不相等 证明被别的命令注册了
}
DeleteCustonCommand(icommand: ICommand)
GetCommandCanUseDefaultHotkey(cmd: ICommand)
{
this._needUpload = true;
delete this._customCommand[icommand.command];
if (!cmd.defaultHotkeys) return false;
let command = this._HotKeyCommandMap.get(cmd.defaultHotkeys);
return !command || command === cmd.command;//如果不相等 证明被别的命令注册了
}
//清空所有的自定义命令和组合键
async Reset()
{
this._needUpload = true;
this._customCommand = {};
this._NeedUpload = true;
this._CustomCommand = {};
this.ClearCustonCommand();
await this.Upload();
await this.InitCommandCustomCmdAndHotkey();
}
async Upload()
{
if (!this._needUpload) return;
if (!this._NeedUpload) return;
let dbStore = await IndexedDbStore.CADStore();
let data = await PostJson(ConfigUrls.Edit, { key: CommandServer.name, value: JSON.stringify(this._customCommand) });
let data = await PostJson(ConfigUrls.Edit, { key: CommandServer.name, value: JSON.stringify(this._CustomCommand) });
if (data.err_code === RequestStatus.Ok)
{
dbStore.Put(StoreName.ConfigData, GetIndexDBID(CommandServer.name), this._customCommand);
dbStore.Put(StoreName.ConfigData, GetIndexDBID(CommandServer.name), this._CustomCommand);
dbStore.Put(StoreName.ConfigVersion, GetIndexDBID(CommandServer.name), data.version);
this._needUpload = false;
this._NeedUpload = false;
}
}
//从服务器下载自定义和组合键并且注册它.
async InitCommandCustomCmdAndHotkey()
{
let commandList = await this.ReadCustomCommandlist();
this._CustomCommandMap.clear();
this._CommandHotKeyMap.clear();
//注册自定义(命令和组合键)
for (let cmd of commandList)
{
if (cmd.customize)
this.RegistCustomCommand(cmd.customize, cmd.command);
//组合键
if (cmd.systemHotkeys)//系统 一定注册
this.RegistHotkey(cmd.systemHotkeys, cmd.command);
else if (cmd.hotkeysCustomize)
this.RegistHotkey(cmd.hotkeysCustomize, cmd.command);
}
//注册默认(命令和组合键)(如果可以的话)
for (let cmd of commandList)
{
//默认自定义命令
if (!cmd.customize && this.GetCommandCanUseDefaultCustomCmd(cmd))
this.RegistCustomCommand(cmd.defaultCustom, cmd.command);//注册默认自定义命令
//默认组合键
if (!cmd.hotkeysCustomize && this.GetCommandCanUseDefaultHotkey(cmd))
this.RegistHotkey(cmd.defaultHotkeys, cmd.command);
}
async ReadCommandlist(): Promise<ICommand[]>
hotkeys.setScope("custom");
}
//清除所有的自定义命令和组合键
ClearCustonCommand()
{
for (let cmd of CommandList)
{
//为了删除感知里的命令列表,所以调用这个删除,否则直接清空列表就可以了
this.DeleteCustomCommand(cmd.command);
cmd.customize = cmd.defaultCustom;
}
//组合键清空
this._CommandHotKeyMap.clear();
this._HotKeyCommandMap.clear();
hotkeys.deleteScope('custom');
}
//从服务器下载自定义命令列表(自定义命令+组合键)
private async ReadCustomCommandlist(): Promise<ICommand[]>
{
let config = await userConfigStore.GetAllConfigs(CommandServer.name);
if (config)
{
this._customCommand = config as any;
this._needUpload = false;
this._CustomCommand = config as any;
this._NeedUpload = false;
for (let cmd of CommandList)
{
let cusCmd = config[cmd.command];
if (cusCmd)
{
cmd.customize = cusCmd.customize;
cmd.customizeed = cusCmd.customize;
cmd.hotkeysCustomize = cusCmd.hotkeysCustomize;
}
}
}
return CommandList;
}
async SaveOldDataToServer()
{
let store = await IndexedDbStore.CADStore();
let customMap = await store.GetDataMap(StoreName.Command) as Map<string, ICommand>;
for (let [k, cmd] of customMap)
{
this._customCommand[k] = cmd;
}
this._needUpload = true;
await this.Upload();
if (!this._needUpload)
{
AppToaster.show({
message: "数据迁移成功,并清理旧数据",
intent: Intent.SUCCESS,
timeout: 2000,
}, "upgrade");
store.Clear(StoreName.Command);
}
}
//保存滚动条高度
private _LastScrollTop: number;
@ -111,14 +201,56 @@ export class CommandServer extends Singleton
this._LastScrollTop = await store.Get(StoreName.FileId, "scrollTop");
return this._LastScrollTop;
}
}
export class UpgradeData implements Command
{
async exec()
//--------------------------------------------------------------------------------------
//内部使用 注册自定义命令和快捷键
//增加自定义命令的注册
private RegistCustomCommand(customCmd: string, cmd: string)
{
const server = CommandServer.GetInstance() as CommandServer;
await server.SaveOldDataToServer();
if (!customCmd) return;
this._CustomCommandMap.set(customCmd, cmd);//注册自定义命令
this._CommandCustomMap.set(cmd, customCmd);
commandMachine.CommandNameSet.add(customCmd);
}
//删除自定义命令注册
private DeleteCustomCommand(cmd: string)
{
let custom = this._CommandCustomMap.get(cmd);
if (custom)
{
this._CommandCustomMap.delete(cmd);
this._CustomCommandMap.delete(custom);
commandMachine.CommandNameSet.delete(custom);
}
}
private RegistHotkey(hotkey: string, command: string)
{
if (!hotkey) return;
hotkeys(hotkey, "custom", (e) =>
{
e.preventDefault();
commandMachine.ExecCommand(command);
});
this._HotKeyCommandMap.set(hotkey, command);
this._CommandHotKeyMap.set(command, hotkey);
}
private DeleteHotkey(command: string)
{
let hotkey = this._CommandHotKeyMap.get(command);
if (hotkey)
{
this._CommandHotKeyMap.delete(command);
this._HotKeyCommandMap.delete(hotkey);
hotkeys.unbind(hotkey);
}
}
}

@ -1,5 +1,4 @@
import { Intent } from '@blueprintjs/core';
import hotkeys from 'hotkeys-js-ext';
import { app } from '../ApplicationServices/Application';
import { arrayLast, arrayRemoveOnce } from '../Common/ArrayExt';
import { ReportError } from '../Common/ErrorMonitoring';
@ -24,17 +23,16 @@ export interface Command
//命令状态机.
class CommandMachine
{
HotKeyList: Map<string, string> = new Map<string, string>();
//命令表
//原始命令集合
CommandMap: Map<string, Command> = new Map<string, Command>();
LastCmd: string;
private _CommandNameList = new Set<string>();
LastExecCmd: string;//最后执行的命令
private _CommandNameSet = new Set<string>();//所有可以调用的命令列表(包括原始命令和自定义命令,提供给InputHint做感知)
async ExecCommand(cmdName: string)
{
const server = CommandServer.GetInstance() as CommandServer;
this.HotKeyList = server.HotKeyListMap;
if (server.CommandListMap.has(cmdName))
cmdName = server.CommandListMap.get(cmdName);
const server = CommandServer.GetInstance();
if (server.CustomCommandMap.has(cmdName))
cmdName = server.CustomCommandMap.get(cmdName);//指向原始命令
if (this.CommandMap.has(cmdName))
{
@ -78,73 +76,23 @@ class CommandMachine
app.Editor.Prompt('未知命令!');
}
//注册原始命令
RegisterCommand(cmdName: string, cmd: Command)
{
cmdName = cmdName.toUpperCase();
this.CommandMap.set(cmdName, cmd);
this._CommandNameList.add(cmdName);
this._CommandNameSet.add(cmdName);
}
//删除原始命令
RemoveCommand(cmdName: string)
{
if (!cmdName) return;
cmdName = cmdName.toUpperCase();
this.CommandMap.delete(cmdName);
this._CommandNameList.delete(cmdName);
}
RegisterCustomCommand(oldName: string, newName: string)
{
let oldCmd = this.CommandMap.get(oldName);
if (oldCmd)
{
this.CommandNameList.add(newName);
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);
this._CommandNameSet.delete(cmdName);
}
/**
* ,.
* @param cmdName
@ -154,10 +102,10 @@ class CommandMachine
{
if (CommandState.CommandIng)
{
app.Editor.Prompt(`命令:"${this.LastCmd}"正忙! 如果是程序错误,请按下Ctrl+Alt+E结束命令!`);
app.Editor.Prompt(`命令:"${this.LastExecCmd}"正忙! 如果是程序错误,请按下Ctrl+Alt+E结束命令!`);
return false;
}
this.LastCmd = cmdName;
this.LastExecCmd = cmdName;
app.Editor.Prompt(cmdName);
CommandState.CommandIng = true;
if (!noHistory)
@ -167,7 +115,7 @@ class CommandMachine
/**
* ,,
* @param [abort] .
* @param [abort]
*/
async CommandEnd(abort: boolean = false, noHistory = false)
{
@ -213,9 +161,9 @@ class CommandMachine
app.Editor.UpdateScreen();
}
get CommandNameList(): Set<string>
get CommandNameSet(): Set<string>
{
return this._CommandNameList;
return this._CommandNameSet;
}
}

@ -1,4 +1,3 @@
import hotkeys from "hotkeys-js-ext";
import { Vector3 } from "three";
import { Command_999 } from "../Add-on/999";
import { ActicityLayerBoard } from "../Add-on/ActivityLayerBoard";
@ -227,7 +226,6 @@ import { Command_Wblock } from "../Add-on/Wblock";
import { Command_ZoomObject, ZoomE } from "../Add-on/ZoomE";
import { CommandNames } from "../Common/CommandNames";
import { IsTest } from "../Common/Deving";
import { CommandServer, UpgradeData } from '../DatabaseServices/CommandServer';
import { RenderType } from "../GraphicsSystem/RenderType";
import { Command_TestContainer } from "../Nest/Test/TestContainer";
import { Command_TestDrawYHData } from "../Nest/Test/TestDrawYHData";
@ -241,7 +239,6 @@ import { Command_TestSum } from "../Nest/Test/TestSum";
import { Command_TestYH2 } from "../Nest/Test/TestYH2";
import { Command_TestYHSingle } from "../Nest/Test/TestYHSingle";
import { Command_TestYHWorker } from "../Nest/Test/TestYHWorker";
import { CommandList, ICommand } from '../UI/Components/CommandPanel/CommandList';
import { Command_ChangeLayout, Command_ModuleBar, Command_PropertiesBar, Command_RightPanel, Command_RightPanelmMaterial, Command_RightPanelScene } from "../UI/Components/CommandPanel/SystemCommand/UICpmmand";
import { EOptionTabId } from "../UI/Components/Modal/OptionModal/ConfigDialog";
import { Align } from './../Add-on/Align';
@ -640,8 +637,6 @@ export function registerCommand()
commandMachine.RegisterCommand(CommandNames.BoardReplaceTempate, new BoardReplaceTempate());
//迁移自定义命令数据
commandMachine.RegisterCommand("upgradedata", new UpgradeData());
commandMachine.RegisterCommand(CommandNames.ResetCustomCommand, new Command_ResetCustomCommand());
commandMachine.RegisterCommand(CommandNames.Dist, new Command_Dist());
@ -706,53 +701,3 @@ export async function LimitCommand()
if (userConfig.showShareModule)
commandMachine.RegisterCommand(CommandNames.TemplateSearch, new Command_TemplateSearch());
}
export async function RegistCustomCommand()
{
let commandList: ICommand[] = [];
let cserver = CommandServer.GetInstance() as CommandServer;
commandList = await cserver.ReadCommandlist();
cserver.CommandListMap.clear();
for (let i of commandList)
{
let customize = i.customize || i.defaultCustom;
if (customize)
{
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()
{
for (let i of CommandList)
{
let customize = i.customize;
if (customize && customize !== i.defaultCustom)
{
commandMachine.RemoveCommand(customize);
i.customize = i.defaultCustom;
}
}
hotkeys.deleteScope('custom');
}

@ -1,4 +1,4 @@
import { Scene, AmbientLight } from "three";
import { AmbientLight, Scene } from "three";
import { app } from "../ApplicationServices/Application";
import { HostApplicationServices } from "../ApplicationServices/HostApplicationServices";
import { DisposeThreeObj, Object3DRemoveAll } from "../Common/Dispose";
@ -58,7 +58,7 @@ export class TempEditor
}
if (CommandState.CommandIng)
{
Log(`${commandMachine.LastCmd}命令执行中!`);
Log(`${commandMachine.LastExecCmd}命令执行中!`);
return;
}

@ -240,23 +240,4 @@ export class IndexedDbStore
};
});
}
async GetDataMap(storeName: StoreName)
{
return new Promise((res) =>
{
let map = new Map();
let store = this.db.transaction(storeName, DbMode.ReadWrite).objectStore(storeName);
let cursorRequest = store.openCursor();
cursorRequest.onsuccess = (e) =>
{
let cursor = cursorRequest.result;
if (cursor)
{
map.set(cursor.key, cursor.value);
cursor.continue();
}
else res(map);
};
});
}
}

@ -31,7 +31,6 @@ export class CommandInput extends React.Component<Props, null>
/>
<div style={{ position: "absolute", left: 60, bottom: 0, width: `calc( 100% - ${60}px)` }}>
<InputHint
cmdList={store.cmdList}
keyWordList={store.keyWordList}
cmdPrompt={store.commandPrompt}
handleInputCallback={store.HandleInput}

@ -83,18 +83,17 @@ export class CommandPanel extends React.Component<{}, CommandPanelState>
handleTabsClick = async () =>
{
let cserver = CommandServer.GetInstance() as CommandServer;
let cmdServer = CommandServer.GetInstance();
let elc = this.ulRef.querySelector(`#${this.id}`) as HTMLElement;
if (elc)
this.scrollCard.scrollTop = elc.offsetTop - 59;//59是该节点到顶部的距离
await cserver.SetLastScrollTop(this.scrollCard.scrollTop);
await cmdServer.SetLastScrollTop(this.scrollCard.scrollTop);
this.inputEl.current.focus();
};
componentWillUnmount()
{
//上传数据
let cserver = CommandServer.GetInstance() as CommandServer;
cserver.Upload();
CommandServer.GetInstance().Upload();
}
render()
{

@ -7,8 +7,8 @@ import { KeyBoard } from "../../../Common/KeyEnum";
import { commandReg } from "../../../Common/Utils";
import { CommandServer } from "../../../DatabaseServices/CommandServer";
import { commandMachine } from "../../../Editor/CommandMachine";
import { ICommand, CommandList } from "./CommandList";
import { ICON_CDN } from "../../IconEnum";
import { ICommand } from "./CommandList";
import { InputHotKeys } from "./InputHotKeys";
enum TipType
@ -33,7 +33,7 @@ export interface CommandItemProps
@observer
export class CommandItem extends React.Component<CommandItemProps, {}>{
@observable private flag: TipType = TipType.OK;
private m_InputEl: HTMLInputElement;
private _CmdInputEl: HTMLInputElement;
@observable private isCNInput: boolean = false;
private isReset = false;
constructor(props)
@ -42,7 +42,7 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
}
componentDidMount()
{
this.m_InputEl.onkeydown = (e) =>
this._CmdInputEl.onkeydown = (e) =>
{
if (e.keyCode === KeyBoard.Escape)
{
@ -60,7 +60,7 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
}
handleLiClick = () =>
{
if (this.isReset || document.activeElement === this.m_InputEl)
if (this.isReset || document.activeElement === this._CmdInputEl)
return;
const command = this.props.commandData;
if (!command.typeId)
@ -77,7 +77,7 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
}
this.flag = TipType.OK;
let target = this.m_InputEl;
let target = this._CmdInputEl;
let value = target.value.trim().toUpperCase();
target.value = value;
if (commandReg.test(value))
@ -91,51 +91,37 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
else
{
let curCmd = this.props.commandData;
for (let cmd of CommandList)
{
if (cmd.command !== curCmd.command
&& ((cmd.customize || cmd.defaultCustom) === value))
{
let oldCmd = CommandServer.GetInstance().CustomCommandMap.get(value);
if (oldCmd && oldCmd !== curCmd.command)//命令被注册
this.flag = TipType.IsExist;
if (value !== curCmd.command && commandMachine.CommandMap.has(value))//命令是原始命令
this.flag = TipType.IsExist;
return;
}
}
}
};
handleOnBlur = () =>
{
let target = this.m_InputEl;
let cserver = CommandServer.GetInstance() as CommandServer;
let cmdServer = CommandServer.GetInstance();
const commandData = this.props.commandData;
if (this.flag === TipType.OK)
{
if (commandData.customize)
cserver.CommandListMap.delete(commandData.customize);
if (this.isReset)
{
if (commandData.customize && commandData.customize !== target.value)
{
commandMachine.RemoveCommand(commandData.customize);//
commandData.customize = undefined;
cserver.DeleteCustonCommand(commandData);
// commandData.customizeed = commandData.customize;
}
}
else
{
commandData.customize = target.value.toUpperCase();
commandData.customize = this._CmdInputEl.value.toUpperCase();
if (commandData.customize === commandData.defaultCustom)
commandData.customize = undefined;
commandData.customizeed = commandData.customize;
commandMachine.RegisterCustomCommand(commandData.command, commandData.customize || commandData.defaultCustom);
cserver.AddCustonCommand(commandData);
}
cmdServer.ChangeCustonCommand(commandData);
}
else
{
target.value = commandData.customizeed || commandData.defaultCustom;
let curCmd = commandData.customize;//如果有默认 就用默认
if (!curCmd)
{
if (cmdServer.GetCommandCanUseDefaultCustomCmd(commandData))
curCmd = commandData.defaultCustom;//默认自定义
else
curCmd = commandData.command;//原始命令
}
this._CmdInputEl.value = curCmd;
this.flag = TipType.OK;
}
};
@ -174,11 +160,12 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
isOpen={this.flag !== TipType.OK}
>
<input
// 自定义命令的输入框
className="hotKeyInput"
type="text"
ref={el => { this.m_InputEl = el; }}
placeholder={store.commandData.defaultCustom}
defaultValue={store.commandData.customize || store.commandData.defaultCustom}
ref={el => { this._CmdInputEl = el; }}
placeholder={store.commandData.customize || (CommandServer.GetInstance().GetCommandCanUseDefaultCustomCmd(store.commandData) ? store.commandData.defaultCustom : store.commandData.command)}
defaultValue={store.commandData.customize || (CommandServer.GetInstance().GetCommandCanUseDefaultCustomCmd(store.commandData) ? store.commandData.defaultCustom : store.commandData.command)}
style={{ backgroundColor: this.props.commandData.typeId ? "#FFFFFF" : "#DDDDDD" }}
disabled={this.props.commandData.typeId ? false : true}
onCompositionStart={() => this.isCNInput = true}
@ -201,7 +188,7 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
onClosed={() =>
{
this.isReset = false;
this.m_InputEl.focus();
this._CmdInputEl.focus();
}}
content={
<div
@ -230,7 +217,14 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
intent={Intent.PRIMARY}
onClick={(e: React.MouseEvent<HTMLElement>) =>
{
this.m_InputEl.value = this.props.commandData.defaultCustom;
let cmdServer = CommandServer.GetInstance();
if (cmdServer.GetCommandCanUseDefaultCustomCmd(this.props.commandData))
this._CmdInputEl.value = this.props.commandData.defaultCustom;
else
this._CmdInputEl.value = this.props.commandData.command;
this.handleOnChange();
this.handleOnBlur();
}}

@ -13,11 +13,10 @@ export interface ICommand
readonly icon?: string,//图标路径(待定)
readonly typeId: string,//i2d,i3d,hb,pz,util
readonly link?: string,//帮助链接
readonly defaultCustom: string,//默认自定义,用于重置
readonly defaultCustom?: string,//默认自定义,用于重置
hotkeysCustomize?: string,//快捷键自定义命令
readonly defaultHotkeys?: string,//默认快捷键
readonly systemHotkeys?: string,//系统默认快捷键
customizeed?: string,//用于保存上一个需要赋初值否则undefinded出错
//------以上非搜索项-----//
readonly type: string,//命令类型
readonly chName: string,//中文名称
@ -2233,7 +2232,6 @@ export const CommandList: ICommand[] = [
icon: IconEnum.ModuleManage,
typeId: "module",
link: `#`,
defaultCustom: "TEMPLATE",
command: CommandNames.Template,
type: "模块",
chName: "模块管理",

@ -1,12 +1,10 @@
import React from "react";
import { observer } from "mobx-react";
import { observable } from "mobx";
import { commandMachine } from "../../../Editor/CommandMachine";
import { CommandItemProps } from "./CommandItem";
import { CommandList } from "./CommandList";
import { Button, Classes, Intent, Popover, Position, Tooltip } from "@blueprintjs/core";
import { observable } from "mobx";
import { observer } from "mobx-react";
import React from "react";
import { KeyBoard } from "../../../Common/KeyEnum";
import { CommandServer } from "../../../DatabaseServices/CommandServer";
import { CommandItemProps } from "./CommandItem";
enum TipType
{
@ -20,7 +18,11 @@ enum TipType
export class InputHotKeys extends React.Component<{ store: CommandItemProps; }, {}> {
keys: string[] = [];
_InputElKey = React.createRef<HTMLInputElement>();
@observable str: string = this.props.store.commandData.hotkeysCustomize || this.props.store.commandData.defaultHotkeys || this.props.store.commandData.systemHotkeys;
@observable str: string = this.props.store.commandData.hotkeysCustomize
|| (CommandServer.GetInstance().GetCommandCanUseDefaultHotkey(this.props.store.commandData)
&& CommandServer.GetInstance().HotKeyCommandMap.get(this.props.store.commandData.defaultHotkeys) ? this.props.store.commandData.defaultHotkeys : "")
|| this.props.store.commandData.systemHotkeys;
@observable flag: TipType = TipType.OK;
@observable hotkey: string = "";
@observable isReset: boolean = false;
@ -58,70 +60,26 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
}
let value = this.str;
let curCmd = this.props.store.commandData;
for (let cmd of CommandList)
{
if (cmd.command !== curCmd.command
&& ((cmd.hotkeysCustomize || cmd.defaultHotkeys || cmd.systemHotkeys) === value))
let oldCmd = CommandServer.GetInstance().HotKeyCommandMap.get(this.str);
if (oldCmd && oldCmd !== curCmd.command)
{
this.flag = TipType.IsExist;
this.hotkey = value;
return;
}
}
};
handleOnBlur = () =>
{
const commandData = this.props.store.commandData;
let cserver = CommandServer.GetInstance() as CommandServer;
let cserver = CommandServer.GetInstance();
if (this.flag === TipType.OK || this.str === "")
{
if (this.str === "")
{
if (commandData.hotkeysCustomize || commandData.defaultHotkeys)
{
if (commandData.defaultHotkeys)
{
if (commandData.hotkeysCustomize !== " ")
{
commandMachine.RemoveCommandDefaultHotKey(commandData.hotkeysCustomize || commandData.defaultHotkeys);
commandData.hotkeysCustomize = " ";
}
}
else
{
cserver.HotKeyListMap.set("cmd" + commandData.command, commandData.command);
commandMachine.RemoveCommandHotKey(commandData.hotkeysCustomize);
commandData.hotkeysCustomize = undefined;
}
cserver.AddCustonCommand(commandData);
}
}
else
{
if (commandData.hotkeysCustomize === " ")
{
if (this.str === " ") return;
commandMachine.RegisterCustomDefaultHotKey(this.str, commandData.command);
}
else
{
if (commandData.hotkeysCustomize)
{
commandMachine.RegisterCustomHotKey(commandData.hotkeysCustomize || "cmd" + commandData.command, this.str);
}
else
{
commandMachine.RegisterHotKey(commandData.defaultHotkeys || "cmd" + commandData.command, this.str);
}
}
commandData.hotkeysCustomize = this.str;
cserver.AddCustonCommand(commandData);
}
cserver.ChangeCustonCommand(commandData);
}
else
{
this.str = commandData.hotkeysCustomize || commandData.defaultHotkeys || "";
}
this.str = commandData.hotkeysCustomize ?? (cserver.GetCommandCanUseDefaultHotkey(commandData) ? (commandData.defaultHotkeys) : "") ?? "";
this.flag = TipType.OK;
};
public render()

@ -10,6 +10,7 @@ import { KeyBoard } from '../../../Common/KeyEnum';
import { Log } from '../../../Common/Log';
import { FixIndex, isLetter, isNum } from '../../../Common/Utils';
import { CameraControlState } from '../../../Editor/CameraControls';
import { commandMachine } from '../../../Editor/CommandMachine';
import { CommandState } from '../../../Editor/CommandState';
import { CommandStore } from '../../Store/CommandStore';
import { CommandInputHeight } from '../CommandInput/CommandInputUI';
@ -17,8 +18,6 @@ import './InputHint.css';
interface InputHintProps
{
cmdList: Set<string>,//命令列表
keyWordList: Array<KeyWord>,//关键字列表
cmdPrompt: string,//提示字符串
@ -139,7 +138,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
}
let intelliSenseCmdList: string[] = [];
for (let cmdName of this.props.cmdList)
for (let cmdName of commandMachine.CommandNameSet)
{
try
{

@ -47,11 +47,6 @@ export class CommandStore
this.promptList.splice(0, 20);
}
get cmdList()
{
return commandMachine.CommandNameList;
}
lastExecTime: number = 0;
HandleInput = (cmd: string) =>
{

@ -13,7 +13,7 @@ import { GetIndexDBID } from "../../Common/Utils";
import { CADFiler } from "../../DatabaseServices/CADFiler";
import { CommandServer } from "../../DatabaseServices/CommandServer";
import { FileServer } from "../../DatabaseServices/FileServer";
import { LimitCommand, RegistCustomCommand, RemoveCustonCommand } from "../../Editor/CommandRegister";
import { LimitCommand } from "../../Editor/CommandRegister";
import { userConfig } from "../../Editor/UserConfig";
import { RenderType } from "../../GraphicsSystem/RenderType";
import { IndexedDbStore, StoreName } from "../../IndexedDb/IndexedDbStore";
@ -167,7 +167,7 @@ export class UserConfigStore extends Singleton
await this.InitUserConfig();
await this.InitBBSTabIndex();
await (DownPanelStore.GetInstance() as DownPanelStore).Update();
await RegistCustomCommand();
CommandServer.GetInstance().InitCommandCustomCmdAndHotkey();
await LimitCommand();
AppToaster.show({
@ -524,7 +524,7 @@ export class UserConfigStore extends Singleton
ClearUserData()
{
(FileServer.GetInstance() as FileServer).Clear();
RemoveCustonCommand();
CommandServer.GetInstance().ClearCustonCommand();
localStorage.removeItem(StoreageKeys.IsLogin);
templateTagCommand.ClearTagList();
appCache.clear();

Loading…
Cancel
Save