gtkitemfactory.c 42.3 KB
Newer Older
Tim Janik's avatar
Tim Janik committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * GtkItemFactory: Flexible item factory with automatic rc handling
 * Copyright (C) 1998 Tim Janik
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
22 23 24 25 26 27 28 29

/*
 * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

30 31
#include	"config.h"

Tim Janik's avatar
Tim Janik committed
32 33 34 35 36 37 38 39
#include	"gtkitemfactory.h"
#include	"gtk/gtksignal.h"
#include	"gtk/gtkoptionmenu.h"
#include	"gtk/gtkmenubar.h"
#include	"gtk/gtkmenu.h"
#include	"gtk/gtkmenuitem.h"
#include	"gtk/gtkradiomenuitem.h"
#include	"gtk/gtkcheckmenuitem.h"
40
#include	"gtk/gtktearoffmenuitem.h"
Tim Janik's avatar
Tim Janik committed
41
#include	"gtk/gtkaccellabel.h"
42
#include        "gdk/gdkkeysyms.h"
Tim Janik's avatar
Tim Janik committed
43 44 45
#include	<string.h>
#include	<sys/stat.h>
#include	<fcntl.h>
46
#ifdef HAVE_UNISTD_H
Tim Janik's avatar
Tim Janik committed
47
#include	<unistd.h>
48
#endif
49
#include	<stdio.h>
Tim Janik's avatar
Tim Janik committed
50

51
#ifdef NATIVE_WIN32
52 53 54 55 56 57
#include	<io.h>		/* For _open and _close */

#ifndef S_ISREG
#define S_ISREG(mode) ((mode)&_S_IFREG)
#endif
#endif
Tim Janik's avatar
Tim Janik committed
58 59 60 61 62 63 64 65 66


/* --- defines --- */
#define		ITEM_FACTORY_STRING	((gchar*) item_factory_string)
#define		ITEM_BLOCK_SIZE		(128)


/* --- structures --- */
typedef struct	_GtkIFCBData		GtkIFCBData;
67
typedef struct  _GtkIFDumpData		GtkIFDumpData;
Tim Janik's avatar
Tim Janik committed
68 69
struct _GtkIFCBData
{
70 71 72 73
  GtkItemFactoryCallback  func;
  guint			  callback_type;
  gpointer		  func_data;
  guint			  callback_action;
Tim Janik's avatar
Tim Janik committed
74
};
75 76 77 78 79 80 81
struct _GtkIFDumpData
{
  GtkPrintFunc	         print_func;
  gpointer	         func_data;
  guint		         modified_only : 1;
  GtkPatternSpec	*pspec;
};
Tim Janik's avatar
Tim Janik committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96


/* --- prototypes --- */
static void	gtk_item_factory_class_init		(GtkItemFactoryClass  *klass);
static void	gtk_item_factory_init			(GtkItemFactory	      *ifactory);
static void	gtk_item_factory_destroy		(GtkObject	      *object);
static void	gtk_item_factory_finalize		(GtkObject	      *object);


/* --- static variables --- */
static GtkItemFactoryClass *gtk_item_factory_class = NULL;
static GtkObjectClass	*parent_class = NULL;
static const gchar	*item_factory_string = "Gtk-<ItemFactory>";
static GMemChunk	*ifactory_item_chunks = NULL;
static GMemChunk	*ifactory_cb_data_chunks = NULL;
97 98 99
static GQuark		 quark_popup_data = 0;
static GQuark		 quark_if_menu_pos = 0;
static GQuark		 quark_item_factory = 0;
100 101 102
static GQuark		 quark_item_path = 0;
static GQuark		 quark_action = 0;
static GQuark		 quark_accel_group = 0;
103 104 105 106 107
static GQuark		 quark_type_item = 0;
static GQuark		 quark_type_title = 0;
static GQuark		 quark_type_radio_item = 0;
static GQuark		 quark_type_check_item = 0;
static GQuark		 quark_type_toggle_item = 0;
108
static GQuark		 quark_type_tearoff_item = 0;
109 110 111
static GQuark		 quark_type_separator_item = 0;
static GQuark		 quark_type_branch = 0;
static GQuark		 quark_type_last_branch = 0;
Tim Janik's avatar
Tim Janik committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
static	GScannerConfig	ifactory_scanner_config =
{
  (
   " \t\n"
   )			/* cset_skip_characters */,
  (
   G_CSET_a_2_z
   "_"
   G_CSET_A_2_Z
   )			/* cset_identifier_first */,
  (
   G_CSET_a_2_z
   "-+_0123456789"
   G_CSET_A_2_Z
   G_CSET_LATINS
   G_CSET_LATINC
   )			/* cset_identifier_nth */,
  ( ";\n" )		/* cpair_comment_single */,
  
  FALSE			/* case_sensitive */,
  
  TRUE			/* skip_comment_multi */,
  TRUE			/* skip_comment_single */,
  FALSE			/* scan_comment_multi */,
  TRUE			/* scan_identifier */,
  FALSE			/* scan_identifier_1char */,
  FALSE			/* scan_identifier_NULL */,
  TRUE			/* scan_symbols */,
  TRUE			/* scan_binary */,
  TRUE			/* scan_octal */,
  TRUE			/* scan_float */,
  TRUE			/* scan_hex */,
  FALSE			/* scan_hex_dollar */,
  TRUE			/* scan_string_sq */,
  TRUE			/* scan_string_dq */,
  TRUE			/* numbers_2_int */,
  FALSE			/* int_2_float */,
  FALSE			/* identifier_2_string */,
  TRUE			/* char_2_token */,
  FALSE			/* symbol_2_token */,
};


