dialogs-commands.c 12.4 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
#include "widgets/gimpsessioninfo.h"
34

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


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

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


/*  public functions  */

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

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

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

69
70
71
72
73
74
75
void
dialogs_create_dockable_cmd_callback (GtkWidget *widget,
				      gpointer   data,
				      guint      action)
{
  if (action)
    {
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
108
      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);
        }
109
110
111
    }
}

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

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

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

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

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

void
145
146
147
dialogs_close_tab_cmd_callback (GtkWidget *widget,
                                gpointer   data,
                                guint      action)
148
{
149
150
151
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
  gint          page_num;
152

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

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
  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;
170

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

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

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

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

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

  view_type = (GimpViewType) action;

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

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

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

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

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

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

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

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

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

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

                  gimp_dockbook_remove (dockbook, dockable);
259

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

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

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

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

  preview_size = (gint) action;

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

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

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

294
      view = gimp_container_view_get_by_dockable (dockable);
295

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

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

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

  tab_style = (gint) action;

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

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

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

326
      dockable->tab_style = tab_style;
327

328
      tab_widget = gimp_dockbook_get_tab_widget (dockbook, dockable);
329

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

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

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

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

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

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

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

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

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

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

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

409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
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))
            {
430
              gtk_window_present (GTK_WINDOW (list->data));
431
432
433
434
435
              break;
            }
        }
    }
}
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
465


/*  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);
}