File: EditorShell.cs

package info (click to toggle)
gtk-sharp 1%3A1.0.10-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,416 kB
  • ctags: 4,465
  • sloc: xml: 224,361; cs: 17,961; sh: 8,422; ansic: 2,724; makefile: 1,604; perl: 1,089
file content (116 lines) | stat: -rw-r--r-- 3,378 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// EditorShell.cs -
//
// Author: Rachel Hestilow  <hestilow@nullenvoid.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General 
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.


namespace GConf.PropertyEditors
{
	using System;
	using System.Collections;

	public class EditorNotSupportedException : Exception
	{
	}
			
	public class InvalidGladeKeyException : Exception
	{
		public InvalidGladeKeyException (string control_name) : base ("No such glade entry \"" + control_name + "\"")
		{
		}
	}

	public class EditorShell
	{
		ArrayList editors = new ArrayList ();
		Hashtable by_key = new Hashtable ();
		Glade.XML gxml;
		GConf.ChangeSet cs = null;
		
		public EditorShell (Glade.XML gxml)
		{
			this.gxml = gxml;
		}

		public EditorShell (Glade.XML gxml, GConf.ChangeSet cs)
		{
			this.gxml = gxml;
			this.cs = cs;
		}

		public void Add (PropertyEditor editor)
		{
			editors.Add (editor);
			if (cs != null)
				editor.ChangeSet = cs;
			editor.Setup ();
		}

		public void Add (string key, string control_name)
		{
			Add (key, control_name, null, null);
		}

		public void Add (string key, string control_name, Type enum_type, int[] enum_values)
		{
			PropertyEditor editor;
			Gtk.Widget control = gxml[control_name];

			if (control == null)
				throw new InvalidGladeKeyException (control_name);

			//if (control is Gnome.ColorPicker)
				//editor = new PropertyEditorColorPicker (key, (Gnome.ColorPicker) control);
			else if (control is Gnome.FileEntry)
				editor = new PropertyEditorFileEntry (key, (Gnome.FileEntry) control);
			else if (control is Gtk.SpinButton)
				editor = new PropertyEditorSpinButton (key, (Gtk.SpinButton) control);
			else if (control is Gtk.RadioButton)
				editor = new PropertyEditorRadioButton (key, (Gtk.RadioButton) control, enum_type, enum_values);
			else if (control is Gtk.ToggleButton)
				editor = new PropertyEditorToggleButton (key, (Gtk.ToggleButton) control);
			else if (control is Gtk.Entry)
				editor = new PropertyEditorEntry (key, (Gtk.Entry) control);
			else if (control is Gtk.OptionMenu)
				editor = new PropertyEditorOptionMenu (key, (Gtk.OptionMenu) control, enum_type, enum_values);
			else
				throw new EditorNotSupportedException ();

			by_key.Add (key, editor);
			Add (editor);
		}

		public void Add (string key, string control_name, Type enum_type)
		{
			Add (key, control_name, enum_type, null);
		}

		public void AddGuard (string key, string control_name)
		{
			if (!by_key.Contains (key))
				return;
			Gtk.Widget control = gxml[control_name];
			if (control == null)
				throw new InvalidGladeKeyException (control_name);
			
			PropertyEditorBool editor = by_key[key] as PropertyEditorBool;
			if (editor == null)
				throw new EditorNotSupportedException ();
			
			editor.AddGuard (control);
		}
	}
}