-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditor.cs
More file actions
161 lines (140 loc) · 4.79 KB
/
Editor.cs
File metadata and controls
161 lines (140 loc) · 4.79 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.VisualBasic;
namespace ED7Editor
{
public partial class Editor : Form
{
public Editor(EditorBase editor)
{
this.editor = editor;
InitializeComponent();
Text = editor.ToString();
this.editor.Update += euh = new EventHandler(editor_Update);
}
EventHandler euh;
void editor_Update(object sender, EventArgs e)
{
var sel = listBox1.SelectedItem as IndexedItem;
listBox1.Items.Clear();
foreach (var item in editor.GetList())
{
listBox1.Items.Add(item);
}
if (sel != null)
SelectItem(sel.Index);
}
EditorBase editor;
private void ItemEditor_Load(object sender, EventArgs e)
{
editor.Refresh();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var x = listBox1.SelectedItem as IndexedItem;
propertyGrid1.SelectedObject = x == null ? null : x.Item;
var root = propertyGrid1.SelectedGridItem;
if (root != null)
{
while (root.Parent != null) root = root.Parent;
AutoExpand(root);
}
}
void AutoExpand(GridItem item)
{
foreach (GridItem property in item.GridItems)
{
AutoExpand(property);
var descriptor = property.PropertyDescriptor;
if (descriptor != null &&
descriptor.Attributes.Contains(new AutoExpandAttribute()))
property.Expanded = true;
}
}
private void Add_Click(object sender, EventArgs e)
{
int index;
string result = Interaction.InputBox("请输入编号:");
if (string.IsNullOrEmpty(result)) return;
if (!int.TryParse(result, out index))
{
MessageBox.Show("请输入一个数字");
return;
}
if (!editor.Add(index))
{
MessageBox.Show("请输入合法的编号(编号重复)");
return;
}
Helper.MakeDirty();
editor.Refresh();
SelectItem(index);
}
private void SelectItem(int index)
{
for (int i = 0; i < listBox1.Items.Count; i++)
if ((listBox1.Items[i] as IndexedItem).Index == index)
{
listBox1.SelectedIndex = i;
}
}
private void Remove_Click(object sender, EventArgs e)
{
if (MessageBox.Show(String.Format("确定要删除“{0}”吗?", listBox1.SelectedItem),
"确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
if (editor.Remove((listBox1.SelectedItem as IndexedItem).Index))
{
Helper.MakeDirty();
editor.Refresh();
}
}
private void Refresh_Click(object sender, EventArgs e)
{
editor.Refresh();
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
Remove.Visible = listBox1.SelectedItems.Count == 1;
}
object clipboard;
private void Copy_Click(object sender, EventArgs e)
{
clipboard = propertyGrid1.SelectedObject;
}
private void Paste_Click(object sender, EventArgs e)
{
if (editor.CopyTo(clipboard, propertyGrid1.SelectedObject))
Helper.MakeDirty();
propertyGrid1.Refresh();
}
private void contextMenuStrip2_Opening(object sender, CancelEventArgs e)
{
Paste.Enabled = clipboard != null;
}
private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
Helper.MakeDirty();
propertyGrid1.Refresh();
}
private void Editor_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
}
private void Editor_Activated(object sender, EventArgs e)
{
this.Opacity = 1;
}
private void Editor_Deactivate(object sender, EventArgs e)
{
this.Opacity = 0.8;
}
}
}