dialogs.c 19.6 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (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
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21
 */

#include "config.h"

#include <gtk/gtk.h>

22 23
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
24 25
#include "libgimpwidgets/gimpwidgets.h"

26
#include "dialogs-types.h"
27

Michael Natterer's avatar
Michael Natterer committed
28
#include "core/gimp.h"
29
#include "core/gimpcontext.h"
30
#include "core/gimplist.h"
31

32
#include "widgets/gimpdialogfactory.h"
33
#include "widgets/gimpdockwindow.h"
34
#include "widgets/gimphelp-ids.h"
35
#include "widgets/gimpmenufactory.h"
36
#include "widgets/gimpsessioninfo.h"
37
#include "widgets/gimptoolbox.h"
38

39 40 41
#include "dialogs.h"
#include "dialogs-constructors.h"

42 43
#include "gimp-intl.h"

44

45 46
GimpDialogFactory *global_dialog_factory  = NULL;
GimpDialogFactory *global_display_factory = NULL;
47

48
GimpContainer     *global_recent_docks    = NULL;
49

50

51
#define FOREIGN(id, singleton, remember_size) \
52 53 54 55 56 57 58 59 60 61 62
  { id             /* identifier       */, \
    NULL           /* name             */, \
    NULL           /* blurb            */, \
    NULL           /* stock_id         */, \
    NULL           /* help_id          */, \
    NULL           /* new_func         */, \
    0              /* view_size        */, \
    singleton      /* singleton        */, \
    TRUE           /* session_managed  */, \
    remember_size  /* remember_size    */, \
    FALSE          /* remember_if_open */, \
63
    TRUE           /* hideable         */, \
64
    FALSE          /* dockable         */}
65

66
#define TOPLEVEL(id, new_func, singleton, session_managed, remember_size) \
67 68 69 70 71 72 73 74 75 76 77
  { id               /* identifier       */, \
    NULL             /* name             */, \
    NULL             /* blurb            */, \
    NULL             /* stock_id         */, \
    NULL             /* help_id          */, \
    new_func         /* new_func         */, \
    0                /* view_size        */, \
    singleton        /* singleton        */, \
    session_managed  /* session_managed  */, \
    remember_size    /* remember_size    */, \
    FALSE            /* remember_if_open */, \
78
    TRUE             /* hideable         */, \
79 80 81 82 83 84 85 86 87 88 89 90 91 92
    FALSE            /* dockable         */}

#define DOCKABLE(id, name, blurb, stock_id, help_id, new_func, view_size, singleton) \
  { id         /* identifier       */, \
    name       /* name             */, \
    blurb      /* blurb            */, \
    stock_id   /* stock_id         */, \
    help_id    /* help_id          */, \
    new_func   /* new_func         */, \
    view_size  /* view_size        */, \
    singleton  /* singleton        */, \
    FALSE      /* session_managed  */, \
    FALSE      /* remember_size    */, \
    TRUE       /* remember_if_open */, \
93
    TRUE       /* hideable         */, \
94 95
    TRUE       /* dockable         */}

96 97 98 99 100 101 102 103 104 105 106 107
#define DOCK(id, new_func) \
  { id         /* identifier       */, \
    NULL       /* name             */, \
    NULL       /* blurb            */, \
    NULL       /* stock_id         */, \
    NULL       /* help_id          */, \
    new_func   /* new_func         */, \
    0          /* view_size        */, \
    FALSE      /* singleton        */, \
    FALSE      /* session_managed  */, \
    FALSE      /* remember_size    */, \
    FALSE      /* remember_if_open */, \
108
    TRUE       /* hideable         */, \
109 110
    FALSE      /* dockable         */}

111 112 113 114 115 116 117 118 119 120 121 122
#define DOCK_WINDOW(id, new_func) \
  { id         /* identifier       */, \
    NULL       /* name             */, \
    NULL       /* blurb            */, \
    NULL       /* stock_id         */, \
    NULL       /* help_id          */, \
    new_func   /* new_func         */, \
    0          /* view_size        */, \
    FALSE      /* singleton        */, \
    TRUE       /* session_managed  */, \
    TRUE       /* remember_size    */, \
    TRUE       /* remember_if_open */, \
123
    TRUE       /* hideable         */, \
124 125
    FALSE      /* dockable         */}

126 127 128 129 130 131 132 133 134 135 136 137
#define LISTGRID(id, name, blurb, stock_id, help_id, view_size) \
  { "gimp-"#id"-list"             /* identifier       */,  \
    name                          /* name             */,  \
    blurb                         /* blurb            */,  \
    stock_id                      /* stock_id         */,  \
    help_id                       /* help_id          */,  \
    dialogs_##id##_list_view_new  /* new_func         */,  \
    view_size                     /* view_size        */,  \
    FALSE                         /* singleton        */,  \
    FALSE                         /* session_managed  */,  \
    FALSE                         /* remember_size    */,  \
    TRUE                          /* remember_if_open */,  \
138
    TRUE                          /* hideable         */,  \
139 140 141 142 143 144 145 146 147 148 149 150
    TRUE                          /* dockable         */}, \
  { "gimp-"#id"-grid"             /* identifier       */,  \
    name                          /* name             */,  \
    blurb                         /* blurb            */,  \
    stock_id                      /* stock_id         */,  \
    help_id                       /* help_id          */,  \
    dialogs_##id##_grid_view_new  /* new_func         */,  \
    view_size                     /* view_size        */,  \
    FALSE                         /* singleton        */,  \
    FALSE                         /* session_managed  */,  \
    FALSE                         /* remember_size    */,  \
    TRUE                          /* remember_if_open */,  \
151
    TRUE                          /* hideable         */,  \
152 153 154 155 156 157 158 159 160 161 162 163 164 165
    TRUE                          /* dockable         */}

#define LIST(id, name, blurb, stock_id, help_id, view_size) \
  { "gimp-"#id"-list"             /* identifier       */, \
    name                          /* name             */, \
    blurb                         /* blurb            */, \
    stock_id                      /* stock_id         */, \
    help_id                       /* help_id          */, \
    dialogs_##id##_list_view_new  /* new_func         */, \
    view_size                     /* view_size        */, \
    FALSE                         /* singleton        */, \
    FALSE                         /* session_managed  */, \
    FALSE                         /* remember_size    */, \
    TRUE                          /* remember_if_open */, \
166
    TRUE                          /* hideable         */, \
167
    TRUE                          /* dockable         */}
168 169


170
static const GimpDialogFactoryEntry entries[] =
171
{
172
  /*  foreign toplevels without constructor  */
173
  FOREIGN ("gimp-brightness-contrast-tool-dialog", TRUE,  FALSE),
174
  FOREIGN ("gimp-color-balance-tool-dialog",       TRUE,  FALSE),
175 176 177 178
  FOREIGN ("gimp-color-picker-tool-dialog",        TRUE,  TRUE),
  FOREIGN ("gimp-colorize-tool-dialog",            TRUE,  FALSE),
  FOREIGN ("gimp-crop-tool-dialog",                TRUE,  FALSE),
  FOREIGN ("gimp-curves-tool-dialog",              TRUE,  TRUE),
179
  FOREIGN ("gimp-desaturate-tool-dialog",          TRUE,  FALSE),
180
  FOREIGN ("gimp-gegl-tool-dialog",                TRUE,  FALSE),
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
  FOREIGN ("gimp-hue-saturation-tool-dialog",      TRUE,  FALSE),
  FOREIGN ("gimp-levels-tool-dialog",              TRUE,  TRUE),
  FOREIGN ("gimp-measure-tool-dialog",             TRUE,  FALSE),
  FOREIGN ("gimp-posterize-tool-dialog",           TRUE,  FALSE),
  FOREIGN ("gimp-rotate-tool-dialog",              TRUE,  FALSE),
  FOREIGN ("gimp-scale-tool-dialog",               TRUE,  FALSE),
  FOREIGN ("gimp-shear-tool-dialog",               TRUE,  FALSE),
  FOREIGN ("gimp-text-tool-dialog",                TRUE,  TRUE),
  FOREIGN ("gimp-threshold-tool-dialog",           TRUE,  FALSE),
  FOREIGN ("gimp-perspective-tool-dialog",         TRUE,  FALSE),

  FOREIGN ("gimp-toolbox-color-dialog",            TRUE,  FALSE),
  FOREIGN ("gimp-gradient-editor-color-dialog",    TRUE,  FALSE),
  FOREIGN ("gimp-palette-editor-color-dialog",     TRUE,  FALSE),
  FOREIGN ("gimp-colormap-editor-color-dialog",    TRUE,  FALSE),

  FOREIGN ("gimp-controller-editor-dialog",        FALSE, TRUE),
  FOREIGN ("gimp-controller-action-dialog",        FALSE, TRUE),
199

200
  /*  ordinary toplevels  */
201 202 203 204 205 206 207 208
  TOPLEVEL ("gimp-image-new-dialog",
            dialogs_image_new_new,          FALSE, TRUE, FALSE),
  TOPLEVEL ("gimp-file-open-dialog",
            dialogs_file_open_new,          TRUE,  TRUE, TRUE),
  TOPLEVEL ("gimp-file-open-location-dialog",
            dialogs_file_open_location_new, FALSE, TRUE, FALSE),
  TOPLEVEL ("gimp-file-save-dialog",
            dialogs_file_save_new,          FALSE, TRUE, TRUE),
209 210
  TOPLEVEL ("gimp-file-export-dialog",
            dialogs_file_export_new,        FALSE, TRUE, TRUE),
211 212

  /*  singleton toplevels  */
213
  TOPLEVEL ("gimp-preferences-dialog",
214
            dialogs_preferences_get,        TRUE, TRUE,  FALSE),
215 216
  TOPLEVEL ("gimp-input-devices-dialog",
            dialogs_input_devices_get,      TRUE, TRUE,  FALSE),
217 218
  TOPLEVEL ("gimp-keyboard-shortcuts-dialog",
            dialogs_keyboard_shortcuts_get, TRUE, TRUE,  TRUE),
219
  TOPLEVEL ("gimp-module-dialog",
220
            dialogs_module_get,             TRUE, TRUE,  TRUE),
221 222
  TOPLEVEL ("gimp-palette-import-dialog",
            dialogs_palette_import_get,     TRUE, TRUE,  TRUE),
223
  TOPLEVEL ("gimp-tips-dialog",
224
            dialogs_tips_get,               TRUE, FALSE, FALSE),
225
  TOPLEVEL ("gimp-about-dialog",
226
            dialogs_about_get,              TRUE, FALSE, FALSE),
227
  TOPLEVEL ("gimp-error-dialog",
228
            dialogs_error_get,              TRUE, FALSE, FALSE),
229
  TOPLEVEL ("gimp-close-all-dialog",
230
            dialogs_close_all_get,          TRUE, FALSE, FALSE),
231
  TOPLEVEL ("gimp-quit-dialog",
232
            dialogs_quit_get,               TRUE, FALSE, FALSE),
233

234
  /*  docks  */
235 236 237 238 239
  DOCK ("gimp-dock",
        dialogs_dock_new),
  DOCK ("gimp-toolbox",
        dialogs_toolbox_new),

240 241 242 243 244 245
  /*  dock windows  */
  DOCK_WINDOW ("gimp-dock-window",
               dialogs_dock_window_new),
  DOCK_WINDOW ("gimp-toolbox-window",
               dialogs_toolbox_dock_window_new),

246
  /*  singleton dockables  */
247 248 249
  DOCKABLE ("gimp-tool-options",
            N_("Tool Options"), NULL, GIMP_STOCK_TOOL_OPTIONS,
            GIMP_HELP_TOOL_OPTIONS_DIALOG,
250
            dialogs_tool_options_new, 0, TRUE),
251 252 253
  DOCKABLE ("gimp-device-status",
            N_("Devices"), N_("Device Status"), GIMP_STOCK_DEVICE_STATUS,
            GIMP_HELP_DEVICE_STATUS_DIALOG,
254
            dialogs_device_status_new, 0, TRUE),
255 256 257
  DOCKABLE ("gimp-error-console",
            N_("Errors"), N_("Error Console"), GIMP_STOCK_WARNING,
            GIMP_HELP_ERRORS_DIALOG,
258 259
            dialogs_error_console_new, 0, TRUE),
  DOCKABLE ("gimp-cursor-view",
260 261
            N_("Pointer"), N_("Pointer Information"), GIMP_STOCK_CURSOR,
            GIMP_HELP_POINTER_INFO_DIALOG,
262
            dialogs_cursor_view_new, 0, TRUE),
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278

  /*  list & grid views  */
  LISTGRID (image, N_("Images"), NULL, GIMP_STOCK_IMAGES,
            GIMP_HELP_IMAGE_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (brush, N_("Brushes"), NULL, GIMP_STOCK_BRUSH,
            GIMP_HELP_BRUSH_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (pattern, N_("Patterns"), NULL, GIMP_STOCK_PATTERN,
            GIMP_HELP_PATTERN_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (gradient, N_("Gradients"), NULL, GIMP_STOCK_GRADIENT,
            GIMP_HELP_GRADIENT_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (palette, N_("Palettes"), NULL, GIMP_STOCK_PALETTE,
            GIMP_HELP_PALETTE_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (font, N_("Fonts"), NULL, GIMP_STOCK_FONT,
            GIMP_HELP_FONT_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (buffer, N_("Buffers"), NULL, GIMP_STOCK_BUFFER,
            GIMP_HELP_BUFFER_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
279
  LISTGRID (document, N_("History"), N_("Document History"), "document-open-recent",
280 281 282
            GIMP_HELP_DOCUMENT_DIALOG, GIMP_VIEW_SIZE_LARGE),
  LISTGRID (template, N_("Templates"), N_("Image Templates"), GIMP_STOCK_TEMPLATE,
            GIMP_HELP_TEMPLATE_DIALOG, GIMP_VIEW_SIZE_SMALL),
283

284
  /* Some things do not have grids, so just list */
285
  LIST (dynamics, N_("Paint Dynamics"), NULL, GIMP_STOCK_DYNAMICS,
286 287
        GIMP_HELP_DYNAMICS_DIALOG, GIMP_VIEW_SIZE_MEDIUM),

288
  /*  image related  */
289 290 291 292 293 294 295 296 297 298 299 300 301
  DOCKABLE ("gimp-layer-list",
            N_("Layers"), NULL, GIMP_STOCK_LAYERS,
            GIMP_HELP_LAYER_DIALOG,
            dialogs_layer_list_view_new, 0, FALSE),
  DOCKABLE ("gimp-channel-list",
            N_("Channels"), NULL, GIMP_STOCK_CHANNELS,
            GIMP_HELP_CHANNEL_DIALOG,
            dialogs_channel_list_view_new, 0, FALSE),
  DOCKABLE ("gimp-vectors-list",
            N_("Paths"), NULL, GIMP_STOCK_PATHS,
            GIMP_HELP_PATH_DIALOG,
            dialogs_vectors_list_view_new, 0, FALSE),
  DOCKABLE ("gimp-indexed-palette",
302
            N_("Colormap"), NULL, GIMP_STOCK_COLORMAP,
303 304 305 306 307 308 309 310 311 312 313 314 315 316
            GIMP_HELP_INDEXED_PALETTE_DIALOG,
            dialogs_colormap_editor_new, 0, FALSE),
  DOCKABLE ("gimp-histogram-editor",
            N_("Histogram"), NULL, GIMP_STOCK_HISTOGRAM,
            GIMP_HELP_HISTOGRAM_DIALOG,
            dialogs_histogram_editor_new, 0, FALSE),
  DOCKABLE ("gimp-selection-editor",
            N_("Selection"), N_("Selection Editor"), GIMP_STOCK_SELECTION,
            GIMP_HELP_SELECTION_DIALOG,
            dialogs_selection_editor_new, 0, FALSE),
  DOCKABLE ("gimp-undo-history",
            N_("Undo"), N_("Undo History"), GIMP_STOCK_UNDO_HISTORY,
            GIMP_HELP_UNDO_DIALOG,
            dialogs_undo_editor_new, 0, FALSE),
317 318 319 320
  DOCKABLE ("gimp-sample-point-editor",
            N_("Sample Points"), N_("Sample Points"), GIMP_STOCK_SAMPLE_POINT,
            GIMP_HELP_SAMPLE_POINT_DIALOG,
            dialogs_sample_point_editor_new, 0, FALSE),
321

322
  /*  display related  */
323 324 325 326
  DOCKABLE ("gimp-navigation-view",
            N_("Navigation"), N_("Display Navigation"), GIMP_STOCK_NAVIGATION,
            GIMP_HELP_NAVIGATION_DIALOG,
            dialogs_navigation_editor_new, 0, FALSE),
327

328
  /*  editors  */
329 330 331 332
  DOCKABLE ("gimp-color-editor",
            N_("FG/BG"), N_("FG/BG Color"), GIMP_STOCK_DEFAULT_COLORS,
            GIMP_HELP_COLOR_DIALOG,
            dialogs_color_editor_new, 0, FALSE),
333

334
  /*  singleton editors  */
335 336 337 338
  DOCKABLE ("gimp-brush-editor",
            N_("Brush Editor"), NULL, GIMP_STOCK_BRUSH,
            GIMP_HELP_BRUSH_EDITOR_DIALOG,
            dialogs_brush_editor_get, 0, TRUE),
339
  DOCKABLE ("gimp-dynamics-editor",
340
            N_("Paint Dynamics Editor"), NULL, GIMP_STOCK_DYNAMICS,
341 342
            GIMP_HELP_DYNAMICS_EDITOR_DIALOG,
            dialogs_dynamics_editor_get, 0, TRUE),
343 344 345 346 347 348 349 350
  DOCKABLE ("gimp-gradient-editor",
            N_("Gradient Editor"), NULL, GIMP_STOCK_GRADIENT,
            GIMP_HELP_GRADIENT_EDITOR_DIALOG,
            dialogs_gradient_editor_get, 0, TRUE),
  DOCKABLE ("gimp-palette-editor",
            N_("Palette Editor"), NULL, GIMP_STOCK_PALETTE,
            GIMP_HELP_PALETTE_EDITOR_DIALOG,
            dialogs_palette_editor_get, 0, TRUE)
351 352 353 354 355
};


/*  public functions  */

356
void
357 358
dialogs_init (Gimp            *gimp,
              GimpMenuFactory *menu_factory)
359
{
360 361
  gint i;

362
  g_return_if_fail (GIMP_IS_GIMP (gimp));
363
  g_return_if_fail (GIMP_IS_MENU_FACTORY (menu_factory));
364

365
  /* Toplevel */
Michael Natterer's avatar
Michael Natterer committed
366
  global_dialog_factory = gimp_dialog_factory_new ("toplevel",
367
                                                   gimp_get_user_context (gimp),
368
                                                   menu_factory);
369

370
  /* Display */
371 372
  global_display_factory = gimp_dialog_factory_new ("display",
                                                    gimp_get_user_context (gimp),
373
                                                    menu_factory);
374

375

376
  for (i = 0; i < G_N_ELEMENTS (entries); i++)
377
    gimp_dialog_factory_register_entry (global_dialog_factory,
378 379 380 381 382 383 384 385 386 387 388
                                        entries[i].identifier,
                                        gettext (entries[i].name),
                                        gettext (entries[i].blurb),
                                        entries[i].stock_id,
                                        entries[i].help_id,
                                        entries[i].new_func,
                                        entries[i].view_size,
                                        entries[i].singleton,
                                        entries[i].session_managed,
                                        entries[i].remember_size,
                                        entries[i].remember_if_open,
389
                                        entries[i].hideable,
390
                                        entries[i].dockable);
391 392

  gimp_dialog_factory_register_entry (global_display_factory,
393
                                      "gimp-empty-image-window",
394 395 396 397 398 399 400
                                      NULL, NULL,
                                      NULL, NULL,
                                      NULL,
                                      -1,
                                      TRUE,
                                      TRUE,
                                      TRUE,
401
                                      FALSE,
402
                                      FALSE,
403
                                      FALSE);
404 405

  global_recent_docks = gimp_list_new (GIMP_TYPE_SESSION_INFO, FALSE);
406
}
407 408

void
Michael Natterer's avatar
Michael Natterer committed
409
dialogs_exit (Gimp *gimp)
410
{
411 412
  g_return_if_fail (GIMP_IS_GIMP (gimp));

413 414
  if (global_dialog_factory)
    {
415
      g_object_unref (global_dialog_factory);
416 417 418
      global_dialog_factory = NULL;
    }

419 420 421 422 423
  if (global_display_factory)
    {
      g_object_unref (global_display_factory);
      global_display_factory = NULL;
    }
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

  if (global_recent_docks)
    {
      g_object_unref (global_recent_docks);
      global_recent_docks = NULL;
    }
}

void
dialogs_load_recent_docks (Gimp *gimp)
{
  gchar  *filename;
  GError *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  filename = gimp_personal_rc_file ("dockrc");

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  if (! gimp_config_deserialize_file (GIMP_CONFIG (global_recent_docks),
                                      filename,
                                      NULL, &error))
    {
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
450
        gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
451 452 453 454

      g_clear_error (&error);
    }

455 456
  gimp_list_reverse (GIMP_LIST (global_recent_docks));

457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
  g_free (filename);
}

void
dialogs_save_recent_docks (Gimp *gimp)
{
  gchar  *filename;
  GError *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  filename = gimp_personal_rc_file ("dockrc");

  if (gimp->be_verbose)
    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));

  if (! gimp_config_serialize_to_file (GIMP_CONFIG (global_recent_docks),
                                       filename,
                                       "recently closed docks",
                                       "end of recently closed docks",
                                       NULL, &error))
    {
479
      gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
480 481 482 483
      g_clear_error (&error);
    }

  g_free (filename);
484
}
485 486 487 488 489 490

GtkWidget *
dialogs_get_toolbox (void)
{
  GList *list;

491
  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (global_dialog_factory), NULL);
492

493
  for (list = gimp_dialog_factory_get_open_dialogs (global_dialog_factory);
494 495 496
       list;
       list = g_list_next (list))
    {
497 498
      if (GIMP_IS_DOCK_WINDOW (list->data) &&
          gimp_dock_window_has_toolbox (list->data))
499 500 501 502 503
        return list->data;
    }

  return NULL;
}