~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to app/actions/actions.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
 
 * This program is free software; you can redistribute it and/or modify
 
4
 * This program is free software: you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
 
6
 * the Free Software Foundation; either version 3 of the License, or
7
7
 * (at your option) any later version.
8
8
 *
9
9
 * This program is distributed in the hope that it will be useful,
12
12
 * GNU General Public License for more details.
13
13
 *
14
14
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
16
 */
18
17
 
19
18
#include "config.h"
20
19
 
 
20
#include <gegl.h>
21
21
#include <gtk/gtk.h>
22
22
 
23
23
#include "libgimpwidgets/gimpwidgets.h"
24
24
 
25
25
#include "actions-types.h"
26
26
 
27
 
#include "config/gimpguiconfig.h"
28
 
 
29
27
#include "core/gimp.h"
30
28
#include "core/gimpcontainer.h"
31
29
#include "core/gimpcontext.h"
32
30
#include "core/gimpimage.h"
 
31
#include "core/gimptooloptions.h"
 
32
#include "core/gimptoolinfo.h"
33
33
 
34
34
#include "widgets/gimpactionfactory.h"
35
35
#include "widgets/gimpactiongroup.h"
37
37
#include "widgets/gimpcontainerview.h"
38
38
#include "widgets/gimpdock.h"
39
39
#include "widgets/gimpdockable.h"
 
40
#include "widgets/gimpdockwindow.h"
40
41
#include "widgets/gimpimageeditor.h"
41
42
#include "widgets/gimpitemtreeview.h"
42
43
 
43
44
#include "display/gimpdisplay.h"
44
45
#include "display/gimpdisplayshell.h"
 
46
#include "display/gimpimagewindow.h"
45
47
#include "display/gimpnavigationeditor.h"
 
48
#include "display/gimpstatusbar.h"
46
49
 
47
50
#include "dialogs/dialogs.h"
48
51
 
61
64
#include "dockable-actions.h"
62
65
#include "documents-actions.h"
63
66
#include "drawable-actions.h"
 
67
#include "dynamics-actions.h"
 
68
#include "dynamics-editor-actions.h"
64
69
#include "edit-actions.h"
65
70
#include "error-console-actions.h"
66
71
#include "file-actions.h"
80
85
#include "select-actions.h"
81
86
#include "templates-actions.h"
82
87
#include "text-editor-actions.h"
 
88
#include "text-tool-actions.h"
83
89
#include "tool-options-actions.h"
 
90
#include "tool-presets-actions.h"
 
91
#include "tool-preset-editor-actions.h"
84
92
#include "tools-actions.h"
85
93
#include "vectors-actions.h"
86
94
#include "view-actions.h"
96
104
 
97
105
/*  private variables  */
98
106
 
99
 
static GimpActionFactoryEntry action_groups[] =
 
