MODULE HotKeysCommands;
IMPORT
SYSTEM,
KernelLog, Modules, Commands, Streams, Strings,
Inputs, KernelLogger,
WMWindowManager, WMComponents, WMEditors, WMGraphics;
CONST
DefaultWidth = 400; DefaultHeight = 40;
DefaultTextColor = WMGraphics.White;
DefaultTextBgColor = 00008080H;
MouseX = "MouseX";
MouseY = "MouseY";
MouseButtons = "MouseButtons";
MouseWheel = "MouseWheel";
TYPE
Window = OBJECT (WMComponents.FormWindow)
VAR
editor : WMEditors.Editor;
PROCEDURE HandleEnter(sender, data : ANY);
VAR commandString : ARRAY 4096 OF CHAR; msg : ARRAY 128 OF CHAR; res : LONGINT;
BEGIN
editor.GetAsString(commandString);
IF commandString # "" THEN
Commands.Call(commandString, {}, res, msg);
IF res # Commands.Ok THEN
KernelLog.String("HotKeysCommands: Failed to execute '"); KernelLog.String(commandString);
KernelLog.String("', res: "); KernelLog.Int(res, 0);
KernelLog.String(" ("); KernelLog.String(msg); KernelLog.String(")");
KernelLog.Ln;
END;
END;
Close;
END HandleEnter;
PROCEDURE HandleEscape(sender, data : ANY);
BEGIN
Close;
END HandleEscape;
PROCEDURE FocusLost;
BEGIN
Close;
END FocusLost;
PROCEDURE Close;
BEGIN
Close^; window := NIL;
END Close;
PROCEDURE CreateForm() : WMComponents.VisualComponent;
BEGIN
NEW(editor);
editor.alignment.Set(WMComponents.AlignClient);
editor.onEnter.Add(HandleEnter);
editor.onEscape.Add(HandleEscape);
editor.allowScrollbars.Set(FALSE);
editor.multiLine.Set(FALSE);
editor.tv.defaultTextColor.Set(DefaultTextColor);
editor.tv.defaultTextBgColor.Set(0);
editor.fillColor.Set(DefaultTextBgColor);
RETURN editor;
END CreateForm;
PROCEDURE &New*;
VAR manager : WMWindowManager.WindowManager;
BEGIN
Init(DefaultWidth, DefaultHeight, TRUE);
SetContent(CreateForm());
SetTitle(Strings.NewString("Enter command: "));
WMWindowManager.ExtAddWindow(SELF, 200, 100, {});
manager := WMWindowManager.GetDefaultManager();
manager.SetFocus(SELF);
editor.SetFocus;
END New;
END Window;
VAR
window : Window;
PROCEDURE SimulateMouse*(context : Commands.Context);
VAR
string : ARRAY 32 OF CHAR; value : LONGINT;
msg : Inputs.MouseMsg;
doHandle : BOOLEAN;
BEGIN
IF context.arg.GetString(string) THEN
IF context.arg.GetInteger(value, FALSE) THEN
doHandle := TRUE;
IF Strings.Match(string, MouseX) THEN msg.dx := value;
ELSIF Strings.Match(string, MouseY) THEN msg.dy := value;
ELSIF Strings.Match(string, MouseWheel) THEN msg.dz := value;
ELSIF Strings.Match(string, MouseButtons) THEN msg.keys := SYSTEM.VAL(SET, value);
ELSE
doHandle := FALSE;
END;
IF doHandle THEN Inputs.mouse.Handle(msg); END;
END;
END;
END SimulateMouse;
PROCEDURE EnterCommand*;
BEGIN {EXCLUSIVE}
IF window = NIL THEN NEW(window); END;
END EnterCommand;
PROCEDURE ClearLog*;
BEGIN
KernelLogger.kernelLog.AcquireWrite;
KernelLogger.kernelLog.Delete(0, KernelLogger.kernelLog.GetLength());
KernelLogger.kernelLog.ReleaseWrite;
END ClearLog;
PROCEDURE Cleanup;
BEGIN {EXCLUSIVE}
IF window # NIL THEN window.Close; window := NIL; END;
END Cleanup;
BEGIN
Modules.InstallTermHandler(Cleanup);
END HotKeysCommands.
HotKeysCommands.ClearLog ~
HotKeysCommands.EnterCommand ~
HotKeysCommands.SimulateMouse MouseWheel -3 ~
SystemTools.Free HotKeysCommands ~