internal void RefreshValues() { if (!DispatcherHelper.UIDispatcher.CheckAccess()) { DispatcherHelper.RunAsync(RefreshValues); return; } if (!ViewModelLocator.GameLoader.ValidGame) { TreeViewItems.Clear(); return; } var path = ViewModelLocator.GameLoader.GamePath; var di = new DirectoryInfo(path); foreach (var d in di.GetDirectories().OrderBy(x => x.Name)) { if (!object.Equals((d.Attributes & FileAttributes.System), FileAttributes.System) && !object.Equals((d.Attributes & FileAttributes.Hidden), FileAttributes.Hidden)) { TreeViewItems.Add(new AssetTreeViewItemViewModel(d)); } } foreach (var f in di.GetFiles().OrderBy(x => x.Name)) { TreeViewItems.Add(new AssetTreeViewItemViewModel(f)); } }
/// <summary> /// 在将要展开节点时 加载子节点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void treeSourcePath_BeforeExpand(object sender, TreeViewCancelEventArgs e) { //01 加载子节点 TreeViewItems.Add(e.Node); //curFilePath = e.Node.Name; dt.Rows.Clear(); //02 加载文件到DataGridView if (e.Node.Tag.ToString() != "This PC") { // e.Node.Nodes.Clear(); TreeNode tNode = e.Node; string path = tNode.Name; if (e.Node.Tag.ToString() == "Documents") { path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } curFilePath = path; //MessageBox.Show(curFilePath); foreach (var file in Directory.GetFiles(path, "*.*", e.Node.Level > 1 ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { FileInfo fileInfo = new FileInfo(file); addToDtRow(dt, fileInfo); } dgvResult.DataSource = dt; } }
public Window1ViewModel() { var drives = Directory.GetLogicalDrives(); foreach (var drive in drives) { var treeItem = new TreeViewItemViewModel ( type: ItemModel.Types.Drive, fullpath: drive, isRoot: true ); treeItem.Expanded += TreeViewItem_Expanded; treeItem.Selected += TreeViewItem_Selected; TreeViewItems.Add(treeItem); var listItem = new ListViewItemViewModel ( type: ItemModel.Types.Drive, fullpath: drive, isRoot: true ); listItem.Selected += ListViewItem_Selected; ListViewItems.Add(listItem); } }
public void OverallSortAllChilds(SortOrder sortOrder) { switch (sortOrder) { case SortOrder.None: break; case SortOrder.Ascending: TreeViewItems = new ObservableCollection <TreeViewItemBase>(TreeViewItems.AsEnumerable().OrderBy(x => x.DisplayName)); //recursive call TreeViewItems.ToList().ForEach(x => x.OverallSortAllChilds(sortOrder)); break; case SortOrder.Descending: TreeViewItems = new ObservableCollection <TreeViewItemBase>(TreeViewItems.AsEnumerable().OrderByDescending(x => x.DisplayName)); //recursive call TreeViewItems.ToList().ForEach(x => x.OverallSortAllChilds(sortOrder)); break; case SortOrder.Reverse: TreeViewItems = new ObservableCollection <TreeViewItemBase>(TreeViewItems.AsEnumerable().Reverse()); //recursive call TreeViewItems.ToList().ForEach(x => x.OverallSortAllChilds(sortOrder)); break; default: throw new NotImplementedException(); } }
void Display(NodeVm rootNodeVm) { var tvis = rootNodeVm.ToTreeViewItem(); TreeViewItems.Clear(); TreeViewItems.Add(tvis); }
private void btnExportSelected_Click(object sender, RoutedEventArgs e) { string fileName, formatId; if (!PromptFileSave(out fileName, out formatId)) { return; } var selectedPerms = new List <IGeometryPermutation>(); foreach (var parent in TreeViewItems.Zip(model.Regions.Except(InvalidRegions), (a, b) => new { Node = a, Region = b })) { if (parent.Node.IsChecked == false) { continue; } foreach (var child in parent.Node.Items.Zip(parent.Region.Permutations.Except(InvalidPermutations), (a, b) => new { Node = a, Permutation = b })) { if (child.Node.IsChecked == true) { selectedPerms.Add(child.Permutation); } } } var masked = new MaskedGeometryModel(model, selectedPerms); ModelViewerPlugin.WriteModelFile(masked, fileName, formatId); }
public void RemoveItem() { if (TreeViewItems.Count > 0) { TreeViewItems.RemoveAt(TreeViewItems.Count - 1); } }
private void UpdateUI() { List <string> expandedNodes = Helpers.GetExpandedNodes(TreeViewItems.Nodes); // Dirty trick to prevent flickering this.BackgroundImage = new Bitmap(TreeViewItems.Width, TreeViewItems.Height); TreeViewItems.DrawToBitmap((Bitmap)this.BackgroundImage, new Rectangle(TreeViewItems.Location, TreeViewItems.Size)); TreeViewItems.Visible = false; TreeViewItems.BeginUpdate(); TreeViewItems.Nodes.Clear(); foreach (Group g in groups.OrderBy(grp => grp.Name)) { AddGroupNode(g, null); } if (selectedNode != null) { SelectNode(TreeViewItems.Nodes, selectedNode.Text); } Helpers.SetExpandedNodes(TreeViewItems.Nodes, expandedNodes); TreeViewItems.EndUpdate(); TreeViewItems.Visible = true; this.BackgroundImage = null; }
public TestTreeViewItem[] GetMainTestGroups() { var list = new List <TreeViewItemBase>(); list.AddRange(TreeViewItems.Where(x => x.GetType() == typeof(TestTreeViewItem))); return(list.Cast <TestTreeViewItem>().ToArray()); }
public void CloseDatabase(string databasePath) { var db = TreeViewItems.Single(x => x.DatabasePath.Equals(databasePath)); TreeViewItems.Remove(db); log.Info("Closed database '" + db.DatabasePath + "'."); }
public void LoadTreeView() { TreeViewItems.Add(new PUTreeViewItemModel() { Header = "第一章", Value = "1", Items = new List <PUTreeViewItemModel>() { new PUTreeViewItemModel() { Header = "第一节", Value = "1.1", }, new PUTreeViewItemModel() { Header = "第二节", Value = "1.2", }, }, }); TreeViewItems.Add(new PUTreeViewItemModel() { Header = "第二章", Value = "2", Items = new List <PUTreeViewItemModel>() { new PUTreeViewItemModel() { Header = "第一节", Value = "2.1", }, new PUTreeViewItemModel() { Header = "第二节", Value = "2.2", }, }, }); TreeViewItems.Add(new PUTreeViewItemModel() { Header = "第三章", Value = "3", Items = new List <PUTreeViewItemModel>() { new PUTreeViewItemModel() { Header = "第一节", Value = "3.1", }, new PUTreeViewItemModel() { Header = "第二节", Value = "3.2", }, }, }); NotifyOfPropertyChange(() => TreeViewItems); }
public void Dispose() { TreeViewItems.Clear(); ClearChildren(); modelGroup.Dispose(); renderer.Dispose(); modelFactory.Dispose(); GC.Collect(); }
public void SetSelectedTreeViewItem(Type type) { if (type == null) { return; } SetSelectedItem(type, TreeViewItems.ToList()); }
/// <summary> /// Closes the module. /// </summary> /// <remarks>Documented by Dev08, 2009-07-15</remarks> private void CloseModule() { SettingsManagerLogic.CloseLearningModule(); TreeViewItems.Clear(); treeViewLearningModule.ItemsSource = null; ExtensionList.Clear(); EnableControls(false); }
public List <TreeViewItemBase> GetOverallChildItems() { var list = new List <TreeViewItemBase>(); list.AddRange(TreeViewItems); //recursive call for childs TreeViewItems.ToList().ForEach(q => list.AddRange(q.GetOverallChildItems())); return(list); }
public TestFunctionTreeViewItem[] GetOverallTestFunctions() { var list = new List <TreeViewItemBase>(); list.AddRange(TreeViewItems.Where(x => x.GetType() == typeof(TestFunctionTreeViewItem))); //recursive call for childs TreeViewItems.ToList().ForEach(q => list.AddRange(q.GetOverallTestFunctions())); return(list.Cast <TestFunctionTreeViewItem>().ToArray()); }
private void SetLod(int index) { TreeViewItems.Clear(); ClearChildren(); element = modelFactory.CreateRenderModel(modelId, index); modelGroup.Children.Add(element); AddRenderModelNodes(renderModel.Regions, r => r.Permutations); AddRenderModelNodes(renderModel.InstanceGroups, g => g.Instances); }
/// <summary> /// Loads the content. /// </summary> /// <remarks>Documented by Dev08, 2009-07-18</remarks> private void LoadContent() { textBlockProgressBar.Text = string.Empty; progressBarLoad.IsIndeterminate = false; TreeViewItems.Add(new LearningModuleTreeViewItem(SettingsManagerLogic.LearningModule)); LearningModuleTreeViewItem item = TreeViewItems[0]; item.ContentLoaded += new EventHandler(ContentLoaded); item.ContentLoading += new LearningModuleTreeViewItem.ContentLoadingEventHandler(ContentLoading); item.LoadLearningModuleContent(); }
private void AddDatabaseToTree(string databasePath) { if (TreeViewItems.Any(x => x.DatabasePath.Equals(databasePath))) { return; } var schemaMapper = new SchemaToViewModelMapper(); var databaseItem = schemaMapper.MapSchemaToViewModel(databasePath); TreeViewItems.Add(databaseItem); log.Info("Opened database '" + databaseItem.DatabasePath + "'."); }
public void RefreshTree() { log.Info("Refreshing the database tree."); var databasePaths = TreeViewItems.Select(x => x.DatabasePath).ToList(); TreeViewItems.Clear(); var schemaMapper = new SchemaToViewModelMapper(); foreach (var path in databasePaths) { TreeViewItems.Add(schemaMapper.MapSchemaToViewModel(path)); } }
protected void OnIsExpandedChanged(bool oldValue) { if (IsExpanded) { try { TreeViewItems.Clear(); DirectoryInfo.EnumerateDirectories().ToList().ForEach(f => TreeViewItems.Add(Create(f))); } catch (UnauthorizedAccessException) { //无权限 } } }
private void SetVariant(int index) { TreeViewItems.Clear(); var variantName = AvailableLods.Skip(index).FirstOrDefault(); objectModel.SetVariant(variantName); foreach (var child in objectModel.Children.OfType <IMeshNode>()) { TreeViewItems.Add(new TreeItemModel { Header = child.Name, IsChecked = true, Tag = child }); } }
public CrawlerTreeViewModel() : base(ViewModelId.CrawlerTree) { crawlingDepth = 2; crawlerOutput = new TreeViewItems(); // Configure buttons state StartBtnEnabled = false; StopBtnEnabled = false; // Register commands StartBtnClick = new ButtonCommandAsync(OnStartCrawling); StopBtnClick = new ButtonCommand(OnStopCrawling); // Init internal tree view items quick access storage treeNodesDict = new Dictionary <int, CrawlerTreeViewItem>(); }
//================================================================================================================================================ // Delegate Command Methods //================================================================================================================================================ #region OnAddProject(object parameter) protected void OnAddProject(object parameter) { Project p = new Project(); Projects.Add(p); //Items.Add(p); NewProjectDialog npd = new NewProjectDialog(p); npd.ShowDialog(); TreeViewItem tvi = new TreeViewItem(); tvi.Header = p.Name; tvi.DataContext = p; TreeViewItems.Add(tvi); CurrentItem = tvi; }
private void DraggingMonitorLoop() { const int scrollMargin = 8; TreeNode lastOver = null; int overItemCount = 0; while (!abortThreads) { if (isDragging && dragginOverNode != null) { try { if (draggingLocation.Y <= scrollMargin) { TreeViewItems.ScrollUp(); } else if (draggingLocation.Y >= TreeViewItems.Height - scrollMargin) { TreeViewItems.ScrollDown(); } else if (lastOver != dragginOverNode) { this.Invoke((MethodInvoker) delegate { if (dragginOverNode.Nodes.Count > 0 && !dragginOverNode.IsExpanded) { lastOver = dragginOverNode; overItemCount = 0; } else { lastOver = null; } }); } else if (lastOver == dragginOverNode && lastOver != null && ++overItemCount >= 10) { this.Invoke((MethodInvoker) delegate { dragginOverNode.Expand(); lastOver = null; }); } } catch { } } Thread.Sleep(100); } }
public void AddItem() { TreeViewItems.Add(new PUTreeViewItemModel() { Header = "第" + (TreeViewItems.Count + 1) + "部分", Value = (TreeViewItems.Count + 1).ToString(), Items = new List <PUTreeViewItemModel>() { new PUTreeViewItemModel() { Header = "Value : " + (TreeViewItems.Count + 1) + "-1", Value = (TreeViewItems.Count + 1) + "-1", }, new PUTreeViewItemModel() { Header = "Value : " + (TreeViewItems.Count + 1) + "-2", Value = (TreeViewItems.Count + 1) + "-2", }, } }); }
private IEnumerable <IGeometryPermutation> GetSelectedPermutations(IGeometryModel model) { foreach (var parent in TreeViewItems.Where(i => i.IsChecked != false)) { var region = model.Regions.ElementAtOrDefault((parent.Tag as RenderModel3D.Region)?.SourceIndex ?? -1); if (region == null) { continue; } foreach (var child in parent.Items.Where(i => i.IsChecked == true)) { var permutation = region.Permutations.ElementAtOrDefault((child.Tag as RenderModel3D.Permutation)?.SourceIndex ?? -1); if (permutation != null) { yield return(permutation); } } } }
private void AddRenderModelNodes <TParent, TChild>(IEnumerable <TParent> collection, Func <TParent, IEnumerable <TChild> > getChildren) where TParent : IMeshNode where TChild : IMeshNode { foreach (var parent in collection) { var parentNode = new TreeItemModel { Header = parent.Name, IsChecked = true, Tag = parent }; foreach (var child in getChildren(parent)) { var childNode = new TreeItemModel { Header = child.Name, IsChecked = true, Tag = child }; parentNode.Items.Add(childNode); } if (parentNode.HasItems) { TreeViewItems.Add(parentNode); } } }
private void directoryTree_BeforeExpand(object sender, TreeViewCancelEventArgs e) { TreeViewItems.Add(e.Node); }
private void SetupEventhandlers() { adConfigMonitor.Changed += (object o, FileSystemEventArgs e) => { if (e.FullPath == adConfigFileName && (DateTime.Now.Ticks - lastConfigUpdate > 500000)) { lastConfigUpdate = DateTime.Now.Ticks; this.Invoke((MethodInvoker) delegate { LoadAddressBook(); }); } }; TreeViewItems.MouseDoubleClick += (object o, MouseEventArgs e) => { TreeNode n = TreeViewItems.GetNodeAt(e.Location); if (n == null || n.Tag is Group) { return; } Connect(); }; TreeViewItems.MouseDown += (object o, MouseEventArgs e) => { TreeNode n = TreeViewItems.GetNodeAt(e.Location); if (n == null || e.Button != MouseButtons.Right) { return; } TreeViewItems.SelectedNode = n; }; TreeViewItems.MouseUp += delegate { isDragging = false; }; TreeViewItems.DragLeave += delegate { isDragging = false; }; TreeViewItems.DragEnter += delegate { isDragging = true; }; TreeViewItems.AfterSelect += delegate { selectedNode = TreeViewItems.SelectedNode; if (selectedNode == null) { return; } HandleNodeSelected(selectedNode); }; TreeViewItems.AfterLabelEdit += (object o, NodeLabelEditEventArgs e) => { if (e.Label != null && e.Label != "") { ((ADItem)e.Node.Tag).Name = e.Label; SaveSettings(true); } }; TreeViewItems.BeforeLabelEdit += (object o, NodeLabelEditEventArgs e) => e.CancelEdit = (e.Node.Parent == null); TreeViewItems.ItemDrag += (object o, ItemDragEventArgs e) => { selectedNode = (TreeNode)e.Item; if (e.Button == MouseButtons.Left) { isDragging = true; TreeViewItems.SelectedNode = selectedNode; TreeViewItems.DoDragDrop(selectedNode, DragDropEffects.Move); } }; TreeViewItems.DragOver += (object o, DragEventArgs e) => { draggingLocation = TreeViewItems.PointToClient(new Point(e.X, e.Y)); dragginOverNode = TreeViewItems.GetNodeAt(draggingLocation); if (dragginOverNode == null || dragginOverNode.Tag is Item) { e.Effect = DragDropEffects.None; } else { e.Effect = e.AllowedEffect; } }; TreeViewItems.DragDrop += (object o, DragEventArgs e) => { dragginOverNode = TreeViewItems.GetNodeAt(TreeViewItems.PointToClient(new Point(e.X, e.Y))); if (dragginOverNode != null) { Group tg = (Group)dragginOverNode.Tag; string nodeText = selectedNode.Text; if (selectedNode.Tag is Item si) { ((Group)si.Parent).Items.Remove(si); tg.Items.Add((Item)si.Clone(tg)); } else { Group sg = (Group)selectedNode.Tag; ((Group)sg.Parent).Groups.Remove(sg); tg.Groups.Add((Group)sg.Clone(sg)); } SaveSettings(false); SelectNode(TreeViewItems.Nodes, nodeText); } }; ConnectToolStripMenuItem.Click += delegate { Connect(); }; AddItemToolStripMenuItem.Click += delegate { AddItem(); }; AddGroupToolStripMenuItem.Click += delegate { AddGroup(); }; RenameToolStripMenuItem.Click += delegate { selectedNode.BeginEdit(); }; DeleteToolStripMenuItem.Click += delegate { DeleteItem(); }; TextBoxDescription.TextChanged += delegate { if (!ignoreTextBoxEvents) { ((Item)selectedNode.Tag).Description = TextBoxDescription.Text; } }; LinkLabelConnect.Click += delegate { Connect(); }; this.FormClosing += delegate { abortThreads = true; while (draggingMonitor.ThreadState == System.Threading.ThreadState.Background) { Thread.Sleep(100); } adConfigMonitor.Dispose(); SaveSettings(true); }; this.KeyDown += (object o, KeyEventArgs e) => { switch (e.KeyCode) { case Keys.F2: if (this.ActiveControl == TreeViewItems) { selectedNode?.BeginEdit(); } break; case Keys.Enter: Connect(); // Avoid the freaking bell... e.Handled = true; e.SuppressKeyPress = true; break; case Keys.Delete: if (this.ActiveControl == TreeViewItems) { DeleteItem(); } break; } }; TextBoxFilter.TextChanged += (object o, EventArgs e) => filterTimer.Change(500, Timeout.Infinite); }