]> git.sur5r.net Git - glabels/blob - src/object-editor-edit-page.c
Imported Upstream version 3.0.0
[glabels] / src / object-editor-edit-page.c
1 /*
2  *  object-editor-edit-page.c
3  *  Copyright (C) 2003-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #include <config.h>
22
23 #include "object-editor.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 #include <math.h>
28
29 #include "prefs.h"
30 #include "color.h"
31 #include "field-button.h"
32 #include "builder-util.h"
33
34 #include "object-editor-private.h"
35
36 #include "debug.h"
37
38
39 /*===========================================*/
40 /* Private macros                            */
41 /*===========================================*/
42
43
44 /*===========================================*/
45 /* Private data types                        */
46 /*===========================================*/
47
48
49 /*===========================================*/
50 /* Private globals                           */
51 /*===========================================*/
52
53
54 /*===========================================*/
55 /* Local function prototypes                 */
56 /*===========================================*/
57
58 static void key_selected_cb (glObjectEditor *editor, gchar *key);
59
60
61 /*--------------------------------------------------------------------------*/
62 /* PRIVATE.  Prepare size page.                                             */
63 /*--------------------------------------------------------------------------*/
64 void
65 gl_object_editor_prepare_edit_page (glObjectEditor       *editor)
66 {
67         gl_debug (DEBUG_EDITOR, "START");
68
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,
74                                      NULL);
75
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
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);
82
83         /* Un-hide */
84         gtk_widget_show_all (editor->priv->edit_page_vbox);
85
86         /* Connect signals */
87         g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_button),
88                                   "key_selected",
89                                   G_CALLBACK (key_selected_cb),
90                                   G_OBJECT (editor));
91
92         gl_debug (DEBUG_EDITOR, "END");
93 }
94
95
96 /*--------------------------------------------------------------------------*/
97 /* PRIVATE.  Menu item activated callback.                                  */
98 /*--------------------------------------------------------------------------*/
99 static void
100 key_selected_cb (glObjectEditor *editor, gchar *key)
101 {
102         GtkTextBuffer *buffer;
103         gchar *field_string;
104  
105         gl_debug (DEBUG_EDITOR, "START");
106  
107         field_string = g_strdup_printf ("${%s}", key);
108         gl_debug (DEBUG_WDGT, "Inserting %s", field_string);
109  
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);
112  
113         g_free (field_string);
114  
115         gl_debug (DEBUG_EDITOR, "END");
116 }
117
118
119 /*****************************************************************************/
120 /* Set text buffer as model for text view/editor.                            */
121 /*****************************************************************************/
122 void
123 gl_object_editor_set_text_buffer (glObjectEditor      *editor,
124                                   GtkTextBuffer       *buffer)
125 {
126         gl_debug (DEBUG_EDITOR, "START");
127
128         gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
129
130         gl_debug (DEBUG_EDITOR, "END");
131 }
132
133
134
135 /*
136  * Local Variables:       -- emacs
137  * mode: C                -- emacs
138  * c-basic-offset: 8      -- emacs
139  * tab-width: 8           -- emacs
140  * indent-tabs-mode: nil  -- emacs
141  * End:                   -- emacs
142  */