dialogs-commands.c 14.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
26
#include "libgimpwidgets/gimpwidgets.h"

27
#include "gui-types.h"
28

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/gimpsessioninfo.h"
36

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


41
42
/*  local function prototypes  */

43
static void   dialogs_create_dock (GdkScreen   *screen,
44
                                   gboolean     show_image_menu,
45
                                   const gchar *tabs[],
46
47
48
49
50
                                   gint         n_tabs);


/*  public functions  */

51
52
53
54
55
56
57
58
void
dialogs_show_toolbox_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
  dialogs_show_toolbox ();
}

59
60
61
62
63
64
65
void
dialogs_create_toplevel_cmd_callback (GtkWidget *widget,
				      gpointer   data,
				      guint      action)
{
  if (action)
    {
66
      const gchar *identifier = g_quark_to_string ((GQuark) action);
Michael Natterer's avatar
Michael Natterer committed
67
68

      if (identifier)
69
70
71
	gimp_dialog_factory_dialog_new (global_dialog_factory,
                                        gtk_widget_get_screen (widget),
                                        identifier, -1);
72
73
74
    }
}

75
76
77
78
79
80
81
void
dialogs_create_dockable_cmd_callback (GtkWidget *widget,
				      gpointer   data,
				      guint      action)
{
  if (action)
    {
82
83
84
85
86
      const gchar *identifier = g_quark_to_string ((GQuark) action);

      if (!identifier)
        return;

87
88
89
      gimp_dialog_factory_dialog_raise (global_dock_factory,
                                        gtk_widget_get_screen (widget),
                                        identifier, -1);
90
91
92
    }
}

93
94
95
96
97
void
dialogs_add_tab_cmd_callback (GtkWidget *widget,
			      gpointer   data,
			      guint      action)
{
98
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
99

100
  if (action)
101
    {
102
103
      GtkWidget   *dockable;
      const gchar *identifier;
104

Michael Natterer's avatar
Michael Natterer committed
105
      identifier = g_quark_to_string ((GQuark) action);
106

Michael Natterer's avatar
Michael Natterer committed
107
108
      if (identifier)
	{
109
110
111
112
113
	  dockable =
            gimp_dialog_factory_dockable_new (dockbook->dock->dialog_factory,
                                              dockbook->dock,
                                              identifier,
                                              -1);
Michael Natterer's avatar
Michael Natterer committed
114

115
116
117
118
119
	  /*  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
120
121
	    gimp_dockbook_add (dockbook, GIMP_DOCKABLE (dockable), -1);
	}
122
123
124
125
    }
}

void
126
127
128
dialogs_close_tab_cmd_callback (GtkWidget *widget,
                                gpointer   data,
                                guint      action)
129
{
130
131
132
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
  gint          page_num;
133

134
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  dockable = (GimpDockable *)
    gtk_notebook_get_nth_page (GTK_NOTEBOOK (dockbook), page_num);

  if (dockable)
    gimp_dockbook_remove (dockbook, dockable);
}

void
dialogs_detach_tab_cmd_callback (GtkWidget *widget,
                                 gpointer   data,
                                 guint      action)
{
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
  gint          page_num;
151

152
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
153

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

157
  if (dockable)
158
    gimp_dockable_detach (dockable);
159
}
160

161
162
163
164
165
void
dialogs_toggle_view_cmd_callback (GtkWidget *widget,
                                  gpointer   data,
                                  guint      action)
{
166
167
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
168
  GimpViewType  view_type;
169
  gint          page_num;
170
171
172
173
174
175

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

  view_type = (GimpViewType) action;

176
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
177

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

181
182
183
  if (dockable)
    {
      GimpDialogFactoryEntry *entry;
184

185
      gimp_dialog_factory_from_widget (GTK_WIDGET (dockable), &entry);
186
187

      if (entry)
188
        {
189
190
          gchar *identifier;
          gchar *substring = NULL;
191

192
          identifier = g_strdup (entry->identifier);
193

194
          substring = strstr (identifier, "grid");
195

196
197
          if (substring && view_type == GIMP_VIEW_TYPE_GRID)
            return;
198

199
200
201
          if (! substring)
            {
              substring = strstr (identifier, "list");
202

203
204
205
              if (substring && view_type == GIMP_VIEW_TYPE_LIST)
                return;
            }
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
          if (substring)
            {
              GimpContainerView *old_view;
              GtkWidget         *new_dockable;
              gint               preview_size = -1;

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

              old_view = gimp_container_view_get_by_dockable (dockable);

              if (old_view)
                preview_size = old_view->preview_size;

              new_dockable =
                gimp_dialog_factory_dockable_new (dockbook->dock->dialog_factory,
                                                  dockbook->dock,
                                                  identifier,
                                                  preview_size);

              /*  Maybe gimp_dialog_factory_dockable_new() returned
               *  an already existing singleton dockable, so check
               *  if it already is attached to a dockbook.
               */
              if (new_dockable && ! GIMP_DOCKABLE (new_dockable)->dockbook)
234
                {
235
236
237
238
                  gimp_dockbook_add (dockbook, GIMP_DOCKABLE (new_dockable),
                                     page_num);

                  gimp_dockbook_remove (dockbook, dockable);
239

240
241
242
                  gtk_notebook_set_current_page (GTK_NOTEBOOK (dockbook),
                                                 page_num);
                }
243
            }
244
245

          g_free (identifier);
246
247
248
249
250
251
252
253
254
        }
    }
}

