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);
80 gtk_widget_set_can_focus (editor->priv->edit_insert_field_button, FALSE);
81 gtk_widget_set_can_default (editor->priv->edit_insert_field_button, FALSE);
84 gtk_widget_show_all (editor->priv->edit_page_vbox);
87 g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_button),
89 G_CALLBACK (key_selected_cb),
92 gl_debug (DEBUG_EDITOR, "END");
96 /*--------------------------------------------------------------------------*/
97 /* PRIVATE. Menu item activated callback. */
98 /*--------------------------------------------------------------------------*/
100 key_selected_cb (glObjectEditor *editor, gchar *key)
102 GtkTextBuffer *buffer;
105 gl_debug (DEBUG_EDITOR, "START");
107 field_string = g_strdup_printf ("${%s}", key);
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");
119 /*****************************************************************************/
120 /* Set text buffer as model for text view/editor. */
121 /*****************************************************************************/
123 gl_object_editor_set_text_buffer (glObjectEditor *editor,
124 GtkTextBuffer *buffer)
126 gl_debug (DEBUG_EDITOR, "START");
128 gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
130 gl_debug (DEBUG_EDITOR, "END");
136 * Local Variables: -- emacs
138 * c-basic-offset: 8 -- emacs
139 * tab-width: 8 -- emacs
140 * indent-tabs-mode: nil -- emacs