123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Windows.Forms;
- using Autodesk.Revit.DB;
- using SAGY.DotNetUtils;
- using SAGY.DotNetUtils.Configration;
- using SAGY.DotNetUtils.WinForms;
- using TSZ.RevitMenu.Configuration;
- using ComboBox = Autodesk.Revit.UI.ComboBox;
- using Tab = TSZ.RevitMenu.Configuration.Tab;
- namespace SAGY.RevitMenu
- {
- public class SetMenuForm : BaseForm
- {
- private System.Windows.Forms.Button bn_Up;
- private System.Windows.Forms.Button btn_Add;
- private System.Windows.Forms.Button btn_Cancle;
- private System.Windows.Forms.Button btn_Delete;
- private System.Windows.Forms.Button btn_Down;
- private System.Windows.Forms.Button btn_OK;
- private System.Windows.Forms.Button btn_ReSet;
- private ComboBox comboBox1;
- private ComboBox comboBox2;
- private IContainer components;
- private GroupBox groupBox1;
- private GroupBox groupBox2;
- private Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> newDic = new Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>>();
- private Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> originDic = new Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>>();
- private TreeView treeView1;
- private TreeView treeView2;
- private List<string> xmlFile = new List<string>();
- public SetMenuForm()
- {
- this.InitializeComponent();
- }
- private void bn_Up_Click(object sender, EventArgs e)
- {
- if ((this.treeView2.SelectedNode != null) && (this.treeView2.SelectedNode.Parent != null))
- {
- if (this.treeView2.SelectedNode.Index > 0)
- {
- TreeNode selectedNode = this.treeView2.SelectedNode;
- int index = this.treeView2.SelectedNode.Index;
- this.treeView2.SelectedNode.Parent.Nodes.RemoveAt(index--);
- this.treeView2.SelectedNode.Parent.Nodes.Insert(index, selectedNode);
- }
- else if (this.treeView2.SelectedNode.Parent.Index > 0)
- {
- TreeNode node = this.treeView2.SelectedNode;
- int num2 = this.treeView2.SelectedNode.Index;
- int num3 = this.treeView2.SelectedNode.Parent.Index;
- this.treeView2.SelectedNode.Parent.Nodes.RemoveAt(num2);
- this.treeView2.Nodes[num3 - 1].Nodes.Add(node);
- }
- this.ChangeData();
- }
- }
- private void btn_Add_Click(object sender, EventArgs e)
- {
- Dictionary<TreeNode, TreeNode> dictionary = new Dictionary<TreeNode, TreeNode>();
- foreach (TreeNode node in this.treeView1.Nodes)
- {
- if ((node.Nodes != null) || (node.Nodes.Count > 0))
- {
- foreach (TreeNode node2 in node.Nodes)
- {
- if (node2.Checked)
- {
- dictionary.Add(node2, node2.Parent);
- }
- }
- }
- }
- List<string> list = new List<string>();
- List<TreeNode> list2 = new List<TreeNode>();
- foreach (KeyValuePair<TreeNode, TreeNode> pair in dictionary)
- {
- if (!list.Contains(pair.Value.Text))
- {
- list.Add(pair.Value.Text);
- TreeNode item = new TreeNode(pair.Value.Text) {
- Tag = pair.Value.Tag
- };
- list2.Add(item);
- }
- }
- int num = 0;
- foreach (string str in list)
- {
- bool flag = false;
- foreach (TreeNode node4 in this.treeView2.Nodes)
- {
- if (str == node4.Text)
- {
- flag = true;
- break;
- }
- }
- if (!flag)
- {
- new TreeNode(str);
- this.treeView2.Nodes.Add(list2[num]);
- }
- num++;
- }
- foreach (KeyValuePair<TreeNode, TreeNode> pair2 in dictionary)
- {
- foreach (TreeNode node5 in this.treeView2.Nodes)
- {
- if (((node5.Nodes == null) && (node5.Nodes.Count <= 0)) || !(node5.Text == pair2.Value.Text))
- {
- continue;
- }
- bool flag2 = false;
- foreach (TreeNode node6 in node5.Nodes)
- {
- if (node6.Text == pair2.Key.Text)
- {
- flag2 = true;
- break;
- }
- }
- if (!flag2)
- {
- node5.Nodes.Add(pair2.Key.Clone() as TreeNode);
- }
- }
- }
- this.ChangeData();
- }
- private void btn_Cancle_Click(object sender, EventArgs e)
- {
- base.Close();
- base.DialogResult = DialogResult.Cancel;
- }
- private void btn_Delete_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < this.treeView2.Nodes.Count; i++)
- {
- TreeNode node = this.treeView2.Nodes[i];
- if (node.Checked)
- {
- node.Remove();
- i--;
- }
- else
- {
- for (int j = 0; j < node.Nodes.Count; j++)
- {
- if (node.Nodes[j].Checked)
- {
- node.Nodes[j].Remove();
- j--;
- }
- }
- }
- }
- this.ChangeData();
- }
- private void btn_Down_Click(object sender, EventArgs e)
- {
- if ((this.treeView2.SelectedNode != null) && (this.treeView2.SelectedNode.Parent != null))
- {
- if (this.treeView2.SelectedNode.Index < (this.treeView2.SelectedNode.Parent.Nodes.Count - 1))
- {
- TreeNode selectedNode = this.treeView2.SelectedNode;
- int index = this.treeView2.SelectedNode.Index;
- this.treeView2.SelectedNode.Parent.Nodes.RemoveAt(index++);
- this.treeView2.SelectedNode.Parent.Nodes.Insert(index, selectedNode);
- }
- else if (this.treeView2.SelectedNode.Parent.Index < (this.treeView2.Nodes.Count - 1))
- {
- TreeNode node = this.treeView2.SelectedNode;
- int num2 = this.treeView2.SelectedNode.Index;
- int num3 = this.treeView2.SelectedNode.Parent.Index;
- this.treeView2.SelectedNode.Parent.Nodes.RemoveAt(num2);
- this.treeView2.Nodes[num3 + 1].Nodes.Insert(0, node);
- }
- this.ChangeData();
- }
- }
- private void btn_OK_Click(object sender, EventArgs e)
- {
- List<Menus> list = new List<Menus>();
- string strPath = Path.Combine(AppBaseInfo.AppRunPath, "Menu");
- string path = Path.Combine(Path.Combine(AppBaseInfo.AppTempFilePath, "Menu"), AppBaseInfo.LoadArgs);
- this.ReadXML(this.xmlFile, list, strPath);
- foreach (Menus menus in list)
- {
- string appName = menus.App.AppName;
- List<Tab> list2 = new List<Tab>();
- List<TSZ.RevitMenu.Configuration.Panel> list3 = new List<TSZ.RevitMenu.Configuration.Panel>();
- foreach (KeyValuePair<Tab, List<TSZ.RevitMenu.Configuration.Panel>> pair in this.newDic)
- {
- if (pair.Key.Modules == appName)
- {
- list2.Add(pair.Key);
- list3.AddRange(pair.Value);
- }
- }
- if (list2.Count > 0)
- {
- menus.Tab = list2.ToArray();
- }
- if (list3.Count > 0)
- {
- menus.Panel = list3.ToArray();
- }
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- XMLFile.SaveXMLFile<Menus>(Path.Combine(path, appName + ".xml"), menus);
- }
- base.DialogResult = DialogResult.OK;
- }
- private void btn_ReSet_Click(object sender, EventArgs e)
- {
- string path = Path.Combine(Path.Combine(AppBaseInfo.AppTempFilePath, "Menu"), AppBaseInfo.LoadArgs);
- if (Directory.Exists(path))
- {
- DirectoryInfo info = new DirectoryInfo(path);
- foreach (FileInfo info2 in info.GetFiles("*.xml"))
- {
- info2.Delete();
- }
- }
- base.DialogResult = DialogResult.OK;
- }
- private void ChangeData()
- {
- foreach (KeyValuePair<Tab, List<TSZ.RevitMenu.Configuration.Panel>> pair in this.newDic)
- {
- if (pair.Key.TabName == this.comboBox2.Text)
- {
- Tab key = pair.Key;
- this.newDic.Remove(pair.Key);
- List<TSZ.RevitMenu.Configuration.Panel> list = new List<TSZ.RevitMenu.Configuration.Panel>();
- foreach (TreeNode node in this.treeView2.Nodes)
- {
- TSZ.RevitMenu.Configuration.Panel tag = node.Tag as TSZ.RevitMenu.Configuration.Panel;
- TSZ.RevitMenu.Configuration.Button[] buttonArray = new TSZ.RevitMenu.Configuration.Button[node.Nodes.Count];
- for (int i = 0; i < node.Nodes.Count; i++)
- {
- buttonArray[i] = node.Nodes[i].Tag as TSZ.RevitMenu.Configuration.Button;
- buttonArray[i].MenuTab = pair.Key.MenuTab;
- buttonArray[i].Modules = pair.Key.Modules;
- }
- tag.Button = buttonArray;
- list.Add(tag);
- }
- this.newDic.Add(key, list);
- break;
- }
- }
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.LoadTreeView(this.comboBox1, this.comboBox1.Text, this.treeView1, this.originDic);
- }
- private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.LoadTreeView(this.comboBox2, this.comboBox2.Text, this.treeView2, this.newDic);
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing && (this.components != null))
- {
- this.components.Dispose();
- }
- base.Dispose(disposing);
- }
- private void GetDictionary(List<Menus> menus, Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> dic)
- {
- List<Tab> list = new List<Tab>();
- List<TSZ.RevitMenu.Configuration.Panel> list2 = new List<TSZ.RevitMenu.Configuration.Panel>();
- for (int i = 0; i < menus.Count; i++)
- {
- list.AddRange(menus[i].Tab);
- list2.AddRange(menus[i].Panel);
- }
- foreach (Tab tab in list)
- {
- List<TSZ.RevitMenu.Configuration.Panel> list3 = new List<TSZ.RevitMenu.Configuration.Panel>();
- foreach (TSZ.RevitMenu.Configuration.Panel panel in list2)
- {
- if (((panel.Button.Length > 0) && (panel.Button[0].MenuTab == tab.MenuTab)) && (panel.Button[0].Modules == tab.Modules))
- {
- list3.Add(panel);
- }
- }
- dic.Add(tab, list3);
- }
- }
- private void InitializeComponent()
- {
- this.comboBox1 = new ComboBox();
- this.btn_Add = new System.Windows.Forms.Button();
- this.btn_Delete = new System.Windows.Forms.Button();
- this.bn_Up = new System.Windows.Forms.Button();
- this.btn_Down = new System.Windows.Forms.Button();
- this.btn_OK = new System.Windows.Forms.Button();
- this.btn_Cancle = new System.Windows.Forms.Button();
- this.treeView1 = new TreeView();
- this.treeView2 = new TreeView();
- this.groupBox1 = new GroupBox();
- this.groupBox2 = new GroupBox();
- this.comboBox2 = new ComboBox();
- this.btn_ReSet = new System.Windows.Forms.Button();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- base.SuspendLayout();
- this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new Point(6, 0x10);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new Size(0x9e, 20);
- this.comboBox1.TabIndex = 0;
- this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
- this.btn_Add.Location = new Point(370, 0x4a);
- this.btn_Add.Name = "btn_Add";
- this.btn_Add.Size = new Size(0x4b, 0x17);
- this.btn_Add.TabIndex = 4;
- this.btn_Add.Text = "添加";
- this.btn_Add.UseVisualStyleBackColor = true;
- this.btn_Add.Click += new EventHandler(this.btn_Add_Click);
- this.btn_Delete.Location = new Point(370, 0x71);
- this.btn_Delete.Name = "btn_Delete";
- this.btn_Delete.Size = new Size(0x4b, 0x17);
- this.btn_Delete.TabIndex = 5;
- this.btn_Delete.Text = "删除";
- this.btn_Delete.UseVisualStyleBackColor = true;
- this.btn_Delete.Click += new EventHandler(this.btn_Delete_Click);
- this.bn_Up.Location = new Point(370, 0x9c);
- this.bn_Up.Name = "bn_Up";
- this.bn_Up.Size = new Size(0x4b, 0x17);
- this.bn_Up.TabIndex = 6;
- this.bn_Up.Text = "上移";
- this.bn_Up.UseVisualStyleBackColor = true;
- this.bn_Up.Click += new EventHandler(this.bn_Up_Click);
- this.btn_Down.Location = new Point(370, 0xc7);
- this.btn_Down.Name = "btn_Down";
- this.btn_Down.Size = new Size(0x4b, 0x17);
- this.btn_Down.TabIndex = 7;
- this.btn_Down.Text = "下移";
- this.btn_Down.UseVisualStyleBackColor = true;
- this.btn_Down.Click += new EventHandler(this.btn_Down_Click);
- this.btn_OK.Location = new Point(0x114, 0x139);
- this.btn_OK.Name = "btn_OK";
- this.btn_OK.Size = new Size(0x4b, 0x17);
- this.btn_OK.TabIndex = 8;
- this.btn_OK.Text = "确定";
- this.btn_OK.UseVisualStyleBackColor = true;
- this.btn_OK.Click += new EventHandler(this.btn_OK_Click);
- this.btn_Cancle.Location = new Point(370, 0x139);
- this.btn_Cancle.Name = "btn_Cancle";
- this.btn_Cancle.Size = new Size(0x4b, 0x17);
- this.btn_Cancle.TabIndex = 9;
- this.btn_Cancle.Text = "取消";
- this.btn_Cancle.UseVisualStyleBackColor = true;
- this.btn_Cancle.Click += new EventHandler(this.btn_Cancle_Click);
- this.treeView1.CheckBoxes = true;
- this.treeView1.Location = new Point(6, 0x21);
- this.treeView1.Name = "treeView1";
- this.treeView1.Size = new Size(0x9e, 0xfd);
- this.treeView1.TabIndex = 10;
- this.treeView1.AfterCheck += new TreeViewEventHandler(this.treeView1_AfterCheck);
- this.treeView2.CheckBoxes = true;
- this.treeView2.Location = new Point(6, 0x21);
- this.treeView2.Name = "treeView2";
- this.treeView2.Size = new Size(0x9e, 0xfd);
- this.treeView2.TabIndex = 11;
- this.treeView2.AfterCheck += new TreeViewEventHandler(this.treeView2_AfterCheck);
- this.groupBox1.Controls.Add(this.treeView1);
- this.groupBox1.Controls.Add(this.comboBox1);
- this.groupBox1.Location = new Point(12, 0x10);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new Size(0xa9, 0x126);
- this.groupBox1.TabIndex = 14;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "设置前菜单";
- this.groupBox2.Controls.Add(this.comboBox2);
- this.groupBox2.Controls.Add(this.treeView2);
- this.groupBox2.Location = new Point(0xbb, 0x10);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new Size(0xa9, 0x126);
- this.groupBox2.TabIndex = 15;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "设置后菜单";
- this.comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
- this.comboBox2.FormattingEnabled = true;
- this.comboBox2.Location = new Point(6, 0x10);
- this.comboBox2.Name = "comboBox2";
- this.comboBox2.Size = new Size(0x9e, 20);
- this.comboBox2.TabIndex = 11;
- this.comboBox2.SelectedIndexChanged += new EventHandler(this.comboBox2_SelectedIndexChanged);
- this.btn_ReSet.Location = new Point(0xb0, 0x13c);
- this.btn_ReSet.Name = "btn_ReSet";
- this.btn_ReSet.Size = new Size(0x4b, 0x17);
- this.btn_ReSet.TabIndex = 0x10;
- this.btn_ReSet.Text = "恢复设置";
- this.btn_ReSet.UseVisualStyleBackColor = true;
- this.btn_ReSet.Click += new EventHandler(this.btn_ReSet_Click);
- base.AutoScaleDimensions = new SizeF(6f, 12f);
- base.AutoScaleMode = AutoScaleMode.Font;
- base.ClientSize = new Size(0x1c5, 350);
- base.Controls.Add(this.btn_ReSet);
- base.Controls.Add(this.groupBox2);
- base.Controls.Add(this.groupBox1);
- base.Controls.Add(this.btn_Cancle);
- base.Controls.Add(this.btn_OK);
- base.Controls.Add(this.btn_Down);
- base.Controls.Add(this.bn_Up);
- base.Controls.Add(this.btn_Delete);
- base.Controls.Add(this.btn_Add);
- base.MaximizeBox = false;
- base.MinimizeBox = false;
- base.Name = "SetMenuForm";
- this.Text = "设置菜单";
- base.Load += new EventHandler(this.SetMenuForm_Load);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- base.ResumeLayout(false);
- }
- private void LoadData(ComboBox cmb, Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> dic)
- {
- foreach (KeyValuePair<Tab, List<TSZ.RevitMenu.Configuration.Panel>> pair in dic)
- {
- cmb.Items.Add(pair.Key.TabName);
- }
- if (cmb.Items.Count > 0)
- {
- cmb.SelectedIndex = 0;
- }
- }
- private void LoadTreeView(ComboBox cmb, string tabName, TreeView tv, Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> dic)
- {
- tv.Nodes.Clear();
- foreach (KeyValuePair<Tab, List<TSZ.RevitMenu.Configuration.Panel>> pair in dic)
- {
- if (pair.Key.TabName == tabName)
- {
- foreach (TSZ.RevitMenu.Configuration.Panel panel in pair.Value)
- {
- TreeNode node = new TreeNode(panel.PanelName) {
- Tag = panel
- };
- foreach (TSZ.RevitMenu.Configuration.Button button in panel.Button)
- {
- if (button.ButtonStyles == "Separator")
- {
- button.ButtonText = "——";
- }
- TreeNode node2 = new TreeNode(button.ButtonText) {
- Tag = button
- };
- node.Nodes.Add(node2);
- }
- tv.Nodes.Add(node);
- }
- }
- }
- }
- private void ReadXML(List<string> xmlFile, List<Menus> menus, string strPath)
- {
- DirectoryInfo info = new DirectoryInfo(strPath);
- foreach (FileInfo info2 in info.GetFiles("*.xml"))
- {
- Menus x = new Menus();
- if (xmlFile.Contains(Path.GetFileNameWithoutExtension(info2.FullName)))
- {
- XMLFile.OpenXMLFile<Menus>(info2.FullName, ref x);
- menus.Add(x);
- }
- }
- }
- private void SetMenuForm_Load(object sender, EventArgs e)
- {
- this.xmlFile.AddRange(AppBaseInfo.LoadArgs.ToString().Split(new char[] { ',' }));
- List<Menus> menus = new List<Menus>();
- List<Menus> list2 = new List<Menus>();
- string strPath = Path.Combine(AppBaseInfo.AppRunPath, "Menu");
- string path = Path.Combine(AppBaseInfo.AppTempFilePath, "Menu");
- this.ReadXML(this.xmlFile, menus, strPath);
- if (Directory.Exists(path))
- {
- this.ReadXML(this.xmlFile, list2, path);
- }
- this.GetDictionary(menus, this.originDic);
- if ((list2 != null) && (list2.Count > 0))
- {
- this.GetDictionary(list2, this.newDic);
- }
- else
- {
- this.newDic = this.originDic;
- }
- this.LoadData(this.comboBox1, this.originDic);
- this.LoadData(this.comboBox2, this.newDic);
- }
- private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
- {
- TreeViewChecked(e);
- }
- private void treeView2_AfterCheck(object sender, TreeViewEventArgs e)
- {
- TreeViewChecked(e);
- }
- private static void TreeViewChecked(TreeViewEventArgs e)
- {
- if (e.Action != TreeViewAction.Unknown)
- {
- if (e.Node.Parent == null)
- {
- foreach (TreeNode node in e.Node.Nodes)
- {
- node.Checked = e.Node.Checked;
- }
- }
- else if (!e.Node.Checked)
- {
- e.Node.Parent.Checked = e.Node.Checked;
- }
- }
- }
- }
- }
|