menus.c 20.7 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* 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
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17 18 19 20 21 22 23 24
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "appenv.h"
#include "colormaps.h"
#include "commands.h"
#include "fileops.h"
25
#include "general.h"
Elliot Lee's avatar
Elliot Lee committed
26 27 28 29 30 31 32
#include "gimprc.h"
#include "interface.h"
#include "menus.h"
#include "paint_funcs.h"
#include "procedural_db.h"
#include "scale.h"
#include "tools.h"
Manish Singh's avatar
Manish Singh committed
33
#include "gdisplay.h"
Chris Lahey's avatar
Chris Lahey committed
34
#include "docindex.h"
Elliot Lee's avatar
Elliot Lee committed
35

36 37 38
#define MRU_MENU_ENTRY_SIZE sizeof ("/File/MRU00")
#define MRU_MENU_ACCEL_SIZE sizeof ("<control>0")

Elliot Lee's avatar
Elliot Lee committed
39
static void menus_init (void);
40

41 42
static GSList *last_opened_raw_filenames = NULL;

43
static GtkItemFactoryEntry toolbox_entries[] =
Elliot Lee's avatar
Elliot Lee committed
44
{
45 46 47 48 49 50 51 52 53 54
  { "/File/New", "<control>N", file_new_cmd_callback, 0 },
  { "/File/Open", "<control>O", file_open_cmd_callback, 0 },
  { "/File/About...", NULL, about_dialog_cmd_callback, 0 },
  { "/File/Preferences...", NULL, file_pref_cmd_callback, 0 },
  { "/File/Tip of the day", NULL, tips_dialog_cmd_callback, 0 },
  { "/File/---", NULL, NULL, 0, "<Separator>" },
  { "/File/Dialogs/Brushes...", "<control><shift>B", dialogs_brushes_cmd_callback, 0 },
  { "/File/Dialogs/Patterns...", "<control><shift>P", dialogs_patterns_cmd_callback, 0 },
  { "/File/Dialogs/Palette...", "<control>P", dialogs_palette_cmd_callback, 0 },
  { "/File/Dialogs/Gradient Editor...", "<control>G", dialogs_gradient_editor_cmd_callback, 0 },
55
  { "/File/Dialogs/Layers & Channels...", "<control>L", dialogs_lc_cmd_callback, 0 },
56 57 58
  { "/File/Dialogs/Tool Options...", "<control><shift>T", dialogs_tools_options_cmd_callback, 0 },
  { "/File/Dialogs/Input Devices...", NULL, dialogs_input_devices_cmd_callback, 0 },
  { "/File/Dialogs/Device Status...", NULL, dialogs_device_status_cmd_callback, 0 },
59
  { "/File/Dialogs/Document Index...", NULL, raise_idea_callback, 0 },
60
  { "/File/Dialogs/Error Console...", NULL, dialogs_error_console_cmd_callback, 0 },
61 62 63 64 65
  { "/File/---", NULL, NULL, 0, "<Separator>" },
};
static guint n_toolbox_entries = sizeof (toolbox_entries) / sizeof (toolbox_entries[0]);
static GtkItemFactory *toolbox_factory = NULL;

