Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        /// <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;
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        void Display(NodeVm rootNodeVm)
        {
            var tvis = rootNodeVm.ToTreeViewItem();

            TreeViewItems.Clear();
            TreeViewItems.Add(tvis);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 public void RemoveItem()
 {
     if (TreeViewItems.Count > 0)
     {
         TreeViewItems.RemoveAt(TreeViewItems.Count - 1);
     }
 }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        public TestTreeViewItem[] GetMainTestGroups()
        {
            var list = new List <TreeViewItemBase>();

            list.AddRange(TreeViewItems.Where(x => x.GetType() == typeof(TestTreeViewItem)));

            return(list.Cast <TestTreeViewItem>().ToArray());
        }
Exemplo n.º 10
0
        public void CloseDatabase(string databasePath)
        {
            var db = TreeViewItems.Single(x => x.DatabasePath.Equals(databasePath));

            TreeViewItems.Remove(db);

            log.Info("Closed database '" + db.DatabasePath + "'.");
        }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
 public void Dispose()
 {
     TreeViewItems.Clear();
     ClearChildren();
     modelGroup.Dispose();
     renderer.Dispose();
     modelFactory.Dispose();
     GC.Collect();
 }
Exemplo n.º 13
0
        public void SetSelectedTreeViewItem(Type type)
        {
            if (type == null)
            {
                return;
            }

            SetSelectedItem(type, TreeViewItems.ToList());
        }
Exemplo n.º 14
0
        /// <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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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());
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        /// <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();
        }
Exemplo n.º 19
0
        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 + "'.");
        }
Exemplo n.º 20
0
        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));
            }
        }
Exemplo n.º 21
0
 protected void OnIsExpandedChanged(bool oldValue)
 {
     if (IsExpanded)
     {
         try
         {
             TreeViewItems.Clear();
             DirectoryInfo.EnumerateDirectories().ToList().ForEach(f => TreeViewItems.Add(Create(f)));
         }
         catch (UnauthorizedAccessException)
         {
             //无权限
         }
     }
 }
Exemplo n.º 22
0
        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
                });
            }
        }
Exemplo n.º 23
0
        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>();
        }
Exemplo n.º 24
0
        //================================================================================================================================================
        // 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;
        }
Exemplo n.º 25
0
        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);
            }
        }
Exemplo n.º 26
0
 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",
             },
         }
     });
 }
Exemplo n.º 27
0
        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);
                    }
                }
            }
        }
Exemplo n.º 28
0
        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);
                }
            }
        }
Exemplo n.º 29
0
 private void directoryTree_BeforeExpand(object sender, TreeViewCancelEventArgs e)
 {
     TreeViewItems.Add(e.Node);
 }
Exemplo n.º 30
0
        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);
        }