Example #1
0
		public NodeEditorWidget (DotNetProject project, AddinRegistry reg, ExtensionNodeType ntype, AddinDescription parentAddinDescription, string parentPath, ExtensionNodeDescription node)
		{
			this.node = node;
			this.project = project;
			tips = new Tooltips ();
			Spacing = 0;
			
			// Header
			
			Label label = new Label ();
			label.Wrap = true;
			label.WidthRequest = 480;
			string txt = "<b>" + node.NodeName + "</b>";
			if (ntype.Description.Length > 0)
				txt += "\n" + GLib.Markup.EscapeText (ntype.Description);
			label.Markup = txt;
			label.Xalign = 0f;
			PackStart (label, false, false, 6);
			PackStart (new HSeparator (), false, false, 0);
			
			// Attributes
			
			grid = new PropertyGrid ();
			grid.CurrentObject = new NodeWrapper (project, reg, ntype, parentAddinDescription, parentPath, node);
			
			PackStart (grid, true, true, 0);
			
			ShowAll ();
			
			grid.ShowHelp = true;
			grid.ShowToolbar = false;
			
		}
Example #2
0
		public NodeEditorDialog (DotNetProject project, AddinRegistry reg, ExtensionNodeType ntype, AddinDescription parentAddinDescription, string parentPath, ExtensionNodeDescription node)
		{
			editor = new NodeEditorWidget (project, reg, ntype, parentAddinDescription, parentPath, node);
			editor.BorderWidth = 12;
			this.VBox.PackStart (editor, true, true, 0);
			this.AddButton (Stock.Cancel, ResponseType.Cancel);
			this.AddButton (Stock.Ok, ResponseType.Ok);
			this.DefaultWidth = 400;
			ShowAll ();
		}
		/// <summary>
		/// Copies data from another node set
		/// </summary>
		/// <param name='nset'>
		/// Node set from which to copy
		/// </param>
		public void CopyFrom (ExtensionNodeSet nset)
		{
			id = nset.id;
			NodeTypes.Clear ();
			foreach (ExtensionNodeType nt in nset.NodeTypes) {
				ExtensionNodeType cnt = new ExtensionNodeType ();
				cnt.CopyFrom (nt);
				NodeTypes.Add (cnt);
			}
			NodeSets.Clear ();
			foreach (string ns in nset.NodeSets)
				NodeSets.Add (ns);
			missingNodeSetId = nset.missingNodeSetId;
		}
		public NodeTypeEditorDialog (DotNetProject project, ExtensionNodeType nt)
		{
			this.Build();
			this.ntype = nt;
			nodeType.Project = project;
			baseType.Project = project;
			
			Fill ();
			
			if (nt.Parent == null) {
				loading = true;
				nodeType.TypeName = "Mono.Addins.TypeExtensionNode";
				entryName.Text = "Type";
				loading = false;
			}
		}
Example #5
0
		public NodeWrapper (DotNetProject project, AddinRegistry reg, ExtensionNodeType ntype, AddinDescription parentAddinDescription, string parentPath, ExtensionNodeDescription node)
		{
			List<PropertyDescriptor> props = new List<PropertyDescriptor> ();
			
			string mainCategory = AddinManager.CurrentLocalizer.GetString ("Node Attributes");

			PropertyDescriptor prop = new MyPropertyDescriptor ("id", typeof(String), AddinManager.CurrentLocalizer.GetString ("Identifier of the extension node"), mainCategory, node);
			props.Add (prop);
			
			foreach (NodeTypeAttribute att in ntype.Attributes) {
				Type pt = Type.GetType (att.Type);
				if (pt == null)
					pt = typeof(string);
				prop = new MyPropertyDescriptor (att.Name, pt, att.Description, mainCategory, node);
				props.Add (prop);
			}
			
/*			int n = 1;
			foreach (ExtensionNodeDescription en in AddinData.GetExtensionNodes (reg, parentAddinDescription, parentPath)) {
				if (en.Id.Length > 0) {
					insBeforeCombo.AppendText (en.Id);
					insAfterCombo.AppendText (en.Id);
					if (en.Id == node.InsertBefore)
						insBeforeCombo.Active = n;
					if (en.Id == node.InsertAfter)
						insAfterCombo.Active = n;
				}
				n++;
			}
			*/
			
			prop = new MyPropertyDescriptor ("insertBefore", typeof(String), AddinManager.CurrentLocalizer.GetString ("Insert Before"), AddinManager.CurrentLocalizer.GetString ("Placement"), node);
			props.Add (prop);
			
			prop = new MyPropertyDescriptor ("insertAfter", typeof(String), AddinManager.CurrentLocalizer.GetString ("Insert After"), AddinManager.CurrentLocalizer.GetString ("Placement"), node);
			props.Add (prop);
			
			properties = new PropertyDescriptorCollection (props.ToArray ());
		}
