Inheritance: Rubberduck.UI.ViewModelBase
示例#1
0
        private void SetErrorState(CodeExplorerItemViewModel itemNode, VBComponent component)
        {
            _errorStateSet = false;

            foreach (var node in itemNode.Items)
            {
                if (node is CodeExplorerCustomFolderViewModel)
                {
                    SetErrorState(node, component);
                }

                if (_errorStateSet)
                {
                    return;
                }

                if (node is CodeExplorerComponentViewModel)
                {
                    var componentNode = (CodeExplorerComponentViewModel)node;
                    if (componentNode.GetSelectedDeclaration().QualifiedName.QualifiedModuleName.Component == component)
                    {
                        componentNode.IsErrorState = true;
                        _errorStateSet             = true;
                    }
                }
            }
        }
示例#2
0
        private void SwitchNodeState(CodeExplorerItemViewModel node, bool expandedState)
        {
            node.IsExpanded = expandedState;

            foreach (var item in node.Items)
            {
                item.IsExpanded = expandedState;
                SwitchNodeState(item, expandedState);
            }
        }
        public CodeExplorerCustomFolderViewModel(CodeExplorerItemViewModel parent, string name, string fullPath)
        {
            _parent          = parent;
            _fullPath        = fullPath;
            _name            = name.Replace("\"", string.Empty);
            _folderAttribute = string.Format("@Folder(\"{0}\")", fullPath.Replace("\"", string.Empty));

            _collapsedIcon = GetImageSource(resx.folder_horizontal);
            _expandedIcon  = GetImageSource(resx.folder_horizontal_open);
        }
        public CodeExplorerCustomFolderViewModel(CodeExplorerItemViewModel parent, string name, string fullPath, IProjectsProvider projectsProvider)
        {
            _parent           = parent;
            _projectsProvider = projectsProvider;
            FullPath          = fullPath;
            Name            = name.Replace("\"", string.Empty);
            FolderAttribute = string.Format("@Folder(\"{0}\")", fullPath.Replace("\"", string.Empty));

            CollapsedIcon = GetImageSource(Resources.CodeExplorer.CodeExplorerUI.FolderClosed);
            ExpandedIcon  = GetImageSource(Resources.CodeExplorer.CodeExplorerUI.FolderOpen);
        }
示例#5
0
        public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declaration declaration, IEnumerable <Declaration> declarations, IProjectsProvider projectsProvider)
        {
            Parent            = parent;
            Declaration       = declaration;
            _projectsProvider = projectsProvider;
            _icon             = Icons[DeclarationType];
            Items             = declarations.GroupBy(item => item.Scope).SelectMany(grouping =>
                                                                                    grouping.Where(item => item.ParentDeclaration != null &&
                                                                                                   item.ParentScope == declaration.Scope &&
                                                                                                   MemberTypes.Contains(item.DeclarationType))
                                                                                    .OrderBy(item => item.QualifiedSelection.Selection.StartLine)
                                                                                    .Select(item => new CodeExplorerMemberViewModel(this, item, grouping)))
                                .ToList <CodeExplorerItemViewModel>();

            _name = Declaration.IdentifierName;

            var qualifiedModuleName = declaration.QualifiedName.QualifiedModuleName;

            try
            {
                if (qualifiedModuleName.ComponentType == ComponentType.Document)
                {
                    var    component = _projectsProvider.Component(qualifiedModuleName);
                    string parenthesizedName;
                    using (var properties = component.Properties)
                    {
                        parenthesizedName = properties["Name"].Value.ToString() ?? String.Empty;
                    }

                    if (ContainsBuiltinDocumentPropertiesProperty())
                    {
                        CodeExplorerItemViewModel node = this;
                        while (node.Parent != null)
                        {
                            node = node.Parent;
                        }

                        ((CodeExplorerProjectViewModel)node).SetParenthesizedName(parenthesizedName);
                    }
                    else
                    {
                        _name += " (" + parenthesizedName + ")";
                    }
                }
            }
            catch
            {
                // gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason)
            }
        }
