~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to app/widgets/gimpactiongroup.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimpactiongroup.c
 
5
 * Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include "libgimpbase/gimpbase.h"
 
27
#include "libgimpwidgets/gimpwidgets.h"
 
28
 
 
29
#include "widgets-types.h"
 
30
 
 
31
#include "core/gimp.h"
 
32
#include "core/gimpviewable.h"
 
33
 
 
34
#include "gimpactiongroup.h"
 
35
#include "gimpaction.h"
 
36
#include "gimpenumaction.h"
 
37
#include "gimppluginaction.h"
 
38
#include "gimpstringaction.h"
 
39
 
 
40
#include "gimp-intl.h"
 
41
 
 
42
 
 
43
enum
 
44
{
 
45
  PROP_0,
 
46
  PROP_GIMP,
 
47
  PROP_LABEL,
 
48
  PROP_STOCK_ID,
 
49
  PROP_MNEMONICS
 
50
};
 
51
 
 
52
 
 
53
static void   gimp_action_group_init           (GimpActionGroup       *group);
 
54
static void   gimp_action_group_class_init     (GimpActionGroupClass  *klass);
 
55
 
 
56
static GObject * gimp_action_group_constructor (GType                  type,
 
57
                                                guint                  n_params,
 
58
                                                GObjectConstructParam *params);
 
59
static void   gimp_action_group_dispose        (GObject               *object);
 
60
static void   gimp_action_group_finalize       (GObject               *object);
 
61
static void   gimp_action_group_set_property   (GObject               *object,
 
62
                                                guint                  prop_id,
 
63
                                                const GValue          *value,
 
64
                                                GParamSpec            *pspec);
 
65
static void   gimp_action_group_get_property   (GObject               *object,
 
66
                                                guint                  prop_id,
 
67
                                                GValue                *value,
 
68
                                                GParamSpec            *pspec);
 
69
 
 
70
 
 
71
static GtkActionGroupClass *parent_class = NULL;
 
72
 
 
73
 
 
74
GType
 
75
gimp_action_group_get_type (void)
 
76
{
 
77
  static GType type = 0;
 
78
 
 
79
  if (!type)
 
80
    {
 
81
      static const GTypeInfo type_info =
 
82
      {
 
83
        sizeof (GimpActionGroupClass),
 
84
        NULL,           /* base_init */
 
85
        NULL,           /* base_finalize */
 
86
        (GClassInitFunc) gimp_action_group_class_init,
 
87
        NULL,           /* class_finalize */
 
88
        NULL,           /* class_data */
 
89
        sizeof (GimpActionGroup),
 
90
        0, /* n_preallocs */
 
91
        (GInstanceInitFunc) gimp_action_group_init,
 
92
      };
 
93
 
 
94
      type = g_type_register_static (GTK_TYPE_ACTION_GROUP,
 
95
                                     "GimpActionGroup",
 
96
                                     &type_info, 0);
 
97
    }
 
98
 
 
99
  return type;
 
100
}
 
101
 
 
102
static void
 
103
gimp_action_group_class_init (GimpActionGroupClass *klass)
 
104
{
 
105
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
106
 
 
107
  parent_class = g_type_class_peek_parent (klass);
 
108
 
 
109
  object_class->constructor  = gimp_action_group_constructor;
 
110
  object_class->dispose      = gimp_action_group_dispose;
 
111
  object_class->finalize     = gimp_action_group_finalize;
 
112
  object_class->set_property = gimp_action_group_set_property;
 
113
  object_class->get_property = gimp_action_group_get_property;
 
114
 
 
115
  g_object_class_install_property (object_class, PROP_GIMP,
 
116
                                   g_param_spec_object ("gimp",
 
117
                                                        NULL, NULL,
 
118
                                                        GIMP_TYPE_GIMP,
 
119
                                                        G_PARAM_READWRITE |
 
120
                                                        G_PARAM_CONSTRUCT_ONLY));
 
121
 
 
122
  g_object_class_install_property (object_class, PROP_LABEL,
 
123
                                   g_param_spec_string ("label",
 
124
                                                        NULL, NULL,
 
125
                                                        NULL,
 
126
                                                        G_PARAM_READWRITE |
 
127
                                                        G_PARAM_CONSTRUCT_ONLY));
 
128
 
 
129
  g_object_class_install_property (object_class, PROP_STOCK_ID,
 
130
                                   g_param_spec_string ("stock-id",
 
131
                                                        NULL, NULL,
 
132
                                                        NULL,
 
133
                                                        G_PARAM_READWRITE |
 
134
                                                        G_PARAM_CONSTRUCT_ONLY));
 
135
 
 
136
  g_object_class_install_property (object_class, PROP_MNEMONICS,
 
137
                                   g_param_spec_boolean ("mnemonics",
 
138
                                                         NULL, NULL,
 
139
                                                         TRUE,
 
140
                                                         G_PARAM_READWRITE |
 
141
                                                         G_PARAM_CONSTRUCT_ONLY));
 
142
 
 
143
  klass->groups = g_hash_table_new_full (g_str_hash, g_str_equal,
 
144
                                         g_free, NULL);
 
145
}
 
