glade-popup.c 21.8 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
/*
 * 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
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jose Maria Celorio's avatar
Jose Maria Celorio committed
17 18 19
 *
 * Authors:
 *   Chema Celorio <chema@celorio.com>
20
 *   Tristan Van Berkom <tvb@gnome.org>
Jose Maria Celorio's avatar
Jose Maria Celorio committed
21 22
 */

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
static void
40
glade_popup_docs_cb (GtkMenuItem *item, GladeWidgetAdaptor *adaptor)
41 42 43
{
  g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));

44 45 46
  glade_app_search_docs (glade_widget_adaptor_get_book (adaptor),
                         glade_widget_adaptor_get_name (adaptor),
                         NULL);
47 48
}

49 50 51
/********************************************************
                      WIDGET POPUP
 *******************************************************/
Jose Maria Celorio's avatar
Jose Maria Celorio committed
52
static void
53
glade_popup_select_cb (GtkMenuItem *item, GladeWidget *widget)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
54
{
55 56
  glade_project_selection_set (glade_widget_get_project (widget),
			       glade_widget_get_object (widget), TRUE);
57
}
58

59
typedef struct {
60
  GladeWidgetAdaptor *adaptor;
61 62 63 64
  GladeProject       *project;
  GladeWidget        *parent;
  GladePlaceholder   *placeholder;
} RootAddData;
65

66 67 68 69
static void
glade_popup_widget_add_cb (GtkMenuItem *item, RootAddData *data)
{
  g_return_if_fail (data->adaptor != NULL);
70

71
  if (!glade_util_check_and_warn_scrollable
72
      (data->parent, data->adaptor, glade_app_get_window ()))
73
    {
74 75
      if (glade_command_create (data->adaptor, data->parent,
				data->placeholder, data->project))
76

77
      glade_project_set_add_item (data->project, NULL);
78
    }
79 80 81
}

static void
82
glade_popup_root_add_cb (GtkMenuItem *item, RootAddData *data)
83
{
84
  glade_command_create (data->adaptor, NULL, NULL, data->project);
85 86
}

87
static void
88
glade_popup_cut_cb (GtkMenuItem *item, GladeWidget *widget)
89
{
90
  GladeProject *project = glade_widget_get_project (widget);
91

92 93 94 95 96 97
  /* Assign selection first only if its not already assigned (it may be a delete
   * of multiple widgets) */
  if (!glade_project_is_selected (project, glade_widget_get_object (widget)))
    glade_project_selection_set (project, glade_widget_get_object (widget), FALSE);

  glade_project_command_cut (project);
Jose Maria Celorio's avatar
Jose Maria Celorio committed
98 99 100
}

static void
101
glade_popup_copy_cb (GtkMenuItem *item, GladeWidget *widget)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
102
{
103
  GladeProject *project = glade_widget_get_project (widget);
104

105
  /* Assign selection first */
106
  if (!glade_project_is_selected (project, glade_widget_get_object (widget)))
107
    glade_project_selection_set (project, glade_widget_get_object (widget), FALSE);
108

109
  glade_project_copy_selection (project);
110
}
Jose Maria Celorio's avatar
Jose Maria Celorio committed
111

112
static void
113
glade_popup_paste_cb (GtkMenuItem *item, gpointer data)
114
{
115 116 117 118 119 120 121 122 123 124 125 126 127
  GladeWidget  *widget = NULL;
  GladeProject *project;

  if (GLADE_IS_WIDGET (data))
    {
      widget  = GLADE_WIDGET (data);
      project = glade_widget_get_project (widget);
    }
  else if (GLADE_IS_PROJECT (data))
    project = GLADE_PROJECT (data);
  else
    g_return_if_reached ();

128 129
  /* The selected widget is the paste destination */
  if (widget)
130
    glade_project_selection_set (project, glade_widget_get_object (widget), FALSE);
131
  else
132
    glade_project_selection_clear (project, FALSE);
133

134
  glade_project_command_paste (project, NULL);
135
}
Jose Maria Celorio's avatar
Jose Maria Celorio committed
136

