dialogs-commands.c 11.6 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;
Michael Natterer's avatar
Michael Natterer committed
62
63
64
65

      identifier = g_quark_to_string ((GQuark) action);

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

70
71
72
73
74
75
76
void
dialogs_create_dockable_cmd_callback (GtkWidget *widget,
				      gpointer   data,
				      guint      action)
{
  if (action)
    {
77
      const gchar *identifier;
78
79
80
81

      identifier = g_quark_to_string ((GQuark) action);

      if (identifier)
82
	gimp_dialog_factory_dialog_raise (global_dock_factory, identifier, -1);
83
84
85
    }
}

86
87
88
89
90
void
dialogs_add_tab_cmd_callback (GtkWidget *widget,
			      gpointer   data,
			      guint      action)
{
91
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
92

93
  if (action)
94
    {
95
96
      GtkWidget   *dockable;
      const gchar *identifier;
97

Michael Natterer's avatar
Michael Natterer committed
98
      identifier = g_quark_to_string ((GQuark) action);
99

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

108
109
110
111
112
	  /*  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
113
114
	    gimp_dockbook_add (dockbook, GIMP_DOCKABLE (dockable), -1);
	}
115
116
117
118
    }
}

void
119
120
121
dialogs_close_tab_cmd_callback (GtkWidget *widget,
                                gpointer   data,
                                guint      action)
122
{
123
124
125
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
  gint          page_num;
126

127
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  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;
144

145
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
146

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

150
151
152
  if (dockable)
    {
      /* TODO */
153
154
    }
}
155

156
157
158
159
160
void
dialogs_toggle_view_cmd_callback (GtkWidget *widget,
                                  gpointer   data,
                                  guint      action)
{
161
162
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
163
  GimpViewType  view_type;
164
  gint          page_num;
165
166
167
168
169
170

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

  view_type = (GimpViewType) action;

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
177
178
  if (dockable)
    {
      GimpDialogFactoryEntry *entry;
179

180
181
182
183
      entry = g_object_get_data (G_OBJECT (dockable),
                                 "gimp-dialog-factory-entry");

      if (entry)
184
        {
185
186
          gchar *identifier;
          gchar *substring = NULL;
187

188
          identifier = g_strdup (entry->identifier);
189

190
          substring = strstr (identifier, "grid");
191

192
193
          if (substring && view_type == GIMP_VIEW_TYPE_GRID)
            return;
194

195
196
197
          if (! substring)
            {
              substring = strstr (identifier, "list");
198

199
200
201
              if (substring && view_type == GIMP_VIEW_TYPE_LIST)
                return;
            }
202

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
          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)
230
                {
231
232
233
234
                  gimp_dockbook_add (dockbook, GIMP_DOCKABLE (new_dockable),
                                     page_num);

                  gimp_dockbook_remove (dockbook, dockable);
235

236
237
238
                  gtk_notebook_set_current_page (GTK_NOTEBOOK (dockbook),
                                                 page_num);
                }
239
            }
240
241

          g_free (identifier);
242
243
244
245
246
247
248
249
250
        }
    }
}

void
dialogs_preview_size_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
251
252
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
  GimpDockable *dockable;
253
  gint          preview_size;
254
  gint          page_num;
255
256
257
258
259
260

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

  preview_size = (gint) action;

261
  page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
262

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

266
267
268
  if (dockable)
    {
      GimpContainerView *view;
269

270
      view = gimp_container_view_get_by_dockable (dockable);
271

272
273
274
      if (view)
        {
          if (view->preview_size != preview_size)
275
276
            gimp_container_view_set_preview_size (view, preview_size,
                                                  view->preview_border_width);
277
278
279
280
        }
    }
}

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

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

  tab_style = (gint) action;

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

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

301
302
303
  if (dockable)
    {
      if (dockable->tab_style != tab_style)
304
305
306
307
308
309
310
311
312
313
314
315
316
317
        {
          GtkWidget *tab_widget;

          dockable->tab_style = tab_style;

          tab_widget = gimp_dockbook_get_tab_widget (dockbook, dockable);

          gtk_notebook_set_tab_label (GTK_NOTEBOOK (dockbook),
                                      GTK_WIDGET (dockable),
                                      tab_widget);
        }
    }
}

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

325
  if (GIMP_IS_IMAGE_DOCK (dockbook->dock))
Michael Natterer's avatar
Michael Natterer committed
326
327
328
329
330
331
    {
      gimp_image_dock_set_show_image_menu (GIMP_IMAGE_DOCK (dockbook->dock),
					   GTK_CHECK_MENU_ITEM (widget)->active);
    }
}

332
333
334
335
336
void
dialogs_toggle_auto_cmd_callback (GtkWidget *widget,
				  gpointer   data,
				  guint      action)
{
337
  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
338

339
  if (GIMP_IS_IMAGE_DOCK (dockbook->dock))
340
341
342
343
344
345
    {
      gimp_image_dock_set_auto_follow_active (GIMP_IMAGE_DOCK (dockbook->dock),
					      GTK_CHECK_MENU_ITEM (widget)->active);
    }
}

346
347
void
dialogs_create_lc_cmd_callback (GtkWidget *widget,
348
349
                                gpointer   data,
                                guint      action)
350
{
351
  static const gchar *tabs[] =
352
  {
353
354
355
356
    "gimp-layer-list",
    "gimp-channel-list",
    "gimp-vectors-list",
    "gimp-indexed-palette"
357
  };
358

359
360
  dialogs_create_dock (tabs, G_N_ELEMENTS (tabs));
}
361

362
363
364
365
366
367
368
369
370
371
372
373
374
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"
  };
375

376
  dialogs_create_dock (tabs, G_N_ELEMENTS (tabs));
377
}
378

379
380
381
382
383
void
dialogs_create_stuff_cmd_callback (GtkWidget *widget,
                                   gpointer   data,
                                   guint      action)
{
384
  static const gchar *tabs[] =
385
  {
386
387
    "gimp-buffer-list",
    "gimp-image-list",
388
389
    "gimp-document-list",
    "gimp-template-list"
390
  };
391

392
  dialogs_create_dock (tabs, G_N_ELEMENTS (tabs));
393
}
394

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
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))
            {
416
              gtk_window_present (GTK_WINDOW (list->data));
417
418
419
420
421
              break;
            }
        }
    }
}
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451


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