glade-popup.c 18.1 KB
Newer Older
Jose Maria Celorio's avatar
Jose Maria Celorio committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2001 Ximian, Inc.
 *
 * 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
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jose Maria Celorio's avatar
Jose Maria Celorio committed
18 19 20 21 22
 *
 * Authors:
 *   Chema Celorio <chema@celorio.com>
 */

23 24 25 26 27 28
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib/gi18n-lib.h>

Jose Maria Celorio's avatar
Jose Maria Celorio committed
29 30
#include "glade.h"
#include "glade-widget.h"
31
#include "glade-widget-adaptor.h"
Jose Maria Celorio's avatar
Jose Maria Celorio committed
32
#include "glade-popup.h"
33
#include "glade-placeholder.h"
34 35
#include "glade-clipboard.h"
#include "glade-command.h"
Joaquín Cuenca Abela's avatar
Joaquín Cuenca Abela committed
36
#include "glade-project.h"
37
#include "glade-app.h"
38

39 40 41
/********************************************************
                      WIDGET POPUP
 *******************************************************/
Jose Maria Celorio's avatar
Jose Maria Celorio committed
42
static void
43
glade_popup_select_cb (GtkMenuItem *item, GladeWidget *widget)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
44
{
Tristan Van Berkom's avatar
Tristan Van Berkom committed
45
	glade_util_clear_selection ();
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
46
	glade_app_selection_set
47
		(glade_widget_get_object (widget), TRUE);
48
}
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
static GladePlaceholder *
find_placeholder (GObject *object)
{
	GtkContainer *container;
	GladePlaceholder *retval = NULL;
	GtkWidget *child;
	GList *c, *l;

	if (!GTK_IS_CONTAINER (object))
		return NULL;

	container = GTK_CONTAINER (object);
	
	for (c = l = glade_util_container_get_all_children (container);
	     l;
	     l = g_list_next (l))
	{
		child = l->data;
		
		if (GLADE_IS_PLACEHOLDER (child))
		{
			retval = GLADE_PLACEHOLDER (child);
			break;
		}
	}
	
	g_list_free (c);

	return retval;
}

static void
glade_popup_placeholder_add_cb (GtkMenuItem *item, GladePlaceholder *placeholder)
{
	GladeWidgetAdaptor *adaptor;
	
	adaptor = glade_palette_get_current_item (glade_app_get_palette ());
	g_return_if_fail (adaptor != NULL);
	
	glade_command_create (adaptor, glade_placeholder_get_parent (placeholder),
						  placeholder, glade_placeholder_get_project (placeholder));
						  
	glade_palette_deselect_current_item (glade_app_get_palette(), TRUE);
}

static void
glade_popup_root_add_cb (GtkMenuItem *item, gpointer *user_data)
{
98 99
	GladeWidgetAdaptor *adaptor = (GladeWidgetAdaptor *)user_data;
	GladePalette *palette = glade_app_get_palette ();
100
	
101 102
	if (!adaptor)
		adaptor = glade_palette_get_current_item (palette);
103 104 105 106 107
	g_return_if_fail (adaptor != NULL);
	
	glade_palette_create_root_widget (palette, adaptor);
}

108 109 110
static void
glade_popup_cut_cb (GtkMenuItem *item, GladeWidget *widget)
{
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
111
	GladeProject *project = glade_app_get_project ();
112

113 114
	glade_util_clear_selection ();
		
115 116 117
	/* Assign selection first */
	if (glade_project_is_selected
	    (project, glade_widget_get_object (widget)) == FALSE)
118
	{
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
119
		glade_app_selection_set
120
			(glade_widget_get_object (widget), FALSE);
121
	}
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
122
	glade_app_command_cut ();
Jose Maria Celorio's avatar
Jose Maria Celorio committed
123 124 125
}