137
static void
138
glade_popup_delete_cb (GtkMenuItem *item, GladeWidget *widget)
139
{
140
  GladeProject *project = glade_widget_get_project (widget);
141

142 143 144
  /* Assign selection first */
  if (glade_project_is_selected
      (project, glade_widget_get_object (widget)) == FALSE)
145
    glade_project_selection_set (project, glade_widget_get_object (widget), FALSE);
146

147
  glade_project_command_delete (project);
Jose Maria Celorio's avatar
Jose Maria Celorio committed
148
}
149

150 151 152
/********************************************************
                  PLACEHOLDER POPUP
 *******************************************************/
153
static void
154 155
glade_popup_placeholder_paste_cb (GtkMenuItem *item,
                                  GladePlaceholder *placeholder)
156
{
157
  GladeProject *project;
158

159
  project = glade_placeholder_get_project (placeholder);
160

161
  glade_project_selection_clear (project, FALSE);
162

163
  glade_project_command_paste (project, placeholder);
164 165
}

166 167 168
/********************************************************
                    POPUP BUILDING
 *******************************************************/
169
static GtkWidget *
170 171 172 173 174 175 176
glade_popup_append_item (GtkWidget *popup_menu,
                         const gchar *stock_id,
                         const gchar *label,
                         GtkWidget *image,
                         gboolean sensitive,
                         gpointer callback,
                         gpointer data)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
177
{
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
  GtkWidget *menu_item;

  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));
    }
  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);
    }
  else if (stock_id)
    menu_item = gtk_image_menu_item_new_from_stock (stock_id, NULL);
  else
    menu_item = gtk_menu_item_new_with_mnemonic (label);

  if (callback)
    g_signal_connect (G_OBJECT (menu_item), "activate",
                      G_CALLBACK (callback), data);

  gtk_widget_set_sensitive (menu_item, sensitive);
  gtk_widget_show (menu_item);
  gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);

  return menu_item;
Jose Maria Celorio's avatar
Jose Maria Celorio committed
206 207
}

208

Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
209
static void
210
glade_popup_menuitem_activated (GtkMenuItem *item, const gchar *action_path)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
211
{
212 213 214
  GladeWidget *widget;

  if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data")))
215 216
    glade_widget_adaptor_action_activate (glade_widget_get_adaptor (widget),
                                          glade_widget_get_object (widget), action_path);
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
217 218
}

219
static void
220 221
glade_popup_menuitem_packing_activated (GtkMenuItem *item,
                                        const gchar *action_path)
222
{
223
  GladeWidget *widget, *parent;
224 225

  if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data")))
226 227 228 229 230 231
    {
      parent = glade_widget_get_parent (widget);
      glade_widget_adaptor_child_action_activate (glade_widget_get_adaptor (parent),
						  glade_widget_get_object (parent),
						  glade_widget_get_object (widget), action_path);
    }
232 233
}

234
static void
235 236
glade_popup_menuitem_ph_packing_activated (GtkMenuItem *item,
                                           const gchar *action_path)
237
{
238 239 240 241 242 243
  GladePlaceholder *ph;
  GladeWidget *parent;

  if ((ph = g_object_get_data (G_OBJECT (item), "gwa-data")))
    {
      parent = glade_placeholder_get_parent (ph);
244 245
      glade_widget_adaptor_child_action_activate (glade_widget_get_adaptor (parent),
                                                  glade_widget_get_object (parent),
246 247
                                                  G_OBJECT (ph), action_path);
    }
248 249
}

250
static gint
251 252 253 254 255
glade_popup_action_populate_menu_real (GtkWidget *menu,
                                       GladeWidget *gwidget,
                                       GList *actions,
                                       GCallback callback,
                                       gpointer data)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
