private void panelAddButton_Click(object sender, RoutedEventArgs e) { if (tabnameTextBox.Text != null && tabnameTextBox.Text.Length > 0 && panelnameTextBox.Text != null && panelnameTextBox.Text.Length > 0 && !panelNames.Contains(tabnameTextBox.Text + " - " + panelnameTextBox.Text)) { try { PanelInfo pnl = new PanelInfo(); pnl.Buttons = new List <ButtonInfo>(); pnl.TabName = tabnameTextBox.Text; pnl.PanelName = panelnameTextBox.Text; panelNames.Add(pnl.TabName + " - " + pnl.PanelName); panels.Add(pnl); selectedLink = null; selectedButton = null; panelsListView.ItemsSource = panels; // Clear the links linkList = new ObservableCollection <CommandInfo>(); linksListView.ItemsSource = linkList; // clear the buttons buttonList = new ObservableCollection <ButtonInfo>(); buttonsListView.ItemsSource = buttonList; tabnameTextBox.Text = string.Empty; panelnameTextBox.Text = string.Empty; BuildXML(); } catch { } } }
private void panelRemoveButton_Click(object sender, RoutedEventArgs e) { int index = panelsListView.SelectedIndex; try { if (index >= 0 && selectedPanel != null) { List <PanelInfo> tempList = new List <PanelInfo>(); foreach (PanelInfo pnl in panels) { tempList.Add(pnl); } tempList.RemoveAt(index); selectedButton = null; buttonList = new ObservableCollection <ButtonInfo>(); linkList = new ObservableCollection <CommandInfo>(); buttonsListView.ItemsSource = buttonList; selectedPanel = null; panelNames.RemoveAt(index); panels = new ObservableCollection <PanelInfo>(); foreach (PanelInfo pnl in tempList) { panels.Add(pnl); } BuildXML(); panelsListView.ItemsSource = panels; panelsListView.DisplayMemberPath = "VisibleName"; } } catch { } }
private void panelsListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedPanel = panels[panelsListView.SelectedIndex]; if (selectedPanel.Buttons == null || selectedPanel.Buttons.Count == 0) { buttonList = new ObservableCollection <ButtonInfo>(); } else { buttonList = new ObservableCollection <ButtonInfo>(); foreach (ButtonInfo btn in selectedPanel.Buttons) { buttonList.Add(btn); } } buttonsListView.ItemsSource = buttonList; buttonsListView.DisplayMemberPath = "Name"; selectedButton = null; linkList = new ObservableCollection <CommandInfo>(); linksListView.ItemsSource = linkList; }
public static void GetPanels(string libPath, out List <PanelInfo> panels) { panels = new List <PanelInfo>(); PanelInfo pi = null; // Use Reflection to iterate through the buttons.dll Assembly assembly = Assembly.LoadFile(libPath); foreach (Type t in assembly.GetTypes()) { // This is the command class, we need to get an instance of it and // iterate through it's properties to determine what to build var obj = Activator.CreateInstance(t); string name = string.Empty; string tooltip = string.Empty; string icon = string.Empty; string address = string.Empty; string buttonId = string.Empty; string buttonType = string.Empty; string buttonName = "Button"; string tabName = string.Empty; string panelName = string.Empty; string fullAddress = t.Namespace + "." + t.Name; foreach (PropertyInfo propInfo in t.GetProperties()) { switch (propInfo.Name) { case "Name": name = propInfo.GetValue(obj).ToString(); if (name.Contains(Environment.NewLine)) { System.Windows.MessageBox.Show("New Line found?"); } name.Replace(Environment.NewLine, "\\n"); break; case "ToolTip": tooltip = propInfo.GetValue(obj).ToString(); break; case "Icon": icon = propInfo.GetValue(obj).ToString(); break; case "Address": address = propInfo.GetValue(obj).ToString(); break; case "ButtonId": buttonId = propInfo.GetValue(obj).ToString(); break; case "ButtonType": buttonType = propInfo.GetValue(obj).ToString(); break; case "ButtonName": buttonName = propInfo.GetValue(obj).ToString(); break; case "TabName": tabName = propInfo.GetValue(obj).ToString(); break; case "PanelName": panelName = propInfo.GetValue(obj).ToString(); break; } } if (pi == null) // construct the pi panel. This should only occur once for the initial panel { pi = new PanelInfo(); pi.PanelName = panelName; pi.TabName = tabName; List <ButtonInfo> buttons = new List <ButtonInfo>(); ButtonInfo button = new ButtonInfo(); button.ButtonId = buttonId; button.Name = buttonName; button.ButtonType = (ButtonType)Enum.Parse(typeof(ButtonType), buttonType); List <CommandInfo> commands = new List <CommandInfo>(); CommandInfo ci = new CommandInfo(); ci.CommandName = name; ci.CommandId = t.Name; ci.FullAssemblyPath = fullAddress; ci.Icon = icon; ci.Address = address; ci.Primary = true; ci.Tooltip = tooltip; ci.Button = button; ci.Panel = pi; commands.Add(ci); button.Commands = commands; buttons.Add(button); pi.Buttons = buttons; } else if (pi.TabName == tabName && pi.PanelName == panelName) { // Add the new command to the existing panel List <ButtonInfo> buttons = pi.Buttons; ButtonInfo button = buttons.Last(); if (button.ButtonId == buttonId) { // Add the command to this button List <CommandInfo> commands = button.Commands; CommandInfo cmd = new CommandInfo(); cmd.CommandName = name; cmd.CommandId = t.Name; cmd.Address = address; cmd.FullAssemblyPath = fullAddress; if (button.ButtonType == ButtonType.SplitButton) { if (icon.Length <= 0 || icon == null) { cmd.Icon = null; } else { cmd.Icon = icon; } cmd.Primary = false; } else { cmd.Icon = icon; cmd.Primary = true; } cmd.Tooltip = tooltip; cmd.Button = button; cmd.Panel = pi; commands.Add(cmd); button.Commands = commands; buttons.RemoveAt(buttons.Count - 1); buttons.Add(button); pi.Buttons = buttons; } else { // Command is on a new button List <CommandInfo> commands = new List <CommandInfo>(); CommandInfo cmd = new CommandInfo(); cmd.CommandName = name; cmd.CommandId = t.Name; cmd.Address = address; cmd.FullAssemblyPath = fullAddress; cmd.Icon = icon; cmd.Primary = true; cmd.Tooltip = tooltip; cmd.Button = button; cmd.Panel = pi; commands.Add(cmd); button = new ButtonInfo(); button.ButtonId = buttonId; button.ButtonType = (ButtonType)Enum.Parse(typeof(ButtonType), buttonType); button.Name = buttonName; button.Commands = commands; buttons.Add(button); pi.Buttons = buttons; } } else { // Add the existing panel to the panels panels.Add(pi); // Create a new PanelSet pi = new PanelInfo(); pi.PanelName = panelName; pi.TabName = tabName; List <ButtonInfo> buttons = new List <ButtonInfo>(); ButtonInfo button = new ButtonInfo(); button.ButtonId = buttonId; button.ButtonType = (ButtonType)Enum.Parse(typeof(ButtonType), buttonType); List <CommandInfo> commands = new List <CommandInfo>(); CommandInfo ci = new CommandInfo(); ci.CommandName = name; ci.CommandId = t.Name; ci.FullAssemblyPath = fullAddress; ci.Address = address; ci.Icon = icon; ci.Primary = true; ci.Tooltip = tooltip; ci.Button = button; ci.Panel = pi; commands.Add(ci); button.Commands = commands; buttons.Add(button); pi.Buttons = buttons; } } // Add the remaining panel set panels.Add(pi); }
public static void GetPanels(string xmlPath, out List <PanelInfo> panels, out List <CommandInfo> allCommands) { panels = new List <PanelInfo>(); allCommands = new List <CommandInfo>(); XmlDocument xmlDoc = new XmlDocument(); try { string xmlStr = File.ReadAllText(xmlPath); xmlStr = EscapeXMLValue(xmlStr); xmlDoc.LoadXml(xmlStr); } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); xmlDoc = null; } if (xmlDoc != null) { // Get the panelsets XmlNodeList panelSets = xmlDoc.SelectNodes("ContentLinks/PanelSet"); int buttonIdCounter = 0; int commandIdCounter = 0; foreach (XmlNode panelSetNode in panelSets) { PanelInfo panel = new PanelInfo(); string tab = null; try { tab = panelSetNode.Attributes["TabName"].Value; } catch { tab = null; } string pnlName = null; try { pnlName = panelSetNode.Attributes["PanelName"].Value; } catch { pnlName = null; } if (tab == null) { tab = panelSetNode.Attributes["tabName"].Value; } if (pnlName == null || pnlName.Length <= 0) { pnlName = panelSetNode.Attributes["panelName"].Value; } panel.TabName = tab; panel.PanelName = pnlName; List <ButtonInfo> buttons = new List <ButtonInfo>(); XmlNodeList buttonNodes = panelSetNode.SelectNodes("Button"); if (buttonNodes.Count == 0) { continue; } foreach (XmlNode buttonNode in buttonNodes) { string button_Style = buttonNode.Attributes["type"].Value; ButtonType bt = ButtonType.PushButton; if (button_Style.ToLower() == "splitbutton") { bt = ButtonType.SplitButton; } else if (button_Style.ToLower() == "stackbutton") { bt = ButtonType.StackButton; } else { bt = ButtonType.PushButton; } string buttonName = buttonNode.Attributes["name"].Value; if (buttonName == null || buttonName.Length == 0) { buttonName = "Button"; } ButtonInfo button = new ButtonInfo(); button.ButtonType = bt; button.ButtonId = "Button_" + buttonIdCounter.ToString(); button.Name = buttonName; List <CommandInfo> commands = new List <CommandInfo>(); XmlNodeList linkNodes = buttonNode.SelectNodes("Link"); if (linkNodes.Count == 0) { continue; } foreach (XmlNode linkNode in linkNodes) { // Get the properties of the link XmlNode nameNode = linkNode.SelectSingleNode("Name"); XmlNode iconNode = linkNode.SelectSingleNode("Icon"); XmlNode addrNode = linkNode.SelectSingleNode("Address"); XmlNode toolTipNode = linkNode.SelectSingleNode("ToolTip"); CommandInfo cmd = new CommandInfo(); cmd.CommandId = "LinkCmd_" + commandIdCounter.ToString(); cmd.CommandName = nameNode.InnerText; if (iconNode != null) { cmd.Icon = iconNode.InnerText; } if (bt == ButtonType.SplitButton && commands.Count == 0) { cmd.Primary = true; } else if (bt == ButtonType.PushButton) { cmd.Primary = true; } else { cmd.Primary = false; } if (toolTipNode != null) { cmd.Tooltip = toolTipNode.InnerText; } cmd.Address = UnescapeXMLValue(addrNode.InnerText); cmd.Button = button; cmd.Panel = panel; commands.Add(cmd); allCommands.Add(cmd); commandIdCounter++; } button.Commands = commands; buttons.Add(button); buttonIdCounter++; } panel.Buttons = buttons; panels.Add(panel); } } }