Esempio n. 1
0
        private ComboBoxWidget CreateComboBox(string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes)
        {
            Dictionary <string, object> dict = null;

            foreach (var attr in attributes)
            {
                if (attr is StaticListAttribute)
                {
                    dict = (Dictionary <string, object>)GetValue(((StaticListAttribute)attr).dictionaryName, o);
                }
            }

            List <string> entries = new List <string> ();

            foreach (string str in dict.Keys)
            {
                entries.Add(str);
            }

            ComboBoxWidget widget = new ComboBoxWidget(entries.ToArray());

            widget.Label = caption;
            widget.AddEvents((int)Gdk.EventMask.ButtonPressMask);
            widget.Active = entries.IndexOf((string)GetValue(member, o));

            widget.Changed += delegate(object sender, EventArgs e) {
                SetValue(member, o, widget.ActiveText);
            };

            return(widget);
        }
Esempio n. 2
0
        private ComboBoxWidget CreateEnumComboBox(string caption, object o, MemberInfo member, object[] attributes)
        {
            var myType = GetTypeForMember(member) !;             // NRT - We're looping through members we got from reflection

            var member_names    = Enum.GetNames(myType);
            var labels          = new List <string> ();
            var label_to_member = new Dictionary <string, string> ();

            foreach (var member_name in member_names)
            {
                var members = myType.GetMember(member_name);

                // Look for a Caption attribute that provides a (translated) description.
                string label;
                var    attrs = members[0].GetCustomAttributes(typeof(CaptionAttribute), false);

                if (attrs.Length > 0)
                {
                    label = Core.Translations.GetString(((CaptionAttribute)attrs[0]).Caption);
                }
                else
                {
                    label = Core.Translations.GetString(member_name);
                }

                label_to_member[label] = member_name;
                labels.Add(label);
            }

            var widget = new ComboBoxWidget(labels.ToArray())
            {
                Label = caption
            };

            widget.AddEvents((int)Gdk.EventMask.ButtonPressMask);

            if (GetValue(member, o) is object obj)
            {
                widget.Active = ((IList)member_names).IndexOf(obj.ToString());
            }

            widget.Changed += delegate(object?sender, EventArgs e) {
                SetValue(member, o, Enum.Parse(myType, label_to_member[widget.ActiveText]));
            };

            return(widget);
        }
Esempio n. 3
0
        private ComboBoxWidget CreateEnumComboBox(string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes)
        {
            Type myType = GetTypeForMember(member);

            string[] entries = Enum.GetNames(myType);

            ComboBoxWidget widget = new ComboBoxWidget(entries);

            widget.Label = caption;
            widget.AddEvents((int)Gdk.EventMask.ButtonPressMask);
            widget.Active = ((IList)entries).IndexOf(GetValue(member, o).ToString());

            widget.Changed += delegate(object sender, EventArgs e) {
                SetValue(member, o, Enum.Parse(myType, widget.ActiveText));
            };

            return(widget);
        }
Esempio n. 4
0
        private ComboBoxWidget CreateEnumComboBox(string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes)
        {
            Type myType = GetTypeForMember(member);

            string[] member_names    = Enum.GetNames(myType);
            var      labels          = new List <string> ();
            var      label_to_member = new Dictionary <string, string> ();

            foreach (var member_name in member_names)
            {
                var members = myType.GetMember(member_name);

                // Look for a Caption attribute that provides a (translated) description.
                string label;
                var    attrs = members [0].GetCustomAttributes(typeof(CaptionAttribute), false);
                if (attrs.Length > 0)
                {
                    label = Catalog.GetString(((CaptionAttribute)attrs [0]).Caption);
                }
                else
                {
                    label = Catalog.GetString(member_name);
                }

                label_to_member [label] = member_name;
                labels.Add(label);
            }

            ComboBoxWidget widget = new ComboBoxWidget(labels.ToArray());

            widget.Label = caption;
            widget.AddEvents((int)Gdk.EventMask.ButtonPressMask);
            widget.Active = ((IList)member_names).IndexOf(GetValue(member, o).ToString());

            widget.Changed += delegate(object sender, EventArgs e) {
                SetValue(member, o, Enum.Parse(myType, label_to_member[widget.ActiveText]));
            };

            return(widget);
        }
