This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Palette.cs
112 lines (88 loc) · 2.2 KB
/
Palette.cs
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
using Gtk;
using Gdk;
using System;
using System.Collections;
using System.Reflection;
namespace Stetic {
public class Palette : Gtk.VBox, IComparer {
Hashtable groups;
Project project;
class Group : Gtk.Expander {
private Gtk.Alignment align;
private Gtk.VBox vbox;
public Group (string name) : base ("<b>" + name + "</b>")
{
vbox = new VBox (false, 5);
align = new Gtk.Alignment (0, 0, 0, 0);
align.SetPadding (0, 0, 20, 0);
align.Child = vbox;
UseMarkup = true;
Expanded = true;
Child = align;
}
public void Append (Widget w)
{
vbox.PackStart (w, false, false, 0);
}
}
public Palette () : base (false, 2)
{
groups = new Hashtable ();
}
public Palette (Project project): this ()
{
this.Project = project;
}
public Project Project {
get { return project; }
set {
project = value;
LoadWidgets (project);
}
}
public void LoadWidgets (Project project)
{
foreach (Group g in groups.Values)
Remove (g);
groups.Clear ();
AddOrGetGroup ("widget", "Widgets");
AddOrGetGroup ("container", "Containers");
AddOrGetGroup ("toolbaritem", "Toolbar Items");
AddOrGetGroup ("window", "Windows");
ArrayList classes = new ArrayList ();
foreach (ClassDescriptor klass in Registry.AllClasses)
classes.Add (klass);
classes.Sort (this);
foreach (ClassDescriptor klass in classes) {
if (klass.Deprecated || klass.Category == "")
continue;
WidgetFactory factory;
if (klass.Category == "window")
factory = new WindowFactory (project, klass);
else
factory = new WidgetFactory (project, klass);
AddOrGetGroup(klass.Category).Append (factory);
}
ShowAll ();
}
int IComparer.Compare (object x, object y)
{
return string.Compare (((ClassDescriptor)x).Label,
((ClassDescriptor)y).Label);
}
private Group AddOrGetGroup (string id, string name)
{
Group group = (Group) groups[id];
if (group == null) {
group = new Group (name);
PackStart (group, false, false, 0);
groups.Add (id, group);
}
return group;
}
private Group AddOrGetGroup (string name)
{
return AddOrGetGroup (name, name);
}
}
}