Exemplo n.º 1
0
 /// <summary>
 /// Set a new <paramref name="model"/> to be displayed in the <see
 /// cref="ListView"/>.
 /// </summary>
 public void SetModel(TreeListViewModel <TNode> model)
 {
     _listView.BeginUpdate();
     try {
         _currentModel = model;
         UpdateListView();
     } finally {
         _listView.EndUpdate();
     }
 }
Exemplo n.º 2
0
            public bool IsExpanded(TreeListViewModel <TNode> model, TNode node, string path)
            {
                bool savedState;

                if (_expandedStates.TryGetValue(path, out savedState))
                {
                    return(savedState);
                }
                return(model.IsNodeExpanded(node));
            }
Exemplo n.º 3
0
        private static string MakeNodePath(TreeListViewModel <TNode> model, string path, TNode node)
        {
            var text = model.GetNodePathComponent(node).Replace('\\', '-');

            if (string.IsNullOrEmpty(path))
            {
                return(text);
            }
            return(path + "\\" + text);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create all list view items corresponding to all the properties and property groups
        /// that should be displayed in the list view. Children of property groups that are not
        /// expanded are skipped -- they will be created when the groups are expanded.
        /// </summary>
        private List <ListViewItem> CreateListViewItems(TreeListViewModel <TNode> model, ExpandedNodeState expandedNodeState)
        {
            var itemList = new List <ListViewItem>();

            if (model == null)
            {
                return(itemList);
            }

            if (model.IsRootVisible())
            {
                CreateListViewItem(itemList, expandedNodeState, "", 0, model, model.GetRootNode());
            }
            else
            {
                Enumerable.Range(0, model.GetChildCount(model.GetRootNode())).ForEach(index => {
                    CreateListViewItem(itemList, expandedNodeState, "", 0, model, model.GetChildAt(model.GetRootNode(), index));
                });
            }
            return(itemList);
        }
Exemplo n.º 5
0
        private void CreateListViewItem(List <ListViewItem> itemList, ExpandedNodeState expandedNodeState, string parentPath, int indent, TreeListViewModel <TNode> model, TNode node)
        {
            var propertyNodePath = MakeNodePath(model, parentPath, node);
            var item             = new ListViewItem();

            itemList.Add(item); // Add the item before (optional) recursive call

            // Add sub-properties recursively (if group)
            if (model.IsNodeExpandable(node))
            {
                var isExpanded = expandedNodeState.IsExpanded(model, node, propertyNodePath);
                item.ImageIndex = isExpanded ? 1 : 0;
                if (isExpanded)
                {
                    Enumerable.Range(0, model.GetChildCount(node)).ForEach(index => {
                        CreateListViewItem(itemList, expandedNodeState, propertyNodePath, indent + 1, model, model.GetChildAt(node, index));
                    });
                }
            }

            // Setup final item properties after recursion, in case property node
            // value, for example, was changed as a side effect of the recursive call.
            item.Text = model.GetNodeText(node);
            var subItemCount = model.GetNodeSubItemCount(node);

            for (var subItem = 0; subItem < subItemCount; subItem++)
            {
                item.SubItems.Add(model.GetNodeSubItemAt(node, subItem));
            }
            item.Tag         = new ListViewItemTag(node, propertyNodePath);
            item.IndentCount = indent;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Remove the current <see cref="TreeNodeCollection"/> and remove all entries
 /// displayed in the <see cref="ListView"/>.
 /// </summary>
 public void Clear()
 {
     _listView.Items.Clear();
     _currentModel = null;
 }