glade-popup.c 23.2 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 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
{
45 46
  glade_util_clear_selection ();
  glade_app_selection_set (glade_widget_get_object (widget), TRUE);
47
}
48

49
static GladePlaceholder *
50
find_placeholder (GObject * object)
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
  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;
77 78 79
}

static void
80 81
glade_popup_placeholder_add_cb (GtkMenuItem * item,
                                GladePlaceholder * placeholder)
82
{
83 84 85 86 87
  GladeWidgetAdaptor *adaptor;
  GladeWidget *parent;

  adaptor = glade_palette_get_current_item (glade_app_get_palette ());
  g_return_if_fail (adaptor != NULL);
88

89
  parent = glade_placeholder_get_parent (placeholder);
90

91 92 93 94 95 96
  if (!glade_util_check_and_warn_scrollable
      (parent, adaptor, glade_app_get_window ()))
    {
      glade_command_create (adaptor, parent,
                            placeholder,
                            glade_placeholder_get_project (placeholder));
97

98 99
      glade_palette_deselect_current_item (glade_app_get_palette (), TRUE);
    }
100 101 102
}

static void
103
glade_popup_root_add_cb (GtkMenuItem * item, gpointer * user_data)
104
{
105 106 107 108 109 110 111 112
  GladeWidgetAdaptor *adaptor = (GladeWidgetAdaptor *) user_data;
  GladePalette *palette = glade_app_get_palette ();

  if (!adaptor)
    adaptor = glade_palette_get_current_item (palette);
  g_return_if_fail (adaptor != NULL);

  glade_palette_create_root_widget (palette, adaptor);
113 114
}

115
static void
116
glade_popup_cut_cb (GtkMenuItem * item, GladeWidget * widget)
117
{
118 119 120 121 122 123 124 125 126 127 128
  GladeProject *project = glade_app_get_project ();

  glade_util_clear_selection ();

  /* Assign selection first */
  if (glade_project_is_selected
      (project, glade_widget_get_object (widget)) == FALSE)
    {
      glade_app_selection_set (glade_widget_get_object (widget), FALSE);
    }
  glade_app_command_cut ();
Jose Maria Celorio's avatar
Jose Maria Celorio committed
129 130 131
}

static void
132
glade_popup_copy_cb (GtkMenuItem * item, GladeWidget * widget)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
133
{
134
  GladeProject *project = glade_app_get_project ();
135

136
  glade_util_clear_selection ();
137

138 139 140 141
  /* Assign selection first */
  if (glade_project_is_selected
      (project, glade_widget_get_object (widget)) == FALSE)
    glade_app_selection_set (glade_widget_get_object (widget), FALSE);
142

143
  glade_app_command_copy ();
144
}
Jose Maria Celorio's avatar
Jose Maria Celorio committed
145

146
static void
147
glade_popup_paste_cb (GtkMenuItem * item, GladeWidget * widget)
148
{
149
  glade_util_clear_selection ();
150

151 152 153 154 155
  /* The selected widget is the paste destination */
  if (widget)
    glade_app_selection_set (glade_widget_get_object (widget), FALSE);
  else
    glade_app_selection_clear (FALSE);
156

157
  glade_app_command_paste (NULL);
158
}
Jose Maria Celorio's avatar
Jose Maria Celorio committed
159

160
static void
161
glade_popup_delete_cb (GtkMenuItem * item, GladeWidget * widget)
162
{
163
  GladeProject *project = glade_app_get_project ();
164

165 166 167 168
  /* Assign selection first */
  if (glade_project_is_selected
      (project, glade_widget_get_object (widget)) == FALSE)
    glade_app_selection_set (glade_widget_get_object (widget), FALSE);
169

170
  glade_app_command_delete ();
Jose Maria Celorio's avatar
Jose Maria Celorio committed
171
}
172

173 174 175
/********************************************************
                  PLACEHOLDER POPUP
 *******************************************************/
176
static void
177 178
glade_popup_placeholder_paste_cb (GtkMenuItem * item,
                                  GladePlaceholder * placeholder)
