[Glade-devel] [patch, glade3] cleanup popup menu



--=-jdNcLd71f1LCXJgsN9J5
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi!

The patch attached cleans up the popup menu making it saner (IMHO before
the code worked by chance since the "activate" event was connected to
functions with different prototypes from that of the event handler).
Beside the Cut, Copy etc in the popup ended up calling different
functions from those in the main menu bar.
Last but not least, after the patch popup menu items have stock icons
and mnemonics :) .

Here are the changes to make review easier:

- remove glade_widget_copy and friends: some codepaths (e.g. the main
menu bar) didn't call these, while others (e.g the popup menu) did;
since they only called glade_command_copy etc, which is what was used in
the other places, remove them and their occurences.

- provide proper callbacks for the popup menu items: e.g.
glade_popup_cut_cb etc; also move in popup.c the
placeholder_paste_callback which was only used here.

- improve glade_popup_append_item so that it handles mnemonics and
icons, beside using g_object_set_data is not needed anymore.

hope it makes sense


ciao
        paolo

--=-jdNcLd71f1LCXJgsN9J5
Content-Disposition: attachment; filename=popup_menu.patch
Content-Type: text/x-patch; name=popup_menu.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

diff -upr gnome2/glade3/ChangeLog glade3/ChangeLog
--- gnome2/glade3/ChangeLog     2003-05-09 07:53:58.000000000 +0200
+++ glade3/ChangeLog    2003-05-09 18:03:54.000000000 +0200
@@ -1,3 +1,13 @@
+2003-05-09  Paolo Borelli  <pborelli katamail com>
+
+       * src/glade-popup.c: hoverhowl the popup menu so that code is 
+       saner and follows the same codepaths of Cut/Copy etc in main 
+       menu. As a nice side effect item now have icon and mnemonics.
+       * src/glade-widget.[ch]: remove remnant of the above work
+       * src/glade-placeholder.[ch]: ditto
+       * src/glade-gtk.c: update for the above
+       * src/glade-project-window.c: update for the above
+
 2003-05-08  Paolo Borelli  <pborelli katamail com>
 
        * src/glade-project.c: fix glade_project_new_from_node so that it 
diff -upr gnome2/glade3/src/glade-gtk.c glade3/src/glade-gtk.c
--- gnome2/glade3/src/glade-gtk.c       2003-03-29 14:49:08.000000000 +0100
+++ glade3/src/glade-gtk.c      2003-05-09 14:25:44.000000000 +0200
@@ -30,6 +30,7 @@
 #include "glade-property.h"
 #include "glade-property-class.h"
 #include "glade-choice.h"
+#include "glade-command.h"
 
 
 static void
@@ -230,7 +231,7 @@ glade_gtk_box_set_size (GObject *object,
                        child_property = glade_property_get_from_id (child_widget->properties, "position");
                        position = glade_property_get_integer (child_property);
                        if (position >= new_size) {
-                               glade_widget_delete (child_widget);
+                               glade_command_delete (child_widget);
                                gtk_container_remove (GTK_CONTAINER (box),
                                                      box_child->widget);
                        }
diff -upr gnome2/glade3/src/glade-placeholder.c glade3/src/glade-placeholder.c
--- gnome2/glade3/src/glade-placeholder.c       2003-05-09 07:53:59.000000000 +0200
+++ glade3/src/glade-placeholder.c      2003-05-09 17:33:58.000000000 +0200
@@ -316,7 +316,9 @@ glade_placeholder_clear_selection_nodes 
 }
 
 static void
-glade_placeholder_on_button_press_event (GladePlaceholder *placeholder, GdkEventButton *event, GladeProject 
*project)
+glade_placeholder_on_button_press_event (GladePlaceholder *placeholder,
+                                        GdkEventButton *event,
+                                        GladeProject *project)
 {
        GladeProjectWindow *gpw;
 
@@ -345,7 +347,6 @@ glade_placeholder_on_button_press_event 
        } else if (event->button == 3) {
                glade_popup_placeholder_pop (placeholder, event);
        }
-                       
 }
 
 static void
