]> git.sur5r.net Git - glabels/commitdiff
2008-02-02 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Sat, 2 Feb 2008 06:44:24 +0000 (06:44 +0000)
committerJim Evins <evins@snaught.com>
Sat, 2 Feb 2008 06:44:24 +0000 (06:44 +0000)
* src/Makefile.am:
* src/wdgt-merge-menu.c:
* src/wdgt-merge-menu.h:
* src/debug.c: (gl_debug_init):
* src/debug.h:
* src/marshal.list:
New merge menu widget.
* data/glade/object-editor.glade:
* src/object-editor-private.h:
* src/object-editor.c: (gl_object_editor_set_key_names):
* src/object-editor-edit-page.c:
(gl_object_editor_prepare_edit_page), (field_selected_cb),
(insert_button_cb):
Simplified UI for inserting fields into text objects by launching
a merge menu and directly inserting fields from the menu.  No more
selecting field in combobox, then pressing insert button.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@740 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/ChangeLog
glabels2/data/glade/object-editor.glade
glabels2/src/Makefile.am
glabels2/src/debug.c
glabels2/src/debug.h
glabels2/src/marshal.list
glabels2/src/object-editor-edit-page.c
glabels2/src/object-editor-private.h
glabels2/src/object-editor.c
glabels2/src/wdgt-merge-menu.c [new file with mode: 0644]
glabels2/src/wdgt-merge-menu.h [new file with mode: 0644]

index 7bed074e691e3a1511f0e5c3b85543b834181996..842c9777bf62928e744976174a4eaf7c55c1ec0a 100644 (file)
@@ -1,3 +1,22 @@
+2008-02-02  Jim Evins  <evins@snaught.com>
+
+       * src/Makefile.am:
+       * src/wdgt-merge-menu.c:
+       * src/wdgt-merge-menu.h:
+       * src/debug.c: (gl_debug_init):
+       * src/debug.h:
+       * src/marshal.list:
+               New merge menu widget.
+       * data/glade/object-editor.glade:
+       * src/object-editor-private.h:
+       * src/object-editor.c: (gl_object_editor_set_key_names):
+       * src/object-editor-edit-page.c:
+       (gl_object_editor_prepare_edit_page), (field_selected_cb),
+       (insert_button_cb):
+               Simplified UI for inserting fields into text objects by launching
+               a merge menu and directly inserting fields from the menu.  No more
+               selecting field in combobox, then pressing insert button.
+
 2008-01-31  Jim Evins  <evins@snaught.com>
 
        * src/label-barcode.c: (draw_object):
index 8ab922df9f7e8f72baa1014c3939f9c1f7edd982..2bf06d13cf127012c34bac6b2a65476d914a4a9d 100644 (file)
                      <property name="homogeneous">False</property>
                      <property name="spacing">12</property>
 
-                     <child>
-                       <widget class="GtkLabel" id="edit_key_label">
-                         <property name="visible">True</property>
-                         <property name="label" translatable="yes">Key:</property>
-                         <property name="use_underline">False</property>
-                         <property name="use_markup">False</property>
-                         <property name="justify">GTK_JUSTIFY_LEFT</property>
-                         <property name="wrap">False</property>
-                         <property name="selectable">False</property>
-                         <property name="xalign">0.5</property>
-                         <property name="yalign">0.5</property>
-                         <property name="xpad">0</property>
-                         <property name="ypad">0</property>
-                         <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                         <property name="width_chars">-1</property>
-                         <property name="single_line_mode">False</property>
-                         <property name="angle">0</property>
-                       </widget>
-                       <packing>
-                         <property name="padding">0</property>
-                         <property name="expand">False</property>
-                         <property name="fill">False</property>
-                       </packing>
-                     </child>
-
-                     <child>
-                       <widget class="GtkComboBox" id="edit_key_combo">
-                         <property name="visible">True</property>
-                         <property name="add_tearoffs">False</property>
-                         <property name="focus_on_click">True</property>
-                       </widget>
-                       <packing>
-                         <property name="padding">0</property>
-                         <property name="expand">True</property>
-                         <property name="fill">True</property>
-                       </packing>
-                     </child>
-
                      <child>
                        <widget class="GtkButton" id="edit_insert_field_button">
                          <property name="visible">True</property>
                        </widget>
                        <packing>
                          <property name="padding">0</property>
-                         <property name="expand">False</property>
+                         <property name="expand">True</property>
                          <property name="fill">False</property>
                        </packing>
                      </child>
