private void LoadStations() { TemporaryValues.stations = dbHelper.GetAllStationsInfoWithDeviceInfo(); if (TemporaryValues.stations != null) { if (TemporaryValues.stations.Count > 0) { ProjectTreeView.BeginUpdate(); // İlk Node seçilir TreeNode node = ProjectTreeView.Nodes[0]; // 2 nolu node'un 'istasyonlar' node u oldugu kabul edilerek devam edilir. if (node.Nodes[1].Nodes != null) { node.Nodes[1].Nodes.Clear(); node.Nodes[1].ContextMenuStrip = contextMenuStrip_Stations; } foreach (Station station in TemporaryValues.stations) { TreeNode node_station = new TreeNode(station.Name); node_station.ContextMenuStrip = contextMenuStrip_Devices; ProjectTreeView.Nodes[0].Nodes[1].Nodes.Add(node_station); AddStationDevicesToTreeView(station.Devices, node_station); } ProjectTreeView.EndUpdate(); } } }
/// <summary> /// Extends the Refresh method to update the contents of the tree. /// </summary> public override void Refresh() { base.Refresh(); if (Core.Project == null || string.IsNullOrEmpty(Core.Project.RootPath)) { return; } // update the icons _iconlist.Images.Clear(); _iconlist.Images.Add(Resources.SphereEditor); _iconlist.Images.Add(Resources.folder_closed); _iconlist.Images.Add(Resources.folder); _iconlist.Images.Add(Resources.new_item); string[] pluginNames = PluginManager.GetNames <IFileOpener>(); foreach (string name in pluginNames) { var plugin = PluginManager.Get <IFileOpener>(name); _iconlist.Images.Add(name, plugin.FileIcon ?? Resources.new_item); } Cursor.Current = Cursors.WaitCursor; // Save currently selected item and folder expansion states string selectedNodePath = ProjectTreeView.SelectedNode != null ? ProjectTreeView.SelectedNode.FullPath : null; var isExpandedTable = new Dictionary <string, bool>(); var nodesToCheck = new Queue <TreeNode>(); if (ProjectTreeView.TopNode != null) { nodesToCheck.Enqueue(ProjectTreeView.TopNode); while (nodesToCheck.Count > 0) { TreeNode node = nodesToCheck.Dequeue(); isExpandedTable.Add(node.FullPath, node.IsExpanded); foreach (TreeNode subnode in node.Nodes) { // emulate a recursive search of the tree view: nodesToCheck.Enqueue(subnode); } } } // Repopulate the tree ProjectTreeView.BeginUpdate(); ProjectTreeView.Nodes.Clear(); var projectNode = new TreeNode(Core.Project.Name) { Tag = "project-node" }; ProjectTreeView.Nodes.Add(projectNode); var baseDir = new DirectoryInfo(SystemWatcher.Path); PopulateDirectoryNode(ProjectTreeView.Nodes[0], baseDir); // Re-expand folders and try to select previously-selected item if (ProjectTreeView.TopNode != null) { nodesToCheck.Clear(); nodesToCheck.Enqueue(ProjectTreeView.TopNode); while (nodesToCheck.Count > 0) { TreeNode node = nodesToCheck.Dequeue(); bool isExpanded; isExpandedTable.TryGetValue(node.FullPath, out isExpanded); if (isExpanded) { node.Expand(); } if (node.FullPath == selectedNodePath) { ProjectTreeView.SelectedNode = node; } foreach (TreeNode subnode in node.Nodes) { // emulate a recursive search of the tree view: nodesToCheck.Enqueue(subnode); } } } if (ProjectTreeView.SelectedNode == null) { ProjectTreeView.SelectedNode = ProjectTreeView.TopNode; } if (!ProjectTreeView.Nodes[0].IsExpanded) { ProjectTreeView.Nodes[0].Expand(); } Cursor.Current = Cursors.Default; ProjectTreeView.EndUpdate(); }