private void addStationButton_Click(object sender, EventArgs e) { List <string> groupNames = new List <string>(); groupNames.Clear(); XDocument xdoc = XDocument.Load(path + "\\bookmarks.xml"); var lv1s = from lv1 in xdoc.Descendants("group").OrderBy(lv1 => lv1.Attribute("name").Value) select new { Group = lv1.Attribute("name").Value }; foreach (var lv1 in lv1s) { groupNames.Add(lv1.Group); } editStation editStation = new editStation(groupNames, "", "", "", ""); editStation.StartPosition = FormStartPosition.CenterParent; editStation.Text = "Add Station"; if (editStation.ShowDialog(this) == DialogResult.OK) { TreeNode newParent = GetNode(editStation.ReturnGroup); if (newParent != null) { TreeNode newStation = new TreeNode(editStation.ReturnName); newStation.Tag = new StationInfo { url = editStation.ReturnURL, img = editStation.ReturnImage }; newParent.Nodes.Add(newStation); stationTreeView.Sort(); stationTreeView.SelectedNode = newStation; newStation.Parent.Expand(); } else { newParent = new TreeNode(editStation.ReturnGroup); TreeNode newStation = new TreeNode(editStation.ReturnName); newStation.Tag = new StationInfo { url = editStation.ReturnURL, img = editStation.ReturnImage }; newParent.Nodes.Add(newStation); stationTreeView.Nodes.Add(newParent); stationTreeView.Sort(); stationTreeView.SelectedNode = newStation; newStation.Parent.Expand(); } } TrimTree(); }
private void AddCustomToStations(object sender, EventArgs e) { editStation editStation = new editStation(groupList, "", currentURL, "", ""); editStation.StartPosition = FormStartPosition.CenterParent; editStation.Icon = Properties.Resources.icons8_radio_tower_34495e; editStation.Text = "Add Station"; if (editStation.ShowDialog(this) == DialogResult.OK) { if (!groupList.Contains(editStation.ReturnGroup)) { XmlDocument doc = new XmlDocument(); doc.Load(path + "\\bookmarks.xml"); XmlElement group = doc.CreateElement("group"); group.SetAttribute("name", editStation.ReturnGroup); group.SetAttribute("img", ""); XmlElement bookmark = doc.CreateElement("bookmark"); bookmark.SetAttribute("name", editStation.ReturnName); bookmark.SetAttribute("url", editStation.ReturnURL); bookmark.SetAttribute("img", editStation.ReturnImage); XmlNode root = doc.SelectSingleNode("bookmarks"); group.AppendChild(bookmark); root.AppendChild(group); doc.Save(path + "\\bookmarks.xml"); Console.WriteLine("it's a new group"); } else { XmlDocument doc = new XmlDocument(); doc.Load(path + "\\bookmarks.xml"); XmlNode root = doc.SelectSingleNode("/bookmarks/group[@name='" + editStation.ReturnGroup + "']"); XmlElement bookmark = doc.CreateElement("bookmark"); bookmark.SetAttribute("name", editStation.ReturnName); bookmark.SetAttribute("url", editStation.ReturnURL); bookmark.SetAttribute("img", editStation.ReturnImage); root.AppendChild(bookmark); doc.Save(path + "\\bookmarks.xml"); } updateStations(); } }
private void button1_Click(object sender, EventArgs e) { if (stationTreeView.SelectedNode.Level == 0) { editGroup editGroup = new editGroup(stationTreeView.SelectedNode.Text, stationTreeView.SelectedNode.Tag.ToString()); editGroup.StartPosition = FormStartPosition.CenterParent; if (editGroup.ShowDialog(this) == DialogResult.OK) { stationTreeView.SelectedNode.Text = editGroup.ReturnValue; stationTreeView.SelectedNode.Tag = editGroup.ReturnImage; stationTreeView.SelectedNode = GetNode(editGroup.ReturnValue); stationTreeView.Sort(); } } else if (stationTreeView.SelectedNode.Level == 1) { List <string> groupNames = new List <string>(); groupNames.Clear(); TreeNodeCollection groupNodes = stationTreeView.Nodes; foreach (TreeNode n in groupNodes) { groupNames.Add(n.Text); } var metainfo = (StationInfo)stationTreeView.SelectedNode.Tag; editStation editStation = new editStation(groupNames, stationTreeView.SelectedNode.Text, metainfo.url, stationTreeView.SelectedNode.Parent.Text, metainfo.img); editStation.StartPosition = FormStartPosition.CenterParent; if (editStation.ShowDialog(this) == DialogResult.OK) { if (stationTreeView.SelectedNode.Parent.Text == editStation.ReturnGroup) { stationTreeView.SelectedNode.Text = editStation.ReturnName; stationTreeView.SelectedNode.Tag = new StationInfo { url = editStation.ReturnURL, img = editStation.ReturnImage }; stationTreeView.Sort(); stationTreeView.SelectedNode = GetNode(editStation.ReturnName); } else { TreeNode newParent = GetNode(editStation.ReturnGroup); if (newParent != null) { stationTreeView.SelectedNode.Remove(); TreeNode newStation = new TreeNode(editStation.ReturnName); newStation.Tag = new StationInfo { url = editStation.ReturnURL, img = editStation.ReturnImage }; newParent.Nodes.Add(newStation); stationTreeView.Sort(); stationTreeView.SelectedNode = newStation; newStation.Parent.Expand(); } else { newParent = new TreeNode(editStation.ReturnGroup); stationTreeView.SelectedNode.Remove(); TreeNode newStation = new TreeNode(editStation.ReturnName); newStation.Tag = new StationInfo { url = editStation.ReturnURL, img = editStation.ReturnImage }; newParent.Nodes.Add(newStation); stationTreeView.Nodes.Add(newParent); stationTreeView.Sort(); stationTreeView.SelectedNode = newStation; newStation.Parent.Expand(); } } TrimTree(); } } }