Skip to content

Commit 5f5fe28

Browse files
committed
move types into their own files
1 parent 92f4165 commit 5f5fe28

File tree

5 files changed

+40
-39
lines changed

5 files changed

+40
-39
lines changed

PdnKeyMapper/DummyEffect.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Diagnostics;
2-
using System.Drawing;
1+
using System.Drawing;
32
using PaintDotNet;
43
using PaintDotNet.Effects;
54

PdnKeyMapper/KeybindAction.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using System.Windows.Forms;
2+
3+
namespace PdnKeyMapper;
4+
5+
public record KeybindAction(string Name, Keys Shortcut, ToolStripMenuItem Item);

PdnKeyMapper/KeybindDialogue.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Collections;
2-
using System.ComponentModel;
32
using System.Drawing;
4-
using System.Text;
53
using System.Windows.Forms;
64
using BrightIdeasSoftware;
75
using PaintDotNet.Effects;
@@ -36,28 +34,28 @@ public KeybindDialogue()
3634
_keybindTree.CellEditFinishing += KeybindTreeOnCellEditFinishing;
3735

3836
_keybindTree.AllColumns.Add(new OLVColumn("Name", "Name") { Width = 450, AspectGetter = ActionNameFormatter });
39-
_keybindTree.AllColumns.Add(new OLVColumn("Shortcut", "Shortcut") { FillsFreeSpace = true, AspectGetter = ShortcutFormatter});
37+
_keybindTree.AllColumns.Add(new OLVColumn("Shortcut", "Shortcut") { FillsFreeSpace = true, AspectGetter = ShortcutFormatter });
4038
_keybindTree.RebuildColumns();
4139

4240
_keybindTree.SetObjects(PdnInternal.MainMenu.Items);
4341
_keybindTree.ExpandAll();
44-
42+
4543
CollectIdentifiers(PdnInternal.MainMenu, _itemIdentifiers);
4644
}
4745

4846
private void KeybindTreeOnCellEditFinishing(object sender, CellEditEventArgs e)
4947
{
5048
if (e.Cancel)
5149
return;
52-
50+
5351
if (e.RowObject is not KeybindAction ka)
5452
return;
5553

5654
var keys = Keys.None;
57-
55+
5856
if (!string.IsNullOrWhiteSpace((string)e.NewValue) && !KeybindManager.TryParseKeys((string)e.NewValue, out keys))
5957
return;
60-
58+
6159
if (keys != Keys.None && !ToolStripManager.IsValidShortcut(keys))
6260
return;
6361

@@ -67,13 +65,13 @@ private void KeybindTreeOnCellEditFinishing(object sender, CellEditEventArgs e)
6765
var config = KeybindManager.ReadConfig();
6866
config[itemId] = KeybindManager.StringifyKeys(keys);
6967
KeybindManager.WriteConfig(config);
70-
68+
7169
_keybindTree.SetObjects(PdnInternal.MainMenu.Items);
7270
}
7371

7472
private static void KeybindTreeOnCellEditStarting(object sender, CellEditEventArgs e)
7573
{
76-
if (e.Column.AspectName != "Shortcut")
74+
if (e.Column.AspectName != "Shortcut")
7775
e.Cancel = true;
7876
}
7977

@@ -92,7 +90,7 @@ private static void CollectIdentifiers(object control, Dictionary<string, string
9290
if (path.Length > 0)
9391
path += ".";
9492
path += dropDownItem.Name;
95-
foreach (var item in dropDownItem.DropDownItems)
93+
foreach (var item in dropDownItem.DropDownItems)
9694
CollectIdentifiers(item, actions, path);
9795

9896
if (dropDownItem.Name.Length > 0)

PdnKeyMapper/KeybindManager.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
using System.ComponentModel;
2-
using System.Diagnostics;
32
using System.Reflection;
43
using System.Text.Json;
5-
using System.Text.Json.Serialization;
64
using System.Windows.Forms;
75

86
namespace PdnKeyMapper;
97

10-
public record KeybindAction(string Name, Keys Shortcut, ToolStripMenuItem Item);
11-
12-
public class KeybindManager
8+
public static class KeybindManager
139
{
1410
public static void HookForm()
1511
{
@@ -106,26 +102,4 @@ public static bool TryParseKeys(string value, out Keys keys)
106102
return false;
107103
}
108104
}
109-
}
110-
111-
public static class TypeExtensions
112-
{
113-
public static object GetPrivateField(this Type t, object? instance, string name)
114-
{
115-
var flags = BindingFlags.NonPublic;
116-
117-
if (instance == null)
118-
flags |= BindingFlags.Static;
119-
else
120-
flags |= BindingFlags.Instance;
121-
122-
return t.GetField(name, flags).GetValue(instance);
123-
}
124-
125-
public static T GetPrivateField<T>(this Type t, object instance, string name)
126-
{
127-
if (t.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(instance) is not T value)
128-
throw new InvalidCastException();
129-
return value;
130-
}
131105
}

PdnKeyMapper/TypeExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Reflection;
2+
3+
namespace PdnKeyMapper;
4+
5+
public static class TypeExtensions
6+
{
7+
public static object GetPrivateField(this Type t, object? instance, string name)
8+
{
9+
var flags = BindingFlags.NonPublic;
10+
11+
if (instance == null)
12+
flags |= BindingFlags.Static;
13+
else
14+
flags |= BindingFlags.Instance;
15+
16+
return t.GetField(name, flags).GetValue(instance);
17+
}
18+
19+
public static T GetPrivateField<T>(this Type t, object instance, string name)
20+
{
21+
if (t.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(instance) is not T value)
22+
throw new InvalidCastException();
23+
return value;
24+
}
25+
}

0 commit comments

Comments
 (0)