66 67 68
static GtkItemFactoryEntry file_menu_separator = { "/File/---", NULL, NULL, 0, "<Separator>" };
static GtkItemFactoryEntry toolbox_end = { "/File/Quit", "<control>Q", file_quit_cmd_callback, 0 };

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
static GtkItemFactoryEntry image_entries[] =
{
  { "/File/New", "<control>N", file_new_cmd_callback, 1 },
  { "/File/Open", "<control>O", file_open_cmd_callback, 0 },
  { "/File/Save", "<control>S", file_save_cmd_callback, 0 },
  { "/File/Save as", NULL, file_save_as_cmd_callback, 0 },
  { "/File/Preferences...", NULL, file_pref_cmd_callback, 0 },
  { "/File/---", NULL, NULL, 0, "<Separator>" },
  
  
  { "/File/Close", "<control>W", file_close_cmd_callback, 0 },
  { "/File/Quit", "<control>Q", file_quit_cmd_callback, 0 },
  { "/File/---", NULL, NULL, 0, "<Separator>" },
  
  { "/Edit/Cut", "<control>X", edit_cut_cmd_callback, 0 },
  { "/Edit/Copy", "<control>C", edit_copy_cmd_callback, 0 },
  { "/Edit/Paste", "<control>V", edit_paste_cmd_callback, 0 },
  { "/Edit/Paste Into", NULL, edit_paste_into_cmd_callback, 0 },
  { "/Edit/Clear", "<control>K", edit_clear_cmd_callback, 0 },
88
  { "/Edit/Fill", "<control>period", edit_fill_cmd_callback, 0 },
89 90 91
  { "/Edit/Stroke", NULL, edit_stroke_cmd_callback, 0 },
  { "/Edit/Undo", "<control>Z", edit_undo_cmd_callback, 0 },
  { "/Edit/Redo", "<control>R", edit_redo_cmd_callback, 0 },
Manish Singh's avatar
Manish Singh committed
92
  { "/Edit/---", NULL, NULL, 0, "<Separator>" },
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
  { "/Edit/Cut Named", "<control><shift>X", edit_named_cut_cmd_callback, 0 },
  { "/Edit/Copy Named", "<control><shift>C", edit_named_copy_cmd_callback, 0 },
  { "/Edit/Paste Named", "<control><shift>V", edit_named_paste_cmd_callback, 0 },
  { "/Edit/---", NULL, NULL, 0, "<Separator>" },
  
  { "/Select/Toggle", "<control>T", select_toggle_cmd_callback, 0 },
  { "/Select/Invert", "<control>I", select_invert_cmd_callback, 0 },
  { "/Select/All", "<control>A", select_all_cmd_callback, 0 },
  { "/Select/None", "<control><shift>A", select_none_cmd_callback, 0 },
  { "/Select/Float", "<control><shift>L", select_float_cmd_callback, 0 },
  { "/Select/Sharpen", "<control><shift>H", select_sharpen_cmd_callback, 0 },
  { "/Select/Border", "<control><shift>B", select_border_cmd_callback, 0 },
  { "/Select/Feather", "<control><shift>F", select_feather_cmd_callback, 0 },
  { "/Select/Grow", NULL, select_grow_cmd_callback, 0 },
  { "/Select/Shrink", NULL, select_shrink_cmd_callback, 0 },
  { "/Select/Save To Channel", NULL, select_save_cmd_callback, 0 },
109 110 111
  /*
  { "/Select/By Color...", NULL, tools_select_cmd_callback, BY_COLOR_SELECT }, 
  */
112 113
  { "/View/Zoom In", "equal", view_zoomin_cmd_callback, 0 },
  { "/View/Zoom Out", "minus", view_zoomout_cmd_callback, 0 },
114 115 116 117 118 119 120 121 122 123 124
  { "/View/Zoom/16:1", NULL, view_zoom_16_1_callback, 0 },
  { "/View/Zoom/8:1", NULL, view_zoom_8_1_callback, 0 },
  { "/View/Zoom/4:1", NULL, view_zoom_4_1_callback, 0 },
  { "/View/Zoom/2:1", NULL, view_zoom_2_1_callback, 0 },
  { "/View/Zoom/1:1", "1", view_zoom_1_1_callback, 0 },
  { "/View/Zoom/1:2", NULL, view_zoom_1_2_callback, 0 },
  { "/View/Zoom/1:4", NULL, view_zoom_1_4_callback, 0 },
  { "/View/Zoom/1:8", NULL, view_zoom_1_8_callback, 0 },
  { "/View/Zoom/1:16", NULL, view_zoom_1_16_callback, 0 },
  { "/View/Window Info...", "<control><shift>I", view_window_info_cmd_callback, 0 },
  { "/View/Toggle Rulers", "<control><shift>R", view_toggle_rulers_cmd_callback, 0, "<ToggleItem>" },
125
  { "/View/Toggle Statusbar", "<control><shift>S", view_toggle_statusbar_cmd_callback, 0, "<ToggleItem>" },
126 127 128 129 130 131 132 133
  { "/View/Toggle Guides", "<control><shift>T", view_toggle_guides_cmd_callback, 0, "<ToggleItem>" },
  { "/View/Snap To Guides", NULL, view_snap_to_guides_cmd_callback, 0, "<ToggleItem>" },
  { "/View/---", NULL, NULL, 0, "<Separator>" },
  { "/View/New View", NULL, view_new_view_cmd_callback, 0 },
  { "/View/Shrink Wrap", "<control>E", view_shrink_wrap_cmd_callback, 0 },
  
  { "/Image/Colors/Equalize", NULL, image_equalize_cmd_callback, 0 },
  { "/Image/Colors/Invert", NULL, image_invert_cmd_callback, 0 },
134 135 136
  /*
  { "/Image/Colors/Posterize", NULL, tools_select_cmd_callback, POSTERIZE },
  { "/Image/Colors/Threshold", NULL, tools_select_cmd_callback, THRESHOLD },
137
  { "/Image/Colors/---", NULL, NULL, 0, "<Separator>" },
138 139 140 141 142 143
  { "/Image/Colors/Color Balance", NULL, tools_select_cmd_callback, COLOR_BALANCE },
  { "/Image/Colors/Brightness-Contrast", NULL, tools_select_cmd_callback, BRIGHTNESS_CONTRAST },
  { "/Image/Colors/Hue-Saturation", NULL, tools_select_cmd_callback, 0 },
  { "/Image/Colors/Curves", NULL, tools_select_cmd_callback, CURVES },
  { "/Image/Colors/Levels", NULL, tools_select_cmd_callback, LEVELS },
  */
144 145 146 147 148 149 150 151 152 153 154 155 156 157
  { "/Image/Colors/---", NULL, NULL, 0, "<Separator>" },
  { "/Image/Colors/Desaturate", NULL, image_desaturate_cmd_callback, 0 },
  { "/Image/Channel Ops/Duplicate", "<control>D", channel_ops_duplicate_cmd_callback, 0 },
  { "/Image/Channel Ops/Offset", "<control><shift>O", channel_ops_offset_cmd_callback, 0 },
  { "/Image/Alpha/Add Alpha Channel", NULL, layers_add_alpha_channel_cmd_callback, 0 },
  
  { "/Image/---", NULL, NULL, 0, "<Separator>" },
  { "/Image/RGB", NULL, image_convert_rgb_cmd_callback, 0 },
  { "/Image/Grayscale", NULL, image_convert_grayscale_cmd_callback, 0 },
  { "/Image/Indexed", NULL, image_convert_indexed_cmd_callback, 0 },
  { "/Image/---", NULL, NULL, 0, "<Separator>" },
  { "/Image/Resize", NULL, image_resize_cmd_callback, 0 },
  { "/Image/Scale", NULL, image_scale_cmd_callback, 0 },
  { "/Image/---", NULL, NULL, 0, "<Separator>" },
158
  /*  { "/Image/Histogram", NULL, tools_select_cmd_callback, HISTOGRAM}, */
159 160 161 162 163 164 165 166 167 168 169 170
  { "/Image/---", NULL, NULL, 0, "<Separator>" },
  
  { "/Layers/Layers & Channels...", "<control>L", dialogs_lc_cmd_callback, 0 },
  { "/Layers/Raise Layer", "<control>F", layers_raise_cmd_callback, 0 },
  { "/Layers/Lower Layer", "<control>B", layers_lower_cmd_callback, 0 },
  { "/Layers/Anchor Layer", "<control>H", layers_anchor_cmd_callback, 0 },
  { "/Layers/Merge Visible Layers", "<control>M", layers_merge_cmd_callback, 0 },
  { "/Layers/Flatten Image", NULL, layers_flatten_cmd_callback, 0 },
  { "/Layers/Alpha To Selection", NULL, layers_alpha_select_cmd_callback, 0 },
  { "/Layers/Mask To Selection", NULL, layers_mask_select_cmd_callback, 0 },
  { "/Layers/Add Alpha Channel", NULL, layers_add_alpha_channel_cmd_callback, 0 },
  
171
  /*  { "/Tools/Rect Select", "R", tools_select_cmd_callback, RECT_SELECT },
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
  { "/Tools/Ellipse Select", "E", tools_select_cmd_callback, ELLIPSE_SELECT },
  { "/Tools/Free Select", "F", tools_select_cmd_callback, FREE_SELECT },
  { "/Tools/Fuzzy Select", "Z", tools_select_cmd_callback, FUZZY_SELECT },
  { "/Tools/Bezier Select", "B", tools_select_cmd_callback, BEZIER_SELECT },
  { "/Tools/Intelligent Scissors", "I", tools_select_cmd_callback, ISCISSORS },
  { "/Tools/Move", "M", tools_select_cmd_callback, MOVE },
  { "/Tools/Magnify", "<shift>M", tools_select_cmd_callback, MAGNIFY },
  { "/Tools/Crop", "<shift>C", tools_select_cmd_callback, CROP },
  { "/Tools/Transform", "<shift>T", tools_select_cmd_callback, ROTATE },
  { "/Tools/Flip", "<shift>F", tools_select_cmd_callback, FLIP_HORZ },
  { "/Tools/Text", "T", tools_select_cmd_callback, TEXT },
  { "/Tools/Color Picker", "O", tools_select_cmd_callback, COLOR_PICKER },
  { "/Tools/Bucket Fill", "<shift>B", tools_select_cmd_callback, BUCKET_FILL },
  { "/Tools/Blend", "L", tools_select_cmd_callback, BLEND },
  { "/Tools/Paintbrush", "P", tools_select_cmd_callback, PAINTBRUSH },
  { "/Tools/Pencil", "<shift>P", tools_select_cmd_callback, PENCIL },
  { "/Tools/Eraser", "<shift>E", tools_select_cmd_callback, ERASER },
  { "/Tools/Airbrush", "A", tools_select_cmd_callback, AIRBRUSH },
  { "/Tools/Clone", "C", tools_select_cmd_callback, CLONE },
  { "/Tools/Convolve", "V", tools_select_cmd_callback, CONVOLVE },
192
  { "/Tools/Ink", "K", tools_select_cmd_callback, INK },
193
  { "/Tools/Default Colors", "D", tools_default_colors_cmd_callback, 0 },
194
  { "/Tools/Swap Colors", "X", tools_swap_colors_cmd_callback, 0 }, */ 
195
  { "/Tools/Toolbox", NULL, toolbox_raise_callback, 0 },
196
  { "/Tools/---", NULL, NULL, 0, "<Separator>" },  
Manish Singh's avatar
Manish Singh committed
197 198
  { "/Tools/Default Colors", "D", tools_default_colors_cmd_callback, 0 },
  { "/Tools/Swap Colors", "X", tools_swap_colors_cmd_callback, 0 },
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
  { "/Filters/", NULL, NULL, 0 },
  { "/Filters/Repeat last", "<alt>F", filters_repeat_cmd_callback, 0x0 },
  { "/Filters/Re-show last", "<alt><shift>F", filters_repeat_cmd_callback, 0x1 },
  { "/Filters/---", NULL, NULL, 0, "<Separator>" },
  
  { "/Script-Fu/", NULL, NULL, 0 },
  
  { "/Dialogs/Brushes...", "<control><shift>B", dialogs_brushes_cmd_callback, 0 },
  { "/Dialogs/Patterns...", "<control><shift>P", dialogs_patterns_cmd_callback, 0 },
  { "/Dialogs/Palette...", "<control>P", dialogs_palette_cmd_callback, 0 },
  { "/Dialogs/Gradient Editor...", "<control>G", dialogs_gradient_editor_cmd_callback, 0 },
  { "/Dialogs/Layers & Channels...", "<control>L", dialogs_lc_cmd_callback, 0 },
  { "/Dialogs/Indexed Palette...", NULL, dialogs_indexed_palette_cmd_callback, 0 },
  { "/Dialogs/Tool Options...", NULL, dialogs_tools_options_cmd_callback, 0 },
  { "/Dialogs/Input Devices...", NULL, dialogs_input_devices_cmd_callback, 0 },
  { "/Dialogs/Device Status...", NULL, dialogs_device_status_cmd_callback, 0 },
};
static guint n_image_entries = sizeof (image_entries) / sizeof (image_entries[0]);
static GtkItemFactory *image_factory = NULL;
Elliot Lee's avatar
Elliot Lee committed
218
  
