Пример #1
0
 void CollectExtensions(AddinDescription desc, string path, List <Extension> extensions, List <ExtensionNodeDescription> nodes)
 {
     foreach (Extension ext in desc.MainModule.Extensions)
     {
         if (ext.Path == path || ext.Path.StartsWith(path + "/"))
         {
             extensions.Add(ext);
         }
         else if (path.StartsWith(ext.Path + "/"))
         {
             string subp = path.Substring(ext.Path.Length);
             ExtensionNodeDescription           foundNode = null;
             ExtensionNodeDescriptionCollection list      = ext.ExtensionNodes;
             foreach (string p in subp.Split('/'))
             {
                 if (p.Length == 0)
                 {
                     continue;
                 }
                 foundNode = list [p];
                 if (foundNode == null)
                 {
                     break;
                 }
             }
             if (foundNode != null)
             {
                 foreach (ExtensionNodeDescription n in foundNode.ChildNodes)
                 {
                     nodes.Add(n);
                 }
             }
         }
     }
 }
        void FillNodes(TreeIter iter, ExtensionNodeSet ns, ExtensionNodeDescriptionCollection nodes)
        {
            ExtensionNodeTypeCollection ntypes = ns.GetAllowedNodeTypes();

            foreach (ExtensionNodeDescription node in nodes)
            {
                if (node.IsCondition)
                {
                    FillNodes(iter, ns, nodes);
                    continue;
                }

                string            id = node.Id;
                ExtensionNodeType nt = ntypes [node.NodeName];

                // The node can only be extended if it has an ID and if it accepts child nodes
                if (id.Length > 0 && (nt.NodeTypes.Count > 0 || nt.NodeSets.Count > 0))
                {
                    TreeIter citer = GetBranch(iter, id + " (" + nt.NodeName + ")", null);
                    store.SetValue(citer, ColObject, node);
                    store.SetValue(citer, ColShowCheck, true);
                    store.SetValue(citer, ColChecked, false);
                    FillExtensionNodeSet(citer, nt);
                    FillNodes(citer, nt, node.ChildNodes);
                }
            }
        }
        ExtensionNodeDescription InsertNode(AddinData adata, ExtensionNodeInfo refNode, DropPosition pos, ExtensionNodeDescription newNode)
        {
            ExtensionNodeDescriptionCollection nodes = null;

            newNode.InsertBefore = "";
            newNode.InsertAfter  = "";

            if (refNode.CanModify)
            {
                if (pos == DropPosition.Into)
                {
                    nodes = refNode.Node.ChildNodes;
                }
                else if (refNode.Node.Parent is ExtensionNodeDescription)
                {
                    nodes = ((ExtensionNodeDescription)refNode.Node.Parent).ChildNodes;
                }
            }
            else
            {
                if (pos == DropPosition.After)
                {
                    newNode.InsertAfter = refNode.Node.Id;
                }
                else if (pos == DropPosition.Before)
                {
                    newNode.InsertBefore = refNode.Node.Id;
                }
            }
            if (nodes == null)
            {
                string path = refNode.Node.GetParentPath();
                if (pos == DropPosition.Into)
                {
                    path += "/" + refNode.Node.Id;
                }
                Extension ext = adata.CachedAddinManifest.MainModule.GetExtension(path);
                nodes = ext.ExtensionNodes;
            }

            for (int n = 0; n < nodes.Count; n++)
            {
                ExtensionNodeDescription node = nodes [n];
                if (node == refNode.Node)
                {
                    if (pos == DropPosition.After)
                    {
                        n++;
                    }
                    nodes.Insert(n, newNode);
                    return(newNode);
                }
            }
            nodes.Add(newNode);
            return(newNode);
        }
