A collection of extension nodes
Inheritance: ObjectDescriptionCollection, NodeElementCollection
Ejemplo n.º 1
0
        internal ExtensionNodeDescription FindExtensionNode(string path, bool lookInDeps)
        {
            // Look in the extensions of this add-in

            foreach (Extension ext in MainModule.Extensions)
            {
                if (path.StartsWith(ext.Path + "/"))
                {
                    string subp = path.Substring(ext.Path.Length).Trim('/');
                    ExtensionNodeDescriptionCollection nodes = ext.ExtensionNodes;
                    ExtensionNodeDescription           node  = null;
                    foreach (string p in subp.Split('/'))
                    {
                        if (p.Length == 0)
                        {
                            continue;
                        }
                        node = nodes [p];
                        if (node == null)
                        {
                            break;
                        }
                        nodes = node.ChildNodes;
                    }
                    if (node != null)
                    {
                        return(node);
                    }
                }
            }

            if (!lookInDeps || OwnerDatabase == null)
            {
                return(null);
            }

            // Look in dependencies

            foreach (Dependency dep in MainModule.Dependencies)
            {
                AddinDependency adep = dep as AddinDependency;
                if (adep == null)
                {
                    continue;
                }
                Addin ad = OwnerDatabase.GetInstalledAddin(Domain, adep.FullAddinId);
                if (ad != null && ad.Description != null)
                {
                    ExtensionNodeDescription node = ad.Description.FindExtensionNode(path, false);
                    if (node != null)
                    {
                        return(node);
                    }
                }
            }
            return(null);
        }
		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;
		}
Ejemplo n.º 3
0
        void AddNodeSorted(ExtensionNodeDescriptionCollection list, ExtensionNodeDescription node, ref int curPos)
        {
            // Adds the node at the correct position, taking into account insertbefore and insertafter

            if (node.InsertAfter.Length > 0) {
                string afterId = node.InsertAfter;
                for (int n=0; n<list.Count; n++) {
                    if (list[n].Id == afterId) {
                        list.Insert (n + 1, node);
                        curPos = n + 2;
                        return;
                    }
                }
            }
            else if (node.InsertBefore.Length > 0) {
                string beforeId = node.InsertBefore;
                for (int n=0; n<list.Count; n++) {
                    if (list[n].Id == beforeId) {
                        list.Insert (n, node);
                        curPos = n + 1;
                        return;
                    }
                }
            }
            if (curPos == -1)
                list.Add (node);
            else
                list.Insert (curPos++, node);
        }
		void AddChildExtensions (AddinDescription conf, ModuleDescription module, AddinUpdateData updateData, string path, ExtensionNodeDescriptionCollection nodes, bool conditionChildren)
		{
			// Don't register conditions as extension nodes.
			if (!conditionChildren)
				updateData.RegisterExtension (conf, module, path);
			
			foreach (ExtensionNodeDescription node in nodes) {
				if (node.NodeName == "ComplexCondition")
					continue;
				relExtensionNodes++;
				string id = node.GetAttribute ("id");
				if (id.Length != 0)
					AddChildExtensions (conf, module, updateData, path + "/" + id, node.ChildNodes, node.NodeName == "Condition");
			}
		}