146
 
 
147
static void
 
148
gimp_action_group_init (GimpActionGroup *group)
 
149
{
 
150
}
 
151
 
 
152
static GObject *
 
153
gimp_action_group_constructor (GType                  type,
 
154
                               guint                  n_params,
 
155
                               GObjectConstructParam *params)
 
156
{
 
157
  GObject         *object;
 
158
  GimpActionGroup *group;
 
159
  const gchar     *name;
 
160
 
 
161
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
162
 
 
163
  group = GIMP_ACTION_GROUP (object);
 
164
 
 
165
  g_assert (GIMP_IS_GIMP (group->gimp));
 
166
 
 
167
  name = gtk_action_group_get_name (GTK_ACTION_GROUP (object));
 
168
 
 
169
  if (name)
 
170
    {
 
171
      GimpActionGroupClass *group_class;
 
172
      GList                *list;
 
173
 
 
174
      group_class = GIMP_ACTION_GROUP_GET_CLASS (object);
 
175
 
 
176
      list = g_hash_table_lookup (group_class->groups, name);
 
177
 
 
178
      list = g_list_append (list, object);
 
179
 
 
180
      g_hash_table_replace (group_class->groups,
 
181
                            g_strdup (name), list);
 
182
    }
 
183
 
 
184
  return object;
 
185
}
 
186
 
 
187
static void
 
188
gimp_action_group_dispose (GObject *object)
 
189
{
 
190
  const gchar *name;
 
191
 
 
192
  name = gtk_action_group_get_name (GTK_ACTION_GROUP (object));
 
193
 
 
194
  if (name)
 
195
    {
 
196
      GimpActionGroupClass *group_class;
 
197
      GList                *list;
 
198
 
 
199
      group_class = GIMP_ACTION_GROUP_GET_CLASS (object);
 
200
 
 
201
      list = g_hash_table_lookup (group_class->groups, name);
 
202
 
 
203
      if (list)
 
204
        {
 
205
          list = g_list_remove (list, object);
 
206
 
 
207
          if (list)
 
208
            g_hash_table_replace (group_class->groups,
 
209
                                  g_strdup (name), list);
 
210
          else
 
211
            g_hash_table_remove (group_class->groups, name);
 
212
        }
 
213
    }
 
214
 
 
215
  G_OBJECT_CLASS (parent_class)->dispose (object);
 
216
}
 
217
 
 
218
static void
 
219
gimp_action_group_finalize (GObject *object)
 
220
{
 
221
  GimpActionGroup *group = GIMP_ACTION_GROUP (object);
 
222
 
 
223
  if (group->label)
 
224
    {
 
225
      g_free (group->label);
 
226
      group->label = NULL;
 
227
    }
 
228
 
 
229
  if (group->stock_id)
 
230
    {
 
231
      g_free (group->stock_id);
 
232
      group->stock_id = NULL;
 
233
    }
 
234
 
 
235
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
236
}
 
237
 
 
238
static void
 
239
gimp_action_group_set_property (GObject      *object,
 
240
                                guint         prop_id,
 
241
                                const GValue *value,
 
242
                                GParamSpec   *pspec)
 