static void
126
glade_popup_copy_cb (GtkMenuItem *item, GladeWidget *widget)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
127
{
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
128
	GladeProject       *project = glade_app_get_project ();
129

130 131
	glade_util_clear_selection ();

132 133 134
	/* Assign selection first */
	if (glade_project_is_selected
	    (project, glade_widget_get_object (widget)) == FALSE)
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
135
		glade_app_selection_set
136
			(glade_widget_get_object (widget), FALSE);
137

Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
138
	glade_app_command_copy ();
139
}
Jose Maria Celorio's avatar
Jose Maria Celorio committed
140

141 142 143
static void
glade_popup_paste_cb (GtkMenuItem *item, GladeWidget *widget)
{
144 145
	glade_util_clear_selection ();

146
	/* The selected widget is the paste destination */
147 148 149 150
	if (widget)
		glade_app_selection_set	(glade_widget_get_object (widget), FALSE);
	else
		glade_app_selection_clear (FALSE);
151

152
	glade_app_command_paste (NULL);
153
}
Jose Maria Celorio's avatar
Jose Maria Celorio committed
154

155 156 157
static void
glade_popup_delete_cb (GtkMenuItem *item, GladeWidget *widget)
{
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
158
	GladeProject       *project = glade_app_get_project ();
159 160 161 162

	/* Assign selection first */
	if (glade_project_is_selected
	    (project, glade_widget_get_object (widget)) == FALSE)
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
163
		glade_app_selection_set
164
			(glade_widget_get_object (widget), FALSE);
165

Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
166
	glade_app_command_delete ();
Jose Maria Celorio's avatar
Jose Maria Celorio committed
167
}
168

169 170 171
/********************************************************
                  PLACEHOLDER POPUP
 *******************************************************/
172
static void
173
glade_popup_placeholder_paste_cb (GtkMenuItem *item,
174
				  GladePlaceholder *placeholder)
175
{
176
	glade_util_clear_selection ();
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
177
	glade_app_selection_clear (FALSE);
178
	
179
	glade_app_command_paste (placeholder);
180 181
}

182 183 184 185

/********************************************************
                    CLIPBOARD POPUP
 *******************************************************/
186
static void
187 188
glade_popup_clipboard_paste_cb (GtkMenuItem      *item,
				GladeWidget      *widget)
189
{
190
	glade_util_clear_selection ();
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
191
	glade_app_selection_clear (FALSE);
192

193
	glade_app_command_paste (NULL);
194 195 196 197 198
}

static void
glade_popup_clipboard_delete_cb (GtkMenuItem *item, GladeWidget *widget)
{
Tristan Van Berkom's avatar
Updated  
Tristan Van Berkom committed
199
	glade_app_command_delete_clipboard ();
200 201
}

202 203 204 205 206 207 208 209 210 211 212 213 214 215
static void
glade_popup_docs_cb (GtkMenuItem *item,
		     GladeWidgetAdaptor *adaptor)
{
	gchar *book;

	g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));

	g_object_get (adaptor, "book", &book, NULL);
	glade_editor_search_doc_search (glade_app_get_editor (), book, adaptor->name, NULL);
	g_free (book);
}


216 217 218
/********************************************************
                    POPUP BUILDING
 *******************************************************/
219
static GtkWidget *
220
glade_popup_append_item (GtkWidget *popup_menu,
221 222
			 const gchar *stock_id,
			 const gchar *label,
223
			 GtkWidget   *image,
224 225 226
			 gboolean sensitive,
			 gpointer callback,
			 gpointer data)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
227 228 229
{
	GtkWidget *menu_item;

Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
230 231 232 233 234 235
	if (stock_id && label)
	{
		menu_item = gtk_image_menu_item_new_with_mnemonic (label);
		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
			gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU));
	}
236 237 238 239 240
	else if (image && label)
	{
		menu_item = gtk_image_menu_item_new_with_mnemonic (label);
		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
	}
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
241
	else if (stock_id)
242 243 244
		menu_item = gtk_image_menu_item_new_from_stock (stock_id, NULL);
	else
		menu_item = gtk_menu_item_new_with_mnemonic (label);