@@ -616,7 +617,7 @@ glade_placeholder_remove_all (GtkWidget 
                        if (glade_placeholder_is (box_child->widget)) {
                                child_widget = glade_widget_get_from_gtk_widget (box_child->widget);
                                if (child_widget)
-                                       glade_widget_delete (child_widget);
+                                       glade_command_delete (child_widget);
                                gtk_container_remove (GTK_CONTAINER (box),
                                                      box_child->widget);
                                element = g_list_first (box->children);
@@ -640,7 +641,7 @@ glade_placeholder_remove_all (GtkWidget 
                                if (glade_placeholder_is (box_child->widget)) {
                                        child_widget = glade_widget_get_from_gtk_widget (box_child->widget);
                                        if (child_widget)
-                                               glade_widget_delete (child_widget);
+                                               glade_command_delete (child_widget);
                                        gtk_container_remove (GTK_CONTAINER (box),
                                        box_child->widget);
                                        element = g_list_first (box->children);
@@ -660,7 +661,7 @@ glade_placeholder_remove_all (GtkWidget 
                        if (glade_placeholder_is (table_child->widget)) {
                                child_widget = glade_widget_get_from_gtk_widget (table_child->widget);
                                if (child_widget)
-                                       glade_widget_delete (child_widget);
+                                       glade_command_delete (child_widget);
                                gtk_container_remove (GTK_CONTAINER (widget),
                                                      table_child->widget);
                                element = g_list_first (GTK_TABLE (widget)->children);
@@ -794,16 +795,3 @@ glade_placeholder_fill_empty (GtkWidget 
        }
 }
 
-void
-glade_placeholder_paste_cb (GtkWidget *button, gpointer data)
-{
-       GladeProjectWindow *gpw;
-
-       gpw = glade_project_window_get ();
-
-       /*
-        * The data parameter is the placeholder we have to replace with the
-        * widget.
-        */
-       glade_command_paste (gpw->active_widget, GTK_WIDGET (data));
-}
diff -upr gnome2/glade3/src/glade-placeholder.h glade3/src/glade-placeholder.h
--- gnome2/glade3/src/glade-placeholder.h       2002-03-18 09:39:43.000000000 +0100
+++ glade3/src/glade-placeholder.h      2003-05-09 17:34:28.000000000 +0200
@@ -29,8 +29,8 @@ gboolean glade_placeholder_is (GtkWidget
 #endif
 
 void glade_placeholder_remove_all (GtkWidget *widget);
+
 void glade_placeholder_fill_empty (GtkWidget *widget);
-void glade_placeholder_paste_cb (GtkWidget *button, gpointer data);
 
 G_END_DECLS
 
diff -upr gnome2/glade3/src/glade-popup.c glade3/src/glade-popup.c
--- gnome2/glade3/src/glade-popup.c     2002-03-18 09:39:43.000000000 +0100
+++ glade3/src/glade-popup.c    2003-05-09 17:52:33.000000000 +0200
@@ -20,58 +20,92 @@
  *   Chema Celorio <chema celorio com>
  */
 
-#define GLADE_POPUP_WIDGET_POINTER "GladePopupWidgetPointer"
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include "glade.h"
 #include "glade-widget.h"
 #include "glade-popup.h"
 #include "glade-placeholder.h"
+#include "glade-clipboard.h"
+#include "glade-command.h"
+#include "glade-project-window.h"
+
+
+static void
+glade_popup_select_cb (GtkMenuItem *item, GladeWidget *widget)
+{
+       glade_widget_select (widget);
+}
+
+static void
+glade_popup_cut_cb (GtkMenuItem *item, GladeWidget *widget)
+{
+       glade_command_cut (widget);
+}
+
+static void
+glade_popup_copy_cb (GtkMenuItem *item, GladeWidget *widget)
+{
+       GladeProjectWindow *gpw;
+
+       gpw = glade_project_window_get ();
+       glade_clipboard_copy (gpw->clipboard, widget);
+}
 
 static void
-glade_popup_menu_detach (GtkWidget *attach_widget,
-                        GtkMenu *menu)
+glade_popup_paste_cb (GtkMenuItem *item, GladeWidget *widget)
 {
+       glade_implement_me ();
+       /*
+        * look in glade-placeholder.c (glade_placeholder_on_button_press_event
+        * for the "paste" operation code.
+        */
+}
 
+static void
+glade_popup_delete_cb (GtkMenuItem *item, GladeWidget *widget)
+{
+       glade_command_delete (widget);
 }
 
 static void
-glade_popup_item_activate_cb (GtkWidget *menu_item,
-                             GladeWidgetFunction function)
+glade_popup_placeholder_paste_cb (GtkMenuItem *item,
+                                 GladePlaceholder *placeholder)
 {
-       GladeWidget *widget;
+       GladeProjectWindow *gpw;
 
-       widget = g_object_get_data (G_OBJECT (menu_item), GLADE_POPUP_WIDGET_POINTER);
+       gpw = glade_project_window_get ();
+       glade_command_paste (gpw->active_widget, placeholder);
+}
 
-       g_return_if_fail (GLADE_IS_WIDGET (widget));
-       g_return_if_fail (GTK_IS_WIDGET (widget->widget));
+static void
+glade_popup_menu_detach (GtkWidget *attach_widget, GtkMenu *menu)
+{
 
-       (*function) (widget);
 }
-                           
+
+/*
+ * If stock_id != NULL, label is ignored
+ */
 static void
 glade_popup_append_item (GtkWidget *popup_menu,
-                        GladeWidget *widget,
-                        const gchar  *label,
-                        GladeWidgetFunction function,
-                        gboolean sensitive)
+                        const gchar *stock_id,
+                        const gchar *label,
+                        gboolean sensitive,
+                        gpointer callback,
+                        gpointer data)
 {
        GtkWidget *menu_item;
 
-       menu_item = gtk_menu_item_new_with_label (label);
+       if (stock_id != NULL)
+               menu_item = gtk_image_menu_item_new_from_stock (stock_id, NULL);
+       else
+               menu_item = gtk_menu_item_new_with_mnemonic (label);
 
-       g_object_set_data (G_OBJECT (menu_item), GLADE_POPUP_WIDGET_POINTER, widget);
-       gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
-                           GTK_SIGNAL_FUNC (glade_popup_item_activate_cb),
-                           function);
+       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);
+       gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);
 }
 
 static GtkWidget *
@@ -98,7 +132,6 @@ glade_popup_populate_childs(GtkWidget* p
                gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu),
                                       child);
 
-                       
                parent = parent->parent;
        }
 }