index d687e1ba8e2183142e080b914678b7155a30467f..41158b67d91e8b3923645107e0c63c80ac1548cc 100644 (file)
@@ -174,6 +174,8 @@ glabels_SOURCES =                   \
        wdgt-rotate-label.h             \
        wdgt-chain-button.c             \
        wdgt-chain-button.h             \
+       wdgt-merge-menu.c               \
+       wdgt-merge-menu.h               \
        cairo-label-path.c              \
        cairo-label-path.h              \
        cairo-markup-path.c             \
index eea3fe5dc36535a24e95646470423fb0ab06a835..c1ef8f7aec08abb4e1c12baeae1c0f871edc3def 100644 (file)
@@ -96,6 +96,8 @@ gl_debug_init (void)
                debug_flags |= GLABELS_DEBUG_WDGT;
        if (g_getenv ("GLABELS_DEBUG_PATH") != NULL)
                debug_flags |= GLABELS_DEBUG_PATH;
+       if (g_getenv ("GLABELS_DEBUG_MERGE_MENU") != NULL)
+               debug_flags |= GLABELS_DEBUG_MERGE_MENU;
 }
 
 
index 5840487d99ef938c18c0f52c7c1811f87990c8f4..1683c3300488e47f8f5d7fbe7eea4c49712c1277 100644 (file)
@@ -66,6 +66,7 @@ typedef enum {
        GLABELS_DEBUG_EDITOR       = 1 << 19,
        GLABELS_DEBUG_WDGT         = 1 << 20,
         GLABELS_DEBUG_PATH         = 1 << 21,
+       GLABELS_DEBUG_MERGE_MENU   = 1 << 22,
 } glDebugSection;
 
 
@@ -95,6 +96,7 @@ typedef enum {
 #define        DEBUG_EDITOR    GLABELS_DEBUG_EDITOR, __FILE__, __LINE__, __FUNCTION__
 #define        DEBUG_WDGT      GLABELS_DEBUG_WDGT,   __FILE__, __LINE__, __FUNCTION__
 #define        DEBUG_PATH      GLABELS_DEBUG_PATH,   __FILE__, __LINE__, __FUNCTION__
+#define        DEBUG_MERGE_MENU      GLABELS_DEBUG_MERGE_MENU,   __FILE__, __LINE__, __FUNCTION__
 
 void gl_debug_init (void);
 
index ea17eaf346794b5eb9eedadc5deb1eb0efbb0385..82aa892c6104ab17fa60ec120aaa4115ec619324 100644 (file)
@@ -5,3 +5,4 @@ VOID:INT,UINT
 VOID:DOUBLE
 VOID:DOUBLE,DOUBLE
 VOID:OBJECT
+VOID:STRING
index 0a21e8d694ce203129af85c00fb59237d0959fda..46edfc18f1a0ada59cd29e17ceaa3f9acfb41d8b 100644 (file)
@@ -33,6 +33,7 @@
 #include "prefs.h"
 #include "mygal/widget-color-combo.h"
 #include "color.h"
+#include "wdgt-merge-menu.h"
 #include "util.h"
 
 #include "object-editor-private.h"
@@ -57,6 +58,8 @@
 
 static void insert_button_cb (glObjectEditor  *editor);
 
+static void field_selected_cb (glObjectEditor *editor, gchar *field);
+
 
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Prepare size page.                                             */
@@ -71,14 +74,10 @@ gl_object_editor_prepare_edit_page (glObjectEditor       *editor)
                glade_xml_get_widget (editor->priv->gui, "edit_page_vbox");
        editor->priv->edit_text_view =
                glade_xml_get_widget (editor->priv->gui, "edit_text_view");
-       editor->priv->edit_key_label =
-               glade_xml_get_widget (editor->priv->gui, "edit_key_label");
-       editor->priv->edit_key_combo =
-               glade_xml_get_widget (editor->priv->gui, "edit_key_combo");
        editor->priv->edit_insert_field_button =
                glade_xml_get_widget (editor->priv->gui, "edit_insert_field_button");
 
-       gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->edit_key_combo));
+       editor->priv->edit_insert_field_menu = gl_wdgt_merge_menu_new ();
 
        /* Un-hide */
        gtk_widget_show_all (editor->priv->edit_page_vbox);