256
{
257 258 259 260 261 262
  GtkWidget *item;
  GList *list;
  gint n = 0;

  for (list = actions; list; list = g_list_next (list))
    {
263 264 265 266
      GladeWidgetAction *action = list->data;
      GWActionClass     *aclass = glade_widget_action_get_class (action);
      GList             *children = glade_widget_action_get_children (action);
      GtkWidget         *submenu = NULL;
267

268 269 270 271
      if (!glade_widget_action_get_visible (action))
	continue;

      if (children)
272 273 274 275
        {
          submenu = gtk_menu_new ();
          n += glade_popup_action_populate_menu_real (submenu,
                                                      gwidget,
276
                                                      children,
277 278 279
                                                      callback, data);
        }
      else
280 281
        submenu = glade_widget_adaptor_action_submenu (glade_widget_get_adaptor (gwidget),
                                                       glade_widget_get_object (gwidget),
282
                                                       aclass->path);
283 284 285


      item = glade_popup_append_item (menu,
286 287 288 289
                                      aclass->stock,
                                      aclass->label, NULL, TRUE,
                                      (children) ? NULL : callback,
                                      (children) ? NULL : aclass->path);
290 291 292

      g_object_set_data (G_OBJECT (item), "gwa-data", data);

293
      gtk_widget_set_sensitive (item, glade_widget_action_get_sensitive (action));
294 295 296 297 298 299 300 301

      if (submenu)
        gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);

      n++;
    }

  return n;
302 303
}

304 305 306 307 308
/*
 * 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.
309
 * @packing: TRUE to include packing actions
310 311 312 313 314 315
 *
 * Populate a GtkMenu with widget's actions
 *
 * Returns the number of action appended to the menu.
 */
gint
316 317 318 319
glade_popup_action_populate_menu (GtkWidget *menu,
                                  GladeWidget *widget,
                                  GladeWidgetAction *action,
                                  gboolean packing)
320
{
321 322 323 324 325
  gint n;

  g_return_val_if_fail (GTK_IS_MENU (menu), 0);
  g_return_val_if_fail (GLADE_IS_WIDGET (widget), 0);

326 327
  g_return_val_if_fail (action == NULL || GLADE_IS_WIDGET_ACTION (action), 0);

328 329
  if (action)
    {
330 331 332 333 334
      GWActionClass *aclass = glade_widget_action_get_class (action);
      GList         *children = glade_widget_action_get_children (action);
      
      if (glade_widget_get_action (widget, aclass->path) &&
	  glade_widget_action_get_visible (action))
335 336
        return glade_popup_action_populate_menu_real (menu,
                                                      widget,
337
                                                      children,
338 339 340 341
                                                      G_CALLBACK
                                                      (glade_popup_menuitem_activated),
                                                      widget);

342 343
      if (glade_widget_get_pack_action (widget, aclass->path) &&
	  glade_widget_action_get_visible (action))
344 345
        return glade_popup_action_populate_menu_real (menu,
                                                      glade_widget_get_parent
346
                                                      (widget), children,
347 348 349 350 351 352 353 354 355
                                                      G_CALLBACK
                                                      (glade_popup_menuitem_packing_activated),
                                                      widget);

      return 0;
    }

  n = glade_popup_action_populate_menu_real (menu,
                                             widget,
356
                                             glade_widget_get_actions (widget),
357 358 359 360
                                             G_CALLBACK
                                             (glade_popup_menuitem_activated),
                                             widget);

361
  if (packing && glade_widget_get_pack_actions (widget))
362 363 364 365 366 367 368
    {
      if (n)
        {
          GtkWidget *separator = gtk_menu_item_new ();
          gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
          gtk_widget_show (separator);
        }
369

370 371 372 373
      n += glade_popup_action_populate_menu_real 
	(menu, glade_widget_get_parent (widget),
	 glade_widget_get_pack_actions (widget),
	 G_CALLBACK (glade_popup_menuitem_packing_activated), widget);
374 375 376
    }

  return n;
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
377
}
378

379
static GtkWidget *
380 381 382 383
glade_popup_create_menu (GladeWidget      *widget,
                         GladePlaceholder *placeholder, 
			 GladeProject     *project,
			 gboolean          packing)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