示例#6
0
        public CodeExplorerMemberViewModel(CodeExplorerItemViewModel parent, Declaration declaration, IEnumerable <Declaration> declarations)
        {
            _parent = parent;

            _declaration = declaration;
            if (declarations != null)
            {
                Items = declarations.Where(item => SubMemberTypes.Contains(item.DeclarationType) && item.ParentDeclaration.Equals(declaration))
                        .OrderBy(item => item.Selection.StartLine)
                        .Select(item => new CodeExplorerMemberViewModel(this, item, null))
                        .ToList <CodeExplorerItemViewModel>();
            }

            var modifier = declaration.Accessibility == Accessibility.Global || declaration.Accessibility == Accessibility.Implicit
                ? Accessibility.Public
                : declaration.Accessibility;
            var key = Tuple.Create(declaration.DeclarationType, modifier);

            _name = DetermineMemberName(declaration);
            _icon = Mappings[key];
        }
示例#7
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);
        }
示例#8
0
 public void AddChild(CodeExplorerItemViewModel item)
 {
     _items.Add(item);
 }
 // I have to set the parent from a different location than
 // the node is created because of the folder helper
 internal void SetParent(CodeExplorerItemViewModel parent)
 {
     _parent = parent;
 }
示例#10
0
        public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declaration declaration, IEnumerable <Declaration> declarations, IProjectsProvider projectsProvider)
        {
            Parent            = parent;
            Declaration       = declaration;
            _projectsProvider = projectsProvider;

            _icon = Icons.ContainsKey(DeclarationType)
                ? Icons[DeclarationType]
                : GetImageSource(CodeExplorerUI.status_offline);

            Items = declarations.GroupBy(item => item.Scope).SelectMany(grouping =>
                                                                        grouping.Where(item => item.ParentDeclaration != null &&
                                                                                       item.ParentScope == declaration.Scope &&
                                                                                       MemberTypes.Contains(item.DeclarationType))
                                                                        .OrderBy(item => item.QualifiedSelection.Selection.StartLine)
                                                                        .Select(item => new CodeExplorerMemberViewModel(this, item, grouping)))
                    .ToList <CodeExplorerItemViewModel>();

            _name = DeclarationType == DeclarationType.ResFile && string.IsNullOrEmpty(Declaration.IdentifierName)
                ? CodeExplorerUI.CodeExplorer_ResourceFileText
                : Declaration.IdentifierName;

            var qualifiedModuleName = declaration.QualifiedName.QualifiedModuleName;

            try
            {
                switch (qualifiedModuleName.ComponentType)
                {
                case ComponentType.Document:
                    var    component = _projectsProvider.Component(qualifiedModuleName);
                    string parenthesizedName;
                    using (var properties = component.Properties)
                    {
                        parenthesizedName = properties["Name"].Value.ToString() ?? string.Empty;
                    }

                    if (ContainsBuiltinDocumentPropertiesProperty())
                    {
                        CodeExplorerItemViewModel node = this;
                        while (node.Parent != null)
                        {
                            node = node.Parent;
                        }

                        ((CodeExplorerProjectViewModel)node).SetParenthesizedName(parenthesizedName);
                    }
                    else
                    {
                        _name += " (" + parenthesizedName + ")";
                    }
                    break;

                case ComponentType.ResFile:
                    var fileName = Declaration.IdentifierName.Split('\\').Last();
                    _name = $"{CodeExplorerUI.CodeExplorer_ResourceFileText} ({fileName})";
                    break;

                case ComponentType.RelatedDocument:
                    _name = $"({Declaration.IdentifierName.Split('\\').Last()})";
                    break;

                default:
                    _name = Declaration.IdentifierName;
                    break;
                }
            }
            catch
            {
                // gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason)
            }
        }
 public void AddChild(CodeExplorerItemViewModel item)
 {
     _items.Add(item);
 }