4
4
using System . Xml ;
5
5
using SPCode . Utils ;
6
6
7
- namespace SPCode . Interop ;
8
-
9
- public class HotkeyControl
7
+ namespace SPCode . Interop
10
8
{
11
- public static Dictionary < string , string > DefaultHotkeys = new ( )
9
+ public class HotkeyControl
12
10
{
13
- { "New" , "Ctrl+N" } ,
14
- { "NewTemplate" , "Ctrl+Shift+N" } ,
15
- { "Open" , "Ctrl+O" } ,
16
- { "ReopenLastClosedTab" , "Ctrl+Shift+T" } ,
17
- { "Save" , "Ctrl+S" } ,
18
- { "SaveAll" , "Ctrl+Shift+S" } ,
19
- { "SaveAs" , "Ctrl+Alt+S" } ,
20
- { "Close" , "Ctrl+W" } ,
21
- { "CloseAll" , "Ctrl+Shift+W" } ,
22
- { "FoldingsExpand" , "Ctrl+P" } ,
23
- { "FoldingsCollapse" , "Ctrl+Shift+P" } ,
24
- { "ReformatCurrent" , "Ctrl+R" } ,
25
- { "ReformatAll" , "Ctrl+Shift+R" } ,
26
- { "GoToLine" , "Ctrl+G" } ,
27
- { "CommentLine" , "Ctrl+K" } ,
28
- { "UncommentLine" , "Ctrl+Shift+K" } ,
29
- { "TransformUppercase" , "Ctrl+U" } ,
30
- { "TransformLowercase" , "Ctrl+Shift+U" } ,
31
- { "DeleteLine" , "Ctrl+D" } ,
32
- { "MoveLineDown" , "Ctrl+Down" } ,
33
- { "MoveLineUp" , "Ctrl+Up" } ,
34
- { "DupeLineDown" , "Ctrl+Alt+Down" } ,
35
- { "DupeLineUp" , "Ctrl+Alt+Up" } ,
36
- { "SearchReplace" , "Ctrl+F" } ,
37
- { "SearchDefinition" , "Ctrl+Shift+F" } ,
38
- { "CompileCurrent" , "F6" } ,
39
- { "CompileAll" , "F5" } ,
40
- { "CopyPlugins" , "F7" } ,
41
- { "UploadFTP" , "F8" } ,
42
- { "StartServer" , "F9" } ,
43
- { "SendRCON" , "F10" } ,
44
- } ;
11
+ public static Dictionary < string , string > DefaultHotkeys = new ( )
12
+ {
13
+ { "New" , "Ctrl+N" } ,
14
+ { "NewTemplate" , "Ctrl+Shift+N" } ,
15
+ { "Open" , "Ctrl+O" } ,
16
+ { "ReopenLastClosedTab" , "Ctrl+Shift+T" } ,
17
+ { "Save" , "Ctrl+S" } ,
18
+ { "SaveAll" , "Ctrl+Shift+S" } ,
19
+ { "SaveAs" , "Ctrl+Alt+S" } ,
20
+ { "Close" , "Ctrl+W" } ,
21
+ { "CloseAll" , "Ctrl+Shift+W" } ,
22
+ { "FoldingsExpand" , "Ctrl+P" } ,
23
+ { "FoldingsCollapse" , "Ctrl+Shift+P" } ,
24
+ { "ReformatCurrent" , "Ctrl+R" } ,
25
+ { "ReformatAll" , "Ctrl+Shift+R" } ,
26
+ { "GoToLine" , "Ctrl+G" } ,
27
+ { "CommentLine" , "Ctrl+K" } ,
28
+ { "UncommentLine" , "Ctrl+Shift+K" } ,
29
+ { "TransformUppercase" , "Ctrl+U" } ,
30
+ { "TransformLowercase" , "Ctrl+Shift+U" } ,
31
+ { "DeleteLine" , "Ctrl+D" } ,
32
+ { "MoveLineDown" , "Ctrl+Down" } ,
33
+ { "MoveLineUp" , "Ctrl+Up" } ,
34
+ { "DupeLineDown" , "Ctrl+Alt+Down" } ,
35
+ { "DupeLineUp" , "Ctrl+Alt+Up" } ,
36
+ { "SearchReplace" , "Ctrl+F" } ,
37
+ { "SearchDefinition" , "Ctrl+Shift+F" } ,
38
+ { "CompileCurrent" , "F6" } ,
39
+ { "CompileAll" , "F5" } ,
40
+ { "CopyPlugins" , "F7" } ,
41
+ { "UploadFTP" , "F8" } ,
42
+ { "StartServer" , "F9" } ,
43
+ { "SendRCON" , "F10" } ,
44
+ } ;
45
45
46
- public static Dictionary < string , string > RestrictedHotkeys = new ( )
47
- {
48
- { "Paste" , "Ctrl+V" } ,
49
- { "Copy" , "Ctrl+C" } ,
50
- { "Cut" , "Ctrl+X" } ,
51
- { "Undo" , "Ctrl+Z" } ,
52
- { "Redo" , "Ctrl+Y" } ,
53
- { "SelectAll" , "Ctrl+A" }
54
- } ;
46
+ public static Dictionary < string , string > RestrictedHotkeys = new ( )
47
+ {
48
+ { "Paste" , "Ctrl+V" } ,
49
+ { "Copy" , "Ctrl+C" } ,
50
+ { "Cut" , "Ctrl+X" } ,
51
+ { "Undo" , "Ctrl+Z" } ,
52
+ { "Redo" , "Ctrl+Y" } ,
53
+ { "SelectAll" , "Ctrl+A" }
54
+ } ;
55
55
56
- /// <summary>
57
- /// Checks if there are new Hotkeys that haven't been added to the Hotkeys file <br>
58
- /// and buffers all Hotkeys to an array in memory.
59
- /// </summary>
60
- public static void CheckAndBufferHotkeys ( )
61
- {
62
- try
56
+ /// <summary>
57
+ /// Checks if there are new Hotkeys that haven't been added to the Hotkeys file <br>
58
+ /// and buffers all Hotkeys to an array in memory.
59
+ /// </summary>
60
+ public static void CheckAndBufferHotkeys ( )
63
61
{
64
- // Load the current Hotkeys file
65
- Program . HotkeysList = new ( ) ;
66
- var document = new XmlDocument ( ) ;
67
- document . Load ( Constants . HotkeysFile ) ;
62
+ try
63
+ {
64
+ // Load the current Hotkeys file
65
+ Program . HotkeysList = new ( ) ;
66
+ var document = new XmlDocument ( ) ;
67
+ document . Load ( Constants . HotkeysFile ) ;
68
68
69
- // Compare with the default hotkeys to check for new commands
70
- var xmlNodes = document . ChildNodes [ 0 ] . ChildNodes . Cast < XmlNode > ( ) . ToList ( ) ;
71
- var defaultHksCount = DefaultHotkeys . Count ;
69
+ // Compare with the default hotkeys to check for new commands
70
+ var xmlNodes = document . ChildNodes [ 0 ] . ChildNodes . Cast < XmlNode > ( ) . ToList ( ) ;
71
+ var defaultHksCount = DefaultHotkeys . Count ;
72
72
73
- // If the count is not equal, there's a new hotkey to be added to the file
74
- if ( xmlNodes . Count != defaultHksCount )
75
- {
76
- // Regular for to get the index
77
- for ( var i = 0 ; i < defaultHksCount ; i ++ )
73
+ // If the count is not equal, there's a new hotkey to be added to the file
74
+ if ( xmlNodes . Count != defaultHksCount )
78
75
{
79
- var currentHk = DefaultHotkeys . ElementAt ( i ) ;
80
- if ( ! xmlNodes . Any ( x => x . Name . Equals ( DefaultHotkeys . ElementAt ( i ) . Key ) ) )
76
+ // Regular for to get the index
77
+ for ( var i = 0 ; i < defaultHksCount ; i ++ )
81
78
{
82
- var element = document . CreateElement ( string . Empty , currentHk . Key , string . Empty ) ;
83
- var text = document . CreateTextNode ( currentHk . Value ) ;
84
- element . AppendChild ( text ) ;
85
- document . ChildNodes [ 0 ] . InsertBefore ( element , document . ChildNodes [ 0 ] . ChildNodes [ i ] ) ;
79
+ var currentHk = DefaultHotkeys . ElementAt ( i ) ;
80
+ if ( ! xmlNodes . Any ( x => x . Name . Equals ( DefaultHotkeys . ElementAt ( i ) . Key ) ) )
81
+ {
82
+ var element = document . CreateElement ( string . Empty , currentHk . Key , string . Empty ) ;
83
+ var text = document . CreateTextNode ( currentHk . Value ) ;
84
+ element . AppendChild ( text ) ;
85
+ document . ChildNodes [ 0 ] . InsertBefore ( element , document . ChildNodes [ 0 ] . ChildNodes [ i ] ) ;
86
+ }
86
87
}
88
+ document . Save ( Constants . HotkeysFile ) ;
89
+ xmlNodes = document . ChildNodes [ 0 ] . ChildNodes . Cast < XmlNode > ( ) . ToList ( ) ;
87
90
}
88
- document . Save ( Constants . HotkeysFile ) ;
89
- xmlNodes = document . ChildNodes [ 0 ] . ChildNodes . Cast < XmlNode > ( ) . ToList ( ) ;
90
- }
91
91
92
- xmlNodes . ForEach ( x =>
93
- {
94
- var hki = new HotkeyInfo ( new Hotkey ( x . InnerText ) , x . Name ) ;
95
- Program . HotkeysList . Add ( hki ) ;
96
- } ) ;
92
+ xmlNodes . ForEach ( x =>
93
+ {
94
+ var hki = new HotkeyInfo ( new Hotkey ( x . InnerText ) , x . Name ) ;
95
+ Program . HotkeysList . Add ( hki ) ;
96
+ } ) ;
97
97
98
+ }
99
+ catch ( Exception ex )
100
+ {
101
+ throw new Exception ( "Error while checking and buffering the hotkeys" , ex ) ;
102
+ }
98
103
}
99
- catch ( Exception ex )
100
- {
101
- throw new Exception ( "Error while checking and buffering the hotkeys" , ex ) ;
102
- }
103
- }
104
104
105
- /// <summary>
106
- /// Creates the default hotkeys, stores them in an XML and buffers them.
107
- /// </summary>
108
- public static void CreateDefaultHotkeys ( )
109
- {
110
- try
105
+ /// <summary>
106
+ /// Creates the default hotkeys, stores them in an XML and buffers them.
107
+ /// </summary>
108
+ public static void CreateDefaultHotkeys ( )
111
109
{
112
- // Create the XML document
113
- var document = new XmlDocument ( ) ;
110
+ try
111
+ {
112
+ // Create the XML document
113
+ var document = new XmlDocument ( ) ;
114
114
115
- var rootElement = document . CreateElement ( string . Empty , "Hotkeys" , string . Empty ) ;
116
- document . AppendChild ( rootElement ) ;
115
+ var rootElement = document . CreateElement ( string . Empty , "Hotkeys" , string . Empty ) ;
116
+ document . AppendChild ( rootElement ) ;
117
117
118
- // Fill it with the default hotkeys from the dictionary
119
- foreach ( var item in DefaultHotkeys )
120
- {
121
- var element = document . CreateElement ( string . Empty , item . Key , string . Empty ) ;
122
- var text = document . CreateTextNode ( item . Value ) ;
123
- element . AppendChild ( text ) ;
124
- rootElement . AppendChild ( element ) ;
125
- }
118
+ // Fill it with the default hotkeys from the dictionary
119
+ foreach ( var item in DefaultHotkeys )
120
+ {
121
+ var element = document . CreateElement ( string . Empty , item . Key , string . Empty ) ;
122
+ var text = document . CreateTextNode ( item . Value ) ;
123
+ element . AppendChild ( text ) ;
124
+ rootElement . AppendChild ( element ) ;
125
+ }
126
126
127
- // Buffer hotkeys in global HotkeyInfo list
128
- Program . HotkeysList = new ( ) ;
129
- foreach ( XmlNode node in document . ChildNodes [ 0 ] . ChildNodes )
127
+ // Buffer hotkeys in global HotkeyInfo list
128
+ Program . HotkeysList = new ( ) ;
129
+ foreach ( XmlNode node in document . ChildNodes [ 0 ] . ChildNodes )
130
+ {
131
+ Program . HotkeysList . Add ( new HotkeyInfo ( new Hotkey ( node . InnerText ) , node . Name ) ) ;
132
+ }
133
+
134
+ document . Save ( Constants . HotkeysFile ) ;
135
+ }
136
+ catch ( Exception ex )
130
137
{
131
- Program . HotkeysList . Add ( new HotkeyInfo ( new Hotkey ( node . InnerText ) , node . Name ) ) ;
138
+ throw new Exception ( "Error while creating the default hotkeys" , ex ) ;
132
139
}
133
-
134
- document . Save ( Constants . HotkeysFile ) ;
135
- }
136
- catch ( Exception ex )
137
- {
138
- throw new Exception ( "Error while creating the default hotkeys" , ex ) ;
139
140
}
140
141
}
141
- }
142
+ }
0 commit comments