dialogs-commands.c 12.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 "widgets/gimpcontainerview.h"
#include "widgets/gimpcontainerview-utils.h"
29
#include "widgets/gimpdialogfactory.h"
30
#include "widgets/gimpdockable.h"
31
#include "widgets/gimpdockbook.h"
Michael Natterer's avatar
Michael Natterer committed
32
#include "widgets/gimpimagedock.h"
33

34
#include "dialogs.h"
35
36
37
#include "dialogs-commands.h"


38
39
40
41
42
43
44
45
/*  local function prototypes  */

static void   dialogs_create_dock (const gchar *tabs[],
                                   gint         n_tabs);


/*  public functions  */

46
47
48
49
50
51
52
53
void
dialogs_show_toolbox_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
  dialogs_show_toolbox ();
}

54
55
56
57
58
59
60
void
dialogs_create_toplevel_cmd_callback (GtkWidget *widget,
				      gpointer   data,
				      guint      action)
{
  if (action)
    {
61
      const gchar *identifier = g_quark_to_string ((GQuark) action);
Michael Natterer's avatar
Michael Natterer committed
62
63

      if (identifier)
64
	gimp_dialog_factory_dialog_new (global_dialog_factory, identifier, -1);
65
66
67
    }
}

68
69
70
71
72
73
74
void
dialogs_create_dockable_cmd_callback (GtkWidget *widget,
				      gpointer   data,
				      guint      action)
{
  if (action)
    {
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
      const gchar *identifier = g_quark_to_string ((GQuark) action);

      if (!identifier)
        return;

      /*  If the identifier is a list, try to find a matching dialog and
       *  raise it. If there's no match, use the first list item.
       */
      if (strchr (identifier, '|'))
        {
          gchar **ids = g_strsplit (identifier, "|", 0);
          gint    i;

          for (i = 0; ids[i]; i++)
            {
              GimpSessionInfo *info;

              info = gimp_dialog_factory_find_session_info (global_dock_factory,
                                                            ids[i]);
              if (info && info->widget)
                break;
            }

          gimp_dialog_factory_dialog_raise (global_dock_factory,
                                            ids[i] ? ids[i] : ids[0], -1);

          g_strfreev (ids);
        }
      else
        {
          gimp_dialog_factory_dialog_raise (global_dock_factory,
                                            identifier, -1);
        }
108
109
110
    }
}

