dialogs-commands.c 15.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

21
22
#include <string.h>

23
24
#include <gtk/gtk.h>

25
#include "gui-types.h"
26

27
28
#include "core/gimpcontext.h"

29
30
#include "widgets/gimpcontainerview.h"
#include "widgets/gimpcontainerview-utils.h"
31
#include "widgets/gimpdialogfactory.h"
32
#include "widgets/gimpdockable.h"
33
#include "widgets/gimpdockbook.h"
Michael Natterer's avatar
Michael Natterer committed
34
#include "widgets/gimpimagedock.h"
35
#include "widgets/gimpitemfactory.h"
36

37
#include "dialogs.h"
38
39
40
#include "dialogs-commands.h"


41
42
43
44
45
46
47
48
void
dialogs_show_toolbox_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
  dialogs_show_toolbox ();
}

49
50
51
52
53
54
55
void
dialogs_create_toplevel_cmd_callback (GtkWidget *widget,
				      gpointer   data,
				      guint      action)
{
  if (action)
    {
56
      const gchar *identifier;
Michael Natterer's avatar
Michael Natterer committed
57
58
59
60

      identifier = g_quark_to_string ((GQuark) action);

      if (identifier)
61
	gimp_dialog_factory_dialog_new (global_dialog_factory, identifier, -1);
62
63
64
    }
}

65
66
67
68
69
70
71
void
dialogs_create_dockable_cmd_callback (GtkWidget *widget,
				      gpointer   data,
				      guint      action)
{
  if (action)
    {
72
      const gchar *identifier;
73
74
75
76

      identifier = g_quark_to_string ((GQuark) action);

      if (identifier)
77
	gimp_dialog_factory_dialog_raise (global_dock_factory, identifier, -1);
78
79
80
    }
}

81
82
83
84
85
86
87
88
89
90
91
void
dialogs_add_tab_cmd_callback (GtkWidget *widget,
			      gpointer   data,
			      guint      action)
{
  GimpDockbook *dockbook;

  dockbook = (GimpDockbook *) gtk_item_factory_popup_data_from_widget (widget);

  if (dockbook && action)
    {
92
93
      GtkWidget   *dockable;
      const gchar *identifier;
94

Michael Natterer's avatar
Michael Natterer committed
95
      identifier = g_quark_to_string ((GQuark) action);
96

Michael Natterer's avatar
Michael Natterer committed
97
98
      if (identifier)
	{
99
100
101
102
103
	  dockable =
            gimp_dialog_factory_dockable_new (dockbook->dock->dialog_factory,
                                              dockbook->dock,
                                              identifier,
                                              -1);
Michael Natterer's avatar
Michael Natterer committed
104

105
106
107
108
109
	  /*  Maybe gimp_dialog_factory_dockable_new() returned an already
	   *  existing singleton dockable, so check if it already is
	   *  attached to a dockbook.
	   */
	  if (dockable && ! GIMP_DOCKABLE (dockable)->dockbook)
Michael Natterer's avatar
Michael Natterer committed
110
111
	    gimp_dockbook_add (dockbook, GIMP_DOCKABLE (dockable), -1);
	}
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    }
}