384
{
385 386 387 388
  GtkWidget          *popup_menu;
  GtkWidget          *separator;
  gboolean            sensitive;
  GladeWidgetAdaptor *adaptor;
389 390 391

  popup_menu = gtk_menu_new ();

392 393 394
  adaptor = glade_project_get_add_item (project);

  if (adaptor)
395
    {
396
      RootAddData *data = g_new (RootAddData, 1);
397
      
398 399
      data->adaptor = adaptor;
      data->project = project;
400 401 402
      data->parent = placeholder ? glade_placeholder_get_parent (placeholder) : widget;
      data->placeholder = placeholder;
      
403 404 405
      g_object_set_data_full (G_OBJECT (popup_menu), "root-data-destroy-me", 
			      data, (GDestroyNotify)g_free);

406
      glade_popup_append_item (popup_menu, NULL, _("_Add widget here"),
407
			       NULL, data->parent != NULL,
408
			       glade_popup_widget_add_cb,
409
			       data);
410 411

      glade_popup_append_item (popup_menu, NULL, _("Add widget as _toplevel"),
412
                               NULL, TRUE, glade_popup_root_add_cb, data);
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448

      separator = gtk_menu_item_new ();
      gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator);
      gtk_widget_show (separator);
    }

  sensitive = (widget != NULL);

  glade_popup_append_item (popup_menu, NULL, _("_Select"), NULL, sensitive,
                           glade_popup_select_cb, widget);
  glade_popup_append_item (popup_menu, GTK_STOCK_CUT, NULL, NULL, sensitive,
                           glade_popup_cut_cb, widget);
  glade_popup_append_item (popup_menu, GTK_STOCK_COPY, NULL, NULL, sensitive,
                           glade_popup_copy_cb, widget);

  /* paste is placholder specific when the popup is on a placeholder */
  sensitive = glade_clipboard_get_has_selection (glade_app_get_clipboard ());

  if (placeholder)
    glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, NULL, sensitive,
                             glade_popup_placeholder_paste_cb, placeholder);
  else if (widget)
    glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, NULL, sensitive,
                             glade_popup_paste_cb, widget);
  else
    glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, NULL, sensitive,
                             glade_popup_paste_cb, NULL);


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


  /* packing actions are a little different on placholders */
  if (placeholder)
    {
449
      if (widget && glade_widget_get_actions (widget))
450 451 452 453 454 455 456 457
        {
          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,
               widget,
458
               glade_widget_get_actions (widget),
459 460 461
               G_CALLBACK (glade_popup_menuitem_activated), widget);
        }

462
      if (glade_placeholder_packing_actions (placeholder))
463 464 465 466 467 468 469 470
        {
          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,
               widget,
471
               glade_placeholder_packing_actions (placeholder),
472 473 474 475
               G_CALLBACK (glade_popup_menuitem_ph_packing_activated),
               placeholder);
        }
    }
476 477
  else if (widget && (glade_widget_get_actions (widget) || 
		      (packing && glade_widget_get_pack_actions (widget))))
478 479 480 481 482 483 484 485 486
    {
      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 (popup_menu, widget, NULL, packing);
    }

  return popup_menu;
Jose Maria Celorio's avatar
Jose Maria Celorio committed
487 488 489
}

void
490 491 492
glade_popup_widget_pop (GladeWidget *widget,
                        GdkEventButton *event,
                        gboolean packing)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
493
{
494 495 496 497 498 499
  GtkWidget *popup_menu;
  gint button;
  gint event_time;

  g_return_if_fail (GLADE_IS_WIDGET (widget) || widget == NULL);

500
  popup_menu = glade_popup_create_menu (widget, NULL, glade_widget_get_project (widget), packing);
501 502 503 504 505 506 507 508 509 510 511 512 513

  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);
Jose Maria Celorio's avatar
Jose Maria Celorio committed
514
}
515 516

void
517 518
glade_popup_placeholder_pop (GladePlaceholder *placeholder,
                             GdkEventButton *event)
519
{
520 521 522 523 524 525 526 527 528
  GladeWidget *widget;
  GtkWidget *popup_menu;
  gint button;
  gint event_time;

  g_return_if_fail (GLADE_IS_PLACEHOLDER (placeholder));

  widget = glade_placeholder_get_parent (placeholder);

529 530
  popup_menu = glade_popup_create_menu (widget, placeholder, 
					glade_widget_get_project (widget), TRUE);
531 532 533 534 535 536 537 538 539 540 541 542 543 544

  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);
545
}
546

547
void
548 549 550
glade_popup_palette_pop (GladePalette       *palette, 
			 GladeWidgetAdaptor *adaptor, 
			 GdkEventButton     *event)
551
{
552 553 554 555
  GladeProject *project;
  GtkWidget *popup_menu;
  gint button;
  gint event_time;
556
  RootAddData *data;
557 558 559 560 561

  g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));

  popup_menu = gtk_menu_new ();

562
  project = glade_palette_get_project (palette);