107
static const GimpActionFactoryEntry action_groups[] =
100
108
{
101
109
  { "brush-editor", N_("Brush Editor"), GIMP_STOCK_BRUSH,
102
110
    brush_editor_actions_setup,
140
148
  { "drawable", N_("Drawable"), GIMP_STOCK_LAYER,
141
149
    drawable_actions_setup,
142
150
    drawable_actions_update },
 
151
  { "dynamics", N_("Paint Dynamics"), GIMP_STOCK_DYNAMICS,
 
152
    dynamics_actions_setup,
 
153
    dynamics_actions_update },
 
154
  { "dynamics-editor", N_("Paint Dynamics Editor"), GIMP_STOCK_DYNAMICS,
 
155
    dynamics_editor_actions_setup,
 
156
    dynamics_editor_actions_update },
143
157
  { "edit", N_("Edit"), GTK_STOCK_EDIT,
144
158
    edit_actions_setup,
145
159
    edit_actions_update },
158
172
  { "gradients", N_("Gradients"), GIMP_STOCK_GRADIENT,
159
173
    gradients_actions_setup,
160
174
    gradients_actions_update },
 
175
  { "tool-presets", N_("Tool Presets"), GIMP_STOCK_TOOL_PRESET,
 
176
    tool_presets_actions_setup,
 
177
    tool_presets_actions_update },
 
178
  { "tool-preset-editor", N_("Tool Preset Editor"), GIMP_STOCK_TOOL_PRESET,
 
179
    tool_preset_editor_actions_setup,
 
180
    tool_preset_editor_actions_update },
161
181
  { "help", N_("Help"), GTK_STOCK_HELP,
162
182
    help_actions_setup,
163
183
    help_actions_update },
194
214
  { "templates", N_("Templates"), GIMP_STOCK_TEMPLATE,
195
215
    templates_actions_setup,
196
216
    templates_actions_update },
 
217
  { "text-tool", N_("Text Tool"), GTK_STOCK_EDIT,
 
218
    text_tool_actions_setup,
 
219
    text_tool_actions_update },
197
220
  { "text-editor", N_("Text Editor"), GTK_STOCK_EDIT,
198
221
    text_editor_actions_setup,
199
222
    text_editor_actions_update },
220
243
void
221
244
actions_init (Gimp *gimp)
222
245
{
223
 
  GimpGuiConfig *gui_config;
224
 
  gint           i;
 
246
  gint i;
225
247
 
226
248
  g_return_if_fail (GIMP_IS_GIMP (gimp));
227
249
  g_return_if_fail (global_action_factory == NULL);
228
250
 
229
 
  gui_config = GIMP_GUI_CONFIG (gimp->config);
230
 
 
231
 
  global_action_factory = gimp_action_factory_new (gimp,
232
 
                                                   gui_config->menu_mnemonics);
 
251
  global_action_factory = gimp_action_factory_new (gimp);
233
252
 
234
253
  for (i = 0; i < G_N_ELEMENTS (action_groups); i++)
235
254
    gimp_action_factory_group_register (global_action_factory,
261
280
 
262
281
  if (GIMP_IS_DISPLAY (data))
263
282
    return ((GimpDisplay *) data)->gimp;
 
283
  else if (GIMP_IS_IMAGE_WINDOW (data))
 
284
    {
 
285
      GimpDisplayShell *shell = gimp_image_window_get_active_shell (data);
 
286
      return shell ? shell->display->gimp : NULL;
 
287
    }
264
288
  else if (GIMP_IS_GIMP (data))
265
289
    return data;
266
290
  else if (GIMP_IS_DOCK (data))
267
 
    context = ((GimpDock *) data)->context;
 
291
    context = gimp_dock_get_context (((GimpDock *) data));
 
292
  else if (GIMP_IS_DOCK_WINDOW (data))
 
293
    context = gimp_dock_window_get_context (((GimpDockWindow *) data));
268
294
  else if (GIMP_IS_CONTAINER_VIEW (data))
269
295
    context = gimp_container_view_get_context ((GimpContainerView *) data);
270
296
  else if (GIMP_IS_CONTAINER_EDITOR (data))
288
314
 
289
315
  if (GIMP_IS_DISPLAY (data))
290
316
    return gimp_get_user_context (((GimpDisplay *) data)->gimp);
 
317
  else if (GIMP_IS_IMAGE_WINDOW (data))
 
318
    {
 
319
      GimpDisplayShell *shell = gimp_image_window_get_active_shell (data);
 
320
      return shell ? gimp_get_user_context (shell->display->gimp) : NULL;
 
321
    }
291
322
  else if (GIMP_IS_GIMP (data))
292
323
    return gimp_get_user_context (data);
293
324
  else if (GIMP_IS_DOCK (data))
294
 
    return ((GimpDock *) data)->context;
 
325
    return gimp_dock_get_context ((GimpDock *) data);
 
326
  else if (GIMP_IS_DOCK_WINDOW (data))
 
327
    return gimp_dock_window_get_context (((GimpDockWindow *) data));
295
328
  else if (GIMP_IS_CONTAINER_VIEW (data))
296
329
    return gimp_container_view_get_context ((GimpContainerView *) data);
297
330
  else if (GIMP_IS_CONTAINER_EDITOR (data))
308
341
action_data_get_image (gpointer data)
309
342
{
310
343
  GimpContext *context = NULL;
 
344
  GimpDisplay *display = NULL;
311
345
 
312
346
  if (! data)
313
347
    return NULL;
314
348
 
315
349
  if (GIMP_IS_DISPLAY (data))
316
 
    return ((GimpDisplay *) data)->image;
 
350
    display = (GimpDisplay *) data;
 
351
  else if (GIMP_IS_IMAGE_WINDOW (data))
 
352
    {
 
353
      GimpDisplayShell *shell = gimp_image_window_get_active_shell (data);
 
354
      display = shell ? shell->display : NULL;
 
355
    }
317
356
  else if (GIMP_IS_GIMP (data))
318
357
    context = gimp_get_user_context (data);
319
358
  else if (GIMP_IS_DOCK (data))
320
 
    context = ((GimpDock *) data)->context;
 
359
    context = gimp_dock_get_context ((GimpDock *) data);
 
360
  else if (GIMP_IS_DOCK_WINDOW (data))
 
361
    context = gimp_dock_window_get_context (((GimpDockWindow *) data));
321
362
  else if (GIMP_IS_ITEM_TREE_VIEW (data))
322
 
    return ((GimpItemTreeView *) data)->image;
 
363
    return gimp_item_tree_view_get_image ((GimpItemTreeView *) data);
323
364
  else if (GIMP_IS_IMAGE_EDITOR (data))
324
365
    return ((GimpImageEditor *) data)->image;
325
366
  else if (GIMP_IS_NAVIGATION_EDITOR (data))
327
368
 
328
369
  if (context)
329
370
    return gimp_context_get_image (context);
 
371
  else if (display)
 
372
    return gimp_display_get_image (display);
330
373
 
331
374
  return NULL;
332
375
}
341
384
 
342
385
  if (GIMP_IS_DISPLAY (data))
343
386
    return data;
 
387
  else if (GIMP_IS_IMAGE_WINDOW (data))
 
388
    {
 
389
      GimpDisplayShell *shell = gimp_image_window_get_active_shell (data);
 
390
      return shell ? shell->display : NULL;
 
391
    }
344
392
  else if (GIMP_IS_GIMP (data))
345
393
    context = gimp_get_user_context (data);
346
394
  else if (GIMP_IS_DOCK (data))
347
 
    context = ((GimpDock *) data)->context;
 
395
    context = gimp_dock_get_context ((GimpDock *) data);
 
396
  else if (GIMP_IS_DOCK_WINDOW (data))
 
397
    context = gimp_dock_window_get_context (((GimpDockWindow *) data));
348
398
  else if (GIMP_IS_NAVIGATION_EDITOR (data))
349
399
    context = ((GimpNavigationEditor *) data)->context;
350
400
 
354
404
  return NULL;
355
405
}
356
406
 
 
407
GimpDisplayShell *
 
408
action_data_get_shell (gpointer data)
 
409
{
 
410
  GimpDisplay      *display = NULL;
 
411
  GimpDisplayShell *shell   = NULL;
 
412
 
 
413
  display = action_data_get_display (data);
 
414
 
 
415
  if (display)
 
416
    shell = gimp_display_get_shell (display);
 
417
 
 
418
  return shell;
 
419
}
 
420
 
357
421
GtkWidget *
358
422
action_data_get_widget (gpointer data)
359
423
{
370
434
    return data;
371
435
 
372
436
  if (display)
373
 
    return display->shell;
 
437
    return GTK_WIDGET (gimp_display_get_shell (display));
374
438
 
375
439
  return dialogs_get_toolbox ();
376
440
}
377
441
 
 
442
gint
 
443
action_data_sel_count (gpointer data)
 
444
{
 
445
  if (GIMP_IS_CONTAINER_EDITOR (data))
 
446
    {
 
447
      GimpContainerEditor  *editor;
 
448
 
 
449
      editor = GIMP_CONTAINER_EDITOR (data);
 
450
      return gimp_container_view_get_selected (editor->view, NULL);
 
451
    }
 
452
  else
 
453
    {
 
454
      return 0;
 
455
    }
 
456
}
 
457
 
378
458
gdouble
379
459
action_select_value (GimpActionSelectType  select_type,
380
460
                     gdouble               value,
461
541
 
462
542
void
463
543
action_select_property (GimpActionSelectType  select_type,
 
544
                        GimpDisplay          *display,
464
545
                        GObject              *object,
465
546
                        const gchar          *property_name,
466
547
                        gdouble               small_inc,
467
548
                        gdouble               inc,
468
549
                        gdouble               skip_inc,
 
550
                        gdouble               delta_factor,
469
551
                        gboolean              wrap)
470
552
{
471
553
  GParamSpec *pspec;
472
554
 
 
555
  g_return_if_fail (display == NULL || GIMP_IS_DISPLAY (display));
473
556
  g_return_if_fail (G_IS_OBJECT (object));
474
557
  g_return_if_fail (property_name != NULL);
475
558
 
487
570
                                   G_PARAM_SPEC_DOUBLE (pspec)->minimum,
488
571
                                   G_PARAM_SPEC_DOUBLE (pspec)->maximum,
489
572
                                   G_PARAM_SPEC_DOUBLE (pspec)->default_value,
490
 
                                   small_inc, inc, skip_inc, 0, wrap);
 
573
                                   small_inc, inc, skip_inc, delta_factor, wrap);
491
574
 
492
575
      g_object_set (object, property_name, value, NULL);
 
576
 
 
577
      if (display)
 
578
        {
 
579
          const gchar *blurb = g_param_spec_get_blurb (pspec);
 
580
 
 
581
          if (blurb)
 
582
            {
 
583
              /*  value description and new value shown in the status bar  */
 
584
              action_message (display, object, _("%s: %.2f"), blurb, value);
 
585
            }
 
586
        }
493
587
    }
494
588
  else if (G_IS_PARAM_SPEC_INT (pspec))
495
589
    {
502
596
                                   G_PARAM_SPEC_INT (pspec)->minimum,
503
597
                                   G_PARAM_SPEC_INT (pspec)->maximum,
504
598
                                   G_PARAM_SPEC_INT (pspec)->default_value,
505
 
                                   small_inc, inc, skip_inc, 0, wrap);
 
599
                                   small_inc, inc, skip_inc, delta_factor, wrap);
506
600
 
507
601
      g_object_set (object, property_name, value, NULL);
 
602
 
 
603
      if (display)
 
604
        {
 
605
          const gchar *blurb = g_param_spec_get_blurb (pspec);
 
606
 
 
607
          if (blurb)
 
608
            {
 
609
              /*  value description and new value shown in the status bar  */
 
610
              action_message (display, object, _("%s: %d"), blurb, value);
 
611
            }
 
612
        }
508
613
    }
