void UpdateObject(WidgetParser parser, string topType, XmlElement objectElem, ITypeDefinition widgetClass, ITypeDefinition wrapperClass)
        {
            if (widgetClass.IsPublic)
            {
                objectElem.RemoveAttribute("internal");
            }
            else
            {
                objectElem.SetAttribute("internal", "true");
            }

            ListDictionary properties = new ListDictionary();
            ListDictionary events     = new ListDictionary();

            parser.CollectMembers(widgetClass, true, topType, properties, events);
            if (wrapperClass != null)
            {
                parser.CollectMembers(wrapperClass, false, null, properties, events);
            }

            foreach (IProperty prop in properties.Values)
            {
                MergeProperty(parser, objectElem, prop);
            }

            foreach (IEvent ev in events.Values)
            {
                MergeEvent(parser, objectElem, ev);
            }

            // Remove old properties
            ArrayList toDelete = new ArrayList();

            foreach (XmlElement xprop in objectElem.SelectNodes("itemgroups/itemgroup/property"))
            {
                if (!properties.Contains(xprop.GetAttribute("name")))
                {
                    toDelete.Add(xprop);
                }
            }

            // Remove old signals
            foreach (XmlElement xevent in objectElem.SelectNodes("signals/itemgroup/signal"))
            {
                if (!events.Contains(xevent.GetAttribute("name")))
                {
                    toDelete.Add(xevent);
                }
            }

            foreach (XmlElement el in toDelete)
            {
                XmlElement pe = (XmlElement)el.ParentNode;
                pe.RemoveChild(el);
                if (pe.ChildNodes.Count == 0)
                {
                    pe.ParentNode.RemoveChild(pe);
                }
            }
        }
Exemple #2
0
        void InsertToolboxItemAttributes(WidgetParser parser, CodeRefactorer cref)
        {
            Dictionary <string, IType> tb_items = parser.GetToolboxItems();

            foreach (string clsname in ObjectNames)
            {
                if (tb_items.ContainsKey(clsname))
                {
                    continue;
                }

                IType cls = parser.GetClass(clsname);
                if (cls == null)
                {
                    continue;
                }

                cref.AddAttribute(cls, "System.ComponentModel.ToolboxItem", true);
                XmlElement elem = DocumentElement.SelectSingleNode("object[@type='" + clsname + "']") as XmlElement;
                if (elem != null && elem.HasAttribute("palette-category"))
                {
                    cref.AddAttribute(cls, "System.ComponentModel.Category", elem.GetAttribute("palette-category"));
                }
            }
        }
        string GetBaseType(WidgetParser parser, ITypeDefinition widgetClass, Stetic.Project stetic)
        {
            string[]  types     = stetic.GetWidgetTypes();
            Hashtable typesHash = new Hashtable();

            foreach (string t in types)
            {
                typesHash [t] = t;
            }

            string ret = parser.GetBaseType(widgetClass, typesHash);

            return(ret ?? "Gtk.Widget");
        }