243
{
 
244
  GimpActionGroup *group = GIMP_ACTION_GROUP (object);
 
245
 
 
246
  switch (prop_id)
 
247
    {
 
248
    case PROP_GIMP:
 
249
      group->gimp = g_value_get_object (value);
 
250
      break;
 
251
    case PROP_LABEL:
 
252
      group->label = g_value_dup_string (value);
 
253
      break;
 
254
    case PROP_STOCK_ID:
 
255
      group->stock_id = g_value_dup_string (value);
 
256
      break;
 
257
    case PROP_MNEMONICS:
 
258
      group->mnemonics = g_value_get_boolean (value);
 
259
      break;
 
260
    default:
 
261
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
262
      break;
 
263
    }
 
264
}
 
265
 
 
266
static void
 
267
gimp_action_group_get_property (GObject    *object,
 
268
                                guint       prop_id,
 
269
                                GValue     *value,
 
270
                                GParamSpec *pspec)
 
271
{
 
272
  GimpActionGroup *group = GIMP_ACTION_GROUP (object);
 
273
 
 
274
  switch (prop_id)
 
275
    {
 
276
    case PROP_GIMP:
 
277
      g_value_set_object (value, group->gimp);
 
278
      break;
 
279
    case PROP_LABEL:
 
280
      g_value_set_string (value, group->label);
 
281
      break;
 
282
    case PROP_STOCK_ID:
 
283
      g_value_set_string (value, group->stock_id);
 
284
      break;
 
285
    case PROP_MNEMONICS:
 
286
      g_value_set_boolean (value, group->mnemonics);
 
287
      break;
 
288
    default:
 
289
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
290
      break;
 
291
    }
 
292
}
 
293
 
 
294
/**
 
295
 * gimp_action_group_new:
 
296
 * @gimp:        the @Gimp instance this action group belongs to
 
297
 * @name:        the name of the action group.
 
298
 * @label:       the user visible label of the action group.
 
299
 * @stock_id:    the icon of the action group.
 
300
 * @mnemonics:   whether or not to show mnemonics.
 
301
 * @user_data:   the user_data for #GtkAction callbacks.
 
302
 * @update_func: the function that will be called on
 
303
 *               gimp_action_group_update().
 
304
 *
 
305
 * Creates a new #GimpActionGroup object. The name of the action group
 
306
 * is used when associating <link linkend="Action-Accel">keybindings</link>
 
307
 * with the actions.
 
308
 *
 
309
 * Returns: the new #GimpActionGroup
 
310
 */
 
311
GimpActionGroup *
 
312
gimp_action_group_new (Gimp                      *gimp,
 
313
                       const gchar               *name,
 
314
                       const gchar               *label,
 
315
                       const gchar               *stock_id,
 
316
                       gboolean                   mnemonics,
 
317
                       gpointer                   user_data,
 
318
                       GimpActionGroupUpdateFunc  update_func)
 
319
{
 
320
  GimpActionGroup *group;
 
321
 
 
322
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
323
  g_return_val_if_fail (name != NULL, NULL);
 
324
 
 
325
  group = g_object_new (GIMP_TYPE_ACTION_GROUP,
 
326
                        "gimp",      gimp,
 
327
                        "name",      name,
 
328
                        "label",     label,
 
329
                        "stock-id",  stock_id,
 
330
                        "mnemonics", mnemonics,
 
331
                        NULL);
 
332
 
 
333
  group->user_data   = user_data;
 
334
  group->update_func = update_func;
 
335
 
 
336
  return group;
 
337
}
 
338
 
 
339
GList *
 
340
gimp_action_groups_from_name (const gchar *name)
 
341
{
 
342
  GimpActionGroupClass *group_class;
 
343
  GList                *list;
 
344
 
 
345
  g_return_val_if_fail (name != NULL, NULL);
 
346
 
 
347
  group_class = g_type_class_ref (GIMP_TYPE_ACTION_GROUP);
 
348
 
 
349
  list = g_hash_table_lookup (group_class->groups, name);
 
350
 
 
351
  g_type_class_unref (group_class);
 
352
 
 
353
  return list;
 
354
}
 
355
 
 
356
void
 
357
gimp_action_group_update (GimpActionGroup *group,
 
358
                          gpointer         update_data)
 
359
{
 
360
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
361
 
 
362
  if (group->update_func)
 
363
    group->update_func (group, update_data);
 
364
}
 
365
 
 
366
void
 