@@ -88,32 +87,50 @@ gl_object_editor_prepare_edit_page (glObjectEditor       *editor)
                                  "clicked",
                                  G_CALLBACK (insert_button_cb),
                                  G_OBJECT (editor));
+       g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_menu),
+                                 "field_selected",
+                                 G_CALLBACK (field_selected_cb),
+                                 G_OBJECT (editor));
 
        gl_debug (DEBUG_EDITOR, "END");
 }
 
 /*--------------------------------------------------------------------------*/
-/* PRIVATE.  Alignment togglebutton callback.                               */
+/* PRIVATE.  Menu item activated callback.                                  */
 /*--------------------------------------------------------------------------*/
 static void
-insert_button_cb (glObjectEditor  *editor)
+field_selected_cb (glObjectEditor *editor, gchar *field)
 {
         GtkTextBuffer *buffer;
-        gchar *key, *field;
+        gchar *field_string;
  
         gl_debug (DEBUG_EDITOR, "START");
  
-       key = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->edit_key_combo));
-        field = g_strdup_printf ("${%s}", key);
-        gl_debug (DEBUG_WDGT, "Inserting %s", field);
+        g_print( "Field activated: \"%s\"\n", field );
+
+        field_string = g_strdup_printf ("${%s}", field);
+        gl_debug (DEBUG_WDGT, "Inserting %s", field_string);
  
         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->edit_text_view));
-        gtk_text_buffer_insert_at_cursor (buffer, field, -1);
+        gtk_text_buffer_insert_at_cursor (buffer, field_string, -1);
  
-        g_free (field);
-        g_free (key);
+        g_free (field_string);
  
+        gl_debug (DEBUG_EDITOR, "END");
+}
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Insert button callback.                                        */
+/*--------------------------------------------------------------------------*/
+static void
+insert_button_cb (glObjectEditor  *editor)
+{
+        gl_debug (DEBUG_EDITOR, "START");
  
+        gtk_widget_show_all (editor->priv->edit_insert_field_menu);
+        gtk_menu_popup (GTK_MENU (editor->priv->edit_insert_field_menu),
+                        NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time ());
+
         gl_debug (DEBUG_EDITOR, "END");
 }
 
