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 "wdgt-merge-menu.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 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_builder_util_get_widgets (editor->priv->builder,
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");
97 /*--------------------------------------------------------------------------*/
98 /* PRIVATE. Menu item activated callback. */
99 /*--------------------------------------------------------------------------*/
101 field_selected_cb (glObjectEditor *editor, gchar *field)
103 GtkTextBuffer *buffer;
106 gl_debug (DEBUG_EDITOR, "START");
108 field_string = g_strdup_printf ("${%s}", field);
109 gl_debug (DEBUG_WDGT, "Inserting %s", field_string);
111 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->edit_text_view));
112 gtk_text_buffer_insert_at_cursor (buffer, field_string, -1);
114 g_free (field_string);
116 gl_debug (DEBUG_EDITOR, "END");
120 /*--------------------------------------------------------------------------*/
121 /* PRIVATE. Insert button callback. */
122 /*--------------------------------------------------------------------------*/
124 insert_button_cb (glObjectEditor *editor)
126 gl_debug (DEBUG_EDITOR, "START");
128 gtk_widget_show_all (editor->priv->edit_insert_field_menu);
129 gtk_menu_popup (GTK_MENU (editor->priv->edit_insert_field_menu),
130 NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time ());
132 gl_debug (DEBUG_EDITOR, "END");
136 /*****************************************************************************/
137 /* Set text buffer as model for text view/editor. */
138 /*****************************************************************************/
140 gl_object_editor_set_text_buffer (glObjectEditor *editor,
141 GtkTextBuffer *buffer)
143 gl_debug (DEBUG_EDITOR, "START");
145 gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
147 gl_debug (DEBUG_EDITOR, "END");
153 * Local Variables: -- emacs
155 * c-basic-offset: 8 -- emacs
156 * tab-width: 8 -- emacs
157 * indent-tabs-mode: nil -- emacs