/* --- functions --- */
GtkType
gtk_item_factory_get_type (void)
{
  static GtkType item_factory_type = 0;
  
  if (!item_factory_type)
    {
163
      static const GtkTypeInfo item_factory_info =
Tim Janik's avatar
Tim Janik committed
164 165 166 167 168 169
      {
	"GtkItemFactory",
	sizeof (GtkItemFactory),
	sizeof (GtkItemFactoryClass),
	(GtkClassInitFunc) gtk_item_factory_class_init,
	(GtkObjectInitFunc) gtk_item_factory_init,
170 171
	/* reserved_1 */ NULL,
	/* reserved_2 */ NULL,
172
        (GtkClassInitFunc) NULL,
Tim Janik's avatar
Tim Janik committed
173 174
      };
      
175
      item_factory_type = gtk_type_unique (GTK_TYPE_OBJECT, &item_factory_info);
Tim Janik's avatar
Tim Janik committed
176 177 178 179 180 181 182 183 184 185 186 187
    }
  
  return item_factory_type;
}

static void
gtk_item_factory_class_init (GtkItemFactoryClass  *class)
{
  GtkObjectClass *object_class;

  gtk_item_factory_class = class;

188
  parent_class = gtk_type_class (GTK_TYPE_OBJECT);
Tim Janik's avatar
Tim Janik committed
189 190 191 192 193 194 195 196 197

  object_class = (GtkObjectClass*) class;

  object_class->destroy = gtk_item_factory_destroy;
  object_class->finalize = gtk_item_factory_finalize;

  class->cpair_comment_single = g_strdup (";\n");

  class->item_ht = g_hash_table_new (g_str_hash, g_str_equal);
198
  class->dummy = NULL;
Tim Janik's avatar
Tim Janik committed
199 200 201 202 203 204 205 206 207 208 209
  ifactory_item_chunks =
    g_mem_chunk_new ("GtkItemFactoryItem",
		     sizeof (GtkItemFactoryItem),
		     sizeof (GtkItemFactoryItem) * ITEM_BLOCK_SIZE,
		     G_ALLOC_ONLY);
  ifactory_cb_data_chunks =
    g_mem_chunk_new ("GtkIFCBData",
		     sizeof (GtkIFCBData),
		     sizeof (GtkIFCBData) * ITEM_BLOCK_SIZE,
		     G_ALLOC_AND_FREE);

210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
  quark_popup_data		= g_quark_from_static_string ("GtkItemFactory-popup-data");
  quark_if_menu_pos		= g_quark_from_static_string ("GtkItemFactory-menu-position");
  quark_item_factory		= g_quark_from_static_string ("GtkItemFactory");
  quark_item_path		= g_quark_from_static_string ("GtkItemFactory-path");
  quark_action			= g_quark_from_static_string ("GtkItemFactory-action");
  quark_accel_group		= g_quark_from_static_string ("GtkAccelGroup");
  quark_type_item		= g_quark_from_static_string ("<Item>");
  quark_type_title		= g_quark_from_static_string ("<Title>");
  quark_type_radio_item		= g_quark_from_static_string ("<RadioItem>");
  quark_type_check_item		= g_quark_from_static_string ("<CheckItem>");
  quark_type_toggle_item	= g_quark_from_static_string ("<ToggleItem>");
  quark_type_tearoff_item	= g_quark_from_static_string ("<Tearoff>");
  quark_type_separator_item	= g_quark_from_static_string ("<Separator>");
  quark_type_branch		= g_quark_from_static_string ("<Branch>");
  quark_type_last_branch	= g_quark_from_static_string ("<LastBranch>");
Tim Janik's avatar
Tim Janik committed
225 226 227 228 229 230 231 232 233 234 235 236
}

static void
gtk_item_factory_init (GtkItemFactory	    *ifactory)
{
  GtkObject *object;

  object = GTK_OBJECT (ifactory);

  ifactory->path = NULL;
  ifactory->accel_group = NULL;
  ifactory->widget = NULL;
237
  ifactory->items = NULL;
Tim Janik's avatar
Tim Janik committed
238 239 240 241 242 243 244 245 246 247 248
}

GtkItemFactory*
gtk_item_factory_new (GtkType	     container_type,
		      const gchar   *path,
		      GtkAccelGroup *accel_group)
{
  GtkItemFactory *ifactory;

  g_return_val_if_fail (path != NULL, NULL);

249
  ifactory = gtk_type_new (GTK_TYPE_ITEM_FACTORY);
Tim Janik's avatar
Tim Janik committed
250 251 252 253 254 255 256 257 258 259 260 261 262
  gtk_item_factory_construct (ifactory, container_type, path, accel_group);

  return ifactory;
}

static void
gtk_item_factory_callback_marshal (GtkWidget *widget,
				   gpointer   func_data)
{
  GtkIFCBData *data;

  data = func_data;

263 264
  if (data->callback_type == 1)
    {
265
      GtkItemFactoryCallback1 func1 = (GtkItemFactoryCallback1) data->func;
266 267 268 269
      func1 (data->func_data, data->callback_action, widget);
    }
  else if (data->callback_type == 2)
    {
270
      GtkItemFactoryCallback2 func2 = (GtkItemFactoryCallback2) data->func;
271 272
      func2 (widget, data->func_data, data->callback_action);
    }
Tim Janik's avatar
Tim Janik committed
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
}