367
gimp_action_group_add_actions (GimpActionGroup *group,
 
368
                               GimpActionEntry *entries,
 
369
                               guint            n_entries)
 
370
{
 
371
  gint i;
 
372
 
 
373
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
374
 
 
375
  for (i = 0; i < n_entries; i++)
 
376
    {
 
377
      GimpAction  *action;
 
378
      gchar       *label;
 
379
      const gchar *tooltip;
 
380
 
 
381
      label   = gettext (entries[i].label);
 
382
      tooltip = gettext (entries[i].tooltip);
 
383
 
 
384
      if (! group->mnemonics)
 
385
        label = gimp_strip_uline (label);
 
386
 
 
387
      action = gimp_action_new (entries[i].name, label, tooltip,
 
388
                                entries[i].stock_id);
 
389
 
 
390
      if (! group->mnemonics)
 
391
        g_free (label);
 
392
 
 
393
      if (entries[i].callback)
 
394
        g_signal_connect (action, "activate",
 
395
                          entries[i].callback,
 
396
                          group->user_data);
 
397
 
 
398
      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
 
399
                                              GTK_ACTION (action),
 
400
                                              entries[i].accelerator);
 
401
 
 
402
      if (entries[i].help_id)
 
403
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
 
404
                                 g_strdup (entries[i].help_id),
 
405
                                 (GDestroyNotify) g_free);
 
406
 
 
407
      g_object_unref (action);
 
408
    }
 
409
}
 
410
 
 
411
void
 
412
gimp_action_group_add_toggle_actions (GimpActionGroup       *group,
 
413
                                      GimpToggleActionEntry *entries,
 
414
                                      guint                  n_entries)
 
415
{
 
416
  gint i;
 
417
 
 
418
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
419
 
 
420
  for (i = 0; i < n_entries; i++)
 
421
    {
 
422
      GtkToggleAction *action;
 
423
      gchar           *label;
 
424
      const gchar     *tooltip;
 
425
 
 
426
      label   = gettext (entries[i].label);
 
427
      tooltip = gettext (entries[i].tooltip);
 
428
 
 
429
      if (! group->mnemonics)
 
430
        label = gimp_strip_uline (label);
 
431
 
 
432
      action = gtk_toggle_action_new (entries[i].name, label, tooltip,
 
433
                                      entries[i].stock_id);
 
434
 
 
435
      if (! group->mnemonics)
 
436
        g_free (label);
 
437
 
 
438
      gtk_toggle_action_set_active (action, entries[i].is_active);
 
439
 
 
440
      if (entries[i].callback)
 
441
        g_signal_connect (action, "toggled",
 
442
                          entries[i].callback,
 
443
                          group->user_data);
 
444
 
 
445
      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
 
446
                                              GTK_ACTION (action),
 
447
                                              entries[i].accelerator);
 
448
 
 
449
      if (entries[i].help_id)
 
450
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
 
451
                                 g_strdup (entries[i].help_id),
 
452
                                 (GDestroyNotify) g_free);
 
453
 
 
454
      g_object_unref (action);
 
455
    }
 
456
}
 
457
 
 
458
void
 
459
gimp_action_group_add_radio_actions (GimpActionGroup      *group,
 
460
                                     GimpRadioActionEntry *entries,
 
461
                                     guint                 n_entries,
 
462
                                     gint                  value,
 
463
                                     GCallback             callback)
 
464
{
 
465
  GtkRadioAction *first_action = NULL;
 
466
  GSList         *radio_group  = NULL;
 
467
  gint            i;
 
468
 
 
469
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
470
 
 
471
  for (i = 0; i < n_entries; i++)
 
472
    {
 
473
      GtkRadioAction *action;
 
474
      gchar          *label;
 
475
      const gchar    *tooltip;
 
476
 
 
477
      label   = gettext (entries[i].label);
 
478
      tooltip = gettext (entries[i].tooltip);
 
479
 
 
480
      if (! group->mnemonics)
 
481
        label = gimp_strip_uline (label);
 
482
 
 
483
      action = gtk_radio_action_new (entries[i].name, label, tooltip,
 
484
                                     entries[i].stock_id,
 
485
                                     entries[i].value);
 
486
 
 
487
      if (! group->mnemonics)
 
488
        g_free (label);
 
489
 
 
490
      if (i == 0)
 
491
        first_action = action;
 
492
 
 
493
      gtk_radio_action_set_group (action, radio_group);
 
494
      radio_group = gtk_radio_action_get_group (action);
 
495
 
 
496
      if (value == entries[i].value)
 
497
        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
 
498
 
 
499
      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
 
500
                                              GTK_ACTION (action),
 
501
                                              entries[i].accelerator);
 
502
 
 
503
      if (entries[i].help_id)
 
504
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
 
505
                                 g_strdup (entries[i].help_id),
 
506
                                 (GDestroyNotify) g_free);
 