void
dialogs_preview_size_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
255
256
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
257
  gint          preview_size;
258
  gint          page_num;
259
260
261
262
263
264

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

  preview_size = (gint) action;

265
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
266

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

270
271
272
  if (dockable)
    {
      GimpContainerView *view;
273

274
      view = gimp_container_view_get_by_dockable (dockable);
275

276
277
278
      if (view && view->preview_size != preview_size)
        gimp_container_view_set_preview_size (view, preview_size,
                                              view->preview_border_width);
279
280
281
    }
}

282
283
284
285
286
void
dialogs_tab_style_cmd_callback (GtkWidget *widget,
                                gpointer   data,
                                guint      action)
{
287
288
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
289
  GimpTabStyle  tab_style;
290
  gint          page_num;
291
292
293
294
295
296

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

  tab_style = (gint) action;

297
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
298

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

302
  if (dockable && dockable->tab_style != tab_style)
303
    {
304
      GtkWidget *tab_widget;
305

306
      dockable->tab_style = tab_style;
307

308
      tab_widget = gimp_dockbook_get_tab_widget (dockbook, dockable);
309

310
311
312
      gtk_notebook_set_tab_label (GTK_NOTEBOOK (dockbook),
                                  GTK_WIDGET (dockable),
                                  tab_widget);
313
314
315
    }
}

