|
|
|
@ -14,73 +14,89 @@ enum TipType
|
|
|
|
|
IsExist = 4, //重复
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SYSTEM_BEGIN_HOTKEYS = ["Shift", "Alt", "Control"];
|
|
|
|
|
|
|
|
|
|
const BEGIN_HOTKEYS = ["End", "Insert", "PageUp", "PageDown", "Home", "Delete"];
|
|
|
|
|
|
|
|
|
|
@observer
|
|
|
|
|
export class InputHotKeys extends React.Component<{ store: CommandItemProps; }, {}> {
|
|
|
|
|
keys: string[] = [];
|
|
|
|
|
_Keys: string[] = [];
|
|
|
|
|
_InputElKey = React.createRef<HTMLInputElement>();
|
|
|
|
|
@observable str: string = this.props.store.commandData.hotkeysCustomize
|
|
|
|
|
@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;
|
|
|
|
|
@observable _Flag: TipType = TipType.OK;
|
|
|
|
|
@observable _Hotkey: string = "";
|
|
|
|
|
@observable _IsReset: boolean = false;
|
|
|
|
|
|
|
|
|
|
checkHotKey = () =>
|
|
|
|
|
{
|
|
|
|
|
if (!this.isReset)
|
|
|
|
|
if (!this._IsReset)
|
|
|
|
|
{
|
|
|
|
|
let keys = [];
|
|
|
|
|
for (let key of this.keys)
|
|
|
|
|
let keys: string[] = [];
|
|
|
|
|
for (let key of this._Keys)
|
|
|
|
|
{
|
|
|
|
|
keys.push(key[0].toUpperCase() + key.substring(1));
|
|
|
|
|
}
|
|
|
|
|
keys.sort((a, b) =>
|
|
|
|
|
{
|
|
|
|
|
return (a.length > b.length) ? -1 : (a.length < b.length) ? 1 : 0;
|
|
|
|
|
return SYSTEM_BEGIN_HOTKEYS.indexOf(b) - SYSTEM_BEGIN_HOTKEYS.indexOf(a);
|
|
|
|
|
});
|
|
|
|
|
this.str = keys.join("+");
|
|
|
|
|
this.flag = TipType.OK;
|
|
|
|
|
if (this.keys[0] !== "Control" && this.keys[0] !== "Alt" && this.keys[0] !== "Shift")
|
|
|
|
|
this._Str = keys.join("+");
|
|
|
|
|
this._Flag = TipType.OK;
|
|
|
|
|
if (!SYSTEM_BEGIN_HOTKEYS.includes(keys[0]) && !BEGIN_HOTKEYS.includes(keys[0]))
|
|
|
|
|
{
|
|
|
|
|
this.flag = TipType.StrIllegal;
|
|
|
|
|
this._Flag = TipType.StrIllegal;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.keys.length == 1)
|
|
|
|
|
if (keys.length == 1 && !BEGIN_HOTKEYS.includes(keys[0]))
|
|
|
|
|
{
|
|
|
|
|
this.flag = TipType.InputNull;
|
|
|
|
|
this._Flag = TipType.InputNull;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (keys.length > 1 && (keys[keys.length - 1] === "Alt" || keys[keys.length - 1] === "Shift"))
|
|
|
|
|
{
|
|
|
|
|
this.flag = TipType.InputNull;
|
|
|
|
|
this._Flag = TipType.InputNull;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (keys.length > 1 && this.includeBeginHotkeys(keys))
|
|
|
|
|
{
|
|
|
|
|
this._Flag = TipType.InputNull;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let value = this.str;
|
|
|
|
|
let value = this._Str;
|
|
|
|
|
let curCmd = this.props.store.commandData;
|
|
|
|
|
|
|
|
|
|
let oldCmd = CommandServer.GetInstance().HotKeyCommandMap.get(this.str);
|
|
|
|
|
let oldCmd = CommandServer.GetInstance().HotKeyCommandMap.get(this._Str);
|
|
|
|
|
if (oldCmd && oldCmd !== curCmd.command)
|
|
|
|
|
{
|
|
|
|
|
this.flag = TipType.IsExist;
|
|
|
|
|
this.hotkey = value;
|
|
|
|
|
this._Flag = TipType.IsExist;
|
|
|
|
|
this._Hotkey = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private includeBeginHotkeys(keys: string[])
|
|
|
|
|
{
|
|
|
|
|
if (BEGIN_HOTKEYS.includes(keys[0]))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleOnBlur = () =>
|
|
|
|
|
{
|
|
|
|
|
const commandData = this.props.store.commandData;
|
|
|
|
|
let cserver = CommandServer.GetInstance();
|
|
|
|
|
if (this.flag === TipType.OK || this.str === "")
|
|
|
|
|
if (this._Flag === TipType.OK || this._Str === "")
|
|
|
|
|
{
|
|
|
|
|
commandData.hotkeysCustomize = this.str;
|
|
|
|
|
commandData.hotkeysCustomize = this._Str;
|
|
|
|
|
cserver.ChangeCustonCommand(commandData);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
this.str = commandData.hotkeysCustomize ?? (cserver.GetCommandCanUseDefaultHotkey(commandData) ? (commandData.defaultHotkeys) : "") ?? "";
|
|
|
|
|
this.flag = TipType.OK;
|
|
|
|
|
this._Str = commandData.hotkeysCustomize ?? (cserver.GetCommandCanUseDefaultHotkey(commandData) ? (commandData.defaultHotkeys) : "") ?? "";
|
|
|
|
|
this._Flag = TipType.OK;
|
|
|
|
|
};
|
|
|
|
|
public render()
|
|
|
|
|
{
|
|
|
|
@ -90,12 +106,13 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
|
|
|
|
|
outline: "none",
|
|
|
|
|
};
|
|
|
|
|
let errorMsg = "";
|
|
|
|
|
if (this.flag & TipType.InputNull)
|
|
|
|
|
if (this._Flag & TipType.InputNull)
|
|
|
|
|
errorMsg = "不允许的快捷键组合!";
|
|
|
|
|
if (this.flag & TipType.StrIllegal)
|
|
|
|
|
if (this._Flag & TipType.StrIllegal)
|
|
|
|
|
errorMsg = "快捷键须以Control或Alt或Shift开头";
|
|
|
|
|
if (this.flag & TipType.IsExist)
|
|
|
|
|
errorMsg = "快捷键 " + this.hotkey + " 重复! 请重新输入!";
|
|
|
|
|
if (this._Flag & TipType.IsExist)
|
|
|
|
|
errorMsg = "快捷键 " + this._Hotkey + " 重复! 请重新输入!";
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="hotKey">
|
|
|
|
|
<div className="hotKeyTooltip">
|
|
|
|
@ -103,7 +120,7 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
|
|
|
|
|
content={errorMsg}
|
|
|
|
|
position={Position.TOP}
|
|
|
|
|
intent={Intent.WARNING}
|
|
|
|
|
isOpen={this.flag !== TipType.OK}
|
|
|
|
|
isOpen={this._Flag !== TipType.OK}
|
|
|
|
|
>
|
|
|
|
|
<input
|
|
|
|
|
style={{ backgroundColor: this.props.store.commandData.systemHotkeys ? "#DDDDDD" : "#FFFFFF" }}
|
|
|
|
@ -115,33 +132,33 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
|
|
|
|
|
{
|
|
|
|
|
if (e.keyCode === KeyBoard.Backspace)
|
|
|
|
|
{
|
|
|
|
|
this.str = "";
|
|
|
|
|
this.flag = TipType.OK;
|
|
|
|
|
this._Str = "";
|
|
|
|
|
this._Flag = TipType.OK;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
window.event.returnValue = false;
|
|
|
|
|
if (e.keyCode === KeyBoard.Escape)
|
|
|
|
|
{
|
|
|
|
|
this.str = this.props.store.commandData.hotkeysCustomize || this.props.store.commandData.defaultHotkeys || "";
|
|
|
|
|
this._Str = this.props.store.commandData.hotkeysCustomize || this.props.store.commandData.defaultHotkeys || "";
|
|
|
|
|
this.props.store.parentInput.current.focus();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.keys.indexOf(e.key) !== -1) return;
|
|
|
|
|
this.keys.push(e.key);
|
|
|
|
|
if (this._Keys.indexOf(e.key) !== -1) return;
|
|
|
|
|
this._Keys.push(e.key);
|
|
|
|
|
this.checkHotKey();
|
|
|
|
|
}}
|
|
|
|
|
onKeyUp={(e) =>
|
|
|
|
|
{
|
|
|
|
|
this.keys = this.keys.filter((key) => key !== e.key);
|
|
|
|
|
this._Keys = this._Keys.filter((key) => key !== e.key);
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}}
|
|
|
|
|
value={this.str}
|
|
|
|
|
value={this._Str}
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
onChange={this.checkHotKey}
|
|
|
|
|
onBlur={(e) =>
|
|
|
|
|
{
|
|
|
|
|
this.keys.length = 0;
|
|
|
|
|
this._Keys.length = 0;
|
|
|
|
|
this.handleOnBlur();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
@ -151,8 +168,8 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
|
|
|
|
|
<Popover
|
|
|
|
|
usePortal={true}
|
|
|
|
|
position={Position.TOP}
|
|
|
|
|
isOpen={this.isReset}
|
|
|
|
|
onClose={() => { this.isReset = false; }}
|
|
|
|
|
isOpen={this._IsReset}
|
|
|
|
|
onClose={() => { this._IsReset = false; }}
|
|
|
|
|
content={
|
|
|
|
|
<div
|
|
|
|
|
tabIndex={1}
|
|
|
|
@ -161,7 +178,7 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
|
|
|
|
|
{
|
|
|
|
|
if (e.keyCode === KeyBoard.Escape)
|
|
|
|
|
{
|
|
|
|
|
this.isReset = false;
|
|
|
|
|
this._IsReset = false;
|
|
|
|
|
this._InputElKey.current.focus();
|
|
|
|
|
}
|
|
|
|
|
else if (e.keyCode === KeyBoard.Enter)
|
|
|
|
@ -175,7 +192,7 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
|
|
|
|
|
text="取消"
|
|
|
|
|
onClick={(event: React.MouseEvent<HTMLElement>) =>
|
|
|
|
|
{
|
|
|
|
|
this.isReset = false;
|
|
|
|
|
this._IsReset = false;
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
@ -184,10 +201,10 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
|
|
|
|
|
intent={Intent.PRIMARY}
|
|
|
|
|
onClick={(event: React.MouseEvent<HTMLElement>) =>
|
|
|
|
|
{
|
|
|
|
|
this.str = this.props.store.commandData.defaultHotkeys || "";
|
|
|
|
|
this._Str = this.props.store.commandData.defaultHotkeys || "";
|
|
|
|
|
this.checkHotKey();
|
|
|
|
|
this.handleOnBlur();
|
|
|
|
|
this.isReset = false;
|
|
|
|
|
this._IsReset = false;
|
|
|
|
|
this._InputElKey.current.focus();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
}}
|
|
|
|
@ -202,7 +219,7 @@ export class InputHotKeys extends React.Component<{ store: CommandItemProps; },
|
|
|
|
|
onClick={(event: React.MouseEvent<HTMLElement>) =>
|
|
|
|
|
{
|
|
|
|
|
if (!this.props.store.commandData.systemHotkeys)
|
|
|
|
|
this.isReset = true;
|
|
|
|
|
this._IsReset = true;
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|