public CommandDescriptor (XmlElement elem, ItemGroup group, ClassDescriptor klass) : base (elem, group, klass)
		{
			name = elem.GetAttribute ("name");
			label = elem.GetAttribute ("label");
			description = elem.GetAttribute ("description");
			checkName = elem.GetAttribute ("check");
			icon = elem.GetAttribute ("icon");
		}
Beispiel #2
0
 protected ItemDescriptor(XmlElement elem, ItemGroup group, ClassDescriptor klass)
 {
     this.klass = klass;
     isInternal = elem.HasAttribute ("internal");
     deps = AddSubprops (elem.SelectNodes ("./disabled-if"), group, klass);
     visdeps = AddSubprops (elem.SelectNodes ("./invisible-if"), group, klass);
     targetGtkVersion = elem.GetAttribute ("gtk-version");
     if (targetGtkVersion.Length == 0)
         targetGtkVersion = null;
 }
Beispiel #3
0
        public void AddGroup(ItemGroup igroup, object instance, string targetGtkVersion)
        {
            ArrayList props = new ArrayList ();
            foreach (ItemDescriptor item in igroup) {
                if (item.IsInternal)
                    continue;
                if (item is PropertyDescriptor && item.SupportsGtkVersion (targetGtkVersion))
                    props.Add (item);
            }

            if (props.Count == 0)
                return;

            InstanceData idata = new InstanceData (instance);
            TreeIter iter = store.AppendValues (igroup.Label, null, true, idata);
            foreach (PropertyDescriptor item in props)
                AppendProperty (iter, (PropertyDescriptor)item, idata);
        }
Beispiel #4
0
 public void AddGroup(ItemGroup igroup)
 {
     AppendGroup(igroup.Label, true);
     foreach (ItemDescriptor item in igroup)
     {
         if (item.IsInternal)
         {
             continue;
         }
         if (item is PropertyDescriptor)
         {
             AppendProperty((PropertyDescriptor)item);
         }
         else if (item is CommandDescriptor)
         {
             AppendCommand((CommandDescriptor)item);
         }
     }
 }