507
 
 
508
      g_object_unref (action);
 
509
    }
 
510
 
 
511
  if (callback && first_action)
 
512
    g_signal_connect (first_action, "changed",
 
513
                      callback,
 
514
                      group->user_data);
 
515
}
 
516
 
 
517
void
 
518
gimp_action_group_add_enum_actions (GimpActionGroup     *group,
 
519
                                    GimpEnumActionEntry *entries,
 
520
                                    guint                n_entries,
 
521
                                    GCallback            callback)
 
522
{
 
523
  gint i;
 
524
 
 
525
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
526
 
 
527
  for (i = 0; i < n_entries; i++)
 
528
    {
 
529
      GimpEnumAction *action;
 
530
      gchar          *label;
 
531
      const gchar    *tooltip;
 
532
 
 
533
      label   = gettext (entries[i].label);
 
534
      tooltip = gettext (entries[i].tooltip);
 
535
 
 
536
      if (! group->mnemonics)
 
537
        label = gimp_strip_uline (label);
 
538
 
 
539
      action = gimp_enum_action_new (entries[i].name, label, tooltip,
 
540
                                     entries[i].stock_id,
 
541
                                     entries[i].value,
 
542
                                     entries[i].value_variable);
 
543
 
 
544
      if (! group->mnemonics)
 
545
        g_free (label);
 
546
 
 
547
      if (callback)
 
548
        g_signal_connect (action, "selected",
 
549
                          callback,
 
550
                          group->user_data);
 
551
 
 
552
      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
 
553
                                              GTK_ACTION (action),
 
554
                                              entries[i].accelerator);
 
555
 
 
556
      if (entries[i].help_id)
 
557
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
 
558
                                 g_strdup (entries[i].help_id),
 
559
                                 (GDestroyNotify) g_free);
 
560
 
 
561
      g_object_unref (action);
 
562
    }
 
563
}
 
564
 
 
565
void
 
566
gimp_action_group_add_string_actions (GimpActionGroup       *group,
 
567
                                      GimpStringActionEntry *entries,
 
568
                                      guint                  n_entries,
 
569
                                      GCallback              callback)
 
570
{
 
571
  gint i;
 
572
 
 
573
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
574
 
 
575
  for (i = 0; i < n_entries; i++)
 
576
    {
 
577
      GimpStringAction *action;
 
578
      gchar            *label;
 
579
      const gchar      *tooltip;
 
580
 
 
581
      label   = gettext (entries[i].label);
 
582
      tooltip = gettext (entries[i].tooltip);
 
583
 
 
584
      if (! group->mnemonics)
 
585
        label = gimp_strip_uline (label);
 
586
 
 
587
      action = gimp_string_action_new (entries[i].name, label, tooltip,
 
588
                                       entries[i].stock_id,
 
589
                                       entries[i].value);
 
590
 
 
591
      if (! group->mnemonics)
 
592
        g_free (label);
 
593
 
 
594
      if (callback)
 
595
        g_signal_connect (action, "selected",
 
596
                          callback,
 
597
                          group->user_data);
 
598
 
 
599
      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
 
600
                                              GTK_ACTION (action),
 
601
                                              entries[i].accelerator);
 
602
 
 
603
      if (entries[i].help_id)
 
604
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
 
605
                                 g_strdup (entries[i].help_id),
 
606
                                 (GDestroyNotify) g_free);
 
607
 
 
608
      g_object_unref (action);
 
609
    }
 
610
}
 
611
 
 
612
void
 
613
gimp_action_group_add_plug_in_actions (GimpActionGroup       *group,
 
614
                                       GimpPlugInActionEntry *entries,
 
615
                                       guint                  n_entries,
 
616
                                       GCallback              callback)
 