Пример #4
0
        internal static ExtensionNodeDescriptionCollection GetExtensionNodes(AddinRegistry registry, AddinDescription desc, string path)
        {
            ArrayList extensions = new ArrayList();

            CollectExtensions(desc, path, extensions);
            foreach (Dependency dep in desc.MainModule.Dependencies)
            {
                AddinDependency adep = dep as AddinDependency;
                if (adep == null)
                {
                    continue;
                }
                Addin addin = registry.GetAddin(adep.FullAddinId);
                if (addin != null)
                {
                    CollectExtensions(addin.Description, path, extensions);
                }
            }

            // Sort the extensions, to make sure they are added in the correct order
            // That is, deepest children last.
            extensions.Sort(new ExtensionComparer());

            ExtensionNodeDescriptionCollection nodes = new ExtensionNodeDescriptionCollection();

            // Add the nodes
            foreach (Extension ext in extensions)
            {
                string subp = path.Substring(ext.Path.Length);
                ExtensionNodeDescriptionCollection col = ext.ExtensionNodes;
                foreach (string p in subp.Split('/'))
                {
                    if (p.Length == 0)
                    {
                        continue;
                    }
                    ExtensionNodeDescription node = col [p];
                    if (node == null)
                    {
                        col = null;
                        break;
                    }
                    else
                    {
                        col = node.ChildNodes;
                    }
                }
                if (col != null)
                {
                    nodes.AddRange(col);
                }
            }
            return(nodes);
        }
Пример #5
0
        int BuildTree(TreeNavigator currentPosition, ExtensionNodeDescriptionCollection nodes, int currentDepth, ref int count)
        {
            int maxDepth = currentDepth;

            // TODO: insertbefore/after

            foreach (ExtensionNodeDescription node in nodes)
            {
                count++;
                var pos = currentPosition.Clone().AddChild();

                var label = GetLabelForNode(node);
                pos.SetValue(labelField, label);

                var childDepth = BuildTree(pos, node.ChildNodes, currentDepth + 1, ref count);
                maxDepth = Math.Max(maxDepth, childDepth);
            }

            return(maxDepth);
        }
Пример #6
0
        void LoadExtensionElement(TreeNode tnode, string addin, ExtensionNodeDescriptionCollection extension, ModuleDescription module, ref int curPos, BaseCondition parentCondition, bool inComplextCondition, List <TreeNode> addedNodes)
        {
            foreach (ExtensionNodeDescription elem in extension)
            {
                if (inComplextCondition)
                {
                    parentCondition     = ReadComplexCondition(elem, parentCondition);
                    inComplextCondition = false;
                    continue;
                }

                if (elem.NodeName == "ComplexCondition")
                {
                    LoadExtensionElement(tnode, addin, elem.ChildNodes, module, ref curPos, parentCondition, true, addedNodes);
                    continue;
                }

                if (elem.NodeName == "Condition")
                {
                    Condition cond = new Condition(AddinEngine, elem, parentCondition);
                    LoadExtensionElement(tnode, addin, elem.ChildNodes, module, ref curPos, cond, false, addedNodes);
                    continue;
                }

                var            pnode          = tnode;
                ExtensionPoint extensionPoint = null;
                while (pnode != null && (extensionPoint = pnode.ExtensionPoint) == null)
                {
                    pnode = pnode.Parent;
                }

                string after = elem.GetAttribute("insertafter");
                if (after.Length == 0 && extensionPoint != null && curPos == -1)
                {
                    after = extensionPoint.DefaultInsertAfter;
                }
                if (after.Length > 0)
                {
                    int i = tnode.Children.IndexOfNode(after);
                    if (i != -1)
                    {
                        curPos = i + 1;
                    }
                }
                string before = elem.GetAttribute("insertbefore");
                if (before.Length == 0 && extensionPoint != null && curPos == -1)
                {
                    before = extensionPoint.DefaultInsertBefore;
                }
                if (before.Length > 0)
                {
                    int i = tnode.Children.IndexOfNode(before);
                    if (i != -1)
                    {
                        curPos = i;
                    }
                }

                // If node position is not explicitly set, add the node at the end
                if (curPos == -1)
                {
                    curPos = tnode.Children.Count;
                }

                // Find the type of the node in this extension
                ExtensionNodeType ntype = addinEngine.FindType(tnode.ExtensionNodeSet, elem.NodeName, addin);

                if (ntype == null)
                {
                    addinEngine.ReportError("Node '" + elem.NodeName + "' not allowed in extension: " + tnode.GetPath(), addin, null, false);
                    continue;
                }

                string id = elem.GetAttribute("id");
                if (id.Length == 0)
                {
                    id = AutoIdPrefix + (++internalId);
                }

                TreeNode cnode = new TreeNode(addinEngine, id);

                ExtensionNode enode = ReadNode(cnode, addin, ntype, elem, module);
                if (enode == null)
                {
                    continue;
                }

                cnode.Condition        = parentCondition;
                cnode.ExtensionNodeSet = ntype;
                tnode.InsertChildNode(curPos, cnode);
                addedNodes.Add(cnode);

                if (cnode.Condition != null)
                {
                    Context.RegisterNodeCondition(cnode, cnode.Condition);
                }

                // Load children
                if (elem.ChildNodes.Count > 0)
                {
                    int cp = 0;
                    LoadExtensionElement(cnode, addin, elem.ChildNodes, module, ref cp, parentCondition, false, addedNodes);
                }

                curPos++;
            }
            if (Context.FireEvents)
            {
                tnode.NotifyChildrenChanged();
            }
        }