Beispiel #5
0
        bool FillGroup(Gtk.TreeIter parentIter, ItemGroup group)
        {
            bool hasSignals = false;

            foreach (SignalDescriptor sd in group)
            {
                if (!sd.SupportsGtkVersion(project.TargetGtkVersion))
                {
                    continue;
                }

                bool         foundSignal  = false;
                Gtk.TreeIter signalParent = parentIter;

                foreach (Signal signal in selection.Signals)
                {
                    if (signal.SignalDescriptor != sd)
                    {
                        continue;
                    }

                    Gtk.TreeIter iter = store.AppendNode(signalParent);
                    if (!foundSignal)
                    {
                        signalParent = iter;
                        store.SetValue(iter, ColSignal, sd.Name);
                        store.SetValue(iter, ColSignalTextWeight, (int)Pango.Weight.Bold);
                        foundSignal = true;
                    }
                    SetSignalData(iter, signal);
                }

                Gtk.TreeIter signalIter = store.AppendNode(signalParent);
                SetEmptySingalRow(signalIter, sd, !foundSignal);

                hasSignals = hasSignals || foundSignal;
            }
            return(hasSignals);
        }
		public TypedSignalDescriptor (XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base (elem, group, klass)
		{
			Load (elem);

			EventInfo eventInfo = FindEvent (klass.WrapperType, klass.WrappedType, name);
			MethodInfo handler = eventInfo.EventHandlerType.GetMethod ("Invoke");
			
			if (elem.HasAttribute ("glade-name"))
				gladeName = elem.GetAttribute ("glade-name");
			else {
				object[] att = eventInfo.GetCustomAttributes (typeof(GLib.SignalAttribute), true);
				if (att.Length > 0)
					gladeName = ((GLib.SignalAttribute)att[0]).CName;
			}
			
			handlerTypeName = eventInfo.EventHandlerType.FullName;
			handlerReturnTypeName = handler.ReturnType.FullName;
			
			ParameterInfo[] pars = handler.GetParameters ();
			handlerParameters = new ParameterDescriptor [pars.Length];
			for (int n=0; n<pars.Length; n++)
				handlerParameters [n] = new ParameterDescriptor (pars[n].Name, pars [n].ParameterType.FullName);
		}
Beispiel #7
0
		ArrayList AddSubprops (XmlNodeList nodes, ItemGroup group, ClassDescriptor klass)
		{
			ArrayList list = null;
			
			// Sub-properties can have a name+value (which checks for the value of a
			// property) or a method name, which should return true if the item has
			// to be disabled/hidden.

			foreach (XmlElement elem in nodes) {
				string name = elem.GetAttribute ("name");
				if (name.Length > 0) {
					string value = elem.GetAttribute ("value");

					PropertyDescriptor prop = (PropertyDescriptor)group[name];
					if (prop == null)
						prop = (PropertyDescriptor)klass[name];
					if (prop == null)
						throw new ArgumentException ("Bad sub-prop " + name);
					if (list == null)
						list = new ArrayList ();
						
					DepInfo info = new DepInfo ();
					info.Property = prop;
					info.Value = prop.StringToValue (value);
					list.Add (info);
				} else if ((name = elem.GetAttribute ("check")).Length > 0) {
					DepInfo info = new DepInfo ();
					info.CheckName = name;
					if (list == null)
						list = new ArrayList ();
					list.Add (info);
				} else {
					throw new ArgumentException ("Bad sub-prop");
				}
			}
			return list;
		}
		protected PropertyDescriptor (XmlElement elem, ItemGroup group, ClassDescriptor klass): base (elem, group, klass)
		{
		}
Beispiel #9
0
		public void AddGroup (ItemGroup igroup)
		{
			AppendGroup (igroup.Label, true);
			foreach (ItemDescriptor item in igroup) {
				if (item.IsInternal)
					continue;
				if (item is PropertyDescriptor)
					AppendProperty ((PropertyDescriptor)item);
				else if (item is CommandDescriptor)
					AppendCommand ((CommandDescriptor)item);
			}
		}
Beispiel #10
0
 static ItemGroup()
 {
     Empty = new ItemGroup();
 }
        public TypedPropertyDescriptor(XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base(elem, group, klass)
        {
            this.klass = klass;
            string propertyName = elem.GetAttribute("name");
            int    dot          = propertyName.IndexOf('.');

            if (dot != -1)
            {
                // Sub-property (eg, "Alignment.Value")
                memberInfo        = FindProperty(klass.WrapperType, klass.WrappedType, propertyName.Substring(0, dot));
                isWrapperProperty = memberInfo.DeclaringType.IsSubclassOf(typeof(ObjectWrapper));
                gladeProperty     = new TypedPropertyDescriptor(isWrapperProperty ? klass.WrapperType : klass.WrappedType, memberInfo.Name);
                propertyInfo      = FindProperty(memberInfo.PropertyType, propertyName.Substring(dot + 1));
            }
            else
            {
                // Basic simple property
                propertyInfo      = FindProperty(klass.WrapperType, klass.WrappedType, propertyName);
                isWrapperProperty = propertyInfo.DeclaringType.IsSubclassOf(typeof(ObjectWrapper));
            }

            // Wrapper properties that override widgets properties (using the same name)
            // must be considered runtime properties (will be available at run-time).
            if (!isWrapperProperty || klass.WrappedType.GetProperty(propertyName) != null)
            {
                isRuntimeProperty = true;
            }

            if (!IsInternal && propertyInfo.PropertyType.IsEnum &&
                Registry.LookupEnum(propertyInfo.PropertyType.FullName) == null)
            {
                throw new ArgumentException("No EnumDescriptor for " + propertyInfo.PropertyType.FullName + "(" + klass.WrappedType.FullName + "." + propertyName + ")");
            }

            pspec = FindPSpec(propertyInfo);

            if (isWrapperProperty && pspec == null)
            {
                PropertyInfo pinfo = klass.WrappedType.GetProperty(propertyInfo.Name, flags);
                if (pinfo != null)
                {
                    pspec = FindPSpec(pinfo);
                }
            }

            if (pspec != null)
            {
                // This information will be overridden by what's specified in the xml file
                description = pspec.Blurb;
                minimum     = pspec.Minimum;
                maximum     = pspec.Maximum;
                label       = propertyName;
                if (!elem.HasAttribute("ignore-default"))
                {
                    hasDefault = Type.GetTypeCode(PropertyType) != TypeCode.Object || PropertyType.IsEnum;
                }
            }
            else
            {
                label         = propertyInfo.Name;
                gladeOverride = true;
            }

            string typeName = elem.GetAttribute("editor");

            if (typeName.Length > 0)
            {
                editorType = Registry.GetType(typeName, false);
            }

            // Look for a default value attribute

            object[] ats = propertyInfo.GetCustomAttributes(typeof(DefaultValueAttribute), true);
            if (ats.Length > 0)
            {
                DefaultValueAttribute at = (DefaultValueAttribute)ats [0];
                defaultValue = at.Value;
            }

            // Load default data
            Load(elem);
        }
		public TypedPropertyDescriptor (XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base (elem, group, klass)
		{
			this.klass = klass;
			string propertyName = elem.GetAttribute ("name");
			int dot = propertyName.IndexOf ('.');

			if (dot != -1) {
				// Sub-property (eg, "Alignment.Value")
				memberInfo = FindProperty (klass.WrapperType, klass.WrappedType, propertyName.Substring (0, dot));
				isWrapperProperty = memberInfo.DeclaringType.IsSubclassOf (typeof (ObjectWrapper));
				gladeProperty = new TypedPropertyDescriptor (isWrapperProperty ? klass.WrapperType : klass.WrappedType, memberInfo.Name);
				propertyInfo = FindProperty (memberInfo.PropertyType, propertyName.Substring (dot + 1));
			} else {
				// Basic simple property
				propertyInfo = FindProperty (klass.WrapperType, klass.WrappedType, propertyName);
				isWrapperProperty = propertyInfo.DeclaringType.IsSubclassOf (typeof (ObjectWrapper));
			}
			
			// Wrapper properties that override widgets properties (using the same name)
			// must be considered runtime properties (will be available at run-time).
			if (!isWrapperProperty || klass.WrappedType.GetProperty (propertyName) != null)
				isRuntimeProperty = true;
			
			if (!IsInternal && propertyInfo.PropertyType.IsEnum &&
			    Registry.LookupEnum (propertyInfo.PropertyType.FullName) == null)
				throw new ArgumentException ("No EnumDescriptor for " + propertyInfo.PropertyType.FullName + "(" + klass.WrappedType.FullName + "." + propertyName + ")");

			pspec = FindPSpec (propertyInfo);
			
			if (isWrapperProperty && pspec == null) {
				PropertyInfo pinfo = klass.WrappedType.GetProperty (propertyInfo.Name, flags);
				if (pinfo != null)
					pspec = FindPSpec (pinfo);
			}

			if (pspec != null) {
				// This information will be overridden by what's specified in the xml file
				description = pspec.Blurb;
				minimum = pspec.Minimum;
				maximum = pspec.Maximum;
				label = propertyName;
				if (!elem.HasAttribute ("ignore-default"))
					hasDefault = Type.GetTypeCode (PropertyType) != TypeCode.Object || PropertyType.IsEnum;
			} else {
				label = propertyInfo.Name;
				gladeOverride = true;
			}

			string typeName = elem.GetAttribute ("editor");
			if (typeName.Length > 0)
				editorType = Registry.GetType (typeName, false);
			
			// Look for a default value attribute
			
			object[] ats = propertyInfo.GetCustomAttributes (typeof(DefaultValueAttribute), true);
			if (ats.Length > 0) {
				DefaultValueAttribute at = (DefaultValueAttribute) ats [0];
				defaultValue = at.Value;
			}
			
			// Load default data
			Load (elem);
		}
		internal protected override ItemDescriptor CreateItemDescriptor (XmlElement elem, ItemGroup group)
		{
			if (elem.Name == "property")
				return new TypedPropertyDescriptor (elem, group, this);
			else if (elem.Name == "signal")
				return new TypedSignalDescriptor (elem, group, this);
			else
				return base.CreateItemDescriptor (elem, group);
		}
Beispiel #14
0
 public void Add(ItemGroup group)
 {
     List.Add(group);
 }
        protected void Load(XmlElement elem)
        {
            if (elem.HasAttribute("cname"))
            {
                cname = elem.GetAttribute("cname");
            }
            else if (cname == null)
            {
                cname = elem.GetAttribute("type");
            }

            label = elem.GetAttribute("label");
            if (label == "")
            {
                label = WrappedTypeName;
                int i = label.LastIndexOf('.');
                if (i != -1)
                {
                    label = label.Substring(i + 1);
                }
            }

            if (elem.HasAttribute("allow-children"))
            {
                allowChildren = elem.GetAttribute("allow-children") == "yes" || elem.GetAttribute("allow-children") == "true";
            }

            category = elem.GetAttribute("palette-category");

            if (elem.HasAttribute("deprecated"))
            {
                deprecated = true;
            }
            if (elem.HasAttribute("hexpandable"))
            {
                hexpandable = true;
            }
            if (elem.HasAttribute("vexpandable"))
            {
                vexpandable = true;
            }
            if (elem.GetAttribute("internal") == "true")
            {
                isInternal = true;
            }

            contextMenu = ItemGroup.Empty;

            baseType = elem.GetAttribute("base-type");
            if (baseType.Length > 0)
            {
                ClassDescriptor basec = Registry.LookupClassByName(baseType);
                if (basec == null)
                {
                    throw new InvalidOperationException("Base type '" + baseType + "' not found.");
                }
                foreach (ItemGroup group in basec.ItemGroups)
                {
                    groups.Add(group);
                }
                foreach (ItemGroup group in basec.SignalGroups)
                {
                    signals.Add(group);
                }
                contextMenu = basec.ContextMenu;
            }
            else
            {
                baseType = null;
            }

            XmlElement groupsElem = elem["itemgroups"];

            if (groupsElem != null)
            {
                foreach (XmlElement groupElem in groupsElem.SelectNodes("itemgroup"))
                {
                    ItemGroup itemgroup;

                    if (groupElem.HasAttribute("ref"))
                    {
                        string refname = groupElem.GetAttribute("ref");
                        itemgroup = Registry.LookupItemGroup(refname);
                    }
                    else
                    {
                        itemgroup = new ItemGroup(groupElem, this);
                    }
                    groups.Add(itemgroup);

                    if (groupElem.HasAttribute("important"))
                    {
                        if (groupElem.GetAttribute("important") == "true")
                        {
                            importantGroups++;
                        }
                    }
                    else if (groups.Count == 1)
                    {
                        importantGroups++;
                    }
                }
            }

            XmlElement signalsElem = elem["signals"];

            if (signalsElem != null)
            {
                foreach (XmlElement groupElem in signalsElem.SelectNodes("itemgroup"))
                {
                    ItemGroup itemgroup;
                    if (groupElem.HasAttribute("ref"))
                    {
                        string refname = groupElem.GetAttribute("ref");
                        itemgroup = Registry.LookupSignalGroup(refname);
                    }
                    else
                    {
                        itemgroup = new ItemGroup(groupElem, this);
                    }
                    signals.Add(itemgroup);
                }
            }

            XmlElement contextElem = elem["contextmenu"];

            if (contextElem != null)
            {
                if (contextElem.HasAttribute("ref"))
                {
                    string refname = contextElem.GetAttribute("ref");
                    contextMenu = Registry.LookupContextMenu(refname);
                }
                else
                {
                    contextMenu = new ItemGroup(contextElem, this);
                }
            }

            XmlElement ichildElem = elem["internal-children"];

            if (ichildElem != null)
            {
                internalChildren = new ItemGroup(ichildElem, this);
            }
            else
            {
                internalChildren = ItemGroup.Empty;
            }

            string initProps = elem.GetAttribute("init-properties");

            if (initProps.Length > 0)
            {
                string[]  props = initProps.Split(' ');
                ArrayList list  = new ArrayList();
                foreach (string prop in props)
                {
                    PropertyDescriptor idesc = this [prop] as PropertyDescriptor;
                    if (idesc == null)
                    {
                        throw new InvalidOperationException("Initialization property not found: " + prop);
                    }
                    list.Add(idesc);
                }
                initializationProperties = (PropertyDescriptor[])list.ToArray(typeof(PropertyDescriptor));
            }
            else
            {
                initializationProperties = emptyPropArray;
            }

            targetGtkVersion = elem.GetAttribute("gtk-version");
            if (targetGtkVersion.Length == 0)
            {
                targetGtkVersion = null;
            }
        }
 protected PropertyDescriptor(XmlElement elem, ItemGroup group, ClassDescriptor klass) : base(elem, group, klass)
 {
 }
Beispiel #17
0
 public SignalDescriptor(XmlElement elem, ItemGroup group, ClassDescriptor klass) : base(elem, group, klass)
 {
 }
		public SignalDescriptor (XmlElement elem, ItemGroup group, ClassDescriptor klass) : base (elem, group, klass)
		{
		}
		static ItemGroup ()
		{
			Empty = new ItemGroup ();
		}
Beispiel #20
0
		internal protected virtual ItemDescriptor CreateItemDescriptor (XmlElement elem, ItemGroup group)
		{
			if (elem.Name == "command")
				return new CommandDescriptor (elem, group, this);
			else
				throw new ApplicationException ("Bad item name " + elem.Name + " in " + WrappedTypeName);
		}
Beispiel #21
0
		protected void Load (XmlElement elem)
		{
			if (elem.HasAttribute ("cname"))
				cname = elem.GetAttribute ("cname");
			else if (cname == null)
				cname = elem.GetAttribute ("type");

			label = elem.GetAttribute ("label");
			if (label == "") {
				label = WrappedTypeName;
				int i = label.LastIndexOf ('.');
				if (i != -1)
					label = label.Substring (i+1);
			}
			
			if (elem.HasAttribute ("allow-children"))
				allowChildren = elem.GetAttribute ("allow-children") == "yes" || elem.GetAttribute ("allow-children") == "true";
				
			category = elem.GetAttribute ("palette-category");

			if (elem.HasAttribute ("deprecated"))
				deprecated = true;
			if (elem.HasAttribute ("hexpandable"))
				hexpandable = true;
			if (elem.HasAttribute ("vexpandable"))
				vexpandable = true;
			if (elem.GetAttribute ("internal") == "true")
				isInternal = true;
			
			contextMenu = ItemGroup.Empty;
			
			baseType = elem.GetAttribute ("base-type");
			if (baseType.Length > 0) {
				ClassDescriptor basec = Registry.LookupClassByName (baseType);
				if (basec == null)
					throw new InvalidOperationException ("Base type '" + baseType + "' not found.");
				foreach (ItemGroup group in basec.ItemGroups)
					groups.Add (group);
				foreach (ItemGroup group in basec.SignalGroups)
					signals.Add (group);
				contextMenu = basec.ContextMenu;
			} else
				baseType = null;

			XmlElement groupsElem = elem["itemgroups"];
			if (groupsElem != null) {
				foreach (XmlElement groupElem in groupsElem.SelectNodes ("itemgroup")) {
					ItemGroup itemgroup;

					if (groupElem.HasAttribute ("ref")) {
						string refname = groupElem.GetAttribute ("ref");
						itemgroup = Registry.LookupItemGroup (refname);
					} else
						itemgroup = new ItemGroup (groupElem, this);
					groups.Add (itemgroup);

					if (groupElem.HasAttribute ("important")) {
						if (groupElem.GetAttribute ("important") == "true")
							importantGroups++;
					} else if (groups.Count == 1)
						importantGroups++;
				}
			}

			XmlElement signalsElem = elem["signals"];
			if (signalsElem != null) {
				foreach (XmlElement groupElem in signalsElem.SelectNodes ("itemgroup")) {
					ItemGroup itemgroup;
					if (groupElem.HasAttribute ("ref")) {
						string refname = groupElem.GetAttribute ("ref");
						itemgroup = Registry.LookupSignalGroup (refname);
					} else
						itemgroup = new ItemGroup (groupElem, this);
					signals.Add (itemgroup);
				}
			}

			XmlElement contextElem = elem["contextmenu"];
			if (contextElem != null) {
				if (contextElem.HasAttribute ("ref")) {
					string refname = contextElem.GetAttribute ("ref");
					contextMenu = Registry.LookupContextMenu (refname);
				} else
					contextMenu = new ItemGroup (contextElem, this);
			}

			XmlElement ichildElem = elem["internal-children"];
			if (ichildElem != null)
				internalChildren = new ItemGroup (ichildElem, this);
			else
				internalChildren = ItemGroup.Empty;

			string initProps = elem.GetAttribute ("init-properties");
			if (initProps.Length > 0) {
				string[] props = initProps.Split (' ');
				ArrayList list = new ArrayList ();
				foreach (string prop in props) {
					PropertyDescriptor idesc = this [prop] as PropertyDescriptor;
					if (idesc == null)
						throw new InvalidOperationException ("Initialization property not found: " + prop);
					list.Add (idesc);
				}
				initializationProperties = (PropertyDescriptor[]) list.ToArray (typeof(PropertyDescriptor));
			} else
				initializationProperties = emptyPropArray;
			
			targetGtkVersion = elem.GetAttribute ("gtk-version");
			if (targetGtkVersion.Length == 0)
				targetGtkVersion = null;
		}
 internal protected virtual ItemDescriptor CreateItemDescriptor(XmlElement elem, ItemGroup group)
 {
     if (elem.Name == "command")
     {
         return(new CommandDescriptor(elem, group, this));
     }
     else
     {
         throw new ApplicationException("Bad item name " + elem.Name + " in " + WrappedTypeName);
     }
 }
		bool FillGroup (Gtk.TreeIter groupIter, ItemGroup group)
		{
			bool hasSignals = false;
			foreach (SignalDescriptor sd in group) {
				if (!sd.SupportsGtkVersion (project.TargetGtkVersion))
					continue;
				
				bool foundSignal = false;
				Gtk.TreeIter parent = groupIter;
				
				foreach (Signal signal in selection.Signals) {
					if (signal.SignalDescriptor != sd) continue;

					Gtk.TreeIter iter = store.AppendValues (parent, null, signal.Handler, false, true, true, (int) Pango.Weight.Normal);
					if (!foundSignal) {
						parent = iter;
						store.SetValue (iter, ColSignal, sd.Name);
						store.SetValue (iter, ColSignalTextWeight, (int) Pango.Weight.Bold);
						hasSignals = foundSignal = true;
					}
				}
				
				InsertEmptySignalRow (parent, foundSignal ? null : sd.Name);
			}
			return hasSignals;
		}
		public void Add (ItemGroup group)
		{
			List.Add (group);
		}
 internal protected override ItemDescriptor CreateItemDescriptor(XmlElement elem, ItemGroup group)
 {
     if (elem.Name == "property")
     {
         return(new TypedPropertyDescriptor(elem, group, this));
     }
     else if (elem.Name == "signal")
     {
         return(new TypedSignalDescriptor(elem, group, this));
     }
     else
     {
         return(base.CreateItemDescriptor(elem, group));
     }
 }
Beispiel #26
0
        bool FillGroup(Gtk.TreeIter parentIter, ItemGroup group)
        {
            bool hasSignals = false;
            foreach (SignalDescriptor sd in group) {
                if (!sd.SupportsGtkVersion (project.TargetGtkVersion))
                    continue;

                bool foundSignal = false;
                Gtk.TreeIter signalParent = parentIter;

                foreach (Signal signal in selection.Signals) {
                    if (signal.SignalDescriptor != sd) continue;

                    Gtk.TreeIter iter = store.AppendNode (signalParent);
                    if (!foundSignal) {
                        signalParent = iter;
                        store.SetValue (iter, ColSignal, sd.Name);
                        store.SetValue (iter, ColSignalTextWeight, (int) Pango.Weight.Bold);
                        foundSignal = true;
                    }
                    SetSignalData (iter, signal);
                }

                Gtk.TreeIter signalIter = store.AppendNode (signalParent);
                SetEmptySingalRow (signalIter, sd, !foundSignal);

                hasSignals = hasSignals || foundSignal;
            }
            return hasSignals;
        }