1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * object-editor.c: object properties editor module
8 * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "object-editor.h"
28 #include <glib/gi18n.h>
29 #include <gtk/gtktextview.h>
30 #include <gtk/gtkcombobox.h>
35 #include "wdgt-merge-menu.h"
38 #include "object-editor-private.h"
42 /*===========================================*/
44 /*===========================================*/
46 /*===========================================*/
47 /* Private data types */
48 /*===========================================*/
50 /*===========================================*/
52 /*===========================================*/
54 /*===========================================*/
55 /* Local function prototypes */
56 /*===========================================*/
58 static void insert_button_cb (glObjectEditor *editor);
60 static void field_selected_cb (glObjectEditor *editor, gchar *field);
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE. Prepare size page. */
65 /*--------------------------------------------------------------------------*/
67 gl_object_editor_prepare_edit_page (glObjectEditor *editor)
69 gl_debug (DEBUG_EDITOR, "START");
71 /* Extract widgets from XML tree. */
72 gl_util_get_builder_widgets (editor->priv->gui,
73 "edit_page_vbox", &editor->priv->edit_page_vbox,
74 "edit_text_view", &editor->priv->edit_text_view,
75 "edit_insert_field_button", &editor->priv->edit_insert_field_button,
78 editor->priv->edit_insert_field_menu = gl_wdgt_merge_menu_new ();
81 gtk_widget_show_all (editor->priv->edit_page_vbox);
84 g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_button),
86 G_CALLBACK (insert_button_cb),
88 g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_menu),
90 G_CALLBACK (field_selected_cb),
93 gl_debug (DEBUG_EDITOR, "END");
96 /*--------------------------------------------------------------------------*/
97 /* PRIVATE. Menu item activated callback. */
98 /*--------------------------------------------------------------------------*/
100 field_selected_cb (glObjectEditor *editor, gchar *field)
102 GtkTextBuffer *buffer;
105 gl_debug (DEBUG_EDITOR, "START");
107 field_string = g_strdup_printf ("${%s}", field);
108 gl_debug (DEBUG_WDGT, "Inserting %s", field_string);
110 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->edit_text_view));
111 gtk_text_buffer_insert_at_cursor (buffer, field_string, -1);
113 g_free (field_string);
115 gl_debug (DEBUG_EDITOR, "END");
118 /*--------------------------------------------------------------------------*/
119 /* PRIVATE. Insert button callback. */
120 /*--------------------------------------------------------------------------*/
122 insert_button_cb (glObjectEditor *editor)
124 gl_debug (DEBUG_EDITOR, "START");
126 gtk_widget_show_all (editor->priv->edit_insert_field_menu);
127 gtk_menu_popup (GTK_MENU (editor->priv->edit_insert_field_menu),
128 NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time ());
130 gl_debug (DEBUG_EDITOR, "END");
133 /*****************************************************************************/
134 /* Set text buffer as model for text view/editor. */
135 /*****************************************************************************/
137 gl_object_editor_set_text_buffer (glObjectEditor *editor,
138 GtkTextBuffer *buffer)
140 gl_debug (DEBUG_EDITOR, "START");
142 gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
144 gl_debug (DEBUG_EDITOR, "END");