Example #6
0
        ExtensionNodeType.FieldData CreateFieldData(MemberInfo member, NodeAttributeAttribute at, out string name, ref ExtensionNodeType.FieldData boundAttributeType)
        {
            ExtensionNodeType.FieldData fdata = new ExtensionNodeType.FieldData ();
            fdata.Member = member;
            fdata.Required = at.Required;
            fdata.Localizable = at.Localizable;

            if (at.Name != null && at.Name.Length > 0)
                name = at.Name;
            else
                name = member.Name;

            if (typeof(CustomExtensionAttribute).IsAssignableFrom (fdata.MemberType)) {
                if (boundAttributeType != null)
                    throw new InvalidOperationException ("Type '" + member.DeclaringType + "' has two members bound to a custom attribute. There can be only one.");
                boundAttributeType = fdata;
                return null;
            }

            return fdata;
        }
Example #7
0
        Dictionary<string, ExtensionNodeType.FieldData> GetMembersMap(Type type, out ExtensionNodeType.FieldData boundAttributeType)
        {
            string fname;
            Dictionary<string,ExtensionNodeType.FieldData> fields = new Dictionary<string, ExtensionNodeType.FieldData> ();
            boundAttributeType = null;

            while (type != typeof(object) && type != null) {
                foreach (FieldInfo field in type.GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) {
                    NodeAttributeAttribute at = (NodeAttributeAttribute) Attribute.GetCustomAttribute (field, typeof(NodeAttributeAttribute), true);
                    if (at != null) {
                        ExtensionNodeType.FieldData fd = CreateFieldData (field, at, out fname, ref boundAttributeType);
                        if (fd != null)
                            fields [fname] = fd;
                    }
                }
                foreach (PropertyInfo prop in type.GetProperties (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) {
                    NodeAttributeAttribute at = (NodeAttributeAttribute) Attribute.GetCustomAttribute (prop, typeof(NodeAttributeAttribute), true);
                    if (at != null) {
                        ExtensionNodeType.FieldData fd = CreateFieldData (prop, at, out fname, ref boundAttributeType);
                        if (fd != null)
                            fields [fname] = fd;
                    }
                }
                type = type.BaseType;
            }
            return fields;
        }
Example #8
0
 /// <summary>
 /// Adds an extension node type.
 /// </summary>
 /// <returns>
 /// The extension node type.
 /// </returns>
 /// <param name='name'>
 /// Name of the node
 /// </param>
 /// <param name='typeName'>
 /// Name of the type that implements the extension node.
 /// </param>
 /// <remarks>
 /// This method can be used to register a new allowed node type for the extension point.
 /// </remarks>
 public ExtensionNodeType AddExtensionNode(string name, string typeName)
 {
     ExtensionNodeType ntype = new ExtensionNodeType ();
     ntype.Id = name;
     ntype.TypeName = typeName;
     NodeSet.NodeTypes.Add (ntype);
     return ntype;
 }
		bool InitializeNodeType (ExtensionNodeType ntype)
		{
			RuntimeAddin p = AddinManager.SessionService.GetAddin (ntype.AddinId);
			if (p == null) {
				if (!AddinManager.SessionService.IsAddinLoaded (ntype.AddinId)) {
					if (!AddinManager.SessionService.LoadAddin (null, ntype.AddinId, false))
						return false;
					p = AddinManager.SessionService.GetAddin (ntype.AddinId);
					if (p == null) {
						AddinManager.ReportError ("Add-in not found", ntype.AddinId, null, false);
						return false;
					}
				}
			}
			
			// If no type name is provided, use TypeExtensionNode by default
			if (ntype.TypeName == null || ntype.TypeName.Length == 0) {
				ntype.Type = typeof(TypeExtensionNode);
				return true;
			}
			
			ntype.Type = p.GetType (ntype.TypeName, false);
			if (ntype.Type == null) {
				AddinManager.ReportError ("Extension node type '" + ntype.TypeName + "' not found.", ntype.AddinId, null, false);
				return false;
			}
			
			Hashtable fields = new Hashtable ();
			
			// Check if the type has NodeAttribute attributes applied to fields.
			foreach (FieldInfo field in ntype.Type.GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
				NodeAttributeAttribute at = (NodeAttributeAttribute) Attribute.GetCustomAttribute (field, typeof(NodeAttributeAttribute), true);
				if (at != null) {
					ExtensionNodeType.FieldData fdata = new ExtensionNodeType.FieldData ();
					fdata.Field = field;
					fdata.Required = at.Required;
					fdata.Localizable = at.Localizable;
					
					string name;
					if (at.Name != null && at.Name.Length > 0)
						name = at.Name;
					else
						name = field.Name;
					
					fields [name] = fdata;
				}
			}
			if (fields.Count > 0)
				ntype.Fields = fields;
				
			return true;
		}
Example #10
0
		protected virtual void OnEditNodeButtonClicked (object sender, System.EventArgs e)
		{
			TreeIter iter;
			tree.Selection.GetSelected (out iter);
			ExtensionNodeType ns = (ExtensionNodeType) store.GetValue (iter, ColObject);
			ExtensionNodeType copy = new ExtensionNodeType ();
			copy.CopyFrom (ns);
			
			NodeTypeEditorDialog dlg = new NodeTypeEditorDialog (project, copy);
			if (dlg.Run () == (int) Gtk.ResponseType.Ok) {
				ns.CopyFrom (copy);
				Update ();
			}
			dlg.Destroy ();
		}
Example #11
0
 string RegisterNodeXml(ExtensionNodeType nt, ArrayList list, Hashtable visited)
 {
     string key = nt.Id + " " + nt.TypeName;
     if (visited.Contains (key))
         return (string) visited [key];
     string k = "ntype_" + uniqueId;
     uniqueId++;
     visited [key] = k;
     list.Add (nt);
     return k;
 }
		public override void Initialize (XElement elem)
		{
			XAttribute att = elem.Attributes [new XName ("id")];
			if (att != null)
				id = att.Value;
			string nodeName = elem.Name.Name;
			BaseExtensionCompletionContext ctx = ParentContext as BaseExtensionCompletionContext;
			foreach (ExtensionNodeType nt in ctx.GetAllowedNodeTypes ()) {
				if (nt.NodeName == nodeName) {
					nodeType = nt;
					break;
				}
			}
		}
Example #13
0
        void ScanNodeType(IAssemblyReflector reflector, AddinDescription config, ExtensionNodeType nt, ArrayList assemblies, Hashtable internalNodeSets)
        {
            if (nt.TypeName.Length == 0)
                nt.TypeName = "Mono.Addins.TypeExtensionNode";

            object ntype = FindAddinType (reflector, nt.TypeName, assemblies);
            if (ntype == null)
                return;

            // Add type information declared with attributes in the code
            ExtensionNodeAttribute nodeAtt = (ExtensionNodeAttribute) reflector.GetCustomAttribute (ntype, typeof(ExtensionNodeAttribute), true);
            if (nodeAtt != null) {
                if (nt.Id.Length == 0 && nodeAtt.NodeName.Length > 0)
                    nt.Id = nodeAtt.NodeName;
                if (nt.Description.Length == 0 && nodeAtt.Description.Length > 0)
                    nt.Description = nodeAtt.Description;
                if (nt.ExtensionAttributeTypeName.Length == 0 && nodeAtt.ExtensionAttributeTypeName.Length > 0)
                    nt.ExtensionAttributeTypeName = nodeAtt.ExtensionAttributeTypeName;
            } else {
                // Use the node type name as default name
                if (nt.Id.Length == 0)
                    nt.Id = reflector.GetTypeName (ntype);
            }

            // Add information about attributes
            object[] fieldAtts = reflector.GetCustomAttributes (ntype, typeof(NodeAttributeAttribute), true);
            foreach (NodeAttributeAttribute fatt in fieldAtts) {
                NodeTypeAttribute natt = new NodeTypeAttribute ();
                natt.Name = fatt.Name;
                natt.Required = fatt.Required;
                if (fatt.TypeName != null)
                    natt.Type = fatt.TypeName;
                if (fatt.Description.Length > 0)
                    natt.Description = fatt.Description;
                nt.Attributes.Add (natt);
            }

            // Check if the type has NodeAttribute attributes applied to fields.
            foreach (object field in reflector.GetFields (ntype)) {
                NodeAttributeAttribute fatt = (NodeAttributeAttribute) reflector.GetCustomAttribute (field, typeof(NodeAttributeAttribute), false);
                if (fatt != null) {
                    NodeTypeAttribute natt = new NodeTypeAttribute ();
                    if (fatt.Name.Length > 0)
                        natt.Name = fatt.Name;
                    else
                        natt.Name = reflector.GetFieldName (field);
                    if (fatt.Description.Length > 0)
                        natt.Description = fatt.Description;
                    natt.Type = reflector.GetFieldTypeFullName (field);
                    natt.Required = fatt.Required;
                    nt.Attributes.Add (natt);
                }
            }

            // Check if the extension type allows children by looking for [ExtensionNodeChild] attributes.
            // First of all, look in the internalNodeSets hashtable, which is being used as cache

            string childSet = (string) internalNodeSets [nt.TypeName];

            if (childSet == null) {
                object[] ats = reflector.GetCustomAttributes (ntype, typeof(ExtensionNodeChildAttribute), true);
                if (ats.Length > 0) {
                    // Create a new node set for this type. It is necessary to create a new node set
                    // instead of just adding child ExtensionNodeType objects to the this node type
                    // because child types references can be recursive.
                    ExtensionNodeSet internalSet = new ExtensionNodeSet ();
                    internalSet.Id = reflector.GetTypeName (ntype) + "_" + Guid.NewGuid().ToString ();
                    foreach (ExtensionNodeChildAttribute at in ats) {
                        ExtensionNodeType internalType = new ExtensionNodeType ();
                        internalType.Id = at.NodeName;
                        internalType.TypeName = at.ExtensionNodeTypeName;
                        internalSet.NodeTypes.Add (internalType);
                    }
                    config.ExtensionNodeSets.Add (internalSet);
                    nt.NodeSets.Add (internalSet.Id);

                    // Register the new set in a hashtable, to allow recursive references to the
                    // same internal set.
                    internalNodeSets [nt.TypeName] = internalSet.Id;
                    internalNodeSets [reflector.GetTypeAssemblyQualifiedName (ntype)] = internalSet.Id;
                    ScanNodeSet (reflector, config, internalSet, assemblies, internalNodeSets);
                }
            }
            else {
                if (childSet.Length == 0) {
                    // The extension type does not declare children.
                    return;
                }
                // The extension type can have children. The allowed children are
                // defined in this extension set.
                nt.NodeSets.Add (childSet);
                return;
            }

            ScanNodeSet (reflector, config, nt, assemblies, internalNodeSets);
        }
Example #14
0
        bool InitializeNodeType(ExtensionNodeType ntype)
        {
            RuntimeAddin p = addinEngine.GetAddin (ntype.AddinId);
            if (p == null) {
                if (!addinEngine.IsAddinLoaded (ntype.AddinId)) {
                    if (!addinEngine.LoadAddin (null, ntype.AddinId, false))
                        return false;
                    p = addinEngine.GetAddin (ntype.AddinId);
                    if (p == null) {
                        addinEngine.ReportError ("Add-in not found", ntype.AddinId, null, false);
                        return false;
                    }
                }
            }

            // If no type name is provided, use TypeExtensionNode by default
            if (ntype.TypeName == null || ntype.TypeName.Length == 0 || ntype.TypeName == typeof(TypeExtensionNode).FullName) {
                // If it has a custom attribute, use the generic version of TypeExtensionNode
                if (ntype.ExtensionAttributeTypeName.Length > 0) {
                    Type attType = p.GetType (ntype.ExtensionAttributeTypeName, false);
                    if (attType == null) {
                        addinEngine.ReportError ("Custom attribute type '" + ntype.ExtensionAttributeTypeName + "' not found.", ntype.AddinId, null, false);
                        return false;
                    }
                    if (ntype.ObjectTypeName.Length > 0 || ntype.TypeName == typeof(TypeExtensionNode).FullName)
                        ntype.Type = typeof(TypeExtensionNode<>).MakeGenericType (attType);
                    else
                        ntype.Type = typeof(ExtensionNode<>).MakeGenericType (attType);
                } else {
                    ntype.Type = typeof(TypeExtensionNode);
                    return true;
                }
            }
            else {
                ntype.Type = p.GetType (ntype.TypeName, false);
                if (ntype.Type == null) {
                    addinEngine.ReportError ("Extension node type '" + ntype.TypeName + "' not found.", ntype.AddinId, null, false);
                    return false;
                }
            }

            // Check if the type has NodeAttribute attributes applied to fields.
            ExtensionNodeType.FieldData boundAttributeType = null;
            Dictionary<string,ExtensionNodeType.FieldData> fields = GetMembersMap (ntype.Type, out boundAttributeType);
            ntype.CustomAttributeMember = boundAttributeType;
            if (fields.Count > 0)
                ntype.Fields = fields;

            // If the node type is bound to a custom attribute and there is a member bound to that attribute,
            // get the member map for the attribute.

            if (boundAttributeType != null) {
                if (ntype.ExtensionAttributeTypeName.Length == 0)
                    throw new InvalidOperationException ("Extension node not bound to a custom attribute.");
                if (ntype.ExtensionAttributeTypeName != boundAttributeType.MemberType.FullName)
                    throw new InvalidOperationException ("Incorrect custom attribute type declaration in " + ntype.Type + ". Expected '" + ntype.ExtensionAttributeTypeName + "' found '" + boundAttributeType.MemberType.FullName + "'");

                fields = GetMembersMap (boundAttributeType.MemberType, out boundAttributeType);
                if (fields.Count > 0)
                    ntype.CustomAttributeFields = fields;
            }

            return true;
        }
		void CreateNode (TreeIter it, Extension ext, ExtensionNodeDescription node, ExtensionNodeType nt)
		{
			ExtensionNodeDescription newNode = new ExtensionNodeDescription (nt.NodeName);
			
			if (ext != null) {
				if (ext.Parent == null)
					adesc.MainModule.Extensions.Add (ext);
				ext.ExtensionNodes.Add (newNode);
			}
			else
				node.ChildNodes.Add (newNode);
			TreeIter nit = AddNode (it, newNode);
			tree.ExpandRow (store.GetPath (it), false);
			tree.Selection.SelectIter (nit);
			NotifyChanged ();
		}
		public ExtensionNodeElement (AddinProjectFlavor proj, ExtensionPoint extensionPoint, ExtensionNodeType info) : base (info.NodeName, info.Description)
		{
			this.proj = proj;
			this.extensionPoint = extensionPoint;
			this.info = info;
		}
		/// <summary>
		///  Copies data from another node set 
		/// </summary>
		public void CopyFrom (ExtensionNodeType ntype)
		{
			base.CopyFrom (ntype);
			this.typeName = ntype.TypeName;
			this.objectTypeName = ntype.ObjectTypeName;
			this.description = ntype.Description;
			this.addinId = ntype.AddinId;
			Attributes.Clear ();
			foreach (NodeTypeAttribute att in ntype.Attributes) {
				NodeTypeAttribute catt = new NodeTypeAttribute ();
				catt.CopyFrom (att);
				Attributes.Add (catt);
			}
		}
		void ScanAssemblyContents (AddinDescription config, Assembly asm, ArrayList hostExtensionClasses, AddinScanResult scanResult)
		{
			// Get dependencies
			
			object[] deps = asm.GetCustomAttributes (typeof(AddinDependencyAttribute), false);
			foreach (AddinDependencyAttribute dep in deps) {
				AddinDependency adep = new AddinDependency ();
				adep.AddinId = dep.Id;
				adep.Version = dep.Version;
				config.MainModule.Dependencies.Add (adep);
			}
			
			// Get extension points
			
			object[] extPoints = asm.GetCustomAttributes (typeof(ExtensionPointAttribute), false);
			foreach (ExtensionPointAttribute ext in extPoints) {
				ExtensionPoint ep = config.AddExtensionPoint (ext.Path);
				ep.Description = ext.Description;
				ep.Name = ext.Name;
				ep.AddExtensionNode (ext.NodeName, ext.NodeType.FullName);
			}
			
			foreach (Type t in asm.GetTypes ()) {
				
				if (Attribute.IsDefined (t, typeof(ExtensionAttribute))) {
					foreach (ExtensionAttribute eatt in t.GetCustomAttributes (typeof(ExtensionAttribute), false)) {
						string path;
						string nodeName;
						
						if (eatt.Path.Length == 0) {
							if (config.IsRoot) {
								// The extension point must be one of the defined by the assembly
								// Look for it later, when the assembly has been fully scanned.
								hostExtensionClasses.Add (t);
								continue;
							}
							else {
								path = GetBaseTypeNameList (t);
								if (path == "$") {
									// The type does not implement any interface and has no superclass.
									// Will be reported later as an error.
									path = "$" + t.FullName;
								}
								nodeName = "Type";
							}
						} else {
							path = eatt.Path;
							nodeName = eatt.NodeName;
						}
							
						ExtensionNodeDescription elem = config.MainModule.AddExtensionNode (path, nodeName);
						if (eatt.Id.Length > 0) {
							elem.SetAttribute ("id", eatt.Id);
							elem.SetAttribute ("type", t.FullName);
						} else {
							elem.SetAttribute ("id", t.FullName);
						}
						if (eatt.InsertAfter.Length > 0)
							elem.SetAttribute ("insertafter", eatt.InsertAfter);
						if (eatt.InsertBefore.Length > 0)
							elem.SetAttribute ("insertbefore", eatt.InsertAfter);
					}
				}
				else if (Attribute.IsDefined (t, typeof(TypeExtensionPointAttribute))) {
					foreach (TypeExtensionPointAttribute epa in t.GetCustomAttributes (typeof(TypeExtensionPointAttribute), false)) {
						ExtensionPoint ep;
						
						ExtensionNodeType nt = new ExtensionNodeType ();
						
						if (epa.Path.Length > 0) {
							ep = config.AddExtensionPoint (epa.Path);
						}
						else {
							ep = config.AddExtensionPoint (GetDefaultTypeExtensionPath (config, t));
							nt.ObjectTypeName = t.FullName;
						}
						nt.Id = epa.NodeName;
						nt.TypeName = epa.NodeType.FullName;
						ep.NodeSet.NodeTypes.Add (nt);
						ep.Description = epa.Description;
						ep.Name = epa.Name;
						ep.RootAddin = config.AddinId;
						ep.SetExtensionsAddinId (config.AddinId);
					}
				}
			}
		}
Example #19
0
        public ExtensionNode ReadNode(TreeNode tnode, string addin, ExtensionNodeType ntype, ExtensionNodeDescription elem, ModuleDescription module)
        {
            try {
                if (ntype.Type == null) {
                    if (!InitializeNodeType (ntype))
                        return null;
                }

                ExtensionNode node;
                node = Activator.CreateInstance (ntype.Type) as ExtensionNode;
                if (node == null) {
                    addinEngine.ReportError ("Extension node type '" + ntype.Type + "' must be a subclass of ExtensionNode", addin, null, false);
                    return null;
                }

                tnode.AttachExtensionNode (node);
                node.SetData (addinEngine, addin, ntype, module);
                node.Read (elem);
                return node;
            }
            catch (Exception ex) {
                addinEngine.ReportError ("Could not read extension node of type '" + ntype.Type + "' from extension path '" + tnode.GetPath() + "'", addin, ex, false);
                return null;
            }
        }
		void InitCollections ()
		{
			nodeTypes = new ExtensionNodeTypeCollection (this);
			nodeSets = new NodeSetIdCollection ();
			
			foreach (XmlNode n in Element.ChildNodes) {
				XmlElement nt = n as XmlElement;
				if (nt == null)
					continue;
				if (nt.LocalName == "ExtensionNode") {
					ExtensionNodeType etype = new ExtensionNodeType (nt);
					nodeTypes.Add (etype);
				}
				else if (nt.LocalName == "ExtensionNodeSet") {
					string id = nt.GetAttribute ("id");
					if (id.Length > 0)
						nodeSets.Add (id);
					else
						missingNodeSetId = true;
				}
			}
		}
		protected virtual void OnButtonOkClicked (object sender, System.EventArgs e)
		{
			ep.Path = entryPath.Text;
			ep.Name = entryName.Text;
			ep.Description = entryDesc.Text;
			
			if (notebook.Page == 0) {
				ep.NodeSet.CopyFrom (new ExtensionNodeSet ());
				ExtensionNodeType nt = new ExtensionNodeType ();
				nt.NodeName = entryNodeName.Text;
				nt.TypeName = "Mono.Addins.TypeExtensionNode";
				nt.ObjectTypeName = baseTypeSelector.TypeName;
				nt.Description = entryNodeDescription.Text;
				ep.NodeSet.NodeTypes.Add (nt);
			}
		}
		internal void SetData (string plugid, ExtensionNodeType nodeType)
		{
			this.addinId = plugid;
			this.nodeType = nodeType;
		}
Example #23
0
        void ScanAssemblyContents(IAssemblyReflector reflector, AddinDescription config, ModuleDescription module, object asm, AddinScanResult scanResult)
        {
            bool isMainModule = module == config.MainModule;

            // Get dependencies

            object[] deps = reflector.GetCustomAttributes (asm, typeof(AddinDependencyAttribute), false);
            foreach (AddinDependencyAttribute dep in deps) {
                AddinDependency adep = new AddinDependency ();
                adep.AddinId = dep.Id;
                adep.Version = dep.Version;
                module.Dependencies.Add (adep);
            }

            if (isMainModule) {

                // Get properties

                object[] props = reflector.GetCustomAttributes (asm, typeof(AddinPropertyAttribute), false);
                foreach (AddinPropertyAttribute prop in props)
                    config.Properties.SetPropertyValue (prop.Name, prop.Value, prop.Locale);

                // Get extension points

                object[] extPoints = reflector.GetCustomAttributes (asm, typeof(ExtensionPointAttribute), false);
                foreach (ExtensionPointAttribute ext in extPoints) {
                    ExtensionPoint ep = config.AddExtensionPoint (ext.Path);
                    ep.Description = ext.Description;
                    ep.Name = ext.Name;
                    ExtensionNodeType nt = ep.AddExtensionNode (ext.NodeName, ext.NodeTypeName);
                    nt.ExtensionAttributeTypeName = ext.ExtensionAttributeTypeName;
                }
            }

            // Look for extension nodes declared using assembly attributes

            foreach (CustomAttribute att in reflector.GetRawCustomAttributes (asm, typeof(CustomExtensionAttribute), true))
                AddCustomAttributeExtension (module, att, "Type");

            // Get extensions or extension points applied to types

            foreach (object t in reflector.GetAssemblyTypes (asm)) {

                string typeFullName = reflector.GetTypeFullName (t);

                // Look for extensions

                object[] extensionAtts = reflector.GetCustomAttributes (t, typeof(ExtensionAttribute), false);
                if (extensionAtts.Length > 0) {
                    Dictionary<string,ExtensionNodeDescription> nodes = new Dictionary<string, ExtensionNodeDescription> ();
                    ExtensionNodeDescription uniqueNode = null;
                    foreach (ExtensionAttribute eatt in extensionAtts) {
                        string path;
                        string nodeName = eatt.NodeName;

                        if (eatt.TypeName.Length > 0) {
                            path = "$" + eatt.TypeName;
                        }
                        else if (eatt.Path.Length == 0) {
                            path = GetBaseTypeNameList (reflector, t);
                            if (path == "$") {
                                // The type does not implement any interface and has no superclass.
                                // Will be reported later as an error.
                                path = "$" + typeFullName;
                            }
                        } else {
                            path = eatt.Path;
                        }

                        ExtensionNodeDescription elem = module.AddExtensionNode (path, nodeName);
                        nodes [path] = elem;
                        uniqueNode = elem;

                        if (eatt.Id.Length > 0) {
                            elem.SetAttribute ("id", eatt.Id);
                            elem.SetAttribute ("type", typeFullName);
                        } else {
                            elem.SetAttribute ("id", typeFullName);
                        }
                        if (eatt.InsertAfter.Length > 0)
                            elem.SetAttribute ("insertafter", eatt.InsertAfter);
                        if (eatt.InsertBefore.Length > 0)
                            elem.SetAttribute ("insertbefore", eatt.InsertBefore);
                    }

                    // Get the node attributes

                    foreach (ExtensionAttributeAttribute eat in reflector.GetCustomAttributes (t, typeof(ExtensionAttributeAttribute), false)) {
                        ExtensionNodeDescription node;
                        if (!string.IsNullOrEmpty (eat.Path))
                            nodes.TryGetValue (eat.Path, out node);
                        else if (eat.TypeName.Length > 0)
                            nodes.TryGetValue ("$" + eat.TypeName, out node);
                        else {
                            if (nodes.Count > 1)
                                throw new Exception ("Missing type or extension path value in ExtensionAttribute for type '" + typeFullName + "'.");
                            node = uniqueNode;
                        }
                        if (node == null)
                            throw new Exception ("Invalid type or path value in ExtensionAttribute for type '" + typeFullName + "'.");

                        node.SetAttribute (eat.Name ?? string.Empty, eat.Value ?? string.Empty);
                    }
                }
                else {
                    // Look for extension points

                    extensionAtts = reflector.GetCustomAttributes (t, typeof(TypeExtensionPointAttribute), false);
                    if (extensionAtts.Length > 0 && isMainModule) {
                        foreach (TypeExtensionPointAttribute epa in extensionAtts) {
                            ExtensionPoint ep;

                            ExtensionNodeType nt = new ExtensionNodeType ();

                            if (epa.Path.Length > 0) {
                                ep = config.AddExtensionPoint (epa.Path);
                            }
                            else {
                                ep = config.AddExtensionPoint (GetDefaultTypeExtensionPath (config, typeFullName));
                                nt.ObjectTypeName = typeFullName;
                            }
                            nt.Id = epa.NodeName;
                            nt.TypeName = epa.NodeTypeName;
                            nt.ExtensionAttributeTypeName = epa.ExtensionAttributeTypeName;
                            ep.NodeSet.NodeTypes.Add (nt);
                            ep.Description = epa.Description;
                            ep.Name = epa.Name;
                            ep.RootAddin = config.AddinId;
                            ep.SetExtensionsAddinId (config.AddinId);
                        }
                    }
                    else {
                        // Look for custom extension attribtues
                        foreach (CustomAttribute att in reflector.GetRawCustomAttributes (t, typeof(CustomExtensionAttribute), false)) {
                            ExtensionNodeDescription elem = AddCustomAttributeExtension (module, att, "Type");
                            elem.SetAttribute ("type", typeFullName);
                            if (string.IsNullOrEmpty (elem.GetAttribute ("id")))
                                elem.SetAttribute ("id", typeFullName);
                        }
                    }
                }
            }
        }
Example #24
0
		protected virtual void OnAddNodeButtonClicked (object sender, System.EventArgs e)
		{
			ExtensionNodeType nt = new ExtensionNodeType ();
			NodeTypeEditorDialog dlg = new NodeTypeEditorDialog (project, nt);
			if (dlg.Run () == (int) Gtk.ResponseType.Ok) {
				nodeSet.NodeTypes.Add (nt);
				Update ();
			}
			dlg.Destroy ();
		}