static void
gtk_item_factory_propagate_accelerator (GtkItemFactoryItem *item,
					GtkWidget          *exclude)
{
  GSList *widget_list;
  GSList *slist;
  
  if (item->in_propagation)
    return;
  
  item->in_propagation = TRUE;
  
  widget_list = NULL;
  for (slist = item->widgets; slist; slist = slist->next)
    {
      GtkWidget *widget;
      
      widget = slist->data;
      
      if (widget != exclude)
	{
	  gtk_widget_ref (widget);
	  widget_list = g_slist_prepend (widget_list, widget);
	}
    }
  
  for (slist = widget_list; slist; slist = slist->next)
    {
      GtkWidget *widget;
304 305
      GtkAccelGroup *accel_group;
      guint signal_id;
Tim Janik's avatar
Tim Janik committed
306 307 308
      
      widget = slist->data;
      
309
      accel_group = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_accel_group);
Tim Janik's avatar
Tim Janik committed
310
      
311 312
      signal_id = gtk_signal_lookup ("activate", GTK_OBJECT_TYPE (widget));
      if (signal_id && accel_group)
Tim Janik's avatar
Tim Janik committed
313
	{
314 315 316 317 318 319 320 321
	  if (item->accelerator_key)
	    gtk_widget_add_accelerator (widget,
					"activate",
					accel_group,
					item->accelerator_key,
					item->accelerator_mods,
					GTK_ACCEL_VISIBLE);
	  else
Tim Janik's avatar
Tim Janik committed
322
	    {
323 324 325 326
	      GSList *work;
	      
	      work = gtk_accel_group_entries_from_object (GTK_OBJECT (widget));
	      while (work)
Tim Janik's avatar
Tim Janik committed
327
		{
328
		  GtkAccelEntry *ac_entry;
Tim Janik's avatar
Tim Janik committed
329
		  
330 331 332 333 334 335 336 337 338
		  ac_entry = work->data;
		  work = work->next;
		  if (ac_entry->accel_flags & GTK_ACCEL_VISIBLE &&
		      ac_entry->accel_group == accel_group &&
		      ac_entry->signal_id == signal_id)
		    gtk_widget_remove_accelerator (GTK_WIDGET (widget),
						   ac_entry->accel_group,
						   ac_entry->accelerator_key,
						   ac_entry->accelerator_mods);
Tim Janik's avatar
Tim Janik committed
339 340 341
		}
	    }
	}
342

Tim Janik's avatar
Tim Janik committed
343 344
      gtk_widget_unref (widget);
    }
345
  
Tim Janik's avatar
Tim Janik committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
  g_slist_free (widget_list);
  
  item->in_propagation = FALSE;
}

static gint
gtk_item_factory_item_add_accelerator (GtkWidget	  *widget,
				       guint               accel_signal_id,
				       GtkAccelGroup      *accel_group,
				       guint               accel_key,
				       guint               accel_mods,
				       GtkAccelFlags       accel_flags,
				       GtkItemFactoryItem *item)
{
  if (!item->in_propagation &&
      g_slist_find (item->widgets, widget) &&
      accel_signal_id == gtk_signal_lookup ("activate", GTK_OBJECT_TYPE (widget)))
    {
      item->accelerator_key = accel_key;
      item->accelerator_mods = accel_mods;
      item->modified = TRUE;
      
      gtk_item_factory_propagate_accelerator (item, widget);
    }

  return TRUE;
}

static void
gtk_item_factory_item_remove_accelerator (GtkWidget	     *widget,
					  GtkAccelGroup      *accel_group,
					  guint               accel_key,
					  guint               accel_mods,
					  GtkItemFactoryItem *item)
{
  if (!item->in_propagation &&
      g_slist_find (item->widgets, widget) &&
      item->accelerator_key == accel_key &&
      item->accelerator_mods == accel_mods)
    {
      item->accelerator_key = 0;
      item->accelerator_mods = 0;
      item->modified = TRUE;
      
      gtk_item_factory_propagate_accelerator (item, widget);
    }
}

static void
gtk_item_factory_item_remove_widget (GtkWidget		*widget,
				     GtkItemFactoryItem *item)
{
  item->widgets = g_slist_remove (item->widgets, widget);
399
  gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_item_factory);
400
  gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_item_path);
Tim Janik's avatar
Tim Janik committed
401 402
}

403 404 405 406 407 408
void
gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
			      const gchar    *full_path,
			      GtkAccelGroup  *accel_group,
			      guint           keyval,
			      GdkModifierType modifiers)
Tim Janik's avatar
Tim Janik committed
409 410 411 412
{
  GtkItemFactoryClass *class;
  GtkItemFactoryItem *item;

413 414
  g_return_if_fail (GTK_IS_WIDGET (accel_widget));
  g_return_if_fail (full_path != NULL);
Tim Janik's avatar
Tim Janik committed
415

416
  class = gtk_type_class (GTK_TYPE_ITEM_FACTORY);
Tim Janik's avatar
Tim Janik committed
417

418 419 420
  keyval = keyval != GDK_VoidSymbol ? keyval : 0;

  item = g_hash_table_lookup (class->item_ht, full_path);
Tim Janik's avatar
Tim Janik committed
421 422 423 424
  if (!item)
    {
      item = g_chunk_new (GtkItemFactoryItem, ifactory_item_chunks);

425
      item->path = g_strdup (full_path);
Tim Janik's avatar
Tim Janik committed
426
      item->accelerator_key = keyval;
427
      item->accelerator_mods = modifiers;
Tim Janik's avatar
Tim Janik committed
428 429
      item->modified = FALSE;
      item->in_propagation = FALSE;
430
      item->dummy = NULL;
Tim Janik's avatar
Tim Janik committed
431 432 433 434 435
      item->widgets = NULL;
      
      g_hash_table_insert (class->item_ht, item->path, item);
    }

436 437
  item->widgets = g_slist_prepend (item->widgets, accel_widget);
  gtk_signal_connect (GTK_OBJECT (accel_widget),
Tim Janik's avatar
Tim Janik committed
438 439 440 441
		      "destroy",
		      GTK_SIGNAL_FUNC (gtk_item_factory_item_remove_widget),
		      item);

442
  /* set the item path for the widget
Tim Janik's avatar
Tim Janik committed
443
   */
444 445 446 447 448 449 450 451 452 453 454 455
  gtk_object_set_data_by_id (GTK_OBJECT (accel_widget), quark_item_path, item->path);
  gtk_widget_set_name (accel_widget, item->path);
  if (accel_group)
    {
      gtk_accel_group_ref (accel_group);
      gtk_object_set_data_by_id_full (GTK_OBJECT (accel_widget),
				      quark_accel_group,
				      accel_group,
				      (GtkDestroyNotify) gtk_accel_group_unref);
    }
  else
    gtk_object_set_data_by_id (GTK_OBJECT (accel_widget), quark_accel_group, NULL);
Tim Janik's avatar
Tim Janik committed
456 457 458

  /* install defined accelerators
   */
459
  if (gtk_signal_lookup ("activate", GTK_OBJECT_TYPE (accel_widget)))
Tim Janik's avatar
Tim Janik committed
460
    {
461 462
      if (item->accelerator_key && accel_group)
	gtk_widget_add_accelerator (accel_widget,
Tim Janik's avatar
Tim Janik committed
463
				    "activate",
464
				    accel_group,
Tim Janik's avatar
Tim Janik committed
465 466 467 468
				    item->accelerator_key,
				    item->accelerator_mods,
				    GTK_ACCEL_VISIBLE);
      else
469
	gtk_widget_remove_accelerators (accel_widget,
Tim Janik's avatar
Tim Janik committed
470 471 472 473 474 475
					"activate",
					TRUE);
    }

  /* keep track of accelerator changes
   */
476
  gtk_signal_connect_after (GTK_OBJECT (accel_widget),
Tim Janik's avatar
Tim Janik committed
477 478 479
			    "add-accelerator",
			    GTK_SIGNAL_FUNC (gtk_item_factory_item_add_accelerator),
			    item);
480
  gtk_signal_connect_after (GTK_OBJECT (accel_widget),
Tim Janik's avatar
Tim Janik committed
481 482 483
			    "remove-accelerator",
			    GTK_SIGNAL_FUNC (gtk_item_factory_item_remove_accelerator),
			    item);
484
}
Tim Janik's avatar
Tim Janik committed
485