index 3a69497b16ef60d35f684d479e6326af21ff6ed4..188064258da530fbc697b2c9ab66fc9ca58da7ef 100644 (file)
@@ -110,9 +110,8 @@ struct _glObjectEditorPrivate {
 
        GtkWidget  *edit_page_vbox;
        GtkWidget  *edit_text_view;
-       GtkWidget  *edit_key_label;
-       GtkWidget  *edit_key_combo;
        GtkWidget  *edit_insert_field_button;
+        GtkWidget  *edit_insert_field_menu;
 
        GtkWidget  *bc_page_vbox;
        GtkWidget  *bc_style_combo;
index d33bb4bcfe75552319824201c53655bd6bb5e8e3..c2941be4bf15fbc189635df62087013b6a62a130 100644 (file)
@@ -38,6 +38,7 @@
 #include "mygal/widget-color-combo.h"
 #include "color.h"
 #include "wdgt-chain-button.h"
+#include "wdgt-merge-menu.h"
 #include "marshal.h"
 #include "util.h"
 
@@ -357,19 +358,12 @@ gl_object_editor_set_key_names (glObjectEditor      *editor,
 {
         GList     *keys;
        GtkWidget *combo;
+       GtkWidget *menu;
        gboolean   fixed_flag;
        gboolean   state;
  
         gl_debug (DEBUG_EDITOR, "START");
 
-       if (editor->priv->edit_key_label) {
-               gtk_widget_set_sensitive (editor->priv->edit_key_label, merge != NULL);
-       }
-       if (editor->priv->edit_key_combo) {
-               gtk_widget_set_sensitive (editor->priv->edit_key_combo, merge != NULL);
-       }
        if (editor->priv->text_auto_shrink_check) {
                gtk_widget_set_sensitive (editor->priv->text_auto_shrink_check,
                                          merge != NULL);
@@ -507,9 +501,9 @@ gl_object_editor_set_key_names (glObjectEditor      *editor,
                gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
        }
 
-       combo = editor->priv->edit_key_combo;
-       if (combo) {
-               gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
+       menu = editor->priv->edit_insert_field_menu;
+       if (menu) {
+               gl_wdgt_merge_menu_set_fields (GL_WDGT_MERGE_MENU(menu), keys);
        }
 
        combo = editor->priv->data_key_combo;
diff --git a/glabels2/src/wdgt-merge-menu.c b/glabels2/src/wdgt-merge-menu.c
new file mode 100644 (file)
index 0000000..bb864c3
--- /dev/null
@@ -0,0 +1,209 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ *  (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ *  wdgt_merge_menu.c:  merge menu widget module
+ *
+ *  Copyright (C) 2008  Jim Evins <evins@snaught.com>.
+ *
+ *  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
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <config.h>
+
+#include "wdgt-merge-menu.h"
+
+#include <string.h>
+#include <gtk/gtkmenuitem.h>
+
+#include "marshal.h"
+
+#include "debug.h"
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+
+struct _glWdgtMergeMenuPrivate {
+
+        GList *menu_items;
+};
+
+enum {
+        FIELD_SELECTED,
+        LAST_SIGNAL
+};
+
+typedef void (*glWdgtMergeMenuSignal) (GObject * object, gpointer data);
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+static gint signals[LAST_SIGNAL] = { 0 };
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+
+static void gl_wdgt_merge_menu_finalize      (GObject              *object);
+
+
+\f
+/****************************************************************************/
+/* Boilerplate Object stuff.                                                */
+/****************************************************************************/
+G_DEFINE_TYPE (glWdgtMergeMenu, gl_wdgt_merge_menu, GTK_TYPE_MENU);
+
+
+static void
+gl_wdgt_merge_menu_class_init (glWdgtMergeMenuClass *class)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+        gl_debug (DEBUG_MERGE_MENU, "START");
+
+        gl_wdgt_merge_menu_parent_class = g_type_class_peek_parent (class);
+
+        object_class->finalize = gl_wdgt_merge_menu_finalize;
+
+        signals[FIELD_SELECTED] =
+            g_signal_new ("field_selected",
+                          G_OBJECT_CLASS_TYPE(object_class),
+                          G_SIGNAL_RUN_LAST,
+                          G_STRUCT_OFFSET (glWdgtMergeMenuClass, field_selected),
+                          NULL, NULL,
+                          gl_marshal_VOID__STRING,
+                          G_TYPE_NONE, 1, G_TYPE_STRING);
+
+        gl_debug (DEBUG_MERGE_MENU, "END");
+}
+
+static void
+gl_wdgt_merge_menu_init (glWdgtMergeMenu *merge_menu)
+{
+        gl_debug (DEBUG_MERGE_MENU, "START");
+
+        merge_menu->priv = g_new0 (glWdgtMergeMenuPrivate, 1);
+
+        gl_debug (DEBUG_MERGE_MENU, "END");
+}
+
+static void
+gl_wdgt_merge_menu_finalize (GObject *object)
+{
+        glWdgtMergeMenu *merge_menu = GL_WDGT_MERGE_MENU (object);
+        GList           *p;
+        GtkWidget       *menu_item;
+        gchar           *field;
+
+        gl_debug (DEBUG_MERGE_MENU, "START");
+
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (GL_IS_WDGT_MERGE_MENU (object));
+
+        for ( p = merge_menu->priv->menu_items; p != NULL; p = p->next )
+        {
+                menu_item = GTK_WIDGET (p->data);
+                field = g_object_get_data (G_OBJECT (menu_item), "field");
+                g_free (field);
+        }
+        g_list_free (merge_menu->priv->menu_items);
+        g_free (merge_menu->priv);
+
+        G_OBJECT_CLASS (gl_wdgt_merge_menu_parent_class)->finalize (object);
+
+        gl_debug (DEBUG_MERGE_MENU, "END");
+}
+
+GtkWidget *
+gl_wdgt_merge_menu_new (void)
+{
+        glWdgtMergeMenu *merge_menu;
+
+        gl_debug (DEBUG_MERGE_MENU, "START");
+
+        merge_menu = g_object_new (gl_wdgt_merge_menu_get_type (), NULL);
+
+        gl_debug (DEBUG_MERGE_MENU, "END");
+
+        return GTK_WIDGET (merge_menu);
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* PRIVATE.  Menu item activation callback.                                 */
+/*--------------------------------------------------------------------------*/
+static void
+activate_cb (GtkMenuItem     *menu_item,
+             glWdgtMergeMenu *merge_menu)
+{
+        gchar *field;
+
+        gl_debug (DEBUG_MERGE_MENU, "START");
+
+        field = g_object_get_data (G_OBJECT (menu_item), "field");
+        gl_debug (DEBUG_MERGE_MENU, "Field activated: \"%s\"\n", field );
+
+        g_signal_emit (G_OBJECT (merge_menu), signals[FIELD_SELECTED], 0, field);
+
+        gl_debug (DEBUG_MERGE_MENU, "END");
+}
+
+/****************************************************************************/
+/* set field names.                                                         */
+/****************************************************************************/
+void
+gl_wdgt_merge_menu_set_fields (glWdgtMergeMenu *merge_menu,
+                               GList           *field_list)
+{
+        GList     *p;
+        GtkWidget *menu_item;
+        gchar     *field;
+
+        gl_debug (DEBUG_MERGE_MENU, "START");
+
+        /*
+         * Remove all old menu items.
+         */
+        for ( p = merge_menu->priv->menu_items; p != NULL; p = p->next )
+        {
+                menu_item = GTK_WIDGET (p->data);
+                field = g_object_get_data (G_OBJECT (menu_item), "field");
+                g_free (field);
+                gtk_widget_destroy (menu_item);
+        }
+        g_list_free (merge_menu->priv->menu_items);
+        merge_menu->priv->menu_items = NULL;
+
+        /*
+         * Add new menu items.
+         */
+        for ( p = field_list; p != NULL; p = p->next )
+        {
+                menu_item = gtk_menu_item_new_with_label (p->data);
+                g_object_set_data (G_OBJECT (menu_item), "field", g_strdup (p->data));
+                g_signal_connect (G_OBJECT (menu_item), "activate", 
+                                  G_CALLBACK (activate_cb), merge_menu);
+                gtk_menu_shell_append (GTK_MENU_SHELL (merge_menu), menu_item);
+                merge_menu->priv->menu_items =
+                        g_list_append (merge_menu->priv->menu_items, menu_item);
+        }
+
+        gl_debug (DEBUG_MERGE_MENU, "END");
+}
+
diff --git a/glabels2/src/wdgt-merge-menu.h b/glabels2/src/wdgt-merge-menu.h
new file mode 100644 (file)
index 0000000..943709d
--- /dev/null
@@ -0,0 +1,75 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ *  (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ *  wdgt_merge_menu.h:  Merge menu widget module header file
+ *
+ *  Copyright (C) 2008  Jim Evins <evins@snaught.com>.
+ *
+ *  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
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#ifndef __WDGT_MERGE_MENU_H__
+#define __WDGT_MERGE_MENU_H__
+
+#include <gtk/gtkmenu.h>
+
+G_BEGIN_DECLS
+
+#define GL_TYPE_WDGT_MERGE_MENU (gl_wdgt_merge_menu_get_type ())
+#define GL_WDGT_MERGE_MENU(obj) \
+        (GTK_CHECK_CAST((obj), GL_TYPE_WDGT_MERGE_MENU, glWdgtMergeMenu ))
+#define GL_WDGT_MERGE_MENU_CLASS(klass) \
+        (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_WDGT_MERGE_MENU, glWdgtMergeMenuClass))
+#define GL_IS_WDGT_MERGE_MENU(obj) \
+        (GTK_CHECK_TYPE ((obj), GL_TYPE_WDGT_MERGE_MENU))
+#define GL_IS_WDGT_MERGE_MENU_CLASS(klass) \
+        (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_WDGT_MERGE_MENU))
+
+
+typedef struct _glWdgtMergeMenu         glWdgtMergeMenu;
+typedef struct _glWdgtMergeMenuClass    glWdgtMergeMenuClass;
+
+typedef struct _glWdgtMergeMenuPrivate  glWdgtMergeMenuPrivate;
+
+
+struct _glWdgtMergeMenu {
+        GtkMenu                  parent_widget;
+
+        glWdgtMergeMenuPrivate  *priv;
+};
+
+
+struct _glWdgtMergeMenuClass {
+        GtkMenuClass             parent_class;
+
+        void (*field_selected) (glWdgtMergeMenu *merge_menu,
+                                gchar           *field,
+                                gpointer         user_data);
+};
+
+
+GType      gl_wdgt_merge_menu_get_type      (void) G_GNUC_CONST;
+
+GtkWidget *gl_wdgt_merge_menu_new           (void);
+
+void       gl_wdgt_merge_menu_set_fields    (glWdgtMergeMenu *merge_menu,
+                                             GList           *field_list);
+
+
+G_END_DECLS
+
+#endif