!1519 功能:新增命令快捷键

pull/1519/MERGE
林三 3 years ago committed by ChenX
parent 3fba1f242d
commit 24d25afa09

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

@ -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 =>
{

@ -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",

@ -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"
}

@ -18,10 +18,10 @@ export class CommandServer extends Singleton
private _customCommand: { [key: string]: ICommand; } = {};
private _needUpload = false;
CommandListMap = new Map<string, string>();
HotKeyListMap = new Map<string, string>();
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()

@ -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<string, string> = new Map<string, string>();
//命令表
CommandMap: Map<string, Command> = new Map<string, Command>();
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

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

@ -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<CommandItemProps, {}>{
@observable private flag: TipType = TipType.OK;
@ -64,6 +67,8 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
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<CommandItemProps, {}>{
<li><span className="bp3-tag bp3-minimal">{store.commandData.type}</span></li>
</ul>
<li>
<Tooltip
content={errorMsg}
position={Position.TOP}
intent={Intent.WARNING}
isOpen={this.flag !== TipType.OK}
>
<input
className="bp3-input"
type="text"
ref={el => { 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}
/>
</Tooltip>
</li>
<li>
<Popover
usePortal={true}
position={Position.RIGHT}
onClosed={() =>
{
this.isReset = false;
this.m_InputEl.focus();
}}
content={
<div
style={popStyle}
tabIndex={1}
onKeyDown={(e) =>
{
if (e.keyCode === KeyBoard.Escape)
<div className="hotKey">
<div className="hotKeyTooltip">
<Tooltip
content={errorMsg}
position={Position.TOP}
intent={Intent.WARNING}
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}
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}
/>
</Tooltip>
</div>
<div className="hotkeyPopover">
<Popover
usePortal={true}
position={Position.RIGHT}
onClosed={() =>
{
this.isReset = false;
this.m_InputEl.focus();
}}
>
<p></p>
<div style={{ display: "flex", justifyContent: "center" }}>
<Button style={{ marginRight: 10 }}
className={Classes.POPOVER_DISMISS}
text="取消" />
content={
<div
style={popStyle}
tabIndex={1}
onKeyDown={(e) =>
{
if (e.keyCode === KeyBoard.Escape)
{
(e.currentTarget.lastElementChild.firstElementChild as HTMLButtonElement).click();
this.m_commandItemEl.parentElement.focus();
}
else if (e.keyCode === KeyBoard.Enter)
(e.currentTarget.lastElementChild.lastElementChild as HTMLButtonElement).click();
e.stopPropagation();
}}
>
<p></p>
<div style={{ display: "flex", justifyContent: "center" }}>
<Button style={{ marginRight: 10 }}
className={Classes.POPOVER_DISMISS}
text="取消" />
<Button
className={Classes.POPOVER_DISMISS}
intent={Intent.PRIMARY}
onClick={(e: React.MouseEvent<HTMLElement>) =>
{
this.m_InputEl.value = this.props.commandData.defaultCustom;
this.handleOnChange();
this.handleOnBlur();
}}
text="确定" />
</div>
</div>
}
target={
<Button
className={Classes.POPOVER_DISMISS}
intent={Intent.PRIMARY}
onClick={(e: React.MouseEvent<HTMLElement>) =>
icon="redo"
onClick={(e) =>
{
this.m_InputEl.value = this.props.commandData.defaultCustom;
this.handleOnChange();
this.handleOnBlur();
if (!this.props.commandData.typeId)
{
e.stopPropagation();
return;
}
this.isReset = true;
}}
text="确定" />
</div>
</div>
}
target={
<Button
className={Classes.POPOVER_DISMISS}
icon="redo"
onClick={() => this.isReset = true}
/>
}
/>
}
/>
</div>
</div >
</li>
<li>
<InputHotKeys store={store} />
</li>
<li>
<Button

@ -1,5 +1,6 @@
import { IconEnum } from "../../IconEnum";
import { CommandNames } from "../../../Common/CommandNames";
import { HotkeyList } from "../../../Common/HotKeyList";
/**
*
* ,,
@ -12,6 +13,9 @@ export interface ICommand
readonly typeId: string,//i2d,i3d,hb,pz,util
readonly link?: string,//帮助链接
readonly defaultCustom: string,//默认自定义,用于重置
hotkeysCustomize?: string,//快捷键自定义命令
readonly defaultHotkeys?: string,//默认快捷键
readonly systemHotkeys?: string,//系统默认快捷键
customizeed?: string,//用于保存上一个需要赋初值否则undefinded出错
//------以上非搜索项-----//
readonly type: string,//命令类型
@ -22,7 +26,6 @@ export interface ICommand
customize?: string,//自定义命令
readonly time?: string,//使用时间(待定)
}
const HelpUrlBase = "https://cfcad.cn/help/#/";
export const CommandList: ICommand[] = [
@ -584,8 +587,9 @@ export const CommandList: ICommand[] = [
defaultCustom: CommandNames.EditSealEdgeData,
command: CommandNames.EditSealEdgeData,
type: "板件编辑",
chName: "批量修改板的封边信息(Alt+S)",
chDes: "批量修改板的封边信息(Alt+S)",
chName: "批量修改板的封边信息",
chDes: "批量修改板的封边信息",
defaultHotkeys: HotkeyList.AS,
},
{
typeId: "bjbj",
@ -593,8 +597,9 @@ export const CommandList: ICommand[] = [
defaultCustom: CommandNames.EditDrilEdgeData,
command: CommandNames.EditDrilEdgeData,
type: "板件编辑",
chName: "批量修改板的排钻信息(Alt+D)",
chDes: "批量修改板的排钻信息(Alt+D)",
chName: "批量修改板的排钻信息",
chDes: "批量修改板的排钻信息",
defaultHotkeys: HotkeyList.AD,
},
{
icon: IconEnum.BBS,
@ -793,6 +798,15 @@ export const CommandList: ICommand[] = [
chName: "模拟造型走刀+排钻+封边",
chDes: "",
},
{
typeId: "bjbj",
defaultCustom: "BUYMATERIAL",
command: CommandNames.SelectAll,
type: "全选",
chName: "全选",
chDes: "",
systemHotkeys: HotkeyList.CA,
},
{
typeId: "bjbj",
defaultCustom: "BBB",
@ -1027,7 +1041,8 @@ export const CommandList: ICommand[] = [
type: "视图",
chName: "聚焦对选中对象",
// enName: "Swiso View",
chDes: "聚焦对选中对象(Alt+F)",
chDes: "聚焦对选中对象",
defaultHotkeys: HotkeyList.AF,
},
{
icon: IconEnum.ExplosionMap,
@ -1216,7 +1231,8 @@ export const CommandList: ICommand[] = [
type: "工具",
chName: "复制到剪贴板",
// enName: "CopyClip",
chDes: "将所选对象复制到剪贴板(Ctrl+C)",
chDes: "将所选对象复制到剪贴板",
systemHotkeys: HotkeyList.CC,
},
{
icon: IconEnum.CopyClip,
@ -1236,7 +1252,8 @@ export const CommandList: ICommand[] = [
command: CommandNames.CopyBase,
type: "工具",
chName: "指定基点复制对象",
chDes: "将所选对象复制到剪贴板(Ctrl+Shift+C)",
chDes: "将所选对象复制到剪贴板",
systemHotkeys: HotkeyList.CSC,
},
{
icon: IconEnum.PasteClip,
@ -1248,6 +1265,7 @@ export const CommandList: ICommand[] = [
chName: "从剪贴板粘贴",
// enName: "PasteClip",
chDes: "将剪贴板中的对象粘贴到当前图形中",
systemHotkeys: HotkeyList.CV,
},
{
icon: IconEnum.Delete,
@ -1259,6 +1277,7 @@ export const CommandList: ICommand[] = [
chName: "删除",
// enName: "Delete",
chDes: "删除已经绘制的图元",
systemHotkeys: HotkeyList.D,
},
{
icon: IconEnum.Move,
@ -1813,6 +1832,7 @@ export const CommandList: ICommand[] = [
type: "文件",
chName: "保存文件",
chDes: "保存当前文件",
systemHotkeys: HotkeyList.CS,
},
{
icon: IconEnum.SaveAs,
@ -1843,6 +1863,7 @@ export const CommandList: ICommand[] = [
type: "文件",
chName: "撤销",
chDes: "撤销上一步操作",
systemHotkeys: HotkeyList.CZ,
},
{
icon: IconEnum.Undo,
@ -1853,6 +1874,7 @@ export const CommandList: ICommand[] = [
type: "文件",
chName: "重做",
chDes: "重做被撤销的操作",
systemHotkeys: HotkeyList.CY,
},
{
icon: IconEnum.Open,
@ -1944,6 +1966,7 @@ export const CommandList: ICommand[] = [
type: "文件",
chName: "一键布局",
chDes: "一键布局",
},
{
icon: IconEnum.OneKeyPrint,
@ -1954,6 +1977,7 @@ export const CommandList: ICommand[] = [
type: "文件",
chName: "一键打印",
chDes: "一键打印",
defaultHotkeys: HotkeyList.CAP,
},
{
icon: IconEnum.Group,
@ -2121,4 +2145,67 @@ export const CommandList: ICommand[] = [
chDes: "共享材质",
},
//#endregion
{
typeId: "",
defaultCustom: "COMANP",
command: CommandNames.Comanp,
type: "内置",
chName: "命令面板与快捷键",
chDes: "系统命令",
systemHotkeys: HotkeyList.F1,
},
{
typeId: "",
defaultCustom: "PROPERTIESBAR",
command: CommandNames.PropertiesBar,
type: "内置",
chName: "左侧特性栏",
chDes: "系统命令",
defaultHotkeys: HotkeyList.C1,
},
{
typeId: "",
defaultCustom: "MODULEBAR",
command: CommandNames.ModuleBar,
type: "内置",
chName: "右侧模块栏",
chDes: "系统命令",
defaultHotkeys: HotkeyList.C2,
},
{
typeId: "",
defaultCustom: "CHANGELAYOUT",
command: CommandNames.ChangeLayout,
type: "内置",
chName: "切换布局",
chDes: "系统命令",
defaultHotkeys: HotkeyList.CB,
},
{
typeId: "",
defaultCustom: "",
command: "",
type: "内置",
chName: "打印",
chDes: "系统命令",
systemHotkeys: HotkeyList.CP,
},
{
typeId: "",
defaultCustom: "RIGHTPANEL",
command: CommandNames.RightPanel,
type: "内置",
chName: "显示模块参数面板",
chDes: "系统命令",
defaultHotkeys: HotkeyList.CM,
},
{
typeId: "",
defaultCustom: "",
command: "",
type: "内置",
chName: "命令强制结束",
chDes: "系统命令",
systemHotkeys: HotkeyList.CAE,
},
];

@ -0,0 +1,258 @@
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 { KeyBoard } from "../../../Common/KeyEnum";
import { CommandServer } from "../../../DatabaseServices/CommandServer";
enum TipType
{
OK = 0,
InputNull = 1, //无效输入
StrIllegal = 2, //非法格式
IsExist = 4, //重复
}
@observer
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 flag: TipType = TipType.OK;
@observable hotkey: string = "";
@observable isReset: boolean = false;
checkHotKey = () =>
{
if (!this.isReset)
{
let keys = [];
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;
});
this.str = keys.join("+");
this.flag = TipType.OK;
if (this.keys[0] !== "Control" && this.keys[0] !== "Alt" && this.keys[0] !== "Shift")
{
this.flag = TipType.StrIllegal;
return;
}
if (this.keys.length == 1)
{
this.flag = TipType.InputNull;
return;
}
if (keys.length > 1 && (keys[keys.length - 1] === "Alt" || keys[keys.length - 1] === "Shift"))
{
this.flag = TipType.InputNull;
return;
}
}
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))
{
this.flag = TipType.IsExist;
this.hotkey = value;
return;
}
}
};
handleOnBlur = () =>
{
const commandData = this.props.store.commandData;
let cserver = CommandServer.GetInstance() as CommandServer;
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);
console.log(cserver);
}
}
else
{
this.str = commandData.hotkeysCustomize || commandData.defaultHotkeys || "";
}
this.flag = TipType.OK;
};
public render()
{
const popStyle: React.CSSProperties = {
maxWidth: "350px",
padding: "10px",
outline: "none",
};
let errorMsg = "";
if (this.flag & TipType.InputNull)
errorMsg = "不允许的快捷键组合!";
if (this.flag & TipType.StrIllegal)
errorMsg = "快捷键须以Control或Alt或Shift开头";
if (this.flag & TipType.IsExist)
errorMsg = "快捷键 " + this.hotkey + " 重复! 请重新输入!";
return (
<div className="hotKey">
<div className="hotKeyTooltip">
<Tooltip
content={errorMsg}
position={Position.TOP}
intent={Intent.WARNING}
isOpen={this.flag !== TipType.OK}
>
<input
style={{ backgroundColor: this.props.store.commandData.systemHotkeys ? "#DDDDDD" : "#FFFFFF" }}
className="hotKeyInput"
type="text"
disabled={this.props.store.commandData.systemHotkeys ? true : false}
ref={this._InputElKey}
onKeyDown={(e) =>
{
if (e.keyCode === KeyBoard.Backspace)
{
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._InputElKey.current.blur();
return;
}
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);
e.preventDefault();
}}
value={this.str}
onClick={(e) => e.stopPropagation()}
onChange={this.checkHotKey}
onBlur={(e) =>
{
this.keys.length = 0;
this.handleOnBlur();
}}
/>
</Tooltip>
</div>
<div className="hotkeyPopover">
<Popover
usePortal={true}
position={Position.TOP}
isOpen={this.isReset}
onClose={() => { this.isReset = false; }}
content={
<div
tabIndex={1}
style={popStyle}
onKeyDown={(e) =>
{
if (e.keyCode === KeyBoard.Escape)
{
this.isReset = false;
this._InputElKey.current.focus();
}
else if (e.keyCode === KeyBoard.Enter)
(e.currentTarget.lastElementChild.lastElementChild as HTMLButtonElement).click();
}}
>
<p></p>
<div style={{ display: "flex", justifyContent: "center" }}>
<Button style={{ marginRight: 10 }}
className={Classes.POPOVER_DISMISS}
text="取消"
onClick={(event: React.MouseEvent<HTMLElement>) =>
{
this.isReset = false;
event.stopPropagation();
}}
/>
<Button
className={Classes.POPOVER_DISMISS}
intent={Intent.PRIMARY}
onClick={(event: React.MouseEvent<HTMLElement>) =>
{
this.str = this.props.store.commandData.defaultHotkeys || "";
this.checkHotKey();
this.handleOnBlur();
this.isReset = false;
this._InputElKey.current.focus();
event.stopPropagation();
}}
text="确定" />
</div>
</div>
}
target={
<Button
className={Classes.POPOVER_DISMISS}
icon="redo"
onClick={(event: React.MouseEvent<HTMLElement>) =>
{
if (!this.props.store.commandData.systemHotkeys)
this.isReset = true;
event.stopPropagation();
}}
/>
}
/>
</div>
</div >
);
}
}

@ -0,0 +1,44 @@
import { Command } from "../../../../Editor/CommandMachine";
import { DownPanelStore } from "../../../Store/DownPanelStore";
import { RightPanelStore } from "../../../Store/RightPanelStore/RightPanelStore";
import { RightTabId } from "../../RightPanel/RightPanel";
export class Command_PropertiesBar implements Command
{
async exec()
{
DownPanelStore.GetInstance().TogglePropertiesPanel();
}
}
export class Command_ModuleBar implements Command
{
async exec()
{
RightPanelStore.GetInstance().m_IsShow = !RightPanelStore.GetInstance().m_IsShow;
}
}
export class Command_ChangeLayout implements Command
{
async exec()
{
let store = DownPanelStore.GetInstance();
store.isLayout = !store.isLayout;
}
}
export class Command_RightPanel implements Command
{
async exec()
{
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;
}
}
}

@ -14,9 +14,31 @@
.bp3-dialog-body {
display : flex;
width : 50vw;
width : 65vw;
min-width: 651px;
.hotKey{
width : 100%;
height : auto;
text-align: center;
margin : 0 auto;
display : flex;
.hotKeyTooltip{
.hotKeyInput {
width : 100%;
height : 30px;
border-radius: 3px;
border : 1px solid #B6B8BA;
font-size : initial;
}
}
.hotkeyPopover{
margin-left: 2px;
}
}
.bp3-tabs {
min-width : 86px;
justify-content: center;
@ -38,7 +60,7 @@
>ul {
>ul>div>h1 {
font-size : 2.5rem !important;
padding-left: 30px;
padding-left: 32px;
margin : 25px 0px;
}
@ -68,11 +90,16 @@
}
&:nth-child(4) {
width: 20%;
width: 18%;
}
&:nth-child(5) {
width: 10%;
width: 23%;
min-width: 100px;
}
&:last-child {
min-width: 60px;
}
>a {
@ -80,7 +107,7 @@
}
>span>span>input {
height : 2.0rem !important;
height : 30px;
width : 100%;
border-radius: 3px;
}

@ -311,7 +311,7 @@ export class DownPanel extends React.Component<{ store?: DownPanelStore; }, {}>
</div>
<Switch
checked={this.props.store.isLayout}
label="切换布局(Ctrl+B)"
label="切换布局"
data-key="isLayout"
onChange={this.handleChange}
style={switchStyle}

@ -312,8 +312,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
ref={el => { this.inputEl = el; }}
onKeyDown={(e) =>
{
if (e.ctrlKey || e.altKey) e.preventDefault();
if (e.ctrlKey || e.altKey || e.shiftKey) e.preventDefault();
if (e.keyCode === KeyBoard.Comma)
e.stopPropagation();
}}

Loading…
Cancel
Save