]> git.sur5r.net Git - glabels/blob - glabels2/src/object-editor-edit-page.c
0e52015a6a75cfa6b8dc11e5e21644ca74f53a74
[glabels] / glabels2 / 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 "wdgt-merge-menu.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 insert_button_cb (glObjectEditor  *editor);
59
60 static void field_selected_cb (glObjectEditor *editor, gchar *field);
61
62
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE.  Prepare size page.                                             */
65 /*--------------------------------------------------------------------------*/
66 void
67 gl_object_editor_prepare_edit_page (glObjectEditor       *editor)
68 {
69         gl_debug (DEBUG_EDITOR, "START");
70
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,
76                                      NULL);
77
78         editor->priv->edit_insert_field_menu = gl_wdgt_merge_menu_new ();
79
80         /* Un-hide */
81         gtk_widget_show_all (editor->priv->edit_page_vbox);
82
83         /* Connect signals */
84         g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_button),
85                                   "clicked",
86                                   G_CALLBACK (insert_button_cb),
87                                   G_OBJECT (editor));
88         g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_menu),
89                                   "field_selected",
90                                   G_CALLBACK (field_selected_cb),
91                                   G_OBJECT (editor));
92
93         gl_debug (DEBUG_EDITOR, "END");
94 }
95
96
97 /*--------------------------------------------------------------------------*/
98 /* PRIVATE.  Menu item activated callback.                                  */
99 /*--------------------------------------------------------------------------*/
100 static void
101 field_selected_cb (glObjectEditor *editor, gchar *field)
102 {
103         GtkTextBuffer *buffer;
104         gchar *field_string;
105  
106         gl_debug (DEBUG_EDITOR, "START");
107  
108         field_string = g_strdup_printf ("${%s}", field);
109         gl_debug (DEBUG_WDGT, "Inserting %s", field_string);
110  
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);
113  
114         g_free (field_string);
115  
116         gl_debug (DEBUG_EDITOR, "END");
117 }
118
119
120 /*--------------------------------------------------------------------------*/
121 /* PRIVATE.  Insert button callback.                                        */
122 /*--------------------------------------------------------------------------*/
123 static void
124 insert_button_cb (glObjectEditor  *editor)
125 {
126         gl_debug (DEBUG_EDITOR, "START");
127  
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 ());
131
132         gl_debug (DEBUG_EDITOR, "END");
133 }
134
135
136 /*****************************************************************************/
137 /* Set text buffer as model for text view/editor.                            */
138 /*****************************************************************************/
139 void
140 gl_object_editor_set_text_buffer (glObjectEditor      *editor,
141                                   GtkTextBuffer       *buffer)
142 {
143         gl_debug (DEBUG_EDITOR, "START");
144
145         gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
146
147         gl_debug (DEBUG_EDITOR, "END");
148 }
149
150
151
152 /*
153  * Local Variables:       -- emacs
154  * mode: C                -- emacs
155  * c-basic-offset: 8      -- emacs
156  * tab-width: 8           -- emacs
157  * indent-tabs-mode: nil  -- emacs
158  * End:                   -- emacs
159  */