Commit abef5b8e2f540de56c7258fa142e1161bbef39c3

  • avatar
  • Sam Thursfield <sam @dja…go.(none)>
  • Tue Aug 11 01:47:25 CEST 2009
Settings editor: undo/redo works.
  
15201520 g_free (property->key);
15211521
15221522 property->key = g_strdup (key);
1523 g_object_notify (property, "settings-key");
15231524};
15241525
15251526const gchar *
  
5151add_property (GladeSettingsEditor *self,
5252 GladeProperty *property)
5353{
54 GtkTreeIter iter;
55 GladePropertyClass *property_class = property->klass;;
56
5457 gtk_list_store_append (GTK_LIST_STORE (self->data), &iter);
5558
5659 // FIXME: set tooltip as klass->name
6464 -1);
6565};
6666
67void
68glade_settings_editor_show (GladeSettingsEditor *self,
69 GladeWidget *widget,
70 GladeProperty *property)
67static gboolean
68find_property (GladeSettingsEditor *self,
69 GladeProperty *property,
70 GtkTreeIter *iter)
7171{
72 glade_settings_editor_set_widget (self, widget);
73 glade_settings_editor_set_property (self, property);
72 gboolean result;
7473
75 gtk_widget_show_all (self->dialog);
76};
74 result = gtk_tree_model_get_iter_first (self->data, iter);
75 while (result)
76 {
77 GladeProperty *found_property;
78 gtk_tree_model_get (self->data, iter,
79 GLADE_SETTINGS_EDITOR_COLUMN_PROPERTY, &found_property,
80 -1);
7781
78void
79glade_settings_editor_set_widget (GladeSettingsEditor *self,
80 GladeWidget *widget)
82 if (found_property == property)
83 return TRUE;
84
85 result = gtk_tree_model_iter_next (self->data, iter);
86 }
87 return FALSE;
88}
89
90static void
91set_widget (GladeSettingsEditor *self,
92 GladeWidget *widget,
93 GladeProperty *initial_property)
8194{
8295 GList *node;
96 GladeProperty *first_property = NULL;
8397
8498 if (widget == self->widget)
8599 return;
106106 for (node=widget->properties; node; node=node->next) {
107107 GladeProperty *property = GLADE_PROPERTY (node->data);
108108
109 if (node->key != NULL) {
110
111
112 };
109 if (first_property == NULL)
110 first_property = property;
111
112 if (property->key != NULL)
113 add_property (self, property);
113114 };
114115
115116 self->widget = widget;
117 if (initial_property == NULL)
118 {
119 /* If this isn't from a glade_settings_editor_set_property call, set first property
120 * as active (and disconnect old property) */
121 glade_settings_editor_set_property (self, first_property);
122 }
116123};
117124
118void
119glade_settings_editor_set_property (GladeSettingsEditor *self,
120 GladeProperty *property)
125static void
126property_settings_key_notify (GladeProperty *property,
127 GParamSpec *pspec,
128 GladeSettingsEditor *self)
121129{
122 GladePropertyClass *property_class = property->klass;;
123130 GtkTreeIter iter;
131 gboolean found;
132 const char *key_name;
124133
125 };
126 };
134 found = find_property (self, property, &iter);
135 g_return_if_fail (found);
127136
128 self->widget = widget;
137 if (property->key == NULL)
138 key_name = KEY_DEFAULT;
139 else key_name = property->key;
140
141 gtk_list_store_set (GTK_LIST_STORE (self->data), &iter,
142 GLADE_SETTINGS_EDITOR_COLUMN_KEY_NAME, key_name,
143 -1);
129144};
130145
131146void
147glade_settings_editor_show (GladeSettingsEditor *self,
148 GladeWidget *widget,
149 GladeProperty *property)
150{
151 glade_settings_editor_set_widget (self, widget);
152 glade_settings_editor_set_property (self, property);
153
154 gtk_widget_show_all (self->dialog);
155};
156
157void
158glade_settings_editor_set_widget (GladeSettingsEditor *self,
159 GladeWidget *widget)
160{
161 set_widget (self, widget, NULL);
162};
163
164void
132165glade_settings_editor_set_property (GladeSettingsEditor *self,
133166 GladeProperty *property)
134167{
135 GladePropertyClass *property_class = property->klass;;
136 GtkTreeIter iter;
137
138168 if (property == self->property)
139169 return;
140170
171 if (self->property_notify_id != 0)
172 g_signal_handler_disconnect (property, self->property_notify_id);
173
141174 if (property->widget != self->widget)
142 glade_settings_editor_set_widget (self, property->widget);
175 set_widget (self, property->widget, property);
143176
144 // FIXME: look for property in list
145 add_property (self, property);
177 if (property->key != NULL)
178 {
179 // FIXME: look for property in list & select it
180 GtkTreeIter iter;
181 gboolean found;
182
183 found = find_property (self, property, &iter);
184 g_warn_if_fail (found);
185 }
186 else
187 add_property (self, property);
188
189 self->property = property;
190 self->property_notify_id = g_signal_connect (property, "notify::settings-key",
191 G_CALLBACK (property_settings_key_notify),
192 self);
146193};
147194
148195static void
320320glade_settings_editor_init (GladeSettingsEditor *self)
321321{
322322 self->widget = NULL;
323 self->property = NULL;
324 self->property_notify_id = 0;
323325};
324326
325327static void
  
3131{
3232 GtkObject parent;
3333
34 GladeWidget *widget; /* Widget currently having its properties bound */
34 GladeWidget *widget; /* Widget currently having its properties bound */
35 GladeProperty *property; /* Currently selected property */
36 int property_notify_id; /* Signal handler connected to notify::settings-key */
3537
3638 GtkWidget *dialog;
3739 GtkTreeModel *data;