void
dialogs_remove_tab_cmd_callback (GtkWidget *widget,
				 gpointer   data,
				 guint      action)
{
  GimpDockbook *dockbook;

  dockbook = (GimpDockbook *) gtk_item_factory_popup_data_from_widget (widget);

  if (dockbook)
    {
126
127
128
129
130
131
132
133
134
135
      GimpDockable *dockable;
      gint          page_num;

      page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));

      dockable = (GimpDockable *)
	gtk_notebook_get_nth_page (GTK_NOTEBOOK (dockbook), page_num);

      if (dockable)
	gimp_dockbook_remove (dockbook, dockable);
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
void
dialogs_toggle_view_cmd_callback (GtkWidget *widget,
                                  gpointer   data,
                                  guint      action)
{
  GimpDockbook *dockbook;
  GimpViewType  view_type;

  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    return;

  dockbook = (GimpDockbook *) gtk_item_factory_popup_data_from_widget (widget);

  view_type = (GimpViewType) action;

  if (dockbook)
    {
      GimpDockable *dockable;
      gint          page_num;

      page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));

      dockable = (GimpDockable *)
	gtk_notebook_get_nth_page (GTK_NOTEBOOK (dockbook), page_num);

      if (dockable)
        {
          GimpDialogFactoryEntry *entry;

          entry = g_object_get_data (G_OBJECT (dockable),
                                     "gimp-dialog-factory-entry");

          if (entry)
            {
              gchar *identifier;
174
              gchar *substring = NULL;
175
176
177
178
179
180
181
182
183
184
185
186
187
188

              identifier = g_strdup (entry->identifier);

              if ((substring = strstr (identifier, "grid")) &&
                  view_type == GIMP_VIEW_TYPE_LIST)
                {
                  memcpy (substring, "list", 4);
                }
              else if ((substring = strstr (identifier, "list")) &&
                       view_type == GIMP_VIEW_TYPE_GRID)
                {
                  memcpy (substring, "grid", 4);
                }

189
              if (substring)
190
191
192
193
194
195
196
197
198
199
200
                {
                  GimpContainerView *old_view;
                  GtkWidget         *new_dockable;
                  gint               preview_size = -1;

                  old_view = gimp_container_view_get_by_dockable (dockable);

                  if (old_view)
                    preview_size = old_view->preview_size;

                  new_dockable =
201
                    gimp_dialog_factory_dockable_new (dockbook->dock->dialog_factory,
202
203
204
205
                                                      dockbook->dock,
                                                      identifier,
                                                      preview_size);

206
                  /*  Maybe gimp_dialog_factory_dockable_new() returned
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
                   *  an already existing singleton dockable, so check
                   *  if it already is attached to a dockbook.
                   */
                  if (new_dockable && ! GIMP_DOCKABLE (new_dockable)->dockbook)
                    {
                      gimp_dockbook_add (dockbook, GIMP_DOCKABLE (new_dockable),
                                         page_num);

                      gimp_dockbook_remove (dockbook, dockable);

                      gtk_notebook_set_current_page (GTK_NOTEBOOK (dockbook),
                                                     page_num);
                    }
                }

              g_free (identifier);
            }
        }
    }
}

void
dialogs_preview_size_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
  GimpDockbook *dockbook;
  gint          preview_size;

  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    return;

  dockbook = (GimpDockbook *) gtk_item_factory_popup_data_from_widget (widget);

  preview_size = (gint) action;

  if (dockbook)
    {
      GimpDockable *dockable;
      gint          page_num;

      page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));

      dockable = (GimpDockable *)
	gtk_notebook_get_nth_page (GTK_NOTEBOOK (dockbook), page_num);

      if (dockable)
        {
          GimpContainerView *view;

          view = gimp_container_view_get_by_dockable (dockable);

          if (view)
260
            gimp_container_view_set_preview_size (view, preview_size);
261
262
263
264
        }
    }
}

Michael Natterer's avatar
Michael Natterer committed
265
266
267
268
269
270
271
272
273
void
dialogs_toggle_image_menu_cmd_callback (GtkWidget *widget,
					gpointer   data,
					guint      action)
{
  GimpDockbook *dockbook;

  dockbook = (GimpDockbook *) gtk_item_factory_popup_data_from_widget (widget);

274
  if (dockbook && GIMP_IS_IMAGE_DOCK (dockbook->dock))
Michael Natterer's avatar
Michael Natterer committed
275
276
277
278
279
280
    {
      gimp_image_dock_set_show_image_menu (GIMP_IMAGE_DOCK (dockbook->dock),
					   GTK_CHECK_MENU_ITEM (widget)->active);
    }
}

281
282
283
284
285
286
287
288
289
void
dialogs_toggle_auto_cmd_callback (GtkWidget *widget,
				  gpointer   data,
				  guint      action)
{
  GimpDockbook *dockbook;

  dockbook = (GimpDockbook *) gtk_item_factory_popup_data_from_widget (widget);

290
  if (dockbook && GIMP_IS_IMAGE_DOCK (dockbook->dock))
291
292
293
294
295
296
    {
      gimp_image_dock_set_auto_follow_active (GIMP_IMAGE_DOCK (dockbook->dock),
					      GTK_CHECK_MENU_ITEM (widget)->active);
    }
}

297
298
void
dialogs_create_lc_cmd_callback (GtkWidget *widget,
299
300
                                gpointer   data,
                                guint      action)
