+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):
<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>
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 \
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;
}
GLABELS_DEBUG_EDITOR = 1 << 19,
GLABELS_DEBUG_WDGT = 1 << 20,
GLABELS_DEBUG_PATH = 1 << 21,
+ GLABELS_DEBUG_MERGE_MENU = 1 << 22,
} glDebugSection;
#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);
VOID:DOUBLE
VOID:DOUBLE,DOUBLE
VOID:OBJECT
+VOID:STRING
#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"
static void insert_button_cb (glObjectEditor *editor);
+static void field_selected_cb (glObjectEditor *editor, gchar *field);
+
/*--------------------------------------------------------------------------*/
/* PRIVATE. Prepare size page. */
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);
"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");
}
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;
#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"
{
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);
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;
--- /dev/null
+/* -*- 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");
+}
+
--- /dev/null
+/* -*- 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