Ejemplo n.º 5
0
        void EnsureInsertionsSorted(ExtensionNodeDescriptionCollection list)
        {
            // Makes sure that the nodes in the collections are properly sorted wrt insertafter and insertbefore attributes
            Dictionary<string,ExtensionNodeDescription> added = new Dictionary<string, ExtensionNodeDescription> ();
            List<ExtensionNodeDescription> halfSorted = new List<ExtensionNodeDescription> ();
            bool orderChanged = false;

            for (int n = list.Count - 1; n >= 0; n--) {
                ExtensionNodeDescription node = list [n];
                if (node.Id.Length > 0)
                    added [node.Id] = node;
                if (node.InsertAfter.Length > 0) {
                    ExtensionNodeDescription relNode;
                    if (added.TryGetValue (node.InsertAfter, out relNode)) {
                        // Out of order. Move it before the referenced node
                        int i = halfSorted.IndexOf (relNode);
                        halfSorted.Insert (i, node);
                        orderChanged = true;
                    } else {
                        halfSorted.Add (node);
                    }
                } else
                    halfSorted.Add (node);
            }
            halfSorted.Reverse ();
            List<ExtensionNodeDescription> fullSorted = new List<ExtensionNodeDescription> ();
            added.Clear ();

            foreach (ExtensionNodeDescription node in halfSorted) {
                if (node.Id.Length > 0)
                    added [node.Id] = node;
                if (node.InsertBefore.Length > 0) {
                    ExtensionNodeDescription relNode;
                    if (added.TryGetValue (node.InsertBefore, out relNode)) {
                        // Out of order. Move it before the referenced node
                        int i = fullSorted.IndexOf (relNode);
                        fullSorted.Insert (i, node);
                        orderChanged = true;
                    } else {
                        fullSorted.Add (node);
                    }
                } else
                    fullSorted.Add (node);
            }
            if (orderChanged) {
                list.Clear ();
                foreach (ExtensionNodeDescription node in fullSorted)
                    list.Add (node);
            }
        }
Ejemplo n.º 6
0
        void AddChildExtensions(AddinDescription conf, ModuleDescription module, AddinUpdateData updateData, AddinIndex index, string path, ExtensionNodeDescriptionCollection nodes, bool conditionChildren)
        {
            // Don't register conditions as extension nodes.
            if (!conditionChildren)
                updateData.RegisterExtension (conf, module, path);

            foreach (ExtensionNodeDescription node in nodes) {
                if (node.NodeName == "ComplexCondition")
                    continue;
                updateData.RelExtensionNodes++;
                string id = node.GetAttribute ("id");
                if (id.Length != 0) {
                    bool isCondition = node.NodeName == "Condition";
                    if (isCondition) {
                        // Find the add-in that provides the implementation for this condition.
                        // Store that id in the condition. The add-in engine will ensure the add-in
                        // is loaded when it tries to evaluate this condition.
                        var condAsm = index.FindCondition (conf, module, id);
                        if (condAsm != null)
                            node.SetAttribute (Condition.SourceAddinAttribute, condAsm);
                    }
                    AddChildExtensions (conf, module, updateData, index, path + "/" + id, node.ChildNodes, isCondition);
                }
            }
        }
Ejemplo n.º 7
0
		internal override void Read (BinaryXmlReader reader)
		{
			path = reader.ReadStringValue ("path");
			nodes = (ExtensionNodeDescriptionCollection) reader.ReadValue ("Nodes", new ExtensionNodeDescriptionCollection (this));
		}
Ejemplo n.º 8
0
 internal override void Read(BinaryXmlReader reader)
 {
     path  = reader.ReadStringValue("path");
     nodes = (ExtensionNodeDescriptionCollection)reader.ReadValue("Nodes", new ExtensionNodeDescriptionCollection(this));
 }
Ejemplo n.º 9
0
 internal override void Read(BinaryXmlReader reader)
 {
     nodeName = reader.ReadStringValue ("nodeName");
     attributes = (string[]) reader.ReadValue ("attributes");
     childNodes = (ExtensionNodeDescriptionCollection) reader.ReadValue ("ChildNodes", new ExtensionNodeDescriptionCollection (this));
 }
Ejemplo n.º 10
0
        void LoadExtensionElement(TreeNode tnode, string addin, ExtensionNodeDescriptionCollection extension, ModuleDescription module, 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, 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 ();
        }
Ejemplo n.º 11
0
 internal override void Read(BinaryXmlReader reader)
 {
     nodeName   = reader.ReadStringValue("nodeName");
     attributes = (string[])reader.ReadValue("attributes");
     childNodes = (ExtensionNodeDescriptionCollection)reader.ReadValue("ChildNodes", new ExtensionNodeDescriptionCollection(this));
 }
Ejemplo n.º 12
0
		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);
				}
			}
		}
		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 ();
		}