Michael Natterer's avatar
Michael Natterer committed
316
317
318
319
320
void
dialogs_toggle_image_menu_cmd_callback (GtkWidget *widget,
					gpointer   data,
					guint      action)
{
321
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
Michael Natterer's avatar
Michael Natterer committed
322

323
  if (GIMP_IS_IMAGE_DOCK (dockbook->dock))
324
325
    gimp_image_dock_set_show_image_menu (GIMP_IMAGE_DOCK (dockbook->dock),
                                         GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
326
327
}

328
329
330
331
332
void
dialogs_toggle_auto_cmd_callback (GtkWidget *widget,
				  gpointer   data,
				  guint      action)
{
333
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
334

335
  if (GIMP_IS_IMAGE_DOCK (dockbook->dock))
336
337
    gimp_image_dock_set_auto_follow_active (GIMP_IMAGE_DOCK (dockbook->dock),
                                            GTK_CHECK_MENU_ITEM (widget)->active);
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
static void
dialogs_change_screen_confirm_callback (GtkWidget *query_box,
                                        gint       value,
                                        gpointer   data)
{
  GdkScreen *screen;

  screen = gdk_display_get_screen (gtk_widget_get_display (GTK_WIDGET (data)),
                                   value);

  if (screen)
    gtk_window_set_screen (GTK_WINDOW (data), screen);
}

static void
dialogs_change_screen_destroy_callback (GtkWidget *query_box,
                                        GtkWidget *dock)
{
  g_object_set_data (G_OBJECT (dock), "gimp-change-screen-dialog", NULL);
}

void
dialogs_change_screen_cmd_callback (GtkWidget *widget,
                                    gpointer   data,
                                    guint      action)
{
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GtkWidget    *dock;
  GdkScreen    *screen;
  GdkDisplay   *display;
  gint          cur_screen;
  gint          num_screens;
  GtkWidget    *qbox;

  dock = GTK_WIDGET (dockbook->dock);

  qbox = g_object_get_data (G_OBJECT (dock), "gimp-change-screen-dialog");

  if (qbox)
    {
      gtk_window_present (GTK_WINDOW (qbox));
      return;
    }

  screen  = gtk_widget_get_screen (dock);
  display = gtk_widget_get_display (dock);

  cur_screen  = gdk_screen_get_number (screen);
  num_screens = gdk_display_get_n_screens (display);

  qbox = gimp_query_int_box ("Move Dock to Screen",
                             dock,
                             NULL, 0,
393
                             "Enter destination screen",
394
395
396
397
398
399
400
401
402
403
404
405
406
407
                             cur_screen, 0, num_screens - 1,
                             G_OBJECT (dock), "destroy",
                             dialogs_change_screen_confirm_callback,
                             dock);

  g_object_set_data (G_OBJECT (dock), "gimp-change-screen-dialog", qbox);

  g_signal_connect (qbox, "destroy",
                    G_CALLBACK (dialogs_change_screen_destroy_callback),
                    dock);

  gtk_widget_show (qbox);
}

408
409
void
dialogs_create_lc_cmd_callback (GtkWidget *widget,
410
411
                                gpointer   data,
                                guint      action)
412
{
413
  static const gchar *tabs[] =
414
  {
415
416
417
418
    "gimp-layer-list",
    "gimp-channel-list",
    "gimp-vectors-list",
    "gimp-indexed-palette"
419
  };
420

421
  dialogs_create_dock (gtk_widget_get_screen (widget), TRUE,
422
                       tabs, G_N_ELEMENTS (tabs));
423
}
424

425
426
427
428
429
430
431
432
433
434
435
436
437
void
dialogs_create_data_cmd_callback (GtkWidget *widget,
                                  gpointer   data,
                                  guint      action)
{
  static const gchar *tabs[] =
  {
    "gimp-brush-grid",
    "gimp-pattern-grid",
    "gimp-gradient-list",
    "gimp-palette-list",
    "gimp-font-list"
  };
438

439
  dialogs_create_dock (gtk_widget_get_screen (widget), FALSE,
440
                       tabs, G_N_ELEMENTS (tabs));
441
}
442

443
444
445
446
447
void
dialogs_create_stuff_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
448
  static const gchar *tabs[] =
449
  {
450
451
    "gimp-buffer-list",
    "gimp-image-list",
452
453
    "gimp-document-list",
    "gimp-template-list"
454
  };
455

456
  dialogs_create_dock (gtk_widget_get_screen (widget), FALSE,
457
                       tabs, G_N_ELEMENTS (tabs));
458
}
459

460
461
462
463
464
465
466
void
dialogs_show_toolbox (void)
{
  if (! global_toolbox_factory->open_dialogs)
    {
      GtkWidget *toolbox;

467
468
      toolbox = gimp_dialog_factory_dock_new (global_toolbox_factory,
                                              gdk_screen_get_default ());
469
470
471
472
473
474
475
476
477
478
479
480
481

      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))
            {
482
              gtk_window_present (GTK_WINDOW (list->data));
483
484
485
486
487
              break;
            }
        }
    }
}
488
489
490
491
492


/*  private functions  */

static void
493
dialogs_create_dock (GdkScreen   *screen,
494
                     gboolean     show_image_menu,
495
                     const gchar *tabs[],
496
497
498
499
500
501
502
                     gint         n_tabs)
{
  GtkWidget *dock;
  GtkWidget *dockbook;
  GtkWidget *dockable;
  gint       i;

503
  dock = gimp_dialog_factory_dock_new (global_dock_factory, screen);
504

505
506
  gimp_image_dock_set_show_image_menu (GIMP_IMAGE_DOCK (dock), show_image_menu);

507
508
509
510
511
512
513
  dockbook = gimp_dockbook_new (global_dock_factory->menu_factory);

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

  for (i = 0; i < n_tabs; i++)
    {
      dockable = gimp_dialog_factory_dialog_new (global_dock_factory,
514
                                                 screen,
515
516
517
518
519
520
521
522
                                                 tabs[i], -1);

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

  gtk_widget_show (dock);
}