Jose Maria Celorio's avatar
Jose Maria Celorio committed
245

Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
246 247 248
	if (callback)
		g_signal_connect (G_OBJECT (menu_item), "activate",
				  G_CALLBACK (callback), data);
Jose Maria Celorio's avatar
Jose Maria Celorio committed
249 250 251

	gtk_widget_set_sensitive (menu_item, sensitive);
	gtk_widget_show (menu_item);
252
	gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);
253 254

	return menu_item;
Jose Maria Celorio's avatar
Jose Maria Celorio committed
255 256
}

257

Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
258
static void
259
glade_popup_menuitem_activated (GtkMenuItem *item, const gchar *action_path)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
260
{
261
	GladeWidget *widget;
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
262
	
263
	if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data")))
264 265 266
		glade_widget_adaptor_action_activate (widget->adaptor,
						      widget->object,
						      action_path);
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
267 268
}

269 270 271 272 273
static void
glade_popup_menuitem_packing_activated (GtkMenuItem *item, const gchar *action_path)
{
	GladeWidget *widget;
	
274
	if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data")))
275 276 277 278 279 280
		glade_widget_adaptor_child_action_activate (widget->parent->adaptor,
							    widget->parent->object,
							    widget->object,
							    action_path);
}

281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
static void
glade_popup_menuitem_ph_packing_activated (GtkMenuItem *item, const gchar *action_path)
{
	GladePlaceholder *ph;
	GladeWidget *parent;
	
	if ((ph = g_object_get_data (G_OBJECT (item), "gwa-data")))
	{
		parent = glade_placeholder_get_parent (ph);
		glade_widget_adaptor_child_action_activate (parent->adaptor,
							    parent->object,
							    G_OBJECT (ph),
							    action_path);
	}
}

297 298
static gint
glade_popup_action_populate_menu_real (GtkWidget *menu,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
299
				       GladeWidget *gwidget,
300 301 302
				       GList *actions,
				       GCallback callback,
				       gpointer data)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
303 304
{
	GtkWidget *item;
305 306
	GList *list;
	gint n = 0;
307

308
	for (list = actions; list; list = g_list_next (list))
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
309
	{
310
		GladeWidgetAction *a = list->data;
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
311
		GtkWidget *submenu = NULL;
312 313

		if (a->actions)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
314 315
		{
			submenu = gtk_menu_new ();
316
			n += glade_popup_action_populate_menu_real (submenu,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
317
								    gwidget,
318 319 320
								    a->actions,
								    callback,
								    data);
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
321
		}
Tristan Van Berkom's avatar
Tristan Van Berkom committed
322 323 324 325 326
		else
			submenu = glade_widget_adaptor_action_submenu (gwidget->adaptor,
								       gwidget->object,
								       a->klass->path);
				
327
				
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
328
		item = glade_popup_append_item (menu, 
329
						a->klass->stock,
330
						a->klass->label, NULL, TRUE,
331 332
						(a->actions) ? NULL : callback,
						(a->actions) ? NULL : a->klass->path);
333
		
334
		g_object_set_data (G_OBJECT (item), "gwa-data", data);
335

336
		gtk_widget_set_sensitive (item, a->sensitive);
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
337 338 339
		
		if (submenu)
			gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
340 341
		
		n++;
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
342
	}
343

344
	return n;
345 346
}

347 348 349 350 351
/*
 * glade_popup_action_populate_menu:
 * @menu: a GtkMenu to put the actions menu items.
 * @widget: A #GladeWidget
 * @action: a @widget subaction or NULL to include all actions.
352
 * @packing: TRUE to include packing actions
353 354 355 356 357 358 359 360
 *
 * Populate a GtkMenu with widget's actions
 *
 * Returns the number of action appended to the menu.
 */
gint
glade_popup_action_populate_menu (GtkWidget *menu,
				  GladeWidget *widget,
361 362
				  GladeWidgetAction *action,
				  gboolean packing)
