]> git.sur5r.net Git - glabels/blob - glabels2/src/object-editor-edit-page.c
2008-10-18 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / object-editor-edit-page.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (GLABELS) Label and Business Card Creation program for GNOME
5  *
6  *  object-editor.c:  object properties editor module
7  *
8  *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23  */
24 #include <config.h>
25
26 #include "object-editor.h"
27
28 #include <glib/gi18n.h>
29 #include <gtk/gtktextview.h>
30 #include <gtk/gtkcombobox.h>
31 #include <math.h>
32
33 #include "prefs.h"
34 #include "color.h"
35 #include "wdgt-merge-menu.h"
36 #include "util.h"
37
38 #include "object-editor-private.h"
39
40 #include "debug.h"
41
42 /*===========================================*/
43 /* Private macros                            */
44 /*===========================================*/
45
46 /*===========================================*/
47 /* Private data types                        */
48 /*===========================================*/
49
50 /*===========================================*/
51 /* Private globals                           */
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_util_get_builder_widgets (editor->priv->gui,
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 /* PRIVATE.  Menu item activated callback.                                  */
98 /*--------------------------------------------------------------------------*/
99 static void
100 field_selected_cb (glObjectEditor *editor, gchar *field)
101 {
102         GtkTextBuffer *buffer;
103         gchar *field_string;
104  
105         gl_debug (DEBUG_EDITOR, "START");
106  
107         field_string = g_strdup_printf ("${%s}", field);
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 /* PRIVATE.  Insert button callback.                                        */
120 /*--------------------------------------------------------------------------*/
121 static void
122 insert_button_cb (glObjectEditor  *editor)
123 {
124         gl_debug (DEBUG_EDITOR, "START");
125  
126         gtk_widget_show_all (editor->priv->edit_insert_field_menu);
127         gtk_menu_popup (GTK_MENU (editor->priv->edit_insert_field_menu),
128                         NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time ());
129
130         gl_debug (DEBUG_EDITOR, "END");
131 }
132
133 /*****************************************************************************/
134 /* Set text buffer as model for text view/editor.                            */
135 /*****************************************************************************/
136 void
137 gl_object_editor_set_text_buffer (glObjectEditor      *editor,
138                                   GtkTextBuffer       *buffer)
139 {
140         gl_debug (DEBUG_EDITOR, "START");
141
142         gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
143
144         gl_debug (DEBUG_EDITOR, "END");
145 }
146