486 487 488 489 490
static void
ifactory_cb_data_free (gpointer mem)
{
  g_mem_chunk_free (ifactory_cb_data_chunks, mem);
}
Tim Janik's avatar
Tim Janik committed
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
static void
gtk_item_factory_add_item (GtkItemFactory		*ifactory,
			   const gchar			*path,
			   const gchar			*accelerator,
			   GtkItemFactoryCallback	callback,
			   guint			callback_action,
			   gpointer			callback_data,
			   guint			callback_type,
			   gchar			*item_type,
			   GtkWidget			*widget)
{
  GtkItemFactoryClass *class;
  GtkItemFactoryItem *item;
  gchar *fpath;
  guint keyval, mods;
  
  g_return_if_fail (widget != NULL);
  g_return_if_fail (item_type != NULL);

  class = GTK_ITEM_FACTORY_CLASS (GTK_OBJECT (ifactory)->klass);

  /* set accelerator group on menu widgets
   */
  if (GTK_IS_MENU (widget))
    gtk_menu_set_accel_group ((GtkMenu*) widget, ifactory->accel_group);
Tim Janik's avatar
Tim Janik committed
517 518 519 520 521 522 523 524 525

  /* connect callback if neccessary
   */
  if (callback)
    {
      GtkIFCBData *data;

      data = g_chunk_new (GtkIFCBData, ifactory_cb_data_chunks);
      data->func = callback;
526
      data->callback_type = callback_type;
Tim Janik's avatar
Tim Janik committed
527 528 529 530 531 532 533 534 535 536 537
      data->func_data = callback_data;
      data->callback_action = callback_action;

      gtk_object_weakref (GTK_OBJECT (widget),
			  ifactory_cb_data_free,
			  data);
      gtk_signal_connect (GTK_OBJECT (widget),
			  "activate",
			  GTK_SIGNAL_FUNC (gtk_item_factory_callback_marshal),
			  data);
    }
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559

  /* link the widget into its item-entry
   * and keep back pointer on both the item factory and the widget
   */
  gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_action, GUINT_TO_POINTER (callback_action));
  gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_item_factory, ifactory);
  if (accelerator)
    gtk_accelerator_parse (accelerator, &keyval, &mods);
  else
    {
      keyval = 0;
      mods = 0;
    }
  fpath = g_strconcat (ifactory->path, path, NULL);
  gtk_item_factory_add_foreign (widget, fpath, ifactory->accel_group, keyval, mods);
  item = g_hash_table_lookup (class->item_ht, fpath);
  g_free (fpath);

  g_return_if_fail (item != NULL);

  if (!g_slist_find (ifactory->items, item))
    ifactory->items = g_slist_prepend (ifactory->items, item);
Tim Janik's avatar
Tim Janik committed
560 561 562 563 564 565 566 567 568 569 570 571 572 573
}

void
gtk_item_factory_construct (GtkItemFactory	*ifactory,
			    GtkType		 container_type,
			    const gchar		*path,
			    GtkAccelGroup	*accel_group)
{
  guint len;

  g_return_if_fail (ifactory != NULL);
  g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
  g_return_if_fail (ifactory->accel_group == NULL);
  g_return_if_fail (path != NULL);
574 575
  if (!gtk_type_is_a (container_type, GTK_TYPE_OPTION_MENU))
    g_return_if_fail (gtk_type_is_a (container_type, GTK_TYPE_MENU_SHELL));
Tim Janik's avatar
Tim Janik committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599

  len = strlen (path);

  if (path[0] != '<' && path[len - 1] != '>')
    {
      g_warning ("GtkItemFactory: invalid factory path `%s'", path);
      return;
    }

  if (accel_group)
    {
      ifactory->accel_group = accel_group;
      gtk_accel_group_ref (ifactory->accel_group);
    }
  else
    ifactory->accel_group = gtk_accel_group_new ();

  ifactory->path = g_strdup (path);
  ifactory->widget =
    gtk_widget_new (container_type,
		    "GtkObject::signal::destroy", gtk_widget_destroyed, &ifactory->widget,
		    NULL);
  gtk_object_ref (GTK_OBJECT (ifactory));
  gtk_object_sink (GTK_OBJECT (ifactory));
600

Tim Janik's avatar
Tim Janik committed
601 602
  gtk_item_factory_add_item (ifactory,
			     "", NULL,
603
			     NULL, 0, NULL, 0,
Tim Janik's avatar
Tim Janik committed
604 605 606 607
			     ITEM_FACTORY_STRING,
			     ifactory->widget);
}

