]> git.sur5r.net Git - glabels/blob - glabels2/src/object-editor-edit-page.c
f7d3bf0d5bfa25ebf427ed756dc30f91d5cc58be
[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         editor->priv->edit_page_vbox =
73                 glade_xml_get_widget (editor->priv->gui, "edit_page_vbox");
74         editor->priv->edit_text_view =
75                 glade_xml_get_widget (editor->priv->gui, "edit_text_view");
76         editor->priv->edit_insert_field_button =
77                 glade_xml_get_widget (editor->priv->gui, "edit_insert_field_button");
78
79         editor->priv->edit_insert_field_menu = gl_wdgt_merge_menu_new ();
80
81         /* Un-hide */
82         gtk_widget_show_all (editor->priv->edit_page_vbox);
83
84         /* Connect signals */
85         g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_button),
86                                   "clicked",
87                                   G_CALLBACK (insert_button_cb),
88                                   G_OBJECT (editor));
89         g_signal_connect_swapped (G_OBJECT (editor->priv->edit_insert_field_menu),
90                                   "field_selected",
91                                   G_CALLBACK (field_selected_cb),
92                                   G_OBJECT (editor));
93
94         gl_debug (DEBUG_EDITOR, "END");
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 /* PRIVATE.  Insert button callback.                                        */
121 /*--------------------------------------------------------------------------*/
122 static void
123 insert_button_cb (glObjectEditor  *editor)
124 {
125         gl_debug (DEBUG_EDITOR, "START");
126  
127         gtk_widget_show_all (editor->priv->edit_insert_field_menu);
128         gtk_menu_popup (GTK_MENU (editor->priv->edit_insert_field_menu),
129                         NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time ());
130
131         gl_debug (DEBUG_EDITOR, "END");
132 }
133
134 /*****************************************************************************/
135 /* Set text buffer as model for text view/editor.                            */
136 /*****************************************************************************/
137 void
138 gl_object_editor_set_text_buffer (glObjectEditor      *editor,
139                                   GtkTextBuffer       *buffer)
140 {
141         gl_debug (DEBUG_EDITOR, "START");
142
143         gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor->priv->edit_text_view), buffer);
144
145         gl_debug (DEBUG_EDITOR, "END");
146 }
147