Example #1
0
        private void AddObject(object obj)
        {
            if (obj is ITreeNode)
            {
                ITreeNode     node     = (ITreeNode)obj;
                DATreeNode    realNode = (DATreeNode)node.RealNode;
                TreeView      tree     = realNode.TreeView;
                ObjectWrapper wrap     = new ObjectWrapper();
                m_objs[obj]  = wrap;
                wrap.varname = "obj" + m_objs.Count.ToString();
                wrap.obj     = obj;
                wrap.cparent = m_ctrls[tree];

                List <string> pathvars = new List <string>();
                ITreeNode     cur      = node;
                while (cur != null && cur.Parent != null)
                {
                    pathvars.Add(AddVariable(cur.TypeTitle, cur.Name, cur));
                    cur = cur.Parent;
                }
                pathvars.Reverse();

                wrap.vardef = String.Format("    {0} = FindNodeByPath({1}, [{2}])\n", wrap.varname, GetControlExpression(tree, false), String.Join(",", pathvars.ToArray()));
            }
        }
Example #2
0
 public void DispatchAddedNode(DATreeNode node)
 {
     if (AddedNode != null)
     {
         AddedNode(this, new NodeEventArgs(node));
     }
 }
Example #3
0
        private void tree_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            try
            {
                if (e.Node is DATreeNode)
                {
                    DATreeNode ada = (DATreeNode)e.Node;

                    if (e.Label == null)
                    {
                        ada.Text = ada.m_node.Title;
                        return;
                    }

                    string newname = e.Label;
                    e.CancelEdit = true;// revert to old name
                    ada.Text     = ada.m_node.Title;
                    MacroManager.RenameNode(ada.m_node, newname);
                    ada.m_node.RenameNode(newname);
                    TreeNodeExtension.CompleteRefresh(ada.m_node.Parent);
                }
            }
            catch (Exception ex)
            {
                Errors.Report(ex);
            }
        }
Example #4
0
 private void tree_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)
 {
     if (m_lastDoubleClick != null && (DateTime.Now - m_lastDoubleClick.Value).TotalSeconds < 3)
     {
         e.CancelEdit = true;
         return;
     }
     if (!TreeBehaviour.AllowRenameNode)
     {
         e.CancelEdit = true;
         return;
     }
     if (ShowingRenameEditor)
     {
         return;
     }
     if (e.Node is DATreeNode)
     {
         DATreeNode ada = (DATreeNode)e.Node;
         if (ada.m_node.AllowRename())
         {
             MainWindow.Instance.RunInMainWindow(ada.ShowRenameEditor);
             e.CancelEdit = true;
             return;
         }
     }
     e.CancelEdit = true;
 }
Example #5
0
        public static ITreeNode FindNode(TreeView tree, IEnumerable path)
        {
            TreeNode curnode = tree.Nodes[0];

            foreach (object oelem in path)
            {
                string elem = oelem.ToString();
                if (String.IsNullOrEmpty(elem))
                {
                    continue;
                }
                TreeNode newcurnode = null;
                foreach (TreeNode child in curnode.Nodes)
                {
                    DATreeNode ada = child as DATreeNode;
                    if (ada != null && ada.m_node.Name == elem)
                    {
                        newcurnode = ada;
                        break;
                    }
                }
                if (newcurnode == null)
                {
                    return(null);
                }
                curnode = newcurnode;
            }
            if (curnode is DATreeNode)
            {
                return(((DATreeNode)curnode).m_node);
            }
            return(null);
        }
Example #6
0
        private void FillChildren()
        {
            if (m_filledChildren)
            {
                return;
            }
            m_filledChildren = true;
            Nodes.Clear();
            //List<TreeNode> nodes = new List<TreeNode>();
            List <ITreeNode> children = new List <ITreeNode>();

            children.AddRange(m_node.GetChildren());
            foreach (var item in TreeExtenderAddonType.Instance.CommonSpace.GetAllAddons())
            {
                var ext = (ITreeExtender)item.InstanceModel;
                try
                {
                    ext.GetExtendedChildren(m_node, children);
                }
                catch (Exception e)
                {
                    Logging.Warning("Error generating node:" + e.ToString());
                }
            }
            Dictionary <string, bool> usedKeys = new Dictionary <string, bool>();

            foreach (ITreeNode child in children)
            {
                if (!m_tree.FilterNode(child))
                {
                    continue;
                }
                if (child.AllowReuse() && m_oldnodes != null && m_oldnodes.ContainsKey(NodeKey(child)) && !usedKeys.ContainsKey(NodeKey(child)))
                {
                    usedKeys[NodeKey(child)] = true;
                    Nodes.Add(m_oldnodes[NodeKey(child)]);
                }
                else
                {
                    var danode = new DATreeNode(child, m_tree);
                    Nodes.Add(danode);
                    if (IsExpanded)
                    {
                        danode.WantChildren();
                        danode.UpdateImageIndex();
                    }
                }
            }
            //Nodes.AddRange(nodes.ToArray());
            m_oldnodes = null;
        }
Example #7
0
        public void RefreshChilds(bool deep)
        {
            bool wasexpanded = IsExpanded;

            m_oldnodes = new Dictionary <string, DATreeNode>();
            foreach (TreeNode node in Nodes)
            {
                if (!(node is DATreeNode))
                {
                    continue;                        // dummy node
                }
                DATreeNode ada = (DATreeNode)node;
                if (ada.IsDead)
                {
                    continue;
                }
                if (!deep)
                {
                    m_oldnodes[NodeKey(ada.m_node)] = ada;
                }
            }
            Nodes.Clear();
            m_filledChildren = false;

            if (m_node.PreparedChildren)
            {
                FillChildren();
            }
            else
            {
                Nodes.Add("__dummy__");
                Collapse();
            }
            if (wasexpanded)
            {
                Expand();
            }
        }
Example #8
0
 private void SetRoot(ITreeNode node)
 {
     if (node != null)
     {
         m_root = new DATreeNode(node, this);
     }
     else
     {
         m_root = null;
     }
     tree.Nodes.Clear();
     if (m_root != null)
     {
         if (VisibleRoot)
         {
             tree.Nodes.Add(m_root);
             m_root.UpdateImageIndex();
             m_root.WantChildren();
             MainWindow.Instance.RunInMainWindow(tree.Nodes[0].Expand);
         }
         else
         {
             foreach (ITreeNode child in m_root.m_node.GetChildrenNow())
             {
                 var ada = new DATreeNode(child, this);
                 ada.UpdateImageIndex();
                 if (FilterNode(child))
                 {
                     tree.Nodes.Add(ada);
                 }
                 ada.WantChildren();
             }
         }
     }
     UpdateToolbarEnabling();
 }