From b4714e50f777fe29eb16a2d729e8b5692ade6c88 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 2 Feb 2008 06:44:24 +0000 Subject: [PATCH] 2008-02-02 Jim Evins * 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 | 19 +++ glabels2/data/glade/object-editor.glade | 40 +---- glabels2/src/Makefile.am | 2 + glabels2/src/debug.c | 2 + glabels2/src/debug.h | 2 + glabels2/src/marshal.list | 1 + glabels2/src/object-editor-edit-page.c | 45 +++-- glabels2/src/object-editor-private.h | 3 +- glabels2/src/object-editor.c | 16 +- glabels2/src/wdgt-merge-menu.c | 209 ++++++++++++++++++++++++ glabels2/src/wdgt-merge-menu.h | 75 +++++++++ 11 files changed, 348 insertions(+), 66 deletions(-) create mode 100644 glabels2/src/wdgt-merge-menu.c create mode 100644 glabels2/src/wdgt-merge-menu.h diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 7bed074e..842c9777 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,22 @@ +2008-02-02 Jim Evins + + * 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 * src/label-barcode.c: (draw_object): diff --git a/glabels2/data/glade/object-editor.glade b/glabels2/data/glade/object-editor.glade index 8ab922df..2bf06d13 100644 --- a/glabels2/data/glade/object-editor.glade +++ b/glabels2/data/glade/object-editor.glade @@ -187,44 +187,6 @@ False 12 - - - True - Key: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - False - True - - - 0 - True - True - - - True @@ -236,7 +198,7 @@ 0 - False + True False diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index d687e1ba..41158b67 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -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 \ diff --git a/glabels2/src/debug.c b/glabels2/src/debug.c index eea3fe5d..c1ef8f7a 100644 --- a/glabels2/src/debug.c +++ b/glabels2/src/debug.c @@ -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; } diff --git a/glabels2/src/debug.h b/glabels2/src/debug.h index 5840487d..1683c330 100644 --- a/glabels2/src/debug.h +++ b/glabels2/src/debug.h @@ -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); diff --git a/glabels2/src/marshal.list b/glabels2/src/marshal.list index ea17eaf3..82aa892c 100644 --- a/glabels2/src/marshal.list +++ b/glabels2/src/marshal.list @@ -5,3 +5,4 @@ VOID:INT,UINT VOID:DOUBLE VOID:DOUBLE,DOUBLE VOID:OBJECT +VOID:STRING diff --git a/glabels2/src/object-editor-edit-page.c b/glabels2/src/object-editor-edit-page.c index 0a21e8d6..46edfc18 100644 --- a/glabels2/src/object-editor-edit-page.c +++ b/glabels2/src/object-editor-edit-page.c @@ -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"); } diff --git a/glabels2/src/object-editor-private.h b/glabels2/src/object-editor-private.h index 3a69497b..18806425 100644 --- a/glabels2/src/object-editor-private.h +++ b/glabels2/src/object-editor-private.h @@ -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; diff --git a/glabels2/src/object-editor.c b/glabels2/src/object-editor.c index d33bb4bc..c2941be4 100644 --- a/glabels2/src/object-editor.c +++ b/glabels2/src/object-editor.c @@ -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 index 00000000..bb864c39 --- /dev/null +++ b/glabels2/src/wdgt-merge-menu.c @@ -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 . + * + * 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 + +#include "wdgt-merge-menu.h" + +#include +#include + +#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); + + + +/****************************************************************************/ +/* 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 index 00000000..943709d9 --- /dev/null +++ b/glabels2/src/wdgt-merge-menu.h @@ -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 . + * + * 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 + +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 -- 2.39.5