111
112
113
114
115
void
dialogs_add_tab_cmd_callback (GtkWidget *widget,
			      gpointer   data,
			      guint      action)
{
116
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
117

118
  if (action)
119
    {
120
121
      GtkWidget   *dockable;
      const gchar *identifier;
122

Michael Natterer's avatar
Michael Natterer committed
123
      identifier = g_quark_to_string ((GQuark) action);
124

Michael Natterer's avatar
Michael Natterer committed
125
126
      if (identifier)
	{
127
128
129
130
131
	  dockable =
            gimp_dialog_factory_dockable_new (dockbook->dock->dialog_factory,
                                              dockbook->dock,
                                              identifier,
                                              -1);
Michael Natterer's avatar
Michael Natterer committed
132

133
134
135
136
137
	  /*  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
138
139
	    gimp_dockbook_add (dockbook, GIMP_DOCKABLE (dockable), -1);
	}
140
141
142
143
    }
}

void
144
145
146
dialogs_close_tab_cmd_callback (GtkWidget *widget,
                                gpointer   data,
                                guint      action)
147
{
148
149
150
  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
156
157
158
159
160
161
162
163
164
165
166
167
168
  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;
169

170
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
171

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

175
  if (dockable)
176
    gimp_dockable_detach (dockable);
177
}
178

179
180
181
182
183
void
dialogs_toggle_view_cmd_callback (GtkWidget *widget,
                                  gpointer   data,
                                  guint      action)
{
184
185
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
186
  GimpViewType  view_type;
187
  gint          page_num;
188
189
190
191
192
193

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

  view_type = (GimpViewType) action;

194
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
195

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

199
200
201
  if (dockable)
    {
      GimpDialogFactoryEntry *entry;
202

203
204
205
206
      entry = g_object_get_data (G_OBJECT (dockable),
                                 "gimp-dialog-factory-entry");

      if (entry)
207
        {
208
209
          gchar *identifier;
          gchar *substring = NULL;
210

211
          identifier = g_strdup (entry->identifier);
212

213
          substring = strstr (identifier, "grid");
214

215
216
          if (substring && view_type == GIMP_VIEW_TYPE_GRID)
            return;
217

218
219
220
          if (! substring)
            {
              substring = strstr (identifier, "list");
221

222
223
224
              if (substring && view_type == GIMP_VIEW_TYPE_LIST)
                return;
            }
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
          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)
253
                {
254
255
256
257
                  gimp_dockbook_add (dockbook, GIMP_DOCKABLE (new_dockable),
                                     page_num);

                  gimp_dockbook_remove (dockbook, dockable);
258

259
260
261
                  gtk_notebook_set_current_page (GTK_NOTEBOOK (dockbook),
                                                 page_num);
                }
262
            }
263
264

          g_free (identifier);
265
266
267
268
269
270
271
272
273
        }
    }
}

void
dialogs_preview_size_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
274
275
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
276
  gint          preview_size;
277
  gint          page_num;
278
279
280
281
282
283

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

  preview_size = (gint) action;

284
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
285

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

289
290
291
  if (dockable)
    {
      GimpContainerView *view;
292

293
      view = gimp_container_view_get_by_dockable (dockable);
294

295
296
297
      if (view && view->preview_size != preview_size)
        gimp_container_view_set_preview_size (view, preview_size,
                                              view->preview_border_width);
298
299
300
    }
}

301
302
303
304
305
void
dialogs_tab_style_cmd_callback (GtkWidget *widget,
                                gpointer   data,
                                guint      action)
{
306
307
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
308
  GimpTabStyle  tab_style;
309
  gint          page_num;
310
311
312
313
314
315

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

  tab_style = (gint) action;

316
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
317

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

321
  if (dockable && dockable->tab_style != tab_style)
322
    {
323
      GtkWidget *tab_widget;
324

325
      dockable->tab_style = tab_style;
326

327
      tab_widget = gimp_dockbook_get_tab_widget (dockbook, dockable);
328

329
330
331
      gtk_notebook_set_tab_label (GTK_NOTEBOOK (dockbook),
                                  GTK_WIDGET (dockable),
                                  tab_widget);
332
333
334
    }
}

Michael Natterer's avatar
Michael Natterer committed
335
336
337
338
339
void
dialogs_toggle_image_menu_cmd_callback (GtkWidget *widget,
					gpointer   data,
					guint      action)
{
340
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
Michael Natterer's avatar
Michael Natterer committed
341

342
  if (GIMP_IS_IMAGE_DOCK (dockbook->dock))
343
344
    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
345
346
}

347
348
349
350
351
void
dialogs_toggle_auto_cmd_callback (GtkWidget *widget,
				  gpointer   data,
				  guint      action)
{
352
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
353

354
  if (GIMP_IS_IMAGE_DOCK (dockbook->dock))
355
356
    gimp_image_dock_set_auto_follow_active (GIMP_IMAGE_DOCK (dockbook->dock),
                                            GTK_CHECK_MENU_ITEM (widget)->active);
357
358
}

359
360
void
dialogs_create_lc_cmd_callback (GtkWidget *widget,
361
362
                                gpointer   data,
                                guint      action)
363
{
364
  static const gchar *tabs[] =
365
  {
366
367
368
369
    "gimp-layer-list",
    "gimp-channel-list",
    "gimp-vectors-list",
    "gimp-indexed-palette"
370
  };
371

372
373
  dialogs_create_dock (tabs, G_N_ELEMENTS (tabs));
}
374

375
376
377
378
379
380
381
382
383
384
385
386
387
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"
  };
388

389
  dialogs_create_dock (tabs, G_N_ELEMENTS (tabs));
390
}
391

392
393
394
395
396
void
dialogs_create_stuff_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
397
  static const gchar *tabs[] =
398
  {
399
400
    "gimp-buffer-list",
    "gimp-image-list",
401
402
    "gimp-document-list",
    "gimp-template-list"
403
  };
404

405
  dialogs_create_dock (tabs, G_N_ELEMENTS (tabs));
406
}
407

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
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))
            {
429
              gtk_window_present (GTK_WINDOW (list->data));
430
431
432
433
434
              break;
            }
        }
    }
}
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464


/*  private functions  */

static void
dialogs_create_dock (const gchar *tabs[],
                     gint         n_tabs)
{
  GtkWidget *dock;
  GtkWidget *dockbook;
  GtkWidget *dockable;
  gint       i;

  dock = gimp_dialog_factory_dock_new (global_dock_factory);

  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,
                                                 tabs[i], -1);

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

  gtk_widget_show (dock);
}