Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 39bae28

Browse files
committed
file scoped namespace + switch exp
1 parent 1456263 commit 39bae28

File tree

95 files changed

+14358
-14478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+14358
-14478
lines changed

Interop/ConfigControl.cs

Lines changed: 144 additions & 145 deletions
Large diffs are not rendered by default.

Interop/HotkeyControl.cs

Lines changed: 122 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -6,152 +6,151 @@
66
using System.Xml;
77
using SPCode.Utils;
88

9-
namespace SPCode.Interop
9+
namespace SPCode.Interop;
10+
11+
public class HotkeyControl
1012
{
11-
public class HotkeyControl
13+
public static Dictionary<string, string> DefaultHotkeys = new()
1214
{
13-
public static Dictionary<string, string> DefaultHotkeys = new()
14-
{
15-
{ "New", "Ctrl+N" },
16-
{ "NewTemplate", "Ctrl+Shift+N" },
17-
{ "Open", "Ctrl+O" },
18-
{ "ReopenLastClosedTab", "Ctrl+Shift+T" },
19-
{ "Save", "Ctrl+S" },
20-
{ "SaveAll", "Ctrl+Shift+S" },
21-
{ "SaveAs", "Ctrl+Alt+S" },
22-
{ "Close", "Ctrl+W" },
23-
{ "CloseAll", "Ctrl+Shift+W" },
24-
{ "FoldingsExpand", "Ctrl+P" },
25-
{ "FoldingsCollapse", "Ctrl+Shift+P" },
26-
{ "ReformatCurrent", "Ctrl+R" },
27-
{ "ReformatAll", "Ctrl+Shift+R" },
28-
{ "GoToLine", "Ctrl+G" },
29-
{ "CommentLine", "Ctrl+K" },
30-
{ "UncommentLine", "Ctrl+Shift+K" },
31-
{ "TransformUppercase", "Ctrl+U" },
32-
{ "TransformLowercase", "Ctrl+Shift+U" },
33-
{ "DeleteLine", "Ctrl+D" },
34-
{ "MoveLineDown", "Ctrl+Down" },
35-
{ "MoveLineUp", "Ctrl+Up" },
36-
{ "DupeLineDown", "Ctrl+Alt+Down" },
37-
{ "DupeLineUp", "Ctrl+Alt+Up" },
38-
{ "SearchReplace", "Ctrl+F" },
39-
{ "SearchDefinition", "Ctrl+Shift+F" },
40-
{ "CompileCurrent", "F6" },
41-
{ "CompileAll", "F5" },
42-
{ "CopyPlugins", "F7" },
43-
{ "UploadFTP", "F8" },
44-
{ "StartServer", "F9" },
45-
{ "SendRCON", "F10" },
46-
};
15+
{ "New", "Ctrl+N" },
16+
{ "NewTemplate", "Ctrl+Shift+N" },
17+
{ "Open", "Ctrl+O" },
18+
{ "ReopenLastClosedTab", "Ctrl+Shift+T" },
19+
{ "Save", "Ctrl+S" },
20+
{ "SaveAll", "Ctrl+Shift+S" },
21+
{ "SaveAs", "Ctrl+Alt+S" },
22+
{ "Close", "Ctrl+W" },
23+
{ "CloseAll", "Ctrl+Shift+W" },
24+
{ "FoldingsExpand", "Ctrl+P" },
25+
{ "FoldingsCollapse", "Ctrl+Shift+P" },
26+
{ "ReformatCurrent", "Ctrl+R" },
27+
{ "ReformatAll", "Ctrl+Shift+R" },
28+
{ "GoToLine", "Ctrl+G" },
29+
{ "CommentLine", "Ctrl+K" },
30+
{ "UncommentLine", "Ctrl+Shift+K" },
31+
{ "TransformUppercase", "Ctrl+U" },
32+
{ "TransformLowercase", "Ctrl+Shift+U" },
33+
{ "DeleteLine", "Ctrl+D" },
34+
{ "MoveLineDown", "Ctrl+Down" },
35+
{ "MoveLineUp", "Ctrl+Up" },
36+
{ "DupeLineDown", "Ctrl+Alt+Down" },
37+
{ "DupeLineUp", "Ctrl+Alt+Up" },
38+
{ "SearchReplace", "Ctrl+F" },
39+
{ "SearchDefinition", "Ctrl+Shift+F" },
40+
{ "CompileCurrent", "F6" },
41+
{ "CompileAll", "F5" },
42+
{ "CopyPlugins", "F7" },
43+
{ "UploadFTP", "F8" },
44+
{ "StartServer", "F9" },
45+
{ "SendRCON", "F10" },
46+
};
4747

48-
public static Dictionary<string, string> RestrictedHotkeys = new()
49-
{
50-
{ "Paste", "Ctrl+V" },
51-
{ "Copy", "Ctrl+C" },
52-
{ "Cut", "Ctrl+X" },
53-
{ "Undo", "Ctrl+Z" },
54-
{ "Redo", "Ctrl+Y" },
55-
{ "SelectAll", "Ctrl+A" }
56-
};
48+
public static Dictionary<string, string> RestrictedHotkeys = new()
49+
{
50+
{ "Paste", "Ctrl+V" },
51+
{ "Copy", "Ctrl+C" },
52+
{ "Cut", "Ctrl+X" },
53+
{ "Undo", "Ctrl+Z" },
54+
{ "Redo", "Ctrl+Y" },
55+
{ "SelectAll", "Ctrl+A" }
56+
};
5757

58-
/// <summary>
59-
/// Checks if there are new Hotkeys that haven't been added to the Hotkeys file <br>
60-
/// and buffers all Hotkeys to an array in memory.
61-
/// </summary>
62-
public static void CheckAndBufferHotkeys()
58+
/// <summary>
59+
/// Checks if there are new Hotkeys that haven't been added to the Hotkeys file <br>
60+
/// and buffers all Hotkeys to an array in memory.
61+
/// </summary>
62+
public static void CheckAndBufferHotkeys()
63+
{
64+
try
6365
{
64-
try
65-
{
66-
// Load the current Hotkeys file
67-
Program.HotkeysList = new();
68-
var document = new XmlDocument();
69-
document.Load(Constants.HotkeysFile);
66+
// Load the current Hotkeys file
67+
Program.HotkeysList = new();
68+
var document = new XmlDocument();
69+
document.Load(Constants.HotkeysFile);
7070

71-
// Compare with the default hotkeys to check for new commands
72-
var xmlNodes = document.ChildNodes[0].ChildNodes.Cast<XmlNode>().ToList();
73-
var defaultHksCount = DefaultHotkeys.Count;
71+
// Compare with the default hotkeys to check for new commands
72+
var xmlNodes = document.ChildNodes[0].ChildNodes.Cast<XmlNode>().ToList();
73+
var defaultHksCount = DefaultHotkeys.Count;
7474

75-
// If the count is not equal, there's a new hotkey to be added to the file
76-
if (xmlNodes.Count != defaultHksCount)
75+
// If the count is not equal, there's a new hotkey to be added to the file
76+
if (xmlNodes.Count != defaultHksCount)
77+
{
78+
// Regular for to get the index
79+
for (var i = 0; i < defaultHksCount; i++)
7780
{
78-
// Regular for to get the index
79-
for (var i = 0; i < defaultHksCount; i++)
81+
var currentHk = DefaultHotkeys.ElementAt(i);
82+
if (!xmlNodes.Any(x => x.Name.Equals(DefaultHotkeys.ElementAt(i).Key)))
8083
{
81-
var currentHk = DefaultHotkeys.ElementAt(i);
82-
if (!xmlNodes.Any(x => x.Name.Equals(DefaultHotkeys.ElementAt(i).Key)))
83-
{
84-
var element = document.CreateElement(string.Empty, currentHk.Key, string.Empty);
85-
var text = document.CreateTextNode(currentHk.Value);
86-
element.AppendChild(text);
87-
document.ChildNodes[0].InsertBefore(element, document.ChildNodes[0].ChildNodes[i]);
88-
}
84+
var element = document.CreateElement(string.Empty, currentHk.Key, string.Empty);
85+
var text = document.CreateTextNode(currentHk.Value);
86+
element.AppendChild(text);
87+
document.ChildNodes[0].InsertBefore(element, document.ChildNodes[0].ChildNodes[i]);
8988
}
90-
document.Save(Constants.HotkeysFile);
91-
xmlNodes = document.ChildNodes[0].ChildNodes.Cast<XmlNode>().ToList();
9289
}
93-
94-
xmlNodes.ForEach(x =>
95-
{
96-
var hki = new HotkeyInfo(new Hotkey(x.InnerText), x.Name);
97-
Program.HotkeysList.Add(hki);
98-
});
99-
90+
document.Save(Constants.HotkeysFile);
91+
xmlNodes = document.ChildNodes[0].ChildNodes.Cast<XmlNode>().ToList();
10092
}
101-
catch (XmlException ex)
93+
94+
xmlNodes.ForEach(x =>
10295
{
103-
var invalidHotkeysFile = Constants.HotkeysFile + ".invalid";
104-
if (File.Exists(invalidHotkeysFile))
105-
{
106-
File.Delete(invalidHotkeysFile);
107-
}
108-
File.Move(Constants.HotkeysFile, invalidHotkeysFile);
109-
CreateDefaultHotkeys();
110-
MessageBox.Show("There was an error parsing the Hotkeys.xml file.\n" +
111-
$"It has been renamed to {invalidHotkeysFile}, and a new one was created.\n" +
112-
$"Details: {ex.Message}", "SPCode Error");
113-
}
114-
catch (Exception ex)
96+
var hki = new HotkeyInfo(new Hotkey(x.InnerText), x.Name);
97+
Program.HotkeysList.Add(hki);
98+
});
99+
100+
}
101+
catch (XmlException ex)
102+
{
103+
var invalidHotkeysFile = Constants.HotkeysFile + ".invalid";
104+
if (File.Exists(invalidHotkeysFile))
115105
{
116-
throw new Exception("Error while checking and buffering the hotkeys", ex);
106+
File.Delete(invalidHotkeysFile);
117107
}
108+
File.Move(Constants.HotkeysFile, invalidHotkeysFile);
109+
CreateDefaultHotkeys();
110+
MessageBox.Show("There was an error parsing the Hotkeys.xml file.\n" +
111+
$"It has been renamed to {invalidHotkeysFile}, and a new one was created.\n" +
112+
$"Details: {ex.Message}", "SPCode Error");
118113
}
119-
120-
/// <summary>
121-
/// Creates the default hotkeys, stores them in an XML and buffers them.
122-
/// </summary>
123-
public static void CreateDefaultHotkeys()
114+
catch (Exception ex)
124115
{
125-
try
126-
{
127-
// Create the XML document
128-
var document = new XmlDocument();
116+
throw new Exception("Error while checking and buffering the hotkeys", ex);
117+
}
118+
}
129119

130-
var rootElement = document.CreateElement(string.Empty, "Hotkeys", string.Empty);
131-
document.AppendChild(rootElement);
120+
/// <summary>
121+
/// Creates the default hotkeys, stores them in an XML and buffers them.
122+
/// </summary>
123+
public static void CreateDefaultHotkeys()
124+
{
125+
try
126+
{
127+
// Create the XML document
128+
var document = new XmlDocument();
132129

133-
// Fill it with the default hotkeys from the dictionary
134-
foreach (var item in DefaultHotkeys)
135-
{
136-
var element = document.CreateElement(string.Empty, item.Key, string.Empty);
137-
var text = document.CreateTextNode(item.Value);
138-
element.AppendChild(text);
139-
rootElement.AppendChild(element);
140-
}
130+
var rootElement = document.CreateElement(string.Empty, "Hotkeys", string.Empty);
131+
document.AppendChild(rootElement);
141132

142-
// Buffer hotkeys in global HotkeyInfo list
143-
Program.HotkeysList = new();
144-
foreach (XmlNode node in document.ChildNodes[0].ChildNodes)
145-
{
146-
Program.HotkeysList.Add(new HotkeyInfo(new Hotkey(node.InnerText), node.Name));
147-
}
148-
149-
document.Save(Constants.HotkeysFile);
133+
// Fill it with the default hotkeys from the dictionary
134+
foreach (var item in DefaultHotkeys)
135+
{
136+
var element = document.CreateElement(string.Empty, item.Key, string.Empty);
137+
var text = document.CreateTextNode(item.Value);
138+
element.AppendChild(text);
139+
rootElement.AppendChild(element);
150140
}
151-
catch (Exception ex)
141+
142+
// Buffer hotkeys in global HotkeyInfo list
143+
Program.HotkeysList = new();
144+
foreach (XmlNode node in document.ChildNodes[0].ChildNodes)
152145
{
153-
throw new Exception("Error while creating the default hotkeys", ex);
146+
Program.HotkeysList.Add(new HotkeyInfo(new Hotkey(node.InnerText), node.Name));
154147
}
148+
149+
document.Save(Constants.HotkeysFile);
150+
}
151+
catch (Exception ex)
152+
{
153+
throw new Exception("Error while creating the default hotkeys", ex);
155154
}
156155
}
157156
}

Interop/LoggingControl.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
using System;
22
using System.Windows.Controls;
33

4-
namespace SPCode.Interop
4+
namespace SPCode.Interop;
5+
6+
public static class LoggingControl
57
{
6-
public static class LoggingControl
8+
public static TextBox LogBox;
9+
public static void LogAction(string message, int newLines = 1)
710
{
8-
public static TextBox LogBox;
9-
public static void LogAction(string message, int newLines = 1)
11+
try
12+
{
13+
LogBox.Text += $"[{DateTime.Now:HH:mm:ss}] {message} {new string('\n', newLines)}";
14+
LogBox.CaretIndex = LogBox.Text.Length;
15+
LogBox.ScrollToEnd();
16+
}
17+
catch (Exception)
1018
{
11-
try
12-
{
13-
LogBox.Text += $"[{DateTime.Now:HH:mm:ss}] {message} {new string('\n', newLines)}";
14-
LogBox.CaretIndex = LogBox.Text.Length;
15-
LogBox.ScrollToEnd();
16-
}
17-
catch (Exception)
18-
{
1919

20-
}
2120
}
2221
}
2322
}

0 commit comments

Comments
 (0)