Пример #7
0
        void LoadExtensionElement(TreeNode tnode, string addin, ExtensionNodeDescriptionCollection extension, ref int curPos, BaseCondition parentCondition, bool inComplextCondition, ArrayList addedNodes)
        {
            foreach (ExtensionNodeDescription elem in extension)
            {
                if (inComplextCondition)
                {
                    parentCondition     = ReadComplexCondition(elem, parentCondition);
                    inComplextCondition = false;
                    continue;
                }

                if (elem.NodeName == "ComplexCondition")
                {
                    LoadExtensionElement(tnode, addin, elem.ChildNodes, ref curPos, parentCondition, true, addedNodes);
                    continue;
                }

                if (elem.NodeName == "Condition")
                {
                    Condition cond = new Condition(elem, parentCondition);
                    LoadExtensionElement(tnode, addin, elem.ChildNodes, ref curPos, cond, false, addedNodes);
                    continue;
                }

                string after = elem.GetAttribute("insertafter");
                if (after.Length > 0)
                {
                    int i = tnode.Children.IndexOfNode(after);
                    if (i != -1)
                    {
                        curPos = i + 1;
                    }
                }
                string before = elem.GetAttribute("insertbefore");
                if (before.Length > 0)
                {
                    int i = tnode.Children.IndexOfNode(before);
                    if (i != -1)
                    {
                        curPos = i;
                    }
                }

                // Find the type of the node in this extension
                ExtensionNodeType ntype = AddinManager.SessionService.FindType(tnode.ExtensionNodeSet, elem.NodeName, addin);

                if (ntype == null)
                {
                    AddinManager.ReportError("Node '" + elem.NodeName + "' not allowed in extension: " + tnode.GetPath(), addin, null, false);
                    continue;
                }

                string id = elem.GetAttribute("id");
                if (id.Length == 0)
                {
                    id = AutoIdPrefix + (++internalId);
                }

                TreeNode cnode = new TreeNode(id);

                ExtensionNode enode = ReadNode(cnode, addin, ntype, elem);
                if (enode == null)
                {
                    continue;
                }

                cnode.Condition        = parentCondition;
                cnode.ExtensionNodeSet = ntype;
                tnode.InsertChildNode(curPos, cnode);
                addedNodes.Add(cnode);

                if (cnode.Condition != null)
                {
                    Context.RegisterNodeCondition(cnode, cnode.Condition);
                }

                // Load children
                if (elem.ChildNodes.Count > 0)
                {
                    int cp = 0;
                    LoadExtensionElement(cnode, addin, elem.ChildNodes, ref cp, parentCondition, false, addedNodes);
                }

                curPos++;
            }
            if (Context.FireEvents)
            {
                tnode.NotifyChildrenChanged();
            }
        }