]> git.sur5r.net Git - glabels/blob - src/object-editor-edit-page.c
Reference glabels.org website
[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         GTK_WIDGET_UNSET_FLAGS (editor->priv->edit_insert_field_button,
80                                 GTK_CAN_FOCUS | GTK_CAN_DEFAULT);
81
82         /* Un-hide */
83         gtk_widget_show_all (editor->priv->edit_page_vbox);
84
85         /* Connect signals */
86         g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_button),
87                                   "key_selected",
88                                   G_CALLBACK (key_selected_cb),
89                                   G_OBJECT (editor));
90
91         gl_debug (DEBUG_EDITOR, "END");
92 }
93
94
95 /*--------------------------------------------------------------------------*/
96 /* PRIVATE.  Menu item activated callback.                                  */
97 /*--------------------------------------------------------------------------*/
98 static void
99 key_selected_cb (glObjectEditor *editor, gchar *key)
100 {
101         GtkTextBuffer *buffer;
102         gchar *field_string;
103  
104         gl_debug (DEBUG_EDITOR, "START");
105  
106         field_string = g_strdup_printf ("${%s}", key);
107         gl_debug (DEBUG_WDGT, "Inserting %s", field_string);
108  
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);
111  
112         g_free (field_string);
113  
114         gl_debug (DEBUG_EDITOR, "END");
115 }
116
117
118 /*****************************************************************************/
119 /* Set text buffer as model for text view/editor.                            */
120 /*****************************************************************************/
121 void
122 gl_object_editor_set_text_buffer (glObjectEditor      *editor,
123                                   GtkTextBuffer       *buffer)
124 {
125         gl_debug (DEBUG_EDITOR, "START");
126
127         gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
128
129         gl_debug (DEBUG_EDITOR, "END");
130 }
131
132
133
134 /*
135  * Local Variables:       -- emacs
136  * mode: C                -- emacs
137  * c-basic-offset: 8      -- emacs
138  * tab-width: 8           -- emacs
139  * indent-tabs-mode: nil  -- emacs
140  * End:                   -- emacs
141  */