219 220 221 222 223 224 225
static GtkItemFactoryEntry load_entries[] =
{
  { "/Automatic", NULL, file_load_by_extension_callback, 0 },
  { "/---", NULL, NULL, 0, "<Separator>" },
};
static guint n_load_entries = sizeof (load_entries) / sizeof (load_entries[0]);
static GtkItemFactory *load_factory = NULL;
Manish Singh's avatar
Manish Singh committed
226
  
227 228 229 230
static GtkItemFactoryEntry save_entries[] =
{
  { "/By extension", NULL, file_save_by_extension_callback, 0 },
  { "/---", NULL, NULL, 0, "<Separator>" },
Elliot Lee's avatar
Elliot Lee committed
231
};
232 233
static guint n_save_entries = sizeof (save_entries) / sizeof (save_entries[0]);
static GtkItemFactory *save_factory = NULL;
Elliot Lee's avatar
Elliot Lee committed
234 235 236

static int initialize = TRUE;

237
extern int num_tools;
Elliot Lee's avatar
Elliot Lee committed
238 239 240

void
menus_get_toolbox_menubar (GtkWidget           **menubar,
241
			   GtkAccelGroup       **accel_group)
Elliot Lee's avatar
Elliot Lee committed
242 243 244
{
  if (initialize)
    menus_init ();
245
  
Elliot Lee's avatar
Elliot Lee committed
246
  if (menubar)
247 248 249
    *menubar = toolbox_factory->widget;
  if (accel_group)
    *accel_group = toolbox_factory->accel_group;
Elliot Lee's avatar
Elliot Lee committed
250 251 252 253
}