@@ -107,20 +140,19 @@ static GtkWidget *
 glade_popup_create_menu (GladeWidget *widget, gboolean add_childs)
 {
        GtkWidget *popup_menu;
-       
-       popup_menu = gtk_menu_new ();
 
-       glade_popup_append_item (popup_menu, widget, _("Select"),
-                                glade_widget_select, TRUE);
-       glade_popup_append_item (popup_menu, widget, _("Cut"),
-                                glade_widget_cut, TRUE);
-       glade_popup_append_item (popup_menu, widget, _("Copy"),
-                                glade_widget_copy, TRUE);
-       glade_popup_append_item (popup_menu, widget, _("Paste"),
-                                glade_widget_paste, TRUE);
+       popup_menu = gtk_menu_new ();
 
-       glade_popup_append_item (popup_menu, widget, _("Delete"),
-                                glade_widget_delete, TRUE);
+       glade_popup_append_item (popup_menu, NULL, _("_Select"), TRUE,
+                                glade_popup_select_cb, widget);
+       glade_popup_append_item (popup_menu, GTK_STOCK_CUT, NULL, TRUE,
+                                glade_popup_cut_cb, widget);
+       glade_popup_append_item (popup_menu, GTK_STOCK_COPY, NULL, TRUE,
+                                glade_popup_copy_cb, widget);
+       glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, TRUE,
+                                glade_popup_paste_cb, widget);
+       glade_popup_append_item (popup_menu, GTK_STOCK_DELETE, NULL, TRUE,
+                                glade_popup_delete_cb, widget);
 
        if (add_childs && widget->parent)
                glade_popup_populate_childs(popup_menu, widget->parent);
@@ -132,21 +164,12 @@ static GtkWidget *
 glade_popup_create_placeholder_menu (GladePlaceholder *placeholder)
 {
        GtkWidget *popup_menu;
-       GtkWidget *menu_item;
        GladeWidget *parent;
        
        popup_menu = gtk_menu_new ();
 
-       menu_item = gtk_menu_item_new_with_label (_("Paste"));
-
-       gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
-                           GTK_SIGNAL_FUNC (glade_placeholder_paste_cb),
-                           placeholder);
-
-       gtk_widget_set_sensitive (menu_item, TRUE);
-       gtk_widget_show (menu_item);
-       gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu),
-                              menu_item);
+       glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, TRUE,
+                                glade_popup_placeholder_paste_cb, placeholder);
 
        if ((parent = glade_placeholder_get_parent(placeholder)) != NULL)
                glade_popup_populate_childs(popup_menu, parent);
@@ -172,7 +195,8 @@ glade_popup_pop (GladeWidget *widget, Gd
 }
 
 void