563

564 565 566 567 568 569
  data = g_new (RootAddData, 1);
  data->adaptor = adaptor;
  data->project = project;
  g_object_set_data_full (G_OBJECT (popup_menu), "root-data-destroy-me", 
			  data, (GDestroyNotify)g_free);

570
  glade_popup_append_item (popup_menu, NULL, _("Add widget as _toplevel"), NULL,
571
                           TRUE, glade_popup_root_add_cb, data);
572

573
  if (glade_widget_adaptor_get_book (adaptor) && glade_util_have_devhelp ())
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
    {
      GtkWidget *icon = glade_util_get_devhelp_icon (GTK_ICON_SIZE_MENU);
      glade_popup_append_item (popup_menu, NULL, _("Read _documentation"), icon,
                               TRUE, glade_popup_docs_cb, adaptor);
    }

  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);
593 594
}

595
static void
596
glade_popup_clear_property_cb (GtkMenuItem *item, GladeProperty *property)
597
{
598
  GValue value = { 0, };
599

600 601 602
  glade_property_get_default (property, &value);
  glade_command_set_property_value (property, &value);
  g_value_unset (&value);
603 604 605
}

static void
606
glade_popup_property_docs_cb (GtkMenuItem *item, GladeProperty *property)
607
{
608
  GladeWidgetAdaptor *adaptor, *prop_adaptor;
609
  GladePropertyClass *pclass;
610
  GParamSpec         *pspec;
611
  gchar              *search;
612

613
  pclass       = glade_property_get_class (property);
614 615 616
  pspec        = glade_property_class_get_pspec (pclass);
  prop_adaptor = glade_property_class_get_adaptor (pclass);
  adaptor      = glade_widget_adaptor_from_pspec (prop_adaptor, pspec);
617
  search       = g_strdup_printf ("The \"%s\" property", glade_property_class_id (pclass));
618

619 620
  glade_app_search_docs (glade_widget_adaptor_get_book (adaptor),
                         g_type_name (pspec->owner_type), search);
621

622
  g_free (search);
623 624 625
}

void
626
glade_popup_property_pop (GladeProperty *property, GdkEventButton *event)
627 628
{

629
  GladeWidgetAdaptor *adaptor, *prop_adaptor;
630
  GladePropertyClass *pclass;
631
  GParamSpec         *pspec;
632 633 634 635
  GtkWidget *popup_menu;
  gint button;
  gint event_time;

636
  pclass       = glade_property_get_class (property);
637 638 639
  pspec        = glade_property_class_get_pspec (pclass);
  prop_adaptor = glade_property_class_get_adaptor (pclass);
  adaptor      = glade_widget_adaptor_from_pspec (prop_adaptor, pspec);
640 641 642 643 644 645 646 647

  g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));

  popup_menu = gtk_menu_new ();

  glade_popup_append_item (popup_menu, GTK_STOCK_CLEAR, _("Set default value"),
                           NULL, TRUE, glade_popup_clear_property_cb, property);

648
  if (!glade_property_class_get_virtual (pclass) &&
649 650
      glade_widget_adaptor_get_book (adaptor) &&
      glade_util_have_devhelp ())
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
    {
      GtkWidget *icon = glade_util_get_devhelp_icon (GTK_ICON_SIZE_MENU);
      glade_popup_append_item (popup_menu, NULL, _("Read _documentation"), icon,
                               TRUE, glade_popup_property_docs_cb, property);
    }

  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);
670 671
}

672
void
673
glade_popup_simple_pop (GladeProject *project, GdkEventButton *event)
674
{
675 676 677 678
  GtkWidget *popup_menu;
  gint button;
  gint event_time;

679
  popup_menu = glade_popup_create_menu (NULL, NULL, project, FALSE);
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
  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);
695 696
}

697
gboolean
698
glade_popup_is_popup_event (GdkEventButton *event)
699
{
700
  g_return_val_if_fail (event, FALSE);
701 702

#ifdef MAC_INTEGRATION
703 704
  return (event->type == GDK_BUTTON_PRESS && event->button == 1 &&
          ((event->state & GDK_MOD1_MASK) != 0));
705
#else
706
  return (event->type == GDK_BUTTON_PRESS && event->button == 3);
707 708
#endif
}