void
menus_get_image_menu (GtkWidget           **menu,
254
		      GtkAccelGroup	  **accel_group)
Elliot Lee's avatar
Elliot Lee committed
255 256 257 258 259
{
  if (initialize)
    menus_init ();

  if (menu)
260 261 262
    *menu = image_factory->widget;
  if (accel_group)
    *accel_group = image_factory->accel_group;
Elliot Lee's avatar
Elliot Lee committed
263 264 265 266
}

void
menus_get_load_menu (GtkWidget           **menu,
267
		     GtkAccelGroup	 **accel_group)
Elliot Lee's avatar
Elliot Lee committed
268 269 270 271 272
{
  if (initialize)
    menus_init ();

  if (menu)
273 274 275
    *menu = load_factory->widget;
  if (accel_group)
    *accel_group = load_factory->accel_group;
Elliot Lee's avatar
Elliot Lee committed
276 277 278 279
}

void
menus_get_save_menu (GtkWidget           **menu,
280
		     GtkAccelGroup	 **accel_group)
Elliot Lee's avatar
Elliot Lee committed
281 282 283 284 285
{
  if (initialize)
    menus_init ();

  if (menu)
286 287 288
    *menu = save_factory->widget;
  if (accel_group)
    *accel_group = save_factory->accel_group;
Elliot Lee's avatar
Elliot Lee committed
289 290 291 292 293 294 295 296 297
}

