Inheritance: CodeExplorerItemViewModel
コード例 #1
0
        private bool AddNodesToTree(CodeExplorerCustomFolderViewModel tree, List <Declaration> items, IGrouping <string, Declaration> grouping)
        {
            foreach (var folder in tree.Items.OfType <CodeExplorerCustomFolderViewModel>())
            {
                if (grouping.Key.Replace("\"", string.Empty) != folder.FullPath)
                {
                    continue;
                }

                if (folder.Parent.Name == string.Empty)
                {
                    folder.SetParent(this);
                }

                var parents = grouping.Where(
                    item => ComponentTypes.Contains(item.DeclarationType) &&
                    item.CustomFolder.Replace("\"", string.Empty) == folder.FullPath)
                              .ToList();

                folder.AddNodes(items.Where(item => parents.Contains(item) || parents.Any(parent =>
                                                                                          (item.ParentDeclaration != null && item.ParentDeclaration.Equals(parent)) ||
                                                                                          item.ComponentName == parent.ComponentName)).ToList());

                return(true);
            }

            return(tree.Items.OfType <CodeExplorerCustomFolderViewModel>().Any(node => AddNodesToTree(node, items, grouping)));
        }
コード例 #2
0
        private void ParserState_ModuleStateChanged(object sender, Parsing.ParseProgressEventArgs e)
        {
            // if we are resolving references, we already have the declarations and don't need to display error
            if (!(e.State == ParserState.Error ||
                  (e.State == ParserState.ResolverError &&
                   e.OldState == ParserState.ResolvingDeclarations)))
            {
                return;
            }

            var components       = e.Component.Collection;
            var componentProject = components.Parent;
            {
                var projectNode = Projects.OfType <CodeExplorerProjectViewModel>()
                                  .FirstOrDefault(p => p.Declaration.Project.Equals(componentProject));

                if (projectNode == null)
                {
                    return;
                }

                SetErrorState(projectNode, e.Component);

                if (_errorStateSet)
                {
                    return;
                }

                // at this point, we know the node is newly added--we have to add a new node, not just change the icon of the old one.
                var projectName = componentProject.Name;
                var folderNode  = projectNode.Items.FirstOrDefault(f => f is CodeExplorerCustomFolderViewModel && f.Name == projectName);

                UiDispatcher.Invoke(() =>
                {
                    if (folderNode == null)
                    {
                        folderNode = new CodeExplorerCustomFolderViewModel(projectNode, projectName, projectName);
                        projectNode.AddChild(folderNode);
                    }

                    var declaration = CreateDeclaration(e.Component);
                    var newNode     = new CodeExplorerComponentViewModel(folderNode, declaration, new List <Declaration>())
                    {
                        IsErrorState = true
                    };

                    folderNode.AddChild(newNode);

                    // Force a refresh. OnPropertyChanged("Projects") didn't work.
                    Projects = Projects;
                });
            }
        }
コード例 #3
0
        public CodeExplorerProjectViewModel(FolderHelper folderHelper, Declaration declaration, IEnumerable <Declaration> declarations)
        {
            _declaration = declaration;
            _name        = _declaration.IdentifierName;
            IsExpanded   = true;
            _folderTree  = folderHelper.GetFolderTree(declaration);

            try
            {
                FillFolders(declarations.ToList());
                Items = _folderTree.Items.ToList();

                _icon = _declaration.Project.Protection == ProjectProtection.Locked
                    ? GetImageSource(resx.lock__exclamation)
                    : GetImageSource(resx.ObjectLibrary);
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #4
0
        private static IEnumerable <CodeExplorerItemViewModel> FindFolders(IEnumerable <Declaration> declarations, char delimiter)
        {
            var root = new CodeExplorerCustomFolderViewModel(string.Empty, new List <Declaration>());

            var items   = declarations.ToList();
            var folders = items.Where(item => ComponentTypes.Contains(item.DeclarationType))
                          .GroupBy(item => item.CustomFolder)
                          .OrderBy(item => item.Key);

            foreach (var grouping in folders)
            {
                CodeExplorerItemViewModel node = root;
                var parts = grouping.Key.Split(delimiter);
                var path  = new StringBuilder();
                foreach (var part in parts)
                {
                    if (path.Length != 0)
                    {
                        path.Append(delimiter);
                    }

                    path.Append(part);
                    var next = node.GetChild(part);
                    if (next == null)
                    {
                        var currentPath = path.ToString();
                        var parents     = grouping.Where(item => ComponentTypes.Contains(item.DeclarationType) && item.CustomFolder == currentPath).ToList();

                        next = new CodeExplorerCustomFolderViewModel(part, items.Where(item =>
                                                                                       parents.Contains(item) || parents.Any(parent =>
                                                                                                                             (item.ParentDeclaration != null && item.ParentDeclaration.Equals(parent)) || item.ComponentName == parent.ComponentName)));
                        node.AddChild(next);
                    }

                    node = next;
                }
            }

            return(root.Items);
        }