301
302
303
304
305
{
  GtkWidget *dock;
  GtkWidget *dockbook;
  GtkWidget *dockable;

306
307
  const gchar *tabs[] =
  {
308
309
310
311
    "gimp-layer-list",
    "gimp-channel-list",
    "gimp-vectors-list",
    "gimp-indexed-palette"
312
313
314
  };
  gint i;

315
316
  dock = gimp_dialog_factory_dock_new (global_dock_factory);

317
318
  gimp_image_dock_set_show_image_menu (GIMP_IMAGE_DOCK (dock), TRUE);

319
  dockbook = gimp_dockbook_new (global_dock_factory->menu_factory);
320
321
322

  gimp_dock_add_book (GIMP_DOCK (dock), GIMP_DOCKBOOK (dockbook), 0);

323
324
325
326
  for (i = 0; i < G_N_ELEMENTS (tabs); i++)
    {
      dockable = gimp_dialog_factory_dialog_new (global_dock_factory,
                                                 tabs[i], -1);
327

328
329
330
      if (dockable && ! GIMP_DOCKABLE (dockable)->dockbook)
        gimp_dock_add (GIMP_DOCK (dock), GIMP_DOCKABLE (dockable), -1, -1);
    }
331

332
333
  gtk_widget_show (dock);
}
334

335
336
337
338
339
340
341
342
343
344
345
void
dialogs_create_stuff_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
  GtkWidget *dock;
  GtkWidget *dockbook;
  GtkWidget *dockable;

  const gchar *tabs[] =
  {
346
347
348
349
350
351
352
    "gimp-brush-grid",
    "gimp-pattern-grid",
    "gimp-gradient-list",
    "gimp-palette-list",
    "gimp-buffer-list",
    "gimp-image-list",
    "gimp-document-history"
353
354
355
356
357
  };
  gint i;

  dock = gimp_dialog_factory_dock_new (global_dock_factory);

358
  dockbook = gimp_dockbook_new (global_dock_factory->menu_factory);
359

360
  gimp_dock_add_book (GIMP_DOCK (dock), GIMP_DOCKBOOK (dockbook), 0);
361

362
363
364
365
366
367
368
369
  for (i = 0; i < G_N_ELEMENTS (tabs); i++)
    {
      dockable = gimp_dialog_factory_dialog_new (global_dock_factory,
                                                 tabs[i], -1);

      if (dockable && ! GIMP_DOCKABLE (dockable)->dockbook)
        gimp_dock_add (GIMP_DOCK (dock), GIMP_DOCKABLE (dockable), -1, -1);
    }
370
371
372

  gtk_widget_show (dock);
}
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
void
dialogs_show_toolbox (void)
{
  if (! global_toolbox_factory->open_dialogs)
    {
      GtkWidget *toolbox;

      toolbox = gimp_dialog_factory_dock_new (global_toolbox_factory);

      gtk_widget_show (toolbox);
    }
  else
    {
      GList *list;

      for (list = global_toolbox_factory->open_dialogs;
           list;
           list = g_list_next (list))
        {
          if (GTK_WIDGET_TOPLEVEL (list->data))
            {
395
              gtk_window_present (GTK_WINDOW (list->data));
396
397
398
399
400
401
              break;
            }
        }
    }
}

402
403
404
405
406
407
408
409
410
411
412
413
414
415
void
dialogs_menu_update (GtkItemFactory *factory,
                     gpointer        data)
{
  GimpDockbook *dockbook;

  dockbook = GIMP_DOCKBOOK (data);

  if (dockbook)
    {
      GimpDockable           *dockable;
      gint                    page_num;
      GimpDialogFactoryEntry *entry;
      GimpContainerView      *view;
416
417
418
      GimpViewType            view_type       = -1;
      gboolean                other_view_type = FALSE;
      GimpPreviewSize         preview_size    = GIMP_PREVIEW_SIZE_NONE;
419
420
421
422
423
424
425
426
427
428
429

      page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));

      dockable = (GimpDockable *)
	gtk_notebook_get_nth_page (GTK_NOTEBOOK (dockbook), page_num);

      entry = g_object_get_data (G_OBJECT (dockable),
                                 "gimp-dialog-factory-entry");

      if (entry)
        {
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
          gchar *identifier;
          gchar *substring = NULL;

          identifier = g_strdup (entry->identifier);

          if ((substring = strstr (identifier, "grid")))
            view_type = GIMP_VIEW_TYPE_GRID;
          else if ((substring = strstr (identifier, "list")))
            view_type = GIMP_VIEW_TYPE_LIST;

          if (substring)
            {
              if (view_type == GIMP_VIEW_TYPE_GRID)
                memcpy (substring, "list", 4);
              else if (view_type == GIMP_VIEW_TYPE_LIST)
                memcpy (substring, "grid", 4);

              if (gimp_dialog_factory_find_entry (dockbook->dock->dialog_factory,
                                                  identifier))
                other_view_type = TRUE;
            }

          g_free (identifier);
453
454
455
456
457
        }

      view = gimp_container_view_get_by_dockable (dockable);

      if (view)