void
menus_create (GtkMenuEntry *entries,
	      int           nmenu_entries)
{
  if (initialize)
    menus_init ();

298
  gtk_item_factory_create_menu_entries (nmenu_entries, entries);
Elliot Lee's avatar
Elliot Lee committed
299 300
}

301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
void
menus_tools_create (ToolInfo *tool_info)
{
  GtkItemFactoryEntry entry;
  
  /* entry.path = g_strconcat ("<Image>", tool_info->menu_path, NULL);*/
  /* entry.callback_data = tool_info; */
  entry.path = tool_info->menu_path;
  entry.accelerator = tool_info->menu_accel;
  entry.callback = tools_select_cmd_callback;
  entry.callback_action = tool_info->tool_id;
  entry.item_type = NULL;
 
  fflush(stderr);
  /*menus_create (&entry, 1);*/
  gtk_item_factory_create_item (image_factory,
				&entry,
				(gpointer)tool_info,
				2);

}

Elliot Lee's avatar
Elliot Lee committed
323 324 325 326
void
menus_set_sensitive (char *path,
		     int   sensitive)
{
327 328
  GtkItemFactory *ifactory;
  GtkWidget *widget = NULL;
Elliot Lee's avatar
Elliot Lee committed
329 330 331 332

  if (initialize)
    menus_init ();

333 334 335 336 337 338 339 340 341 342
  ifactory = gtk_item_factory_from_path (path);

  if (ifactory)
    {
      widget = gtk_item_factory_get_widget (ifactory, path);
      
      gtk_widget_set_sensitive (widget, sensitive);
    }
  if (!ifactory || !widget)
    printf ("Unable to set sensitivity for menu which doesn't exist:\n%s", path);
Elliot Lee's avatar
Elliot Lee committed
343 344 345 346 347 348
}

