]> git.sur5r.net Git - glabels/commitdiff
Make glFieldButtonMenu multi-columned for large number of keys.
authorJim Evins <evins@snaught.com>
Thu, 22 Oct 2009 02:34:10 +0000 (22:34 -0400)
committerJim Evins <evins@snaught.com>
Thu, 22 Oct 2009 02:34:10 +0000 (22:34 -0400)
Make glFieldButtonMenu multi-columned for large number of keys.  I don't know
why, but I need to unrealize the old menu whenever reloading a new set of
keys -- otherwise, the new menu would not render properly.

Also, cleared the CAN_FOCUS and CAN_DEFAULT bits for the instance in
the object editor text edit page, so that it would not steal the focus
from the text editor.

src/field-button-menu.c
src/object-editor-edit-page.c

index 38f23481a12326de0d66ed3fc883132055767d5b..37509f22644a0e3821758c86fd444a810052b867 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "debug.h"
 
+#define MAX_MENU_ROWS 25
 
 /*===========================================*/
 /* Private types                             */
@@ -176,6 +177,7 @@ gl_field_button_menu_set_keys (glFieldButtonMenu *this,
         GList     *p;
         GtkWidget *menu_item;
         gchar     *key;
+        gint       i, i_row, i_col;
 
         gl_debug (DEBUG_FIELD_BUTTON, "START");
 
@@ -187,24 +189,34 @@ gl_field_button_menu_set_keys (glFieldButtonMenu *this,
                 menu_item = GTK_WIDGET (p->data);
                 key = g_object_get_data (G_OBJECT (menu_item), "key");
                 g_free (key);
-                gtk_widget_destroy (menu_item);
+                gtk_container_remove (GTK_CONTAINER (this), menu_item);
         }
         g_list_free (this->priv->menu_items);
         this->priv->menu_items = NULL;
+        gtk_widget_unrealize (GTK_WIDGET (this)); /* Start over with new Gdk resources. */
 
         /*
          * Add new menu items.
          */
-        for ( p = key_list; p != NULL; p = p->next )
+        for ( p = key_list, i = 0; p != NULL; p = p->next, i++ )
         {
-                gl_debug (DEBUG_FIELD_BUTTON, "Adding key: %s", p->data);
-                menu_item = gtk_menu_item_new_with_label (p->data);
-                g_object_set_data (G_OBJECT (menu_item), "key", g_strdup (p->data));
-                g_signal_connect (G_OBJECT (menu_item), "activate", 
-                                  G_CALLBACK (activate_cb), this);
-                gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
-                this->priv->menu_items =
-                        g_list_append (this->priv->menu_items, menu_item);
+                if ( p->data && strlen (p->data) )
+                {
+
+                        gl_debug (DEBUG_FIELD_BUTTON, "Adding key: %s", p->data);
+
+                        menu_item = gtk_menu_item_new_with_label (p->data);
+                        gtk_widget_show (menu_item);
+                        g_object_set_data (G_OBJECT (menu_item), "key", g_strdup (p->data));
+                        g_signal_connect (G_OBJECT (menu_item), "activate", 
+                                          G_CALLBACK (activate_cb), this);
+                        this->priv->menu_items =
+                                g_list_append (this->priv->menu_items, menu_item);
+
+                        i_row = i % MAX_MENU_ROWS;
+                        i_col = i / MAX_MENU_ROWS;
+                        gtk_menu_attach (GTK_MENU (this), menu_item, i_col, i_col+1, i_row, i_row+1);
+                }
         }
 
         gl_debug (DEBUG_FIELD_BUTTON, "END");
index 949f02396957dd3986245301a91c3748bb4d02cf..c85ff5be584975201c33bac2485d0f465214a13e 100644 (file)
@@ -76,6 +76,8 @@ gl_object_editor_prepare_edit_page (glObjectEditor       *editor)
        editor->priv->edit_insert_field_button = gl_field_button_new (_("Insert merge field"));
         gtk_box_pack_start (GTK_BOX (editor->priv->edit_insert_field_vbox),
                             editor->priv->edit_insert_field_button, FALSE, FALSE, 0);
+        GTK_WIDGET_UNSET_FLAGS (editor->priv->edit_insert_field_button,
+                                GTK_CAN_FOCUS | GTK_CAN_DEFAULT);
 
        /* Un-hide */
        gtk_widget_show_all (editor->priv->edit_page_vbox);