Exemple #4
0
        public void Update(WidgetParser parser, Stetic.Project stetic, CodeRefactorer refactorer)
        {
            if (AttrSyncState == SyncState.Unspecified)
            {
                if (refactorer != null)
                {
                    InsertToolboxItemAttributes(parser, refactorer);
                    AttrSyncState = SyncState.On;
                }
                return;
            }
            else if (AttrSyncState == SyncState.Off)
            {
                return;
            }

            StringCollection tb_names = new StringCollection();

            foreach (IType cls in parser.GetToolboxItems().Values)
            {
                UpdateClass(parser, stetic, cls, null);
                tb_names.Add(cls.FullName);
            }

            List <XmlElement> toDelete = new List <XmlElement> ();

            foreach (XmlElement elem in SelectNodes("objects/object"))
            {
                string name = elem.GetAttribute("type");
                if (!tb_names.Contains(name))
                {
                    toDelete.Add(elem);
                }
            }

            foreach (XmlElement elem in toDelete)
            {
                elem.ParentNode.RemoveChild(elem);
            }

            Save();
        }
        void MergeEvent(WidgetParser parser, XmlElement objectElem, IEvent evnt)
        {
            XmlElement itemGroups = objectElem ["signals"];

            if (itemGroups == null)
            {
                itemGroups = objectElem.OwnerDocument.CreateElement("signals");
                objectElem.AppendChild(itemGroups);
            }

            string     cat       = parser.GetCategory(evnt);
            XmlElement itemGroup = GetItemGroup(evnt.DeclaringType, itemGroups, cat, "Signals");

            XmlElement signalElem = (XmlElement)itemGroup.SelectSingleNode("signal[@name='" + evnt.Name + "']");

            if (signalElem == null)
            {
                signalElem = itemGroup.OwnerDocument.CreateElement("signal");
                signalElem.SetAttribute("name", evnt.Name);
                itemGroup.AppendChild(signalElem);
            }
        }
        void MergeProperty(WidgetParser parser, XmlElement objectElem, IProperty prop)
        {
            XmlElement itemGroups = objectElem ["itemgroups"];

            if (itemGroups == null)
            {
                itemGroups = objectElem.OwnerDocument.CreateElement("itemgroups");
                objectElem.AppendChild(itemGroups);
            }

            string     cat       = parser.GetCategory(prop);
            XmlElement itemGroup = GetItemGroup(prop.DeclaringType, itemGroups, cat, "Properties");

            XmlElement propElem = (XmlElement)itemGroup.SelectSingleNode("property[@name='" + prop.Name + "']");

            if (propElem == null)
            {
                propElem = itemGroup.OwnerDocument.CreateElement("property");
                propElem.SetAttribute("name", prop.Name);
                itemGroup.AppendChild(propElem);
            }
        }
        void UpdateClass(WidgetParser parser, Stetic.Project stetic, ITypeDefinition widgetClass, ITypeDefinition wrapperClass)
        {
            string     typeName     = widgetClass.FullName;
            string     basetypeName = GetBaseType(parser, widgetClass, stetic);
            XmlElement objectElem   = (XmlElement)SelectSingleNode("objects/object[@type='" + typeName + "']");

            if (objectElem == null)
            {
                // The widget class is not yet in the XML file. Create an element for it.
                objectElem = CreateElement("object");
                objectElem.SetAttribute("type", typeName);
                string category = parser.GetCategory(widgetClass);
                if (category == String.Empty)
                {
                    objectElem.SetAttribute("palette-category", "General");
                }
                else
                {
                    objectElem.SetAttribute("palette-category", category);
                }
                objectElem.SetAttribute("allow-children", "false");
                if (wrapperClass != null)
                {
                    objectElem.SetAttribute("wrapper", wrapperClass.FullName);
                }

                // By default add a reference to Gtk.Widget properties and events
                XmlElement itemGroups = objectElem.OwnerDocument.CreateElement("itemgroups");
                objectElem.AppendChild(itemGroups);

                itemGroups = objectElem.OwnerDocument.CreateElement("signals");
                objectElem.AppendChild(itemGroups);

                objectElem.SetAttribute("base-type", basetypeName);
                DocumentElement.AppendChild(objectElem);
            }

            UpdateObject(parser, basetypeName, objectElem, widgetClass, wrapperClass);
        }
        void InsertToolboxItemAttributes(WidgetParser parser)
        {
            var tb_items = parser.GetToolboxItems();

            foreach (string clsname in ObjectNames)
            {
                if (tb_items.ContainsKey(clsname))
                {
                    continue;
                }

                var cls = parser.GetClass(clsname);
                if (cls == null)
                {
                    continue;
                }
                CodeGenerationService.AddAttribute(cls, "System.ComponentModel.ToolboxItem", true);
                XmlElement elem = DocumentElement.SelectSingleNode("object[@type='" + clsname + "']") as XmlElement;
                if (elem != null && elem.HasAttribute("palette-category"))
                {
                    CodeGenerationService.AddAttribute(cls, "System.ComponentModel.Category", elem.GetAttribute("palette-category"));
                }
            }
        }
		void MergeEvent (WidgetParser parser, XmlElement objectElem, IEventSymbol evnt)
		{
			XmlElement itemGroups = objectElem ["signals"];
			if (itemGroups == null) {
				itemGroups = objectElem.OwnerDocument.CreateElement ("signals");
				objectElem.AppendChild (itemGroups);
			}
			
			string cat = evnt.GetComponentCategory ();
			XmlElement itemGroup = GetItemGroup (evnt.ContainingType, itemGroups, cat, "Signals");
			
			XmlElement signalElem = (XmlElement) itemGroup.SelectSingleNode ("signal[@name='" + evnt.Name + "']");
			if (signalElem == null) {
				signalElem = itemGroup.OwnerDocument.CreateElement ("signal");
				signalElem.SetAttribute ("name", evnt.Name);
				itemGroup.AppendChild (signalElem);
			}
		}
		void UpdateObject (WidgetParser parser, string topType, XmlElement objectElem, ITypeSymbol widgetClass, ITypeSymbol wrapperClass)
		{
			if (widgetClass.DeclaredAccessibility == Accessibility.Public)
				objectElem.RemoveAttribute ("internal");
			else
				objectElem.SetAttribute ("internal", "true");

			ListDictionary properties = new ListDictionary ();
			ListDictionary events = new ListDictionary ();
			
			parser.CollectMembers (widgetClass, true, topType, properties, events);
			if (wrapperClass != null)
				parser.CollectMembers (wrapperClass, false, null, properties, events);
			
			foreach (IPropertySymbol prop in properties.Values)
				MergeProperty (parser, objectElem, prop);
			
			foreach (IEventSymbol ev in events.Values)
				MergeEvent (parser, objectElem, ev);
			
			// Remove old properties
			ArrayList toDelete = new ArrayList ();
			foreach (XmlElement xprop in objectElem.SelectNodes ("itemgroups/itemgroup/property")) {
				if (!properties.Contains (xprop.GetAttribute ("name")))
					toDelete.Add (xprop);
			}
			
			// Remove old signals
			foreach (XmlElement xevent in objectElem.SelectNodes ("signals/itemgroup/signal")) {
				if (!events.Contains (xevent.GetAttribute ("name")))
					toDelete.Add (xevent);
			}
			
			foreach (XmlElement el in toDelete) {
				XmlElement pe = (XmlElement) el.ParentNode;
				pe.RemoveChild (el);
				if (pe.ChildNodes.Count == 0)
					pe.ParentNode.RemoveChild (pe);
			}
		}
		void MergeProperty (WidgetParser parser, XmlElement objectElem, IPropertySymbol prop)
		{
			XmlElement itemGroups = objectElem ["itemgroups"];
			if (itemGroups == null) {
				itemGroups = objectElem.OwnerDocument.CreateElement ("itemgroups");
				objectElem.AppendChild (itemGroups);
			}
			
			string cat = prop.GetComponentCategory ();
			XmlElement itemGroup = GetItemGroup (prop.ContainingType, itemGroups, cat, "Properties");
			
			XmlElement propElem = (XmlElement) itemGroup.SelectSingleNode ("property[@name='" + prop.Name + "']");
			if (propElem == null) {
				propElem = itemGroup.OwnerDocument.CreateElement ("property");
				propElem.SetAttribute ("name", prop.Name);
				itemGroup.AppendChild (propElem);
			}
		}
		string GetBaseType (WidgetParser parser, ITypeSymbol widgetClass, Stetic.Project stetic)
		{
			string[] types = stetic.GetWidgetTypes ();
			Hashtable typesHash = new Hashtable ();
			foreach (string t in types)
				typesHash [t] = t;
				
			string ret = parser.GetBaseType (widgetClass, typesHash);
			return ret ?? "Gtk.Widget";
		}
		void UpdateClass (WidgetParser parser, Stetic.Project stetic, ITypeSymbol widgetClass, ITypeSymbol wrapperClass)
		{
			string typeName = widgetClass.GetFullName();
			string basetypeName = GetBaseType (parser, widgetClass, stetic);
			XmlElement objectElem = (XmlElement) SelectSingleNode ("objects/object[@type='" + typeName + "']");
			
			if (objectElem == null) {
			
				// The widget class is not yet in the XML file. Create an element for it.
				objectElem = CreateElement ("object");
				objectElem.SetAttribute ("type", typeName);
				string category = widgetClass.GetComponentCategory();
				if (category == String.Empty)
					objectElem.SetAttribute ("palette-category", "General");
				else
					objectElem.SetAttribute ("palette-category", category);
				objectElem.SetAttribute ("allow-children", "false");
				if (wrapperClass != null)
					objectElem.SetAttribute ("wrapper", wrapperClass.GetFullName());
				
				// By default add a reference to Gtk.Widget properties and events
				XmlElement itemGroups = objectElem.OwnerDocument.CreateElement ("itemgroups");
				objectElem.AppendChild (itemGroups);
				
				itemGroups = objectElem.OwnerDocument.CreateElement ("signals");
				objectElem.AppendChild (itemGroups);
				
				objectElem.SetAttribute ("base-type", basetypeName);
				DocumentElement.AppendChild (objectElem);
			}
			
			UpdateObject (parser, basetypeName, objectElem, widgetClass, wrapperClass);
		}
		public void Update (WidgetParser parser, Stetic.Project stetic)
		{
			if (AttrSyncState == SyncState.Unspecified) {
				InsertToolboxItemAttributes (parser);
				AttrSyncState = SyncState.On;
				return;
			} else if (AttrSyncState == SyncState.Off)
				return;

			StringCollection tb_names = new StringCollection ();
			foreach (var cls in parser.GetToolboxItems().Values) {
				UpdateClass (parser, stetic, cls, null);
				tb_names.Add (cls.GetFullName ());
			}

			List<XmlElement> toDelete = new List<XmlElement> ();

			foreach (XmlElement elem in SelectNodes ("objects/object")) {
				string name = elem.GetAttribute ("type");
				if (!tb_names.Contains (name))
					toDelete.Add (elem);
			}

			foreach (XmlElement elem in toDelete)
				elem.ParentNode.RemoveChild (elem);

			Save ();
		}
		void InsertToolboxItemAttributes (WidgetParser parser)
		{
			var tb_items = parser.GetToolboxItems ();
			foreach (string clsname in ObjectNames) {
				if (tb_items.ContainsKey (clsname))
					continue;

				var cls = parser.GetClass (clsname);
				if (cls == null)
					continue;
				CodeGenerationService.AddAttribute (cls, "System.ComponentModel.ToolboxItem", true);
				XmlElement elem = DocumentElement.SelectSingleNode ("object[@type='" + clsname + "']") as XmlElement;
				if (elem != null && elem.HasAttribute ("palette-category")) {
					CodeGenerationService.AddAttribute (cls, "System.ComponentModel.Category", elem.GetAttribute ("palette-category"));
				}
			}
		}
		void InsertToolboxItemAttributes (WidgetParser parser, CodeRefactorer cref)
		{
			Dictionary<string, IType> tb_items = parser.GetToolboxItems ();
			foreach (string clsname in ObjectNames) {
				if (tb_items.ContainsKey (clsname))
					continue;

				IType cls = parser.GetClass (clsname);
				if (cls == null)
					continue;

				cref.AddAttribute (cls, "System.ComponentModel.ToolboxItem", true);
				XmlElement elem = DocumentElement.SelectSingleNode ("object[@type='" + clsname + "']") as XmlElement;
				if (elem != null && elem.HasAttribute ("palette-category"))
					cref.AddAttribute (cls, "System.ComponentModel.Category", elem.GetAttribute ("palette-category"));
			}
		}