617
{
 
618
  gint i;
 
619
 
 
620
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
621
 
 
622
  for (i = 0; i < n_entries; i++)
 
623
    {
 
624
      GimpPlugInAction *action;
 
625
      gchar            *label;
 
626
 
 
627
      label = (gchar *) entries[i].label;
 
628
 
 
629
      if (! group->mnemonics)
 
630
        label = gimp_strip_uline (label);
 
631
 
 
632
      action = gimp_plug_in_action_new (entries[i].name,
 
633
                                        label,
 
634
                                        entries[i].tooltip,
 
635
                                        entries[i].stock_id,
 
636
                                        entries[i].proc_def);
 
637
 
 
638
      if (! group->mnemonics)
 
639
        g_free (label);
 
640
 
 
641
      if (callback)
 
642
        g_signal_connect (action, "selected",
 
643
                          callback,
 
644
                          group->user_data);
 
645
 
 
646
      gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
 
647
                                              GTK_ACTION (action),
 
648
                                              entries[i].accelerator);
 
649
 
 
650
      if (entries[i].help_id)
 
651
        g_object_set_qdata_full (G_OBJECT (action), GIMP_HELP_ID,
 
652
                                 g_strdup (entries[i].help_id),
 
653
                                 (GDestroyNotify) g_free);
 
654
 
 
655
      g_object_unref (action);
 
656
    }
 
657
}
 
658
 
 
659
void
 
660
gimp_action_group_set_action_visible (GimpActionGroup *group,
 
661
                                      const gchar     *action_name,
 
662
                                      gboolean         visible)
 
663
{
 
664
  GtkAction *action;
 
665
 
 
666
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
667
  g_return_if_fail (action_name != NULL);
 
668
 
 
669
  action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
 
670
 
 
671
  if (! action)
 
672
    {
 
673
      g_warning ("%s: Unable to set visibility of action "
 
674
                 "which doesn't exist: %s",
 
675
                 G_STRFUNC, action_name);
 
676
      return;
 
677
    }
 
678
 
 
679
  g_object_set (action, "visible", visible ? TRUE : FALSE, NULL);
 
680
}
 
681
 
 
682
void
 
683
gimp_action_group_set_action_sensitive (GimpActionGroup *group,
 
684
                                        const gchar     *action_name,
 
685
                                        gboolean         sensitive)
 
686
{
 
687
  GtkAction *action;
 
688
 
 
689
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
690
  g_return_if_fail (action_name != NULL);
 
691
 
 
692
  action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
 
693
 
 
694
  if (! action)
 
695
    {
 
696
      g_warning ("%s: Unable to set sensitivity of action "
 
697
                 "which doesn't exist: %s",
 
698
                 G_STRFUNC, action_name);
 
699
      return;
 
700
    }
 
701
 
 
702
  g_object_set (action, "sensitive", sensitive ? TRUE : FALSE, NULL);
 
703
}
 
704
 
 
705
void
 
706
gimp_action_group_set_action_active (GimpActionGroup *group,
 
707
                                     const gchar     *action_name,
 
708
                                     gboolean         active)
 
709
{
 
710
  GtkAction *action;
 
711
 
 
712
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
713
  g_return_if_fail (action_name != NULL);
 
714
 
 
715
  action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
 
716
 
 
717
  if (! action)
 
718
    {
 
719
      g_warning ("%s: Unable to set \"active\" of action "
 
720
                 "which doesn't exist: %s",
 
721
                 G_STRFUNC, action_name);
 
722
      return;
 
723
    }
 
724
 
 
725
  if (! GTK_IS_TOGGLE_ACTION (action))
 
726
    {
 
727
      g_warning ("%s: Unable to set \"active\" of action "
 
728
                 "which is not a GtkToggleAction: %s",
 
729
                 G_STRFUNC, action_name);
 
730
      return;
 
731
    }
 
732
 
 
733
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
 
734
                                active ? TRUE : FALSE);
 
735
}
 
736
 
 
737
void
 
738
gimp_action_group_set_action_label (GimpActionGroup *group,
 
739
                                    const gchar     *action_name,
 
740
                                    const gchar     *label)
 
