-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMainForm.cs
70 lines (61 loc) · 2.1 KB
/
MainForm.cs
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
// Copyright Bastian Eicher
// Licensed under the MIT License
using System;
using System.Drawing;
using System.Windows.Forms;
using NanoByte.Common.Undo;
using NanoByte.StructureEditor.Sample.Controls;
namespace NanoByte.StructureEditor.Sample;
public class MainForm : Form
{
private readonly AddressBookEditor _editor = new()
{
Dock = DockStyle.Fill,
Padding = new Padding(8)
};
public MainForm()
{
SuspendLayout();
SetupComponents();
ResumeLayout(performLayout: false);
_editor.Open(CommandManager.For(SampleData.AddressBook));
}
private void SetupComponents()
{
Text = "Structure Editor Sample";
AutoScaleDimensions = new SizeF(6F, 13F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 600);
FormClosing += (_, e) => { e.Cancel = !_editor.Closing(); };
Controls.Add(_editor);
static ToolStripMenuItem MenuItem(string text, Action action, Keys hotKey = Keys.None)
{
var button = new ToolStripMenuItem {Text = text, ShortcutKeys = hotKey};
button.Click += (_, _) => action();
return button;
}
Controls.Add(new MenuStrip
{
Items =
{
new ToolStripMenuItem("&File")
{
DropDownItems =
{
MenuItem("&Open...", _editor.Open, hotKey: Keys.Control | Keys.O),
MenuItem("&Save...", () => _editor.Save(), hotKey: Keys.Control | Keys.S),
MenuItem("Save &As...", () => _editor.SaveAs())
}
},
new ToolStripMenuItem("&Edit")
{
DropDownItems =
{
MenuItem("&Undo", _editor.Undo, hotKey: Keys.Control | Keys.Z),
MenuItem("&Redo", _editor.Redo, hotKey: Keys.Control | Keys.Y)
}
}
}
});
}
}