179
{
180 181 182 183
  glade_util_clear_selection ();
  glade_app_selection_clear (FALSE);

  glade_app_command_paste (placeholder);
184 185
}

186 187 188 189

/********************************************************
                    CLIPBOARD POPUP
 *******************************************************/
190
static void
191
glade_popup_clipboard_paste_cb (GtkMenuItem * item, GladeWidget * widget)
192
{
193 194
  glade_util_clear_selection ();
  glade_app_selection_clear (FALSE);
195

196
  glade_app_command_paste (NULL);
197 198 199
}

static void
200
glade_popup_clipboard_delete_cb (GtkMenuItem * item, GladeWidget * widget)
201
{
202
  glade_app_command_delete_clipboard ();
203 204
}

205
static void
206
glade_popup_docs_cb (GtkMenuItem * item, GladeWidgetAdaptor * adaptor)
207
{
208
  gchar *book;
209

210
  g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));
211

212
  g_object_get (adaptor, "book", &book, NULL);
213 214
  glade_editor_search_doc_search (glade_app_get_editor (), book, 
				  glade_widget_adaptor_get_name (adaptor),
215 216
                                  NULL);
  g_free (book);
217 218 219
}


220 221 222
/********************************************************
                    POPUP BUILDING
 *******************************************************/
223
static GtkWidget *
224 225 226 227 228
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
229
{
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
  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
258 259
}

260

Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
261
static void
262
glade_popup_menuitem_activated (GtkMenuItem * item, const gchar * action_path)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
263
{
264 265 266
  GladeWidget *widget;

  if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data")))
267 268
    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
269 270
}

271
static void
272 273
glade_popup_menuitem_packing_activated (GtkMenuItem * item,
                                        const gchar * action_path)
274
{
275
  GladeWidget *widget, *parent;
276 277

  if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data")))
278 279 280 281 282 283
    {
      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);
    }
284 285
}

286
static void
287 288
glade_popup_menuitem_ph_packing_activated (GtkMenuItem * item,
                                           const gchar * action_path)
289
{
290 291 292 293 294 295
  GladePlaceholder *ph;
  GladeWidget *parent;

  if ((ph = g_object_get_data (G_OBJECT (item), "gwa-data")))
    {
      parent = glade_placeholder_get_parent (ph);
296 297
      glade_widget_adaptor_child_action_activate (glade_widget_get_adaptor (parent),
                                                  glade_widget_get_object (parent),
298 299
                                                  G_OBJECT (ph), action_path);
    }
300 301
}

302
static gint
303 304 305 306
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
307
{
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
  GtkWidget *item;
  GList *list;
  gint n = 0;

  for (list = actions; list; list = g_list_next (list))
    {
      GladeWidgetAction *a = list->data;
      GtkWidget *submenu = NULL;

      if (a->actions)
        {
          submenu = gtk_menu_new ();
          n += glade_popup_action_populate_menu_real (submenu,
                                                      gwidget,
                                                      a->actions,
                                                      callback, data);
        }
      else
326 327
        submenu = glade_widget_adaptor_action_submenu (glade_widget_get_adaptor (gwidget),
                                                       glade_widget_get_object (gwidget),
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
                                                       a->klass->path);


      item = glade_popup_append_item (menu,
                                      a->klass->stock,
                                      a->klass->label, NULL, TRUE,
                                      (a->actions) ? NULL : callback,
                                      (a->actions) ? NULL : a->klass->path);

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

      gtk_widget_set_sensitive (item, a->sensitive);

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

      n++;
    }

  return n;
348 349
}

350 351 352 353 354
/*
 * 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.
355
 * @packing: TRUE to include packing actions
356 357 358 359 360 361
 *
 * Populate a GtkMenu with widget's actions
 *
 * Returns the number of action appended to the menu.
 */