363
{
364 365
	gint n;

366 367
	g_return_val_if_fail (GTK_IS_MENU (menu), 0);
	g_return_val_if_fail (GLADE_IS_WIDGET (widget), 0);
368
	
369
	if (action)
370
	{
371
		g_return_val_if_fail (GLADE_IS_WIDGET_ACTION (action), 0);
372
		if (glade_widget_get_action (widget, action->klass->path))
373
			return glade_popup_action_populate_menu_real (menu,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
374
								      widget,
375 376 377
								      action->actions,
								      G_CALLBACK (glade_popup_menuitem_activated),
								      widget);
378 379
		
		if (glade_widget_get_pack_action (widget, action->klass->path))
380
			return glade_popup_action_populate_menu_real (menu,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
381
								      glade_widget_get_parent (widget),
382 383 384 385
								      action->actions,
								      G_CALLBACK (glade_popup_menuitem_packing_activated),
								      widget);

386
		return 0;
387
	}
388
	
389
	n = glade_popup_action_populate_menu_real (menu,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
390
						   widget,
391 392 393
						   widget->actions,
						   G_CALLBACK (glade_popup_menuitem_activated),
						   widget);
394
	
395
	if (packing && widget->packing_actions)
396 397 398 399 400 401 402
	{
		if (n)
		{
			GtkWidget *separator = gtk_menu_item_new ();
			gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
			gtk_widget_show (separator);
		}
403
		n += glade_popup_action_populate_menu_real (menu,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
404
							    glade_widget_get_parent (widget),
405 406 407
							    widget->packing_actions,
							    G_CALLBACK (glade_popup_menuitem_packing_activated),
							    widget);
408 409 410
	}
	
	return n;
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
411
}
412

413
static GtkWidget *
414 415 416
glade_popup_create_menu (GladeWidget      *widget,
			 GladePlaceholder *placeholder,
			 gboolean          packing)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
417
{
418 419
	GladeProjectFormat fmt;
	GladeProject *project;
420
	GtkWidget *popup_menu;
421 422 423
	GtkWidget *separator;
	GList *list;
	gboolean   sensitive, non_window;
424
	GladePlaceholder *tmp_placeholder;
425
	gchar     *book;
426 427 428

	sensitive = glade_palette_get_current_item (glade_app_get_palette ()) != NULL;

429 430 431 432 433
	/* Resolve project format first... */
	project = widget ? glade_widget_get_project (widget) :
		placeholder ? glade_placeholder_get_project (placeholder) : glade_app_get_project ();
	fmt = glade_project_get_format (project);

434

435
	popup_menu = gtk_menu_new ();
436 437 438 439 440 441
	
	if (sensitive)
	{		
		tmp_placeholder = placeholder;
		if (!tmp_placeholder && widget)
			tmp_placeholder = find_placeholder (glade_widget_get_object (widget));
442
		glade_popup_append_item (popup_menu, NULL, _("_Add widget here"), NULL, tmp_placeholder != NULL,
443
					 glade_popup_placeholder_add_cb, tmp_placeholder);
444 445
		glade_popup_append_item (popup_menu, NULL, _("Add widget as _toplevel"), NULL, 
					 fmt != GLADE_PROJECT_FORMAT_LIBGLADE,
446 447
					 glade_popup_root_add_cb, NULL);

448
		separator = gtk_menu_item_new ();		
449 450 451
		gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator);
		gtk_widget_show (separator);
	}
452

453 454 455
	sensitive = (widget != NULL);

	glade_popup_append_item (popup_menu, NULL, _("_Select"), NULL, sensitive,
456
				 glade_popup_select_cb, widget);
457
	glade_popup_append_item (popup_menu, GTK_STOCK_CUT, NULL, NULL, sensitive,
458
				 glade_popup_cut_cb, widget);
459
	glade_popup_append_item (popup_menu, GTK_STOCK_COPY, NULL, NULL, sensitive,
460
				 glade_popup_copy_cb, widget);
461

462
	/* paste is placholder specific when the popup is on a placeholder */
463
	sensitive = glade_clipboard_get_has_selection (glade_app_get_clipboard ());