608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
GtkItemFactory*
gtk_item_factory_from_path (const gchar      *path)
{
  GtkItemFactoryClass *class;
  GtkItemFactoryItem *item;
  gchar *fname;
  guint i;

  g_return_val_if_fail (path != NULL, NULL);
  g_return_val_if_fail (path[0] == '<', NULL);

  class = gtk_type_class (GTK_TYPE_ITEM_FACTORY);

  i = 0;
  while (path[i] && path[i] != '>')
    i++;
  if (path[i] != '>')
    {
      g_warning ("gtk_item_factory_from_path(): invalid factory path \"%s\"",
		 path);
      return NULL;
    }
  fname = g_new (gchar, i + 2);
  g_memmove (fname, path, i + 1);
  fname[i + 1] = 0;

  item = g_hash_table_lookup (class->item_ht, fname);
635 636 637

  g_free (fname);

638 639 640 641 642 643
  if (item && item->widgets)
    return gtk_item_factory_from_widget (item->widgets->data);

  return NULL;
}

Tim Janik's avatar
Tim Janik committed
644
static void
Tim Janik's avatar
Tim Janik committed
645
gtk_item_factory_destroy (GtkObject *object)
Tim Janik's avatar
Tim Janik committed
646 647 648 649 650 651 652 653 654 655 656
{
  GtkItemFactory *ifactory;
  GSList *slist;

  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_ITEM_FACTORY (object));

  ifactory = (GtkItemFactory*) object;

  if (ifactory->widget)
    {
Tim Janik's avatar
Tim Janik committed
657
      GtkObject *dobj;
Tim Janik's avatar
Tim Janik committed
658

Tim Janik's avatar
Tim Janik committed
659
      dobj = GTK_OBJECT (ifactory->widget);
Tim Janik's avatar
Tim Janik committed
660

Tim Janik's avatar
Tim Janik committed
661 662 663 664
      gtk_object_ref (dobj);
      gtk_object_sink (dobj);
      gtk_object_destroy (dobj);
      gtk_object_unref (dobj);
Tim Janik's avatar
Tim Janik committed
665 666 667 668

      ifactory->widget = NULL;
    }

669 670 671 672 673 674 675 676 677 678 679
  for (slist = ifactory->items; slist; slist = slist->next)
    {
      GtkItemFactoryItem *item = slist->data;
      GSList *link;
      
      for (link = item->widgets; link; link = link->next)
	if (gtk_object_get_data_by_id (link->data, quark_item_factory))
	  gtk_object_remove_data_by_id (link->data, quark_item_factory);
    }
  g_slist_free (ifactory->items);
  ifactory->items = NULL;
Tim Janik's avatar
Tim Janik committed
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697

  parent_class->destroy (object);
}

static void
gtk_item_factory_finalize (GtkObject		  *object)
{
  GtkItemFactory *ifactory;

  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_ITEM_FACTORY (object));

  ifactory = GTK_ITEM_FACTORY (object);

  gtk_accel_group_unref (ifactory->accel_group);
  g_free (ifactory->path);
  g_assert (ifactory->widget == NULL);

698 699 700
  if (ifactory->translate_data && ifactory->translate_notify)
    ifactory->translate_notify (ifactory->translate_data);
  
Tim Janik's avatar
Tim Janik committed
701 702 703 704 705 706 707 708 709
  parent_class->finalize (object);
}

GtkItemFactory*
gtk_item_factory_from_widget (GtkWidget	       *widget)
{
  g_return_val_if_fail (widget != NULL, NULL);
  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);

710
  return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_factory);
Tim Janik's avatar
Tim Janik committed
711 712 713 714 715 716 717 718
}

gchar*
gtk_item_factory_path_from_widget (GtkWidget	    *widget)
{
  g_return_val_if_fail (widget != NULL, NULL);
  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);

719
  return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_item_path);
Tim Janik's avatar
Tim Janik committed
720 721 722 723 724 725 726 727
}

static void
gtk_item_factory_foreach (gpointer hash_key,
			  gpointer value,
			  gpointer user_data)
{
  GtkItemFactoryItem *item;
728
  GtkIFDumpData *data;
Tim Janik's avatar
Tim Janik committed
729 730 731 732 733 734 735
  gchar *string;
  gchar *name;
  gchar comment_prefix[2] = "\000\000";

  item = value;
  data = user_data;

736
  if (data->pspec && !gtk_pattern_match_string (data->pspec, item->path))
Tim Janik's avatar
Tim Janik committed
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
    return;

  comment_prefix[0] = gtk_item_factory_class->cpair_comment_single[0];

  name = gtk_accelerator_name (item->accelerator_key, item->accelerator_mods);
  string = g_strconcat (item->modified ? "" : comment_prefix,
			"(menu-path \"",
			hash_key,
			"\" \"",
			name,
			"\")",
			NULL);
  g_free (name);

  data->print_func (data->func_data, string);

  g_free (string);
}

void
757 758 759 760
gtk_item_factory_dump_items (GtkPatternSpec	 *path_pspec,
			     gboolean		  modified_only,
			     GtkPrintFunc	  print_func,
			     gpointer		  func_data)
