コード例 #1
0
        public DocumentNode AddDocumentNode(int docID, bool needVisible, string nodeTitle, bool links)
        {
            if (documentNodes == null)
            {
                documentNodes = new SynchronizedCollection <KeyValuePair <int, DocumentNode> >();
            }
            int indexOf = -1;

            for (int i = 0; i < documentNodes.Count && indexOf == -1; i++)
            {
                if (documentNodes[i].Key == docID)
                {
                    indexOf = i;
                }
            }

            if (indexOf == -1)
            {
                try
                {
                    var newNode = new DocumentNode(docID, docID.ToString(), nodeTitle, links);
                    documentNodes.Add(new KeyValuePair <int, DocumentNode>(docID, newNode));
                    if (!Environment.UserSettings.LinkDocIDs.Contains(docID))
                    {
                        Environment.UserSettings.LinkDocIDs.Add(docID);
                    }

                    if (workFolderNodes.Count > 0)
                    {
                        int placeid = WorkFolderNode.Index;
                        Nodes.Insert(placeid + 1, newNode);
                        lastOverNode = null;
                    }
                    else
                    {
                        Nodes.Insert(1, newNode);
                    }
                    // убираем болд
                    newNode.RemoveBoldRecursive();

                    return(newNode);
                }
                catch
                {
                    if (Environment.UserSettings.LinkDocIDs.Contains(docID))
                    {
                        Environment.UserSettings.LinkDocIDs.Remove(docID);
                    }
                    return(null);
                }
            }

            DocumentNode docNode = documentNodes[indexOf].Value;

            docNode.LoadSubNodes();
            if (!Nodes.Contains(docNode))
            {
                if (workFolderNodes.Count > 0)
                {
                    int placeid = WorkFolderNode.Index;
                    Nodes.Insert(placeid + 1, docNode);
                    lastOverNode = null;
                }
                else
                {
                    Nodes.Insert(1, docNode);
                }
            }
            if (needVisible)
            {
                docNode.EnsureVisible();
            }
            return(docNode);
        }