This repository was archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMainWindowInputHandler.cs
More file actions
104 lines (94 loc) · 3.47 KB
/
Copy pathMainWindowInputHandler.cs
File metadata and controls
104 lines (94 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using SPCode.Utils;
namespace SPCode.UI;
public partial class MainWindow
{
#region Variables
public Dictionary<string, Action> Commands;
#endregion
#region Events
private void MainWindowEvent_KeyDown(object sender, KeyEventArgs e)
{
if (!e.IsDown)
{
return;
}
var key = e.Key;
var modifiers = Keyboard.Modifiers;
if (key == Key.Escape && CompileOutputRow.Height.Value > 8.0)
{
CloseErrorResultGrid(null, null);
}
if (key == Key.System)
{
key = e.SystemKey;
}
if (!HotkeyUtils.IsKeyModifier(key))
{
ProcessHotkey(new Hotkey(key, modifiers));
}
}
#endregion
#region Methods
/// <summary>
/// Processes the received hotkey and matches it with the associated command.
/// </summary>
/// <param name="hk">The hotkey to process</param>
/// <param name="e">Optional arguments from EditorElement to process input from there by calling Handled to true</param>
public void ProcessHotkey(Hotkey hk, KeyEventArgs e = null)
{
var hotkeyInfo = Program.HotkeysList.FirstOrDefault(x => x.Hotkey != null && x.Hotkey.ToString() == hk.ToString());
if (hotkeyInfo != null)
{
Commands[hotkeyInfo.Command]();
if (e != null)
{
e.Handled = true;
}
}
}
/// <summary>
/// Loads the commands dictionary.
/// </summary>
private void LoadCommandsDictionary()
{
Commands = new()
{
{ "New", Command_New },
{ "NewTemplate", Command_NewFromTemplate },
{ "Open", Command_Open },
{ "ReopenLastClosedTab", Command_ReopenLastClosedTab },
{ "Save", Command_Save },
{ "SaveAll", Command_SaveAll },
{ "SaveAs", Command_SaveAs },
{ "Close", Command_Close },
{ "CloseAll", Command_CloseAll },
{ "FoldingsExpand", () => Command_FlushFoldingState(true) },
{ "FoldingsCollapse", () => Command_FlushFoldingState(false) },
{ "ReformatCurrent", () => Command_TidyCode(false) },
{ "ReformatAll", () => Command_TidyCode(true) },
{ "GoToLine", Command_GoToLine },
{ "CommentLine", () => Command_ToggleCommentLine(true) },
{ "UncommentLine", () => Command_ToggleCommentLine(false) },
{ "TransformUppercase", () => Command_ChangeCase(true) },
{ "TransformLowercase", () => Command_ChangeCase(false) },
{ "DeleteLine", Command_DeleteLine },
{ "MoveLineDown", () => GetCurrentEditorElement().MoveLine(true) },
{ "MoveLineUp", () => GetCurrentEditorElement().MoveLine(false) },
{ "DupeLineDown", () => GetCurrentEditorElement().DuplicateLine(true) },
{ "DupeLineUp", () => GetCurrentEditorElement().DuplicateLine(false) },
{ "SearchReplace", Command_FindReplace },
{ "SearchDefinition", Command_OpenSPDef },
{ "CompileCurrent", () => Compile_SPScripts(false) },
{ "CompileAll", () => Compile_SPScripts() },
{ "CopyPlugins", Copy_Plugins },
{ "UploadFTP", FTPUpload_Plugins },
{ "StartServer", Server_Start },
{ "SendRCON", Server_Query },
};
}
#endregion
}