741
{
 
742
  GtkAction *action;
 
743
  gchar     *stripped;
 
744
 
 
745
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
746
  g_return_if_fail (action_name != NULL);
 
747
 
 
748
  action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
 
749
 
 
750
  if (! action)
 
751
    {
 
752
      g_warning ("%s: Unable to set label of action "
 
753
                 "which doesn't exist: %s",
 
754
                 G_STRFUNC, action_name);
 
755
      return;
 
756
    }
 
757
 
 
758
  if (! group->mnemonics)
 
759
    stripped = gimp_strip_uline (label);
 
760
  else
 
761
    stripped = (gchar *) label;
 
762
 
 
763
  g_object_set (action, "label", stripped, NULL);
 
764
 
 
765
  if (! group->mnemonics)
 
766
    g_free (stripped);
 
767
}
 
768
 
 
769
void
 
770
gimp_action_group_set_action_color (GimpActionGroup *group,
 
771
                                    const gchar     *action_name,
 
772
                                    const GimpRGB   *color,
 
773
                                    gboolean         set_label)
 
774
{
 
775
  GtkAction *action;
 
776
 
 
777
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
778
  g_return_if_fail (action_name != NULL);
 
779
 
 
780
  action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
 
781
 
 
782
  if (! action)
 
783
    {
 
784
      g_warning ("%s: Unable to set color of action "
 
785
                 "which doesn't exist: %s",
 
786
                 G_STRFUNC, action_name);
 
787
      return;
 
788
    }
 
789
 
 
790
  if (! GIMP_IS_ACTION (action))
 
791
    {
 
792
      g_warning ("%s: Unable to set \"color\" of action "
 
793
                 "which is not a GimpAction: %s",
 
794
                 G_STRFUNC, action_name);
 
795
      return;
 
796
    }
 
797
 
 
798
  if (set_label)
 
799
    {
 
800
      gchar *label;
 
801
 
 
802
      if (color)
 
803
        label = g_strdup_printf (_("RGBA (%0.3f, %0.3f, %0.3f, %0.3f)"),
 
804
                                 color->r, color->g, color->b, color->a);
 
805
      else
 
806
        label = g_strdup (_("(none)"));
 
807
 
 
808
      g_object_set (action,
 
809
                    "color", color,
 
810
                    "label", label,
 
811
                    NULL);
 
812
      g_free (label);
 
813
    }
 
814
  else
 
815
    {
 
816
      g_object_set (action, "color", color, NULL);
 
817
    }
 
818
}
 
819
 
 
820
void
 
821
gimp_action_group_set_action_viewable (GimpActionGroup *group,
 
822
                                       const gchar     *action_name,
 
823
                                       GimpViewable    *viewable)
 
824
{
 
825
  GtkAction *action;
 
826
 
 
827
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
828
  g_return_if_fail (action_name != NULL);
 
829
  g_return_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable));
 
830
 
 
831
  action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
 
832
 
 
833
  if (! action)
 
834
    {
 
835
      g_warning ("%s: Unable to set viewable of action "
 
836
                 "which doesn't exist: %s",
 
837
                 G_STRFUNC, action_name);
 
838
      return;
 
839
    }
 
840
 
 
841
  if (! GIMP_IS_ACTION (action))
 
842
    {
 
843
      g_warning ("%s: Unable to set \"viewable\" of action "
 
844
                 "which is not a GimpAction: %s",
 
845
                 G_STRFUNC, action_name);
 
846
      return;
 
847
    }
 
848
 
 
849
  g_object_set (action, "viewable", viewable, NULL);
 
850
}
 
851
 
 
852
void
 
853
gimp_action_group_set_action_important (GimpActionGroup *group,
 
854
                                        const gchar     *action_name,
 
855
                                        gboolean         is_important)
 
856
{
 
857
  GtkAction *action;
 
858
 
 
859
  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
 
860
  g_return_if_fail (action_name != NULL);
 
861
 
 
862
  action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
 
863
 
 
864
  if (! action)
 
865
    {
 
866
      g_warning ("%s: Unable to set \"is-important\" of action "
 
867
                 "which doesn't exist: %s",
 
868
                 G_STRFUNC, action_name);
 
869
      return;
 
870
    }
 
871
 
 
872
  g_object_set (action, "is-important", is_important ? TRUE : FALSE, NULL);
 
873
}