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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Tristan Van Berkom.
*
* This library is free software; you can redistribute it and/or it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Authors:
* Tristan Van Berkom <tvb@gnome.org>
*/
#include <config.h>
#include <gladeui/glade.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdkkeysyms.h>
#include "glade-activatable-editor.h"
static void glade_activatable_editor_finalize (GObject *object);
static void glade_activatable_editor_editable_init (GladeEditableIface *iface);
static void glade_activatable_editor_grab_focus (GtkWidget *widget);
G_DEFINE_TYPE_WITH_CODE (GladeActivatableEditor, glade_activatable_editor, GTK_TYPE_VBOX,
G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE,
glade_activatable_editor_editable_init));
static void
glade_activatable_editor_class_init (GladeActivatableEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = glade_activatable_editor_finalize;
widget_class->grab_focus = glade_activatable_editor_grab_focus;
}
static void
glade_activatable_editor_init (GladeActivatableEditor *self)
{
}
static void
project_changed (GladeProject *project,
GladeCommand *command,
gboolean execute,
GladeActivatableEditor *activatable_editor)
{
if (activatable_editor->modifying ||
!GTK_WIDGET_MAPPED (activatable_editor))
return;
/* Reload on all commands */
glade_editable_load (GLADE_EDITABLE (activatable_editor), activatable_editor->loaded_widget);
}
static void
project_finalized (GladeActivatableEditor *activatable_editor,
GladeProject *where_project_was)
{
activatable_editor->loaded_widget = NULL;
glade_editable_load (GLADE_EDITABLE (activatable_editor), NULL);
}
static void
glade_activatable_editor_load (GladeEditable *editable,
GladeWidget *widget)
{
GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (editable);
GList *l;
activatable_editor->loading = TRUE;
/* Since we watch the project*/
if (activatable_editor->loaded_widget)
{
/* watch custom-child and use-stock properties here for reloads !!! */
g_signal_handlers_disconnect_by_func (G_OBJECT (activatable_editor->loaded_widget->project),
G_CALLBACK (project_changed), activatable_editor);
/* The widget could die unexpectedly... */
g_object_weak_unref (G_OBJECT (activatable_editor->loaded_widget->project),
(GWeakNotify)project_finalized,
activatable_editor);
}
/* Mark our widget... */
activatable_editor->loaded_widget = widget;
if (activatable_editor->loaded_widget)
{
/* This fires for undo/redo */
g_signal_connect (G_OBJECT (activatable_editor->loaded_widget->project), "changed",
G_CALLBACK (project_changed), activatable_editor);
/* The widget/project could die unexpectedly... */
g_object_weak_ref (G_OBJECT (activatable_editor->loaded_widget->project),
(GWeakNotify)project_finalized,
activatable_editor);
}
/* load the embedded editable... */
if (activatable_editor->embed)
glade_editable_load (GLADE_EDITABLE (activatable_editor->embed), widget);
for (l = activatable_editor->properties; l; l = l->next)
glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget);
if (widget)
{
}
activatable_editor->loading = FALSE;
}
static void
glade_activatable_editor_set_show_name (GladeEditable *editable,
gboolean show_name)
{
GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (editable);
glade_editable_set_show_name (GLADE_EDITABLE (activatable_editor->embed), show_name);
}
static void
glade_activatable_editor_editable_init (GladeEditableIface *iface)
{
iface->load = glade_activatable_editor_load;
iface->set_show_name = glade_activatable_editor_set_show_name;
}
static void
glade_activatable_editor_finalize (GObject *object)
{
GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (object);
if (activatable_editor->properties)
g_list_free (activatable_editor->properties);
activatable_editor->properties = NULL;
activatable_editor->embed = NULL;
glade_editable_load (GLADE_EDITABLE (object), NULL);
G_OBJECT_CLASS (glade_activatable_editor_parent_class)->finalize (object);
}
static void
glade_activatable_editor_grab_focus (GtkWidget *widget)
{
GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (widget);
gtk_widget_grab_focus (activatable_editor->embed);
}
static void
table_attach (GtkWidget *table,
GtkWidget *child,
gint pos, gint row,
GtkSizeGroup *group)
{
gtk_table_attach (GTK_TABLE (table), child,
pos, pos+1, row, row +1,
pos ? 0 : GTK_EXPAND | GTK_FILL,
GTK_EXPAND | GTK_FILL,
3, 1);
if (pos)
gtk_size_group_add_widget (group, child);
}
static void
reset_property (GladeWidget *gwidget,
const gchar *property_name)
{
GladeProperty *property;
GValue value = { 0, };
if ((property = glade_widget_get_property (gwidget, property_name)) != NULL)
{
glade_property_get_default (property, &value);
glade_command_set_property_value (property, &value);
g_value_unset (&value);
}
}
static GladeWidget *
get_image_widget (GladeWidget *widget)
{
GtkWidget *image = NULL;
if (GTK_IS_IMAGE_MENU_ITEM (widget->object))
image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget->object));
return image ? glade_widget_get_from_gobject (image) : NULL;
}
static void
reset_properties (GladeWidget *gwidget,
GtkAction *action,
gboolean use_appearance,
gboolean use_appearance_changed)
{
reset_property (gwidget, "visible");
reset_property (gwidget, "sensitive");
if (GTK_IS_MENU_ITEM (gwidget->object))
{
if (!use_appearance_changed)
reset_property (gwidget, "accel-group");
if (use_appearance)
{
GladeWidget *image;
GladeProperty *property;
reset_property (gwidget, "stock");
reset_property (gwidget, "use-underline");
reset_property (gwidget, "use-stock");
/* Delete image... */
if ((image = get_image_widget (gwidget)) != NULL)
{
GList list = { 0, };
list.data = image;
glade_command_unlock_widget (image);
glade_command_delete (&list);
}
property = glade_widget_get_property (gwidget, "label");
glade_command_set_property (property, NULL);
}
else if (use_appearance_changed)
{
reset_property (gwidget, "stock");
reset_property (gwidget, "use-underline");
reset_property (gwidget, "use-stock");
reset_property (gwidget, "label");
}
}
else if (GTK_IS_TOOL_ITEM (gwidget->object))
{
reset_property (gwidget, "visible-horizontal");
reset_property (gwidget, "visible-vertical");
reset_property (gwidget, "is-important");
if (use_appearance || use_appearance_changed)
{
reset_property (gwidget, "label-widget");
reset_property (gwidget, "custom-label");
reset_property (gwidget, "stock-id");
reset_property (gwidget, "icon-name");
reset_property (gwidget, "icon");
reset_property (gwidget, "icon-widget");
reset_property (gwidget, "image-mode");
}
}
else if (GTK_IS_BUTTON (gwidget->object))
{
reset_property (gwidget, "active");
if (use_appearance)
{
GtkWidget *button, *child;
GladeWidget *gchild = NULL;
GladeProperty *property;
/* If theres a widget customly inside... command remove it first... */
button = GTK_WIDGET (gwidget->object);
child = gtk_bin_get_child (GTK_BIN (button));
if (child)
gchild = glade_widget_get_from_gobject (child);
if (gchild && gchild->parent == gwidget)
{
GList widgets = { 0, };
widgets.data = gchild;
glade_command_delete (&widgets);
}
reset_property (gwidget, "custom-child");
reset_property (gwidget, "stock");
//reset_property (gwidget, "use-stock");
property = glade_widget_get_property (gwidget, "label");
glade_command_set_property (property, "");
} else if (use_appearance_changed) {
reset_property (gwidget, "label");
reset_property (gwidget, "custom-child");
reset_property (gwidget, "stock");
//reset_property (gwidget, "use-stock");
}
}
/* Make sure none of our property resets screw with the current selection,
* since we rely on the selection during commit time.
*/
glade_project_selection_set (gwidget->project, gwidget->object, TRUE);
}
static void
related_action_pre_commit (GladeEditorProperty *property,
GValue *value,
GladeActivatableEditor *activatable_editor)
{
GladeWidget *gwidget = activatable_editor->loaded_widget;
GtkAction *action = g_value_get_object (value);
gboolean use_appearance = FALSE;
glade_widget_property_get (gwidget, "use-action-appearance", &use_appearance);
glade_command_push_group (_("Setting %s action"), gwidget->name);
reset_properties (gwidget, action, use_appearance, FALSE);
}
static void
related_action_post_commit (GladeEditorProperty *property,
GValue *value,
GladeActivatableEditor *activatable_editor)
{
glade_command_pop_group ();
}
static void
use_appearance_pre_commit (GladeEditorProperty *property,
GValue *value,
GladeActivatableEditor *activatable_editor)
{
GladeWidget *gwidget = activatable_editor->loaded_widget;
GtkAction *action = NULL;
gboolean use_appearance = g_value_get_boolean (value);
glade_widget_property_get (gwidget, "related-action", &action);
glade_command_push_group (use_appearance ?
_("Setting %s to use action appearance") :
_("Setting %s to not use action appearance"),
gwidget->name);
reset_properties (gwidget, action, use_appearance, TRUE);
}
static void
use_appearance_post_commit (GladeEditorProperty *property,
GValue *value,
GladeActivatableEditor *activatable_editor)
{
glade_command_pop_group ();
}
GtkWidget *
glade_activatable_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditable *embed)
{
GladeActivatableEditor *activatable_editor;
GladeEditorProperty *eprop;
GtkWidget *table, *frame, *alignment, *label;
GtkSizeGroup *group;
gchar *str;
gint row = 0;
g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL);
activatable_editor = g_object_new (GLADE_TYPE_ACTIVATABLE_EDITOR, NULL);
activatable_editor->embed = GTK_WIDGET (embed);
/* Pack the parent on top... */
gtk_box_pack_start (GTK_BOX (activatable_editor), GTK_WIDGET (embed), FALSE, FALSE, 0);
str = g_strdup_printf ("<b>%s</b>", _("Action"));
label = gtk_label_new (str);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
g_free (str);
frame = gtk_frame_new (NULL);
gtk_frame_set_label_widget (GTK_FRAME (frame), label);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
gtk_box_pack_start (GTK_BOX (activatable_editor), frame, FALSE, FALSE, 4);
alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
gtk_container_add (GTK_CONTAINER (frame), alignment);
table = gtk_table_new (0, 0, FALSE);
gtk_container_add (GTK_CONTAINER (alignment), table);
group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "related-action", FALSE, TRUE);
table_attach (table, eprop->item_label, 0, row, group);
table_attach (table, GTK_WIDGET (eprop), 1, row++, group);
activatable_editor->properties = g_list_prepend (activatable_editor->properties, eprop);
g_signal_connect (G_OBJECT (eprop), "commit",
G_CALLBACK (related_action_pre_commit), activatable_editor);
g_signal_connect_after (G_OBJECT (eprop), "commit",
G_CALLBACK (related_action_post_commit), activatable_editor);
eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "use-action-appearance", FALSE, TRUE);
table_attach (table, eprop->item_label, 0, row, group);
table_attach (table, GTK_WIDGET (eprop), 1, row++, group);
activatable_editor->properties = g_list_prepend (activatable_editor->properties, eprop);
gtk_widget_show_all (GTK_WIDGET (activatable_editor));
g_signal_connect (G_OBJECT (eprop), "commit",
G_CALLBACK (use_appearance_pre_commit), activatable_editor);
g_signal_connect_after (G_OBJECT (eprop), "commit",
G_CALLBACK (use_appearance_post_commit), activatable_editor);
return GTK_WIDGET (activatable_editor);
}
|