464 465 466 467 468
	non_window = FALSE;
	for (list = glade_app_get_clipboard ()->selection; list; list = list->next)
		if (!GTK_IS_WINDOW (GLADE_WIDGET (list->data)->object))
			non_window = TRUE;

469
	if (placeholder)
470
		glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, NULL, sensitive,
471
					 glade_popup_placeholder_paste_cb, placeholder);
472
	else if (widget)
473
		glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, NULL, sensitive,
474
					 glade_popup_paste_cb, widget);
475 476 477 478 479
	else
		/* No toplevel non-GtkWindow pastes in libglade */
		glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, NULL, 
					 sensitive && !(non_window &&  (fmt == GLADE_PROJECT_FORMAT_LIBGLADE)),
					 glade_popup_paste_cb, NULL);
480

481 482 483


	glade_popup_append_item (popup_menu, GTK_STOCK_DELETE, NULL, NULL, (widget != NULL),
484
				 glade_popup_delete_cb, widget);
485

486 487

	/* packing actions are a little different on placholders */
488
	if (placeholder)
489
	{
490
		if (widget && widget->actions)
491 492 493 494
		{
			GtkWidget *separator = gtk_menu_item_new ();
			gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator);
			gtk_widget_show (separator);
495

496 497
			glade_popup_action_populate_menu_real
				(popup_menu,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
498
				 widget,
499 500 501 502 503 504 505 506 507 508 509 510 511
				 widget->actions,
				 G_CALLBACK (glade_popup_menuitem_activated),
				 widget);
		}

		if (placeholder->packing_actions)
		{
			GtkWidget *separator = gtk_menu_item_new ();
			gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator);
			gtk_widget_show (separator);
			
			glade_popup_action_populate_menu_real
				(popup_menu,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
512
				 widget,
513 514 515 516
				 placeholder->packing_actions,
				 G_CALLBACK (glade_popup_menuitem_ph_packing_activated),
				 placeholder);
		}
517
	}
518
	else if (widget && (widget->actions || (packing && widget->packing_actions)))
519 520 521 522 523
	{
		GtkWidget *separator = gtk_menu_item_new ();
		gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator);
		gtk_widget_show (separator);

524
		glade_popup_action_populate_menu (popup_menu, widget, NULL, packing);
525
	}
526

527
	if (widget)
528
	{
529 530 531 532 533 534 535 536 537 538 539 540
		g_object_get (widget->adaptor, "book", &book, NULL);
		if (book)
		{
			GtkWidget *icon = glade_util_get_devhelp_icon (GTK_ICON_SIZE_MENU);
			GtkWidget *separator = gtk_menu_item_new ();
			gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator);
			gtk_widget_show (separator);
			
			glade_popup_append_item (popup_menu, NULL, _("Read _documentation"), icon, TRUE,
						 glade_popup_docs_cb, widget->adaptor);
		}
		g_free (book);
541 542
	}

543
	return popup_menu;
Jose Maria Celorio's avatar
Jose Maria Celorio committed
544 545
}

546 547 548 549 550 551 552
static GtkWidget *
glade_popup_create_clipboard_menu (GladeWidget *widget)
{
	GtkWidget *popup_menu;
	
	popup_menu = gtk_menu_new ();

553
	if (GTK_WIDGET_TOPLEVEL (glade_widget_get_object (widget)))
554 555
	{
		glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, 
556
					 NULL, NULL, TRUE,
557 558 559
					 glade_popup_clipboard_paste_cb, NULL);
	}

560
	glade_popup_append_item (popup_menu, GTK_STOCK_DELETE, NULL, NULL, TRUE,
561 562 563 564 565
				 glade_popup_clipboard_delete_cb, widget);

	return popup_menu;
}

Jose Maria Celorio's avatar
Jose Maria Celorio committed
566
void
567 568 569
glade_popup_widget_pop (GladeWidget *widget,
			GdkEventButton *event,
			gboolean packing)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