void
menus_set_state (char *path,
		 int   state)
{
349 350
  GtkItemFactory *ifactory;
  GtkWidget *widget = NULL;
Elliot Lee's avatar
Elliot Lee committed
351 352 353 354

  if (initialize)
    menus_init ();

355
  ifactory = gtk_item_factory_from_path (path);
Elliot Lee's avatar
Elliot Lee committed
356

357 358 359
  if (ifactory)
    {
      widget = gtk_item_factory_get_widget (ifactory, path);
Elliot Lee's avatar
Elliot Lee committed
360

361 362 363 364 365 366 367
      if (widget && GTK_IS_CHECK_MENU_ITEM (widget))
	gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (widget), state);
      else
	widget = NULL;
    }
  if (!ifactory || !widget)
    printf ("Unable to set state for menu which doesn't exist:\n%s", path);
Elliot Lee's avatar
Elliot Lee committed
368 369 370 371 372 373 374 375
}

void
menus_destroy (char *path)
{
  if (initialize)
    menus_init ();

376
  gtk_item_factories_path_delete (NULL, path);
Elliot Lee's avatar
Elliot Lee committed
377 378 379 380 381
}

void
menus_quit ()
{
382 383 384 385 386
  gchar *filename;

  filename = g_strconcat (gimp_directory (), "/menurc", NULL);
  gtk_item_factory_dump_rc (filename, NULL, TRUE);
  g_free (filename);
Elliot Lee's avatar
Elliot Lee committed
387

scott's avatar
scott committed
388 389
  if (!initialize)
    {
390 391 392 393
      gtk_object_unref (GTK_OBJECT (toolbox_factory));
      gtk_object_unref (GTK_OBJECT (image_factory));
      gtk_object_unref (GTK_OBJECT (load_factory));
      gtk_object_unref (GTK_OBJECT (save_factory));
scott's avatar
scott committed
394 395
    }

Elliot Lee's avatar
Elliot Lee committed
396 397
}

398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
void
menus_last_opened_cmd_callback (GtkWidget           *widget,
                                gpointer             callback_data,
                                guint                num)
{
  gchar *filename, *raw_filename;

  raw_filename = ((GString *) g_slist_nth_data (last_opened_raw_filenames, num))->str;
  filename = prune_filename (raw_filename);

  if (!file_open(raw_filename, filename))
    g_message ("Error opening file: %s\n", raw_filename);
}

void
menus_last_opened_update_labels ()
{
  GSList	*filename_slist;
  GString	*entry_filename, *path;
  GtkWidget	*widget;
  gint		i;
419
  guint         num_entries;
420 421 422 423 424

  entry_filename = g_string_new ("");
  path = g_string_new ("");

  filename_slist = last_opened_raw_filenames;
425
  num_entries = g_slist_length (last_opened_raw_filenames); 
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449

  for (i = 1; i <= num_entries; i++)
    {
      g_string_sprintf (entry_filename, "%d. %s", i, prune_filename (((GString *) filename_slist->data)->str));

      g_string_sprintf (path, "/File/MRU%02d", i);

      widget = gtk_item_factory_get_widget (toolbox_factory, path->str);
      gtk_widget_show (widget);

      gtk_label_set (GTK_LABEL (GTK_BIN (widget)->child), entry_filename->str);
      
      filename_slist = filename_slist->next;
    }

  g_string_free (entry_filename, TRUE);
  g_string_free (path, TRUE);
}

void
menus_last_opened_add (gchar *filename)
{
  GString	*raw_filename;
  GtkWidget	*widget;
450 451 452
  guint         num_entries;

  num_entries = g_slist_length (last_opened_raw_filenames);
453 454 455

  if (num_entries == last_opened_size)
    {
456 457
      g_slist_remove_link (last_opened_raw_filenames, 
			   g_slist_last (last_opened_raw_filenames));
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
    }

  raw_filename = g_string_new (filename);
  last_opened_raw_filenames = g_slist_prepend (last_opened_raw_filenames, raw_filename);

  if (num_entries == 0)
    {
      widget = gtk_item_factory_get_widget (toolbox_factory, file_menu_separator.path);
      gtk_widget_show (widget);
    }

  menus_last_opened_update_labels ();
}

void
menus_init_mru ()
{
  gchar			*paths, *accelerators;
  gint			i;
  GtkItemFactoryEntry	*last_opened_entries;
  GtkWidget		*widget;
  
  last_opened_entries = g_new (GtkItemFactoryEntry, last_opened_size);

  paths = g_new (gchar, last_opened_size * MRU_MENU_ENTRY_SIZE);
  accelerators = g_new (gchar, 9 * MRU_MENU_ACCEL_SIZE);

  for (i = 0; i < last_opened_size; i++)
    {
      gchar *path, *accelerator;
      
      path = &paths[i * MRU_MENU_ENTRY_SIZE];
      if (i < 9)
        accelerator = &accelerators[i * MRU_MENU_ACCEL_SIZE];
      else
        accelerator = NULL;
    
      last_opened_entries[i].path = path;
      last_opened_entries[i].accelerator = accelerator;
      last_opened_entries[i].callback = (GtkItemFactoryCallback) menus_last_opened_cmd_callback;
      last_opened_entries[i].callback_action = i;
      last_opened_entries[i].item_type = NULL;

      sprintf (path, "/File/MRU%02d", i + 1);
      sprintf (accelerator, "<control>%d", i + 1);
    }

  gtk_item_factory_create_items_ac (toolbox_factory, last_opened_size,
  				    last_opened_entries, NULL, 2);
  gtk_item_factory_create_item (toolbox_factory, &file_menu_separator, NULL, 2);
  gtk_item_factory_create_item (toolbox_factory, &toolbox_end, NULL, 2);

  for (i=0; i < last_opened_size; i++)
    {
      widget = gtk_item_factory_get_widget (toolbox_factory,
      					    last_opened_entries[i].path);
      gtk_widget_hide (widget);
    }

  widget = gtk_item_factory_get_widget (toolbox_factory, file_menu_separator.path);
  gtk_widget_hide (widget);
  
  g_free (paths);
  g_free (accelerators);
  g_free (last_opened_entries);
}

/*  This is separate from menus_init() in case the last_opened_size changes,
    or for any other reason we might want to regen just the toolbox menu     */
void
menus_init_toolbox ()
{
  toolbox_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<Toolbox>", NULL);
  gtk_item_factory_create_items_ac (toolbox_factory, n_toolbox_entries,
				    toolbox_entries, NULL, 2);
  menus_init_mru ();
}
Elliot Lee's avatar
Elliot Lee committed
535 536 537 538

static void
menus_init ()
{
539 540
  int i;

Elliot Lee's avatar
Elliot Lee committed
541 542
  if (initialize)
    {
543
      gchar *filename;
Elliot Lee's avatar
Elliot Lee committed
544

545
      initialize = FALSE;
Elliot Lee's avatar
Elliot Lee committed
546

547 548
      menus_init_toolbox ();

549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
      image_factory = gtk_item_factory_new (GTK_TYPE_MENU, "<Image>", NULL);
      gtk_item_factory_create_items_ac (image_factory,
					n_image_entries,
					image_entries,
					NULL, 2);
      load_factory = gtk_item_factory_new (GTK_TYPE_MENU, "<Load>", NULL);
      gtk_item_factory_create_items_ac (load_factory,
					n_load_entries,
					load_entries,
					NULL, 2);
      save_factory = gtk_item_factory_new (GTK_TYPE_MENU, "<Save>", NULL);
      gtk_item_factory_create_items_ac (save_factory,
					n_save_entries,
					save_entries,
					NULL, 2);
564 565 566 567 568 569
      for (i = 0; i < num_tools; i++)
	{
	  /* FIXME this need to use access functions to check a flag */
	  if (tool_info[i].menu_path)
	    menus_tools_create (tool_info+i);
	}
570 571 572
      filename = g_strconcat (gimp_directory (), "/menurc", NULL);
      gtk_item_factory_parse_rc (filename);
      g_free (filename);
Elliot Lee's avatar
Elliot Lee committed
573 574
    }
}