Esempio n. 5
0
        private ComboBoxWidget CreateComboBox(string caption, object o, MemberInfo member, object[] attributes)
        {
            Dictionary <string, object>?dict = null;

            foreach (var attr in attributes)
            {
                if (attr is StaticListAttribute attribute && GetValue(attribute.DictionaryName, o) is Dictionary <string, object> d)
                {
                    dict = d;
                }
            }

            var entries = new List <string> ();

            if (dict != null)
            {
                foreach (var str in dict.Keys)
                {
                    entries.Add(str);
                }
            }

            var widget = new ComboBoxWidget(entries.ToArray())
            {
                Label = caption
            };

            widget.AddEvents((int)Gdk.EventMask.ButtonPressMask);

            if (GetValue(member, o) is string s)
            {
                widget.Active = entries.IndexOf(s);
            }

            widget.Changed += delegate(object?sender, EventArgs e) {
                SetValue(member, o, widget.ActiveText);
            };

            return(widget);
        }
Esempio n. 6
0
		private ComboBoxWidget CreateComboBox (string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes)
		{
			Dictionary<string, object> dict = null;

			foreach (var attr in attributes) {
				if (attr is StaticListAttribute)
					dict = (Dictionary<string, object>)GetValue (((StaticListAttribute)attr).dictionaryName, o);
			}

			List<string> entries = new List<string> ();
			foreach (string str in dict.Keys)
				entries.Add (str);

			ComboBoxWidget widget = new ComboBoxWidget (entries.ToArray ());

			widget.Label = caption;
			widget.AddEvents ((int)Gdk.EventMask.ButtonPressMask);
			widget.Active = entries.IndexOf ((string)GetValue (member, o));

			widget.Changed += delegate (object sender, EventArgs e) {
				SetValue (member, o, widget.ActiveText);
			};

			return widget;
		}
Esempio n. 7
0
		private ComboBoxWidget CreateEnumComboBox (string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes)
		{
			Type myType = GetTypeForMember (member);

			string[] member_names = Enum.GetNames (myType);
			var labels = new List<string> ();
			var label_to_member = new Dictionary<string, string> ();

			foreach (var member_name in member_names)
			{
				var members = myType.GetMember (member_name);

				// Look for a Caption attribute that provides a (translated) description.
				string label;
				var attrs = members [0].GetCustomAttributes (typeof(CaptionAttribute), false);
				if (attrs.Length > 0)
					label = Catalog.GetString (((CaptionAttribute)attrs [0]).Caption);
				else
					label = Catalog.GetString (member_name);

				label_to_member [label] = member_name;
				labels.Add (label);
			}

			ComboBoxWidget widget = new ComboBoxWidget (labels.ToArray ());

			widget.Label = caption;
			widget.AddEvents ((int)Gdk.EventMask.ButtonPressMask);
			widget.Active = ((IList)member_names).IndexOf (GetValue (member, o).ToString ());

			widget.Changed += delegate (object sender, EventArgs e) {
				SetValue (member, o, Enum.Parse (myType, label_to_member[widget.ActiveText]));
			};

			return widget;
		}
Esempio n. 8
0
        private ComboBoxWidget CreateEnumComboBox(string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes)
        {
            Type myType = GetTypeForMember (member);
            string[] entries = Enum.GetNames(myType);

            ComboBoxWidget widget = new ComboBoxWidget (entries);

            widget.Label = caption;
            widget.AddEvents ((int)Gdk.EventMask.ButtonPressMask);
            widget.Active = ((IList)entries).IndexOf (GetValue (member, o).ToString());

            widget.Changed += delegate (object sender, EventArgs e) {
                SetValue (member, o, Enum.Parse(myType, widget.ActiveText));
            };

            return widget;
        }