-glade_popup_placeholder_pop (GladePlaceholder *placeholder, GdkEventButton *event)
+glade_popup_placeholder_pop (GladePlaceholder *placeholder,
+                            GdkEventButton *event)
 {
        GtkWidget *popup_menu;
 
diff -upr gnome2/glade3/src/glade-project-window.c glade3/src/glade-project-window.c
--- gnome2/glade3/src/glade-project-window.c    2003-05-05 14:11:36.000000000 +0200
+++ glade3/src/glade-project-window.c   2003-05-09 14:25:44.000000000 +0200
@@ -296,7 +296,7 @@ gpw_delete_cb (void)
        list = g_list_copy (selection);
        free_me = list;
        for (; list; list = list->next)
-               glade_widget_delete (list->data);
+               glade_command_delete (list->data);
        g_list_free (free_me);
 
        /* Right now deleting widgets like this is not a problem, cause we
diff -upr gnome2/glade3/src/glade-widget.c glade3/src/glade-widget.c
--- gnome2/glade3/src/glade-widget.c    2003-05-09 07:54:08.000000000 +0200
+++ glade3/src/glade-widget.c   2003-05-09 17:48:05.000000000 +0200
@@ -253,7 +253,9 @@ glade_widget_get_from_event_widget (GtkW
  * Return Value: 
  **/
 static gboolean
-glade_widget_button_press (GtkWidget *event_widget, GdkEventButton *event, gpointer not_used)
+glade_widget_button_press (GtkWidget *event_widget,
+                          GdkEventButton *event,
+                          gpointer not_used)
 {
        GladeProjectWindow *gpw;
        GladeWidget *glade_widget;
@@ -540,14 +542,14 @@ glade_widget_key_press(GtkWidget *event_
                project = glade_widget->project;
                g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE);
 
-               /* The selection value changes when we do glade_widget_delete,
+               /* The selection value changes when we do glade_command_delete,
                   so if we just try to follow selection->next after the
-                  glade_widget_delete, we are going directly to a segfault (if lucky) */
+                  glade_command_delete, we are going directly to a segfault (if lucky) */
                while ((selection = glade_project_selection_get(project)) != NULL) {
                        g_return_val_if_fail (selection->data != NULL, FALSE);
 
                        glade_widget = GLADE_WIDGET (selection->data);
-                       glade_widget_delete (glade_widget);
+                       glade_command_delete (glade_widget);
                }
        }
 
@@ -1093,15 +1095,12 @@ glade_widget_set_name (GladeWidget *widg
        glade_project_widget_name_changed (widget->project, widget);
 }
 
-
-
 void
 glade_widget_select (GladeWidget *widget)
 {
        glade_project_selection_set (widget, TRUE);
 }
 
-
 static void
 glade_widget_clear_draw_selection (GladeWidget *widget)
 {
@@ -1227,46 +1226,6 @@ glade_widget_replace_with_placeholder (G
        return placeholder;
 }
 
-void
-glade_widget_delete (GladeWidget *widget)
-{
-       g_return_if_fail (widget != NULL);
-       glade_command_delete (widget);
-}
-
-void
-glade_widget_cut (GladeWidget *widget)
-{
-       GladeProjectWindow *gpw;
-       GladeClipboard *clipboard;
-
-       gpw = glade_project_window_get ();
-       clipboard = gpw->clipboard;
-       glade_command_cut (widget);
-}
-
-void
-glade_widget_copy (GladeWidget *widget)
-{
-       GladeProjectWindow *gpw;
-       GladeClipboard *clipboard;
-
-       gpw = glade_project_window_get ();
-       clipboard = gpw->clipboard;
-
-       glade_clipboard_copy (clipboard, widget);
-}
-
-void
-glade_widget_paste (GladeWidget *widget)
-{
-       glade_implement_me ();
-       /*
-        * look in glade-placeholder.c (glade_placeholder_on_button_press_event
-        * for the "paste" operation code.
-        */
-}
-
 /**
  * glade_widget_new_from_class_name:
  * @class_name: 
diff -upr gnome2/glade3/src/glade-widget.h glade3/src/glade-widget.h
--- gnome2/glade3/src/glade-widget.h    2002-04-12 11:01:35.000000000 +0200
+++ glade3/src/glade-widget.h   2003-05-09 14:25:44.000000000 +0200
@@ -90,10 +90,6 @@ void glade_widget_flag_selected   (Glade
 void glade_widget_flag_unselected (GladeWidget *widget);
 
 void glade_widget_select (GladeWidget *widget);
-void glade_widget_delete (GladeWidget *widget);
-void glade_widget_cut    (GladeWidget *widget);
-void glade_widget_copy   (GladeWidget *widget);
-void glade_widget_paste  (GladeWidget *widget);
 
 GladeWidget *glade_widget_clone (GladeWidget *widget);
 GladePlaceholder * glade_widget_replace_with_placeholder (GladeWidget *widget);

--=-jdNcLd71f1LCXJgsN9J5--





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]