2 * object-editor-edit-page.c
3 * Copyright (C) 2003-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "object-editor.h"
25 #include <glib/gi18n.h>
31 #include "field-button.h"
32 #include "builder-util.h"
34 #include "object-editor-private.h"
39 /*===========================================*/
41 /*===========================================*/
44 /*===========================================*/
45 /* Private data types */
46 /*===========================================*/
49 /*===========================================*/
51 /*===========================================*/
54 /*===========================================*/
55 /* Local function prototypes */
56 /*===========================================*/
58 static void key_selected_cb (glObjectEditor *editor, gchar *key);
61 /*--------------------------------------------------------------------------*/
62 /* PRIVATE. Prepare size page. */
63 /*--------------------------------------------------------------------------*/
65 gl_object_editor_prepare_edit_page (glObjectEditor *editor)
67 gl_debug (DEBUG_EDITOR, "START");
69 /* Extract widgets from XML tree. */
70 gl_builder_util_get_widgets (editor->priv->builder,
71 "edit_page_vbox", &editor->priv->edit_page_vbox,
72 "edit_text_view", &editor->priv->edit_text_view,
73 "edit_insert_field_vbox", &editor->priv->edit_insert_field_vbox,
76 editor->priv->edit_insert_field_button = gl_field_button_new (_("Insert merge field"));
77 gtk_box_pack_start (GTK_BOX (editor->priv->edit_insert_field_vbox),
78 editor->priv->edit_insert_field_button, FALSE, FALSE, 0);
79 GTK_WIDGET_UNSET_FLAGS (editor->priv->edit_insert_field_button,
80 GTK_CAN_FOCUS | GTK_CAN_DEFAULT);
83 gtk_widget_show_all (editor->priv->edit_page_vbox);
86 g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_button),
88 G_CALLBACK (key_selected_cb),
91 gl_debug (DEBUG_EDITOR, "END");
95 /*--------------------------------------------------------------------------*/
96 /* PRIVATE. Menu item activated callback. */
97 /*--------------------------------------------------------------------------*/
99 key_selected_cb (glObjectEditor *editor, gchar *key)
101 GtkTextBuffer *buffer;
104 gl_debug (DEBUG_EDITOR, "START");
106 field_string = g_strdup_printf ("${%s}", key);
107 gl_debug (DEBUG_WDGT, "Inserting %s", field_string);
109 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->edit_text_view));
110 gtk_text_buffer_insert_at_cursor (buffer, field_string, -1);
112 g_free (field_string);
114 gl_debug (DEBUG_EDITOR, "END");
118 /*****************************************************************************/
119 /* Set text buffer as model for text view/editor. */
120 /*****************************************************************************/
122 gl_object_editor_set_text_buffer (glObjectEditor *editor,
123 GtkTextBuffer *buffer)
125 gl_debug (DEBUG_EDITOR, "START");
127 gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
129 gl_debug (DEBUG_EDITOR, "END");
135 * Local Variables: -- emacs
137 * c-basic-offset: 8 -- emacs
138 * tab-width: 8 -- emacs
139 * indent-tabs-mode: nil -- emacs