570 571
{
	GtkWidget *popup_menu;
572 573 574
	gint button;
	gint event_time;

575
	g_return_if_fail (GLADE_IS_WIDGET (widget) || widget == NULL);
Jose Maria Celorio's avatar
Jose Maria Celorio committed
576

577
	popup_menu = glade_popup_create_menu (widget, NULL, packing);
Jose Maria Celorio's avatar
Jose Maria Celorio committed
578

579 580 581 582 583 584 585 586 587 588
	if (event)
	{
		button = event->button;
		event_time = event->time;
	}
	else
	{
		button = 0;
		event_time = gtk_get_current_event_time ();
	}
Jose Maria Celorio's avatar
Jose Maria Celorio committed
589
	gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL,
590
			NULL, NULL, button, event_time);
Jose Maria Celorio's avatar
Jose Maria Celorio committed
591
}
592 593

void
594 595
glade_popup_placeholder_pop (GladePlaceholder *placeholder,
			     GdkEventButton *event)
596
{
597
	GladeWidget *widget;
598
	GtkWidget *popup_menu;
599 600 601 602
	gint button;
	gint event_time;

	g_return_if_fail (GLADE_IS_PLACEHOLDER (placeholder));
603

604 605 606
	widget = glade_placeholder_get_parent (placeholder);
	
	popup_menu = glade_popup_create_menu (widget, placeholder, TRUE);
607

608 609 610 611 612 613 614 615 616 617
	if (event)
	{
		button = event->button;
		event_time = event->time;
	}
	else
	{
		button = 0;
		event_time = gtk_get_current_event_time ();
	}
618 619

	gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL,
620
			NULL, NULL, button, event_time);
621
}
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648

void
glade_popup_clipboard_pop (GladeWidget    *widget,
			   GdkEventButton *event)
{
	GtkWidget *popup_menu;
	gint button;
	gint event_time;

	g_return_if_fail (GLADE_IS_WIDGET (widget));

	popup_menu = glade_popup_create_clipboard_menu (widget);

	if (event)
	{
		button = event->button;
		event_time = event->time;
	}
	else
	{
		button = 0;
		event_time = gtk_get_current_event_time ();
	}

	gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL,
			NULL, NULL, button, event_time);
}
649

650 651 652 653
void
glade_popup_palette_pop (GladeWidgetAdaptor *adaptor,
			 GdkEventButton     *event)
{
654 655
	GladeProjectFormat fmt;
	GladeProject *project;
656 657 658 659 660 661 662 663
	GtkWidget *popup_menu;
	gchar *book = NULL;
	gint button;
	gint event_time;

	g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));

	popup_menu = gtk_menu_new ();
664 665 666
	
	project = glade_app_get_project ();
	fmt = glade_project_get_format (project);
667

668 669
	glade_popup_append_item (popup_menu, NULL, _("Add widget as _toplevel"), NULL, 
				 (fmt != GLADE_PROJECT_FORMAT_LIBGLADE),
670 671 672 673
				 glade_popup_root_add_cb, adaptor);

	g_object_get (adaptor, "book", &book, NULL);
	if (book)
674 675 676
	{
		GtkWidget *icon = glade_util_get_devhelp_icon (GTK_ICON_SIZE_MENU);
		glade_popup_append_item (popup_menu, NULL, _("Read _documentation"), icon, TRUE,
677
					 glade_popup_docs_cb, adaptor);
678
	}
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
	g_free (book);


	if (event)
	{
		button = event->button;
		event_time = event->time;
	}
	else
	{
		button = 0;
		event_time = gtk_get_current_event_time ();
	}

	gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL,
			NULL, NULL, button, event_time);
}


698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
void
glade_popup_simple_pop (GdkEventButton *event)
{
	GtkWidget *popup_menu;
	gint button;
	gint event_time;
	
	popup_menu = glade_popup_create_menu (NULL, NULL, FALSE);
	if (!popup_menu)
		return;

	if (event)
	{
		button = event->button;
		event_time = event->time;
	}
	else
	{
		button = 0;
		event_time = gtk_get_current_event_time ();
	}
	gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL,
		NULL, NULL, button, event_time);
}