509
614
  else
510
615
    {
526
631
  if (! current)
527
632
    return NULL;
528
633
 
529
 
  n_children = gimp_container_num_children (container);
 
634
  n_children = gimp_container_get_n_children (container);
530
635
 
531
636
  if (n_children == 0)
532
637
    return NULL;
569
674
 
570
675
  return gimp_container_get_child_by_index (container, select_index);
571
676
}
 
677
 
 
678
void
 
679
action_message (GimpDisplay *display,
 
680
                GObject     *object,
 
681
                const gchar *format,
 
682
                ...)
 
683
{
 
684
  GimpDisplayShell *shell     = gimp_display_get_shell (display);
 
685
  GimpStatusbar    *statusbar = gimp_display_shell_get_statusbar (shell);
 
686
  const gchar      *stock_id  = NULL;
 
687
  va_list           args;
 
688
 
 
689
  if (GIMP_IS_TOOL_OPTIONS (object))
 
690
    {
 
691
      GimpToolInfo *tool_info = GIMP_TOOL_OPTIONS (object)->tool_info;
 
692
 
 
693
      stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
 
694
    }
 
695
  else if (GIMP_IS_VIEWABLE (object))
 
696
    {
 
697
      stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (object));
 
698
    }
 
699
 
 
700
  va_start (args, format);
 
701
  gimp_statusbar_push_temp_valist (statusbar, GIMP_MESSAGE_INFO,
 
702
                                   stock_id, format, args);
 
703
  va_end (args);
 
704
}