]> git.sur5r.net Git - glabels/blob - src/object-editor-edit-page.c
Imported Upstream version 2.2.8
[glabels] / 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 "mygal/widget-color-combo.h"
35 #include "color.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
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         editor->priv->edit_page_vbox =
71                 glade_xml_get_widget (editor->priv->gui, "edit_page_vbox");
72         editor->priv->edit_text_view =
73                 glade_xml_get_widget (editor->priv->gui, "edit_text_view");
74         editor->priv->edit_key_label =
75                 glade_xml_get_widget (editor->priv->gui, "edit_key_label");
76         editor->priv->edit_key_combo =
77                 glade_xml_get_widget (editor->priv->gui, "edit_key_combo");
78         editor->priv->edit_insert_field_button =
79                 glade_xml_get_widget (editor->priv->gui, "edit_insert_field_button");
80
81         gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->edit_key_combo));
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                                   "clicked",
89                                   G_CALLBACK (insert_button_cb),
90                                   G_OBJECT (editor));
91
92         gl_debug (DEBUG_EDITOR, "END");
93 }
94
95 /*--------------------------------------------------------------------------*/
96 /* PRIVATE.  Alignment togglebutton callback.                               */
97 /*--------------------------------------------------------------------------*/
98 static void
99 insert_button_cb (glObjectEditor  *editor)
100 {
101         GtkTextBuffer *buffer;
102         gchar *key, *field;
103  
104         gl_debug (DEBUG_EDITOR, "START");
105  
106         key = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->edit_key_combo));
107         field = g_strdup_printf ("${%s}", key);
108         gl_debug (DEBUG_WDGT, "Inserting %s", field);
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, -1);
112  
113         g_free (field);
114         g_free (key);
115  
116  
117         gl_debug (DEBUG_EDITOR, "END");
118 }
119
120 /*****************************************************************************/
121 /* Set text buffer as model for text view/editor.                            */
122 /*****************************************************************************/
123 void
124 gl_object_editor_set_text_buffer (glObjectEditor      *editor,
125                                   GtkTextBuffer       *buffer)
126 {
127         gl_debug (DEBUG_EDITOR, "START");
128
129         gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
130
131         gl_debug (DEBUG_EDITOR, "END");
132 }
133