gint
362 363 364
glade_popup_action_populate_menu (GtkWidget * menu,
                                  GladeWidget * widget,
                                  GladeWidgetAction * action, gboolean packing)
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
  gint n;

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

  if (action)
    {
      g_return_val_if_fail (GLADE_IS_WIDGET_ACTION (action), 0);
      if (glade_widget_get_action (widget, action->klass->path))
        return glade_popup_action_populate_menu_real (menu,
                                                      widget,
                                                      action->actions,
                                                      G_CALLBACK
                                                      (glade_popup_menuitem_activated),
                                                      widget);

      if (glade_widget_get_pack_action (widget, action->klass->path))
        return glade_popup_action_populate_menu_real (menu,
                                                      glade_widget_get_parent
                                                      (widget), action->actions,
                                                      G_CALLBACK
                                                      (glade_popup_menuitem_packing_activated),
                                                      widget);

      return 0;
    }

  n = glade_popup_action_populate_menu_real (menu,
                                             widget,
395
                                             glade_widget_get_actions (widget),
396 397 398 399
                                             G_CALLBACK
                                             (glade_popup_menuitem_activated),
                                             widget);

400
  if (packing && glade_widget_get_pack_actions (widget))
401 402 403 404 405 406 407
    {
      if (n)
        {
          GtkWidget *separator = gtk_menu_item_new ();
          gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
          gtk_widget_show (separator);
        }
408 409 410 411
      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);
412 413 414
    }

  return n;
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
415
}
416

417
static GtkWidget *
418 419
glade_popup_create_menu (GladeWidget * widget,
                         GladePlaceholder * placeholder, gboolean packing)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
420
{
421 422 423 424 425 426 427 428
  GtkWidget *popup_menu;
  GtkWidget *separator;
  gboolean sensitive;
  GladePlaceholder *tmp_placeholder;
  gchar *book;

  popup_menu = gtk_menu_new ();

429
  if (glade_palette_get_current_item (glade_app_get_palette ()))
430
    {
431 432 433 434 435 436 437 438 439
      tmp_placeholder = placeholder;
      if (!tmp_placeholder && widget)
	tmp_placeholder =
	  find_placeholder (glade_widget_get_object (widget));

      glade_popup_append_item (popup_menu, NULL, _("_Add widget here"),
			       NULL, tmp_placeholder != NULL,
			       glade_popup_placeholder_add_cb,
			       tmp_placeholder);
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

      glade_popup_append_item (popup_menu, NULL, _("Add widget as _toplevel"),
                               NULL, TRUE, glade_popup_root_add_cb, NULL);

      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)
    {
479
      if (widget && glade_widget_get_actions (widget))
480 481 482 483 484 485 486 487
        {
          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,
488
               glade_widget_get_actions (widget),
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
               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,
               widget,
               placeholder->packing_actions,
               G_CALLBACK (glade_popup_menuitem_ph_packing_activated),
               placeholder);
        }
    }
506 507
  else if (widget && (glade_widget_get_actions (widget) || 
		      (packing && glade_widget_get_pack_actions (widget))))
508 509 510 511 512 513 514 515 516 517
    {
      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);
    }

  if (widget)
    {
518
      g_object_get (glade_widget_get_adaptor (widget), "book", &book, NULL);
519 520 521 522 523 524 525 526 527
      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,
528
                                   glade_widget_get_adaptor (widget));
529 530 531 532 533
        }
      g_free (book);
    }

  return popup_menu;
Jose Maria Celorio's avatar
Jose Maria Celorio committed
534 535
}

536
static GtkWidget *
537
glade_popup_create_clipboard_menu (GladeWidget * widget)
538
{
539
  GtkWidget *popup_menu;
540

541
  popup_menu = gtk_menu_new ();
542

543 544 545 546 547 548
  if (gtk_widget_is_toplevel (GTK_WIDGET (glade_widget_get_object (widget))))
    {
      glade_popup_append_item (popup_menu, GTK_STOCK_PASTE,
                               NULL, NULL, TRUE,
                               glade_popup_clipboard_paste_cb, NULL);
    }
549

550 551 552 553
  glade_popup_append_item (popup_menu, GTK_STOCK_DELETE, NULL, NULL, TRUE,
                           glade_popup_clipboard_delete_cb, widget);

  return popup_menu;
554 555
}