458
        preview_size = view->preview_size;
459
460
461

#define SET_ACTIVE(path,active) \
        gimp_item_factory_set_active (factory, (path), (active))
462
463
#define SET_VISIBLE(path,active) \
        gimp_item_factory_set_visible (factory, (path), (active))
464
465
#define SET_SENSITIVE(path,sensitive) \
        gimp_item_factory_set_sensitive (factory, (path), (sensitive))
466

467
468
      SET_VISIBLE ("/view-type-separator",
                   preview_size != GIMP_PREVIEW_SIZE_NONE || view_type != -1);
469

470
471
472
      SET_VISIBLE ("/Preview Size", preview_size != GIMP_PREVIEW_SIZE_NONE);

      if (preview_size != GIMP_PREVIEW_SIZE_NONE)
473
        {
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
          if (preview_size >= GIMP_PREVIEW_SIZE_GIGANTIC)
            {
              SET_ACTIVE ("/Preview Size/Gigantic", TRUE);
            }
          else if (preview_size >= GIMP_PREVIEW_SIZE_ENORMOUS)
            {
              SET_ACTIVE ("/Preview Size/Enormous", TRUE);
            }
          else if (preview_size >= GIMP_PREVIEW_SIZE_HUGE)
            {
              SET_ACTIVE ("/Preview Size/Huge", TRUE);
            }
          else if (preview_size >= GIMP_PREVIEW_SIZE_EXTRA_LARGE)
            {
              SET_ACTIVE ("/Preview Size/Extra Large", TRUE);
            }
          else if (preview_size >= GIMP_PREVIEW_SIZE_LARGE)
            {
              SET_ACTIVE ("/Preview Size/Large", TRUE);
            }
          else if (preview_size >= GIMP_PREVIEW_SIZE_MEDIUM)
            {
              SET_ACTIVE ("/Preview Size/Medium", TRUE);
            }
          else if (preview_size >= GIMP_PREVIEW_SIZE_SMALL)
            {
              SET_ACTIVE ("/Preview Size/Small", TRUE);
            }
          else if (preview_size >= GIMP_PREVIEW_SIZE_EXTRA_SMALL)
            {
              SET_ACTIVE ("/Preview Size/Extra Small", TRUE);
            }
          else if (preview_size >= GIMP_PREVIEW_SIZE_TINY)
            {
              SET_ACTIVE ("/Preview Size/Tiny", TRUE);
            }
510
        }
511
512
513
514
515

      SET_VISIBLE ("/View as Grid", view_type != -1);
      SET_VISIBLE ("/View as List", view_type != -1);

      if (view_type != -1)
516
        {
517
518
519
520
521
522
523
          if (view_type == GIMP_VIEW_TYPE_LIST)
            SET_ACTIVE ("/View as List", TRUE);
          else
            SET_ACTIVE ("/View as Grid", TRUE);

          SET_SENSITIVE ("/View as Grid", other_view_type);
          SET_SENSITIVE ("/View as List", other_view_type);
524
525
        }

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
      if (GIMP_IS_IMAGE_DOCK (dockbook->dock))
        {
          SET_VISIBLE ("/image-menu-separator",     TRUE);
          SET_VISIBLE ("/Show Image Menu",          TRUE);
          SET_VISIBLE ("/Auto Follow Active Image", TRUE);

          SET_ACTIVE ("/Show Image Menu",
                      GIMP_IMAGE_DOCK (dockbook->dock)->show_image_menu);
          SET_ACTIVE ("/Auto Follow Active Image",
                      GIMP_IMAGE_DOCK (dockbook->dock)->auto_follow_active);
        }
      else
        {
          SET_VISIBLE ("/image-menu-separator",     FALSE);
          SET_VISIBLE ("/Show Image Menu",          FALSE);
          SET_VISIBLE ("/Auto Follow Active Image", FALSE);
        }
543
544

#undef SET_ACTIVE
545
#undef SET_VISIBLE
546
#undef SET_SENSITIVE
547
548
    }
}