-
Notifications
You must be signed in to change notification settings - Fork 2
/
OptionsForm.cs
223 lines (188 loc) · 6.96 KB
/
OptionsForm.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Tekla.Structures;
using Tekla.Structures.Model;
namespace TeklaToolbar
{
public partial class CustomiseForm : Form
{
public string strMacrosFolder = "";
public string strModelingMacrosFolder = "";
public string strTeklaToolbarFolder = "";
Model model = new Model();
Properties.Settings settings = new global::TeklaToolbar.Properties.Settings();
public CustomiseForm()
{
InitializeComponent();
}
private void Options_Load(object sender, EventArgs e)
{
treeView1.Nodes.Clear();
TreeViewSerializer serializer = new TreeViewSerializer();
serializer.DeserializeTreeView(treeView1);
model.GetAdvancedOption("XS_MACRO_DIRECTORY", ref strMacrosFolder);
strModelingMacrosFolder = strMacrosFolder + @"\modeling\";
strTeklaToolbarFolder = strMacrosFolder + @"\modeling\TeklaToolbar\";
DirectoryInfo MacrosFolder = new DirectoryInfo(strTeklaToolbarFolder);
if (MacrosFolder.Exists)
{
FileInfo[] files = MacrosFolder.GetFiles(".cs");
foreach (FileInfo macro in MacrosFolder.GetFiles("*.cs"))
{
ListViewItem listviewitem = new ListViewItem(macro.Name);
listviewitem.Tag = macro.FullName;
listView1.Items.Add(listviewitem);
}
}
treeView1.SelectedNode = new TreeNode();
}
private void btnSave_Click(object sender, EventArgs e)
{
}
private void newRootFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void newSubFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void insertMacroToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void moveUpToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void moveDownToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void insertSeperatorToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void OptionsForm_FormClosing(object sender, FormClosingEventArgs e)
{
TreeViewSerializer serializer = new TreeViewSerializer();
serializer.SerializeTreeView(treeView1);
}
private void newMainFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
TreeNode tn = new TreeNode("New Node");
tn.Tag = "Folder";
treeView1.BeginUpdate();
treeView1.Nodes.Add(tn);
treeView1.EndUpdate();
treeView1.SelectedNode = null;
}
catch { }
}
private void newSubFolderToolStripMenuItem1_Click(object sender, EventArgs e)
{
try
{
TreeNode tn = new TreeNode("New Node");
tn.Tag = "Folder";
treeView1.BeginUpdate();
if (treeView1.SelectedNode == null) treeView1.Nodes.Add(tn);
else if (treeView1.SelectedNode != null) treeView1.SelectedNode.Nodes.Add(tn);
treeView1.EndUpdate();
}
catch { }
}
private void treeView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete) if (treeView1.SelectedNode != null) treeView1.SelectedNode.Remove();
if (e.KeyCode == Keys.F2) treeView1.SelectedNode.BeginEdit();
}
private void moveUpToolStripButton_Click(object sender, EventArgs e)
{
Extensions.MoveNodeUp(treeView1.SelectedNode);
}
private void moveDownToolStripButton_Click(object sender, EventArgs e)
{
Extensions.MoveNodeDown(treeView1.SelectedNode);
}
private void addMacroToolStripButton_Click(object sender, EventArgs e)
{
if (treeView1.SelectedNode != null && treeView1.SelectedNode.Tag.ToString() == "Folder" && listView1.SelectedItems != null)
{
ListViewItem listviewitem = listView1.SelectedItems[0];
TreeNode tn = new TreeNode(listviewitem.Text);
tn.Tag = listviewitem.Tag.ToString();
treeView1.BeginUpdate();
treeView1.SelectedNode.Nodes.Add(tn);
treeView1.EndUpdate();
}
}
private void addSeparatorToolStripButton_Click(object sender, EventArgs e)
{
try
{
TreeNode tn = new TreeNode("-");
treeView1.BeginUpdate();
if (treeView1.SelectedNode == null) treeView1.Nodes.Add(tn);
else if (treeView1.SelectedNode != null) treeView1.SelectedNode.Nodes.Add(tn);
treeView1.EndUpdate();
treeView1.SelectedNode = null;
}
catch { }
}
}
public static class Extensions
{
public static void MoveNodeUp(TreeNode node)
{
TreeNode parent = node.Parent;
TreeView view = node.TreeView;
if (parent != null)
{
int index = parent.Nodes.IndexOf(node);
if (index > 0)
{
parent.Nodes.RemoveAt(index);
parent.Nodes.Insert(index - 1, node);
}
}
else if (node.TreeView.Nodes.Contains(node))
{
int index = view.Nodes.IndexOf(node);
if (index > 0)
{
view.Nodes.RemoveAt(index);
view.Nodes.Insert(index - 1, node);
}
}
node.TreeView.SelectedNode = node;
}
public static void MoveNodeDown(TreeNode node)
{
TreeNode parent = node.Parent;
TreeView view = node.TreeView;
if (parent != null)
{
int index = parent.Nodes.IndexOf(node);
if (index < parent.Nodes.Count - 1)
{
parent.Nodes.RemoveAt(index);
parent.Nodes.Insert(index + 1, node);
}
}
else if (node.TreeView.Nodes.Contains(node))
{
int index = view.Nodes.IndexOf(node);
if (index < view.Nodes.Count - 1)
{
view.Nodes.RemoveAt(index);
view.Nodes.Insert(index + 1, node);
}
}
node.TreeView.SelectedNode = node;
}
}
}