Jose Maria Celorio's avatar
Jose Maria Celorio committed
556
void
557 558
glade_popup_widget_pop (GladeWidget * widget,
                        GdkEventButton * event, gboolean packing)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
559
{
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
  GtkWidget *popup_menu;
  gint button;
  gint event_time;

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

  popup_menu = glade_popup_create_menu (widget, NULL, packing);

  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
580
}
581 582

void
583 584
glade_popup_placeholder_pop (GladePlaceholder * placeholder,
                             GdkEventButton * event)
585
{
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
  GladeWidget *widget;
  GtkWidget *popup_menu;
  gint button;
  gint event_time;

  g_return_if_fail (GLADE_IS_PLACEHOLDER (placeholder));

  widget = glade_placeholder_get_parent (placeholder);

  popup_menu = glade_popup_create_menu (widget, placeholder, TRUE);

  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);
610
}
611 612

void
613
glade_popup_clipboard_pop (GladeWidget * widget, GdkEventButton * event)
614
{
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
  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);
636
}
637

638
void
639
glade_popup_palette_pop (GladeWidgetAdaptor * adaptor, GdkEventButton * event)
640
{
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
  GladeProject *project;
  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 ();

  project = glade_app_get_project ();

  glade_popup_append_item (popup_menu, NULL, _("Add widget as _toplevel"), NULL,
                           TRUE, glade_popup_root_add_cb, adaptor);

  g_object_get (adaptor, "book", &book, NULL);
  if (book && glade_util_have_devhelp ())
    {
      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);
    }
  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);
679 680
}

681
static void
682
glade_popup_clear_property_cb (GtkMenuItem * item, GladeProperty * property)
683
{
684
  GValue value = { 0, };
685

686 687 688
  glade_property_get_default (property, &value);
  glade_command_set_property_value (property, &value);
  g_value_unset (&value);
689 690 691
}

static void
692
glade_popup_property_docs_cb (GtkMenuItem * item, GladeProperty * property)
693
{
694
  GladeWidgetAdaptor *adaptor, *prop_adaptor;
695
  GladePropertyClass *pclass;
696
  gchar *search, *book;
697

698 699 700 701
  pclass       = glade_property_get_class (property);
  prop_adaptor = glade_widget_adaptor_from_pclass (pclass);
  adaptor      = glade_widget_adaptor_from_pspec (prop_adaptor, pclass->pspec);
  search       = g_strdup_printf ("The %s property", pclass->id);
702

703
  g_object_get (adaptor, "book", &book, NULL);
704

705
  glade_editor_search_doc_search (glade_app_get_editor (),
706 707
                                  book, 
				  g_type_name (pclass->pspec->owner_type), search);
708

709 710
  g_free (book);
  g_free (search);
711 712 713
}

void
714
glade_popup_property_pop (GladeProperty * property, GdkEventButton * event)
715 716
{

717
  GladeWidgetAdaptor *adaptor, *prop_adaptor;
718
  GladePropertyClass *pclass;
719 720 721 722 723
  GtkWidget *popup_menu;
  gchar *book = NULL;
  gint button;
  gint event_time;

724 725 726
  pclass       = glade_property_get_class (property);
  prop_adaptor = glade_widget_adaptor_from_pclass (pclass);
  adaptor      = glade_widget_adaptor_from_pspec (prop_adaptor, pclass->pspec);
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757

  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);

  g_object_get (adaptor, "book", &book, NULL);
  if (book && glade_util_have_devhelp ())
    {
      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);
    }
  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);
758 759
}

760

761
void
762
glade_popup_simple_pop (GdkEventButton * event)
763
{
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
  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);
784 785
}

786
gboolean
787
glade_popup_is_popup_event (GdkEventButton * event)
788
{
789
  g_return_val_if_fail (event, FALSE);
790 791

#ifdef MAC_INTEGRATION
792 793
  return (event->type == GDK_BUTTON_PRESS && event->button == 1 &&
          ((event->state & GDK_MOD1_MASK) != 0));
794
#else
795
  return (event->type == GDK_BUTTON_PRESS && event->button == 3);
796 797
#endif
}