Tim Janik's avatar
Tim Janik committed
761
{
762
  GtkIFDumpData data;
Tim Janik's avatar
Tim Janik committed
763 764 765 766 767 768 769 770 771

  g_return_if_fail (print_func != NULL);

  if (!gtk_item_factory_class)
    gtk_type_class (GTK_TYPE_ITEM_FACTORY);

  data.print_func = print_func;
  data.func_data = func_data;
  data.modified_only = (modified_only != FALSE);
772
  data.pspec = path_pspec;
Tim Janik's avatar
Tim Janik committed
773 774 775 776

  g_hash_table_foreach (gtk_item_factory_class->item_ht, gtk_item_factory_foreach, &data);
}

777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
void
gtk_item_factory_print_func (gpointer FILE_pointer,
			     gchar   *string)
{
  FILE *f_out = FILE_pointer;

  g_return_if_fail (FILE_pointer != NULL);
  g_return_if_fail (string != NULL);
  
  fputs (string, f_out);
  fputc ('\n', f_out);
}

void
gtk_item_factory_dump_rc (const gchar            *file_name,
			  GtkPatternSpec         *path_pspec,
			  gboolean                modified_only)
{
  FILE *f_out;

  g_return_if_fail (file_name != NULL);

  f_out = fopen (file_name, "w");
  if (!f_out)
    return;

  fputs ("; ", f_out);
804 805
  if (g_get_prgname ())
    fputs (g_get_prgname (), f_out);
806 807 808 809 810 811 812 813 814 815 816 817
  fputs (" GtkItemFactory rc-file         -*- scheme -*-\n", f_out);
  fputs ("; this file is an automated menu-path dump\n", f_out);
  fputs (";\n", f_out);

  gtk_item_factory_dump_items (path_pspec,
			       modified_only,
			       gtk_item_factory_print_func,
			       f_out);

  fclose (f_out);
}

Tim Janik's avatar
Tim Janik committed
818
void
819 820 821 822
gtk_item_factory_create_items (GtkItemFactory	   *ifactory,
			       guint		    n_entries,
			       GtkItemFactoryEntry *entries,
			       gpointer		    callback_data)
823 824 825 826 827
{
  gtk_item_factory_create_items_ac (ifactory, n_entries, entries, callback_data, 1);
}

void
828 829 830 831 832
gtk_item_factory_create_items_ac (GtkItemFactory      *ifactory,
				  guint		       n_entries,
				  GtkItemFactoryEntry *entries,
				  gpointer	       callback_data,
				  guint		       callback_type)
Tim Janik's avatar
Tim Janik committed
833 834 835 836 837
{
  guint i;

  g_return_if_fail (ifactory != NULL);
  g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
838 839 840 841 842
  g_return_if_fail (callback_type >= 1 && callback_type <= 2);

  if (n_entries == 0)
    return;

Tim Janik's avatar
Tim Janik committed
843 844 845
  g_return_if_fail (entries != NULL);

  for (i = 0; i < n_entries; i++)
846
    gtk_item_factory_create_item (ifactory, entries + i, callback_data, callback_type);
Tim Janik's avatar
Tim Janik committed
847 848 849
}

GtkWidget*
850 851
gtk_item_factory_get_widget (GtkItemFactory *ifactory,
			     const gchar    *path)
Tim Janik's avatar
Tim Janik committed
852 853 854 855 856 857 858 859 860
{
  GtkItemFactoryClass *class;
  GtkItemFactoryItem *item;

  g_return_val_if_fail (GTK_IS_ITEM_FACTORY (ifactory), NULL);
  g_return_val_if_fail (path != NULL, NULL);

  class = GTK_ITEM_FACTORY_CLASS (GTK_OBJECT (ifactory)->klass);

861 862 863 864 865 866 867 868 869 870
  if (path[0] == '<')
    item = g_hash_table_lookup (class->item_ht, (gpointer) path);
  else
    {
      gchar *fpath;

      fpath = g_strconcat (ifactory->path, path, NULL);
      item = g_hash_table_lookup (class->item_ht, fpath);
      g_free (fpath);
    }
Tim Janik's avatar
Tim Janik committed
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886

  if (item)
    {
      GSList *slist;

      for (slist = item->widgets; slist; slist = slist->next)
	{
	  if (gtk_item_factory_from_widget (slist->data) == ifactory)
	    return slist->data;
	}
    }

  return NULL;
}

GtkWidget*
887 888
gtk_item_factory_get_widget_by_action (GtkItemFactory *ifactory,
				       guint	       action)
Tim Janik's avatar
Tim Janik committed
889 890 891 892 893
{
  GSList *slist;

  g_return_val_if_fail (GTK_IS_ITEM_FACTORY (ifactory), NULL);

894
  for (slist = ifactory->items; slist; slist = slist->next)
Tim Janik's avatar
Tim Janik committed
895
    {
896 897
      GtkItemFactoryItem *item = slist->data;
      GSList *link;
Tim Janik's avatar
Tim Janik committed
898

899 900 901 902
      for (link = item->widgets; link; link = link->next)
	if (gtk_object_get_data_by_id (link->data, quark_item_factory) == ifactory &&
	    gtk_object_get_data_by_id (link->data, quark_action) == GUINT_TO_POINTER (action))
	  return link->data;
Tim Janik's avatar
Tim Janik committed
903 904 905 906 907
    }

  return NULL;
}

908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
GtkWidget*
gtk_item_factory_get_item (GtkItemFactory *ifactory,
			   const gchar    *path)
{
  GtkWidget *widget;

  g_return_val_if_fail (GTK_IS_ITEM_FACTORY (ifactory), NULL);
  g_return_val_if_fail (path != NULL, NULL);

  widget = gtk_item_factory_get_widget (ifactory, path);

  if (GTK_IS_MENU (widget))
    widget = gtk_menu_get_attach_widget (GTK_MENU (widget));

  return GTK_IS_ITEM (widget) ? widget : NULL;
}

GtkWidget*
gtk_item_factory_get_item_by_action (GtkItemFactory *ifactory,
				     guint	     action)
{
  GtkWidget *widget;

  g_return_val_if_fail (GTK_IS_ITEM_FACTORY (ifactory), NULL);

  widget = gtk_item_factory_get_widget_by_action (ifactory, action);

  if (GTK_IS_MENU (widget))
    widget = gtk_menu_get_attach_widget (GTK_MENU (widget));

  return GTK_IS_ITEM (widget) ? widget : NULL;
}

941
static gboolean
942 943 944 945 946
gtk_item_factory_parse_path (GtkItemFactory *ifactory,
			     gchar          *str,
			     gchar         **path,
			     gchar         **parent_path,
			     gchar         **item)
947
{
948
  gchar *translation;
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
  gchar *p, *q;

  *path = g_strdup (str);

  p = q = *path;
  while (*p)
    {
      if (*p != '_')
	{
	  *q++ = *p;
	}
      p++;
    }
  *q = 0;

  *parent_path = g_strdup (*path);
  p = strrchr (*parent_path, '/');
  if (!p)
    {
      g_warning ("GtkItemFactory: invalid entry path `%s'", str);
      return FALSE;
    }
  *p = 0;

973 974 975 976 977 978
  if (ifactory->translate_func)
    translation = ifactory->translate_func (str, ifactory->translate_data);
  else
    translation = str;
			      
  p = strrchr (translation, '/');
979 980 981 982 983 984 985
  p++;

  *item = g_strdup (p);

  return TRUE;
}

Tim Janik's avatar
Tim Janik committed
986 987 988
void
gtk_item_factory_create_item (GtkItemFactory	     *ifactory,
			      GtkItemFactoryEntry    *entry,
989 990
			      gpointer		      callback_data,
			      guint		      callback_type)
Tim Janik's avatar
Tim Janik committed
991 992 993 994
{
  GtkWidget *parent;
  GtkWidget *widget;
  GSList *radio_group;
995
  gchar *name;
Tim Janik's avatar
Tim Janik committed
996
  gchar *parent_path;
997 998
  gchar *path;
  guint accel_key;
Tim Janik's avatar
Tim Janik committed
999 1000
  guint type_id;
  GtkType type;
1001
  gchar *item_type_path;
Tim Janik's avatar
Tim Janik committed
1002 1003 1004 1005 1006

  g_return_if_fail (ifactory != NULL);
  g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
  g_return_if_fail (entry != NULL);
  g_return_if_fail (entry->path != NULL);
1007
  g_return_if_fail (entry->path[0] == '/');
1008
  g_return_if_fail (callback_type >= 1 && callback_type <= 2);
Tim Janik's avatar
Tim Janik committed
1009 1010

  if (!entry->item_type ||
1011 1012
      entry->item_type[0] == 0)
    {
1013
      item_type_path = "<Item>";
1014
      type_id = quark_type_item;
1015
    }
Tim Janik's avatar
Tim Janik committed
1016
  else
1017 1018 1019 1020
    {
      item_type_path = entry->item_type;
      type_id = gtk_object_data_try_key (item_type_path);
    }
Tim Janik's avatar
Tim Janik committed
1021 1022

  radio_group = NULL;
1023
  if (type_id == quark_type_item)
1024
    type = GTK_TYPE_MENU_ITEM;
1025
  else if (type_id == quark_type_title)
1026
    type = GTK_TYPE_MENU_ITEM;
1027
  else if (type_id == quark_type_radio_item)
1028
    type = GTK_TYPE_RADIO_MENU_ITEM;
1029
  else if (type_id == quark_type_check_item)
1030
    type = GTK_TYPE_CHECK_MENU_ITEM;
1031 1032
  else if (type_id == quark_type_tearoff_item)
    type = GTK_TYPE_TEAROFF_MENU_ITEM;
1033
  else if (type_id == quark_type_toggle_item)
1034
    type = GTK_TYPE_CHECK_MENU_ITEM;
1035
  else if (type_id == quark_type_separator_item)
1036
    type = GTK_TYPE_MENU_ITEM;
1037
  else if (type_id == quark_type_branch)
1038
    type = GTK_TYPE_MENU_ITEM;
1039
  else if (type_id == quark_type_last_branch)
1040
    type = GTK_TYPE_MENU_ITEM;
Tim Janik's avatar
Tim Janik committed
1041 1042 1043 1044
  else
    {
      GtkWidget *radio_link;

1045
      radio_link = gtk_item_factory_get_widget (ifactory, item_type_path);
Tim Janik's avatar
Tim Janik committed
1046 1047
      if (radio_link && GTK_IS_RADIO_MENU_ITEM (radio_link))
	{
1048
	  type = GTK_TYPE_RADIO_MENU_ITEM;
Tim Janik's avatar
Tim Janik committed
1049 1050 1051 1052 1053 1054
	  radio_group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (radio_link));
	}
      else
	{
	  g_warning ("GtkItemFactory: entry path `%s' has invalid type `%s'",
		     entry->path,
1055
		     item_type_path);
Tim Janik's avatar
Tim Janik committed
1056 1057 1058 1059
	  return;
	}
    }

1060
  if (!gtk_item_factory_parse_path (ifactory, entry->path, 
1061 1062
				    &path, &parent_path, &name))
    return;
1063

Tim Janik's avatar
Tim Janik committed
1064 1065 1066 1067
  parent = gtk_item_factory_get_widget (ifactory, parent_path);
  if (!parent)
    {
      GtkItemFactoryEntry pentry;
1068
      gchar *ppath, *p;
Tim Janik's avatar
Tim Janik committed
1069

1070 1071 1072 1073 1074
      ppath = g_strdup (entry->path);
      p = strrchr (ppath, '/');
      g_return_if_fail (p != NULL);
      *p = 0;
      pentry.path = ppath;
Tim Janik's avatar
Tim Janik committed
1075 1076 1077 1078 1079
      pentry.accelerator = NULL;
      pentry.callback = NULL;
      pentry.callback_action = 0;
      pentry.item_type = "<Branch>";

1080
      gtk_item_factory_create_item (ifactory, &pentry, NULL, 1);
1081
      g_free (ppath);
Tim Janik's avatar
Tim Janik committed
1082 1083

      parent = gtk_item_factory_get_widget (ifactory, parent_path);
1084
      g_return_if_fail (parent != NULL);
Tim Janik's avatar
Tim Janik committed
1085 1086 1087
    }
  g_free (parent_path);

1088
  g_return_if_fail (GTK_IS_CONTAINER (parent));
1089

Tim Janik's avatar
Tim Janik committed
1090 1091
  widget = gtk_widget_new (type,
			   "GtkWidget::visible", TRUE,
1092 1093
			   "GtkWidget::sensitive", (type_id != quark_type_separator_item &&
						    type_id != quark_type_title),
Tim Janik's avatar
Tim Janik committed
1094 1095 1096
			   "GtkWidget::parent", parent,
			   NULL);

1097
  if (type == GTK_TYPE_RADIO_MENU_ITEM)
Tim Janik's avatar
Tim Janik committed
1098 1099 1100
    gtk_radio_menu_item_set_group (GTK_RADIO_MENU_ITEM (widget), radio_group);
  if (GTK_IS_CHECK_MENU_ITEM (widget))
    gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (widget), TRUE);
1101 1102 1103 1104 1105

  /* install underline accelerators for this item
   */
  if (type_id != quark_type_separator_item && 
      type_id != quark_type_tearoff_item &&
1106
      *name)
Tim Janik's avatar
Tim Janik committed
1107 1108
    {
      GtkWidget *label;
1109 1110 1111 1112 1113 1114 1115 1116
      
      label = gtk_widget_new (GTK_TYPE_ACCEL_LABEL,
			      "GtkWidget::visible", TRUE,
			      "GtkWidget::parent", widget,
			      "GtkAccelLabel::accel_widget", widget,
			      "GtkMisc::xalign", 0.0,
			      NULL);
      
1117
      accel_key = gtk_label_parse_uline (GTK_LABEL (label), name);
1118 1119
      
      if (accel_key != GDK_VoidSymbol)
1120
	{
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
	  if (GTK_IS_MENU_BAR (parent))
	    gtk_widget_add_accelerator (widget,
					"activate_item",
					ifactory->accel_group,
					accel_key, GDK_MOD1_MASK,
					GTK_ACCEL_LOCKED);

	  if (GTK_IS_MENU (parent))
	    gtk_widget_add_accelerator (widget,
					"activate_item",
					gtk_menu_ensure_uline_accel_group (GTK_MENU (parent)),
					accel_key, 0,
					GTK_ACCEL_LOCKED);
1134
	}
Tim Janik's avatar
Tim Janik committed
1135
    }
1136
  
1137
  g_free (name);
1138
  
1139 1140
  if (type_id == quark_type_branch ||
      type_id == quark_type_last_branch)
Tim Janik's avatar
Tim Janik committed
1141
    {
1142 1143 1144
      if (entry->callback)
	g_warning ("gtk_item_factory_create_item(): Can't specify a callback on a branch: \"%s\"",
		   entry->path);
1145
      
1146
      if (type_id == quark_type_last_branch)
Tim Janik's avatar
Tim Janik committed
1147
	gtk_menu_item_right_justify (GTK_MENU_ITEM (widget));
1148
      
Tim Janik's avatar
Tim Janik committed
1149
      parent = widget;
1150 1151
      widget = gtk_widget_new (GTK_TYPE_MENU,
			       NULL);
1152
      
Tim Janik's avatar
Tim Janik committed
1153 1154 1155 1156
      gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), widget);
    }	   
  
  gtk_item_factory_add_item (ifactory,
1157
			     path, entry->accelerator,
1158
			     (type_id == quark_type_branch ||
1159 1160
			      type_id == quark_type_last_branch) ?
			      (GtkItemFactoryCallback) NULL : entry->callback,
1161
			     entry->callback_action, callback_data,
1162
			     callback_type,
1163
			     item_type_path,
Tim Janik's avatar
Tim Janik committed
1164
			     widget);
1165 1166

  g_free (path);
Tim Janik's avatar
Tim Janik committed
1167 1168 1169
}

void
1170 1171 1172
gtk_item_factory_create_menu_entries (guint              n_entries,
				      GtkMenuEntry      *entries)
{
1173 1174
  static GtkPatternSpec pspec_separator = { 42, 0 };
  static GtkPatternSpec pspec_check = { 42, 0 };
1175 1176 1177 1178 1179 1180
  guint i;

  if (!n_entries)
    return;
  g_return_if_fail (entries != NULL);

1181 1182 1183 1184 1185
  if (pspec_separator.pattern_length == 0)
    {
      gtk_pattern_spec_init (&pspec_separator, "*<separator>*");
      gtk_pattern_spec_init (&pspec_check, "*<check>*");
    }
1186 1187 1188 1189 1190 1191

  for (i = 0; i < n_entries; i++)
    {
      GtkItemFactory *ifactory;
      GtkItemFactoryEntry entry;
      gchar *path;
1192
      gchar *cpath;
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206

      path = entries[i].path;
      ifactory = gtk_item_factory_from_path (path);
      if (!ifactory)
	{
	  g_warning ("gtk_item_factory_create_menu_entries(): "
		     "entry[%u] refers to unknown item factory: \"%s\"",
		     i, entries[i].path);
	  continue;
	}

      while (*path != '>')
	path++;
      path++;
1207
      cpath = NULL;
1208 1209 1210 1211 1212

      entry.path = path;
      entry.accelerator = entries[i].accelerator;
      entry.callback = entries[i].callback;
      entry.callback_action = 0;
1213
      if (gtk_pattern_match_string (&pspec_separator, path))
1214
	entry.item_type = "<Separator>";
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229