]> git.sur5r.net Git - glabels/blob - src/ui-sidebar.c
Removed non-existent filenames from po/POTFILES.in
[glabels] / src / ui-sidebar.c
1 /*
2  *  ui-sidebar.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 "ui-sidebar.h"
24
25 #include <glib/gi18n.h>
26
27 #include "ui-util.h"
28 #include "object-editor.h"
29 #include "stock.h"
30
31 #include "debug.h"
32
33
34 /*===========================================================================*/
35 /* Private macros and constants.                                             */
36 /*===========================================================================*/
37
38 #define DEFAULT_SIDEBAR_WIDTH 340
39
40
41 /*===========================================================================*/
42 /* Private data types                                                        */
43 /*===========================================================================*/
44
45 struct _glUISidebarPrivate {
46
47         glView              *view;
48
49         GtkWidget           *child;
50         GtkWidget           *empty_child;
51 };
52
53 /*===========================================================================*/
54 /* Private globals                                                           */
55 /*===========================================================================*/
56
57
58 /*===========================================================================*/
59 /* Local function prototypes                                                 */
60 /*===========================================================================*/
61
62 static void     gl_ui_sidebar_finalize      (GObject              *object);
63
64 static void     gl_ui_sidebar_construct     (glUISidebar          *sidebar);
65
66 static void     selection_changed_cb        (glView               *view,
67                                              glUISidebar          *sidebar);
68
69
70 /****************************************************************************/
71 /* Boilerplate Object stuff.                                                */
72 /****************************************************************************/
73 G_DEFINE_TYPE (glUISidebar, gl_ui_sidebar, GTK_TYPE_VBOX);
74
75
76 static void
77 gl_ui_sidebar_class_init (glUISidebarClass *class)
78 {
79         GObjectClass   *object_class     = G_OBJECT_CLASS (class);
80
81         gl_debug (DEBUG_UI, "START");
82
83         gl_ui_sidebar_parent_class = g_type_class_peek_parent (class);
84
85         object_class->finalize = gl_ui_sidebar_finalize;
86
87         gl_debug (DEBUG_UI, "END");
88 }
89
90
91 static void
92 gl_ui_sidebar_init (glUISidebar *sidebar)
93 {
94         gl_debug (DEBUG_UI, "START");
95
96         sidebar->priv = g_new0 (glUISidebarPrivate, 1);
97
98         gl_debug (DEBUG_UI, "END");
99 }
100
101
102 static void
103 gl_ui_sidebar_finalize (GObject *object)
104 {
105         glUISidebar *sidebar = GL_UI_SIDEBAR (object);
106
107         gl_debug (DEBUG_UI, "START");
108
109         g_return_if_fail (object != NULL);
110         g_return_if_fail (GL_IS_UI_SIDEBAR (object));
111
112         if (sidebar->priv->view) {
113                 g_object_unref (G_OBJECT(sidebar->priv->view));
114         }
115         g_free (sidebar->priv);
116
117         G_OBJECT_CLASS (gl_ui_sidebar_parent_class)->finalize (object);
118
119         gl_debug (DEBUG_UI, "END");
120 }
121
122
123 /****************************************************************************/
124 /* Create a NEW sidebar.                                                    */
125 /****************************************************************************/
126 GtkWidget *
127 gl_ui_sidebar_new (void)
128 {
129         glUISidebar *sidebar;
130
131         gl_debug (DEBUG_UI, "START");
132
133         sidebar = g_object_new (gl_ui_sidebar_get_type (), NULL);
134
135         gtk_widget_set_size_request (GTK_WIDGET (sidebar), DEFAULT_SIDEBAR_WIDTH, -1);
136
137         gl_ui_sidebar_construct (sidebar);
138
139         gl_debug (DEBUG_UI, "END");
140
141         return GTK_WIDGET(sidebar);
142 }
143
144
145 /******************************************************************************/
146 /* Initialize property toolbar.                                               */
147 /******************************************************************************/
148 static void
149 gl_ui_sidebar_construct (glUISidebar       *sidebar)
150 {
151         gl_debug (DEBUG_UI, "START");
152
153         sidebar->priv->empty_child = gl_object_editor_new (GL_STOCK_PROPERTIES,
154                                                            _("Object properties"),
155                                                            NULL,
156                                                            GL_OBJECT_EDITOR_EMPTY,
157                                                            NULL);
158
159         sidebar->priv->child = g_object_ref (sidebar->priv->empty_child);
160         gtk_widget_show (sidebar->priv->child);
161         gtk_container_add (GTK_CONTAINER(sidebar), sidebar->priv->child);
162
163         gtk_widget_set_sensitive (GTK_WIDGET (sidebar), FALSE);
164
165         gl_debug (DEBUG_UI, "END");
166 }
167
168
169 /****************************************************************************/
170 /* Set view associated with sidebar.                                        */
171 /****************************************************************************/
172 void
173 gl_ui_sidebar_set_view (glUISidebar *sidebar,
174                         glView      *view)
175 {
176         gl_debug (DEBUG_UI, "START");
177
178         g_return_if_fail (view && GL_IS_VIEW (view));
179
180         gtk_widget_set_sensitive (GTK_WIDGET (sidebar), TRUE);
181
182         sidebar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
183
184         g_signal_connect (G_OBJECT(view), "selection_changed",
185                           G_CALLBACK(selection_changed_cb), sidebar);
186
187         gl_debug (DEBUG_UI, "END");
188 }
189
190
191 /*---------------------------------------------------------------------------*/
192 /* PRIVATE.  View "selection state changed" callback.                        */
193 /*---------------------------------------------------------------------------*/
194 static void 
195 selection_changed_cb (glView      *view,
196                       glUISidebar *sidebar)
197 {
198         gl_debug (DEBUG_UI, "START");
199
200         g_return_if_fail (view && GL_IS_VIEW (view));
201         g_return_if_fail (sidebar && GL_IS_UI_SIDEBAR (sidebar));
202
203         gtk_container_remove (GTK_CONTAINER(sidebar), sidebar->priv->child);
204
205         if (gl_view_is_selection_empty (view) || !gl_view_is_selection_atomic (view)) {
206
207                 sidebar->priv->child = g_object_ref (sidebar->priv->empty_child);
208                 
209         } else {
210
211                 sidebar->priv->child = g_object_ref (gl_view_get_editor (view));
212
213         }
214
215         gtk_widget_show (sidebar->priv->child);
216
217         gtk_box_pack_start (GTK_BOX(sidebar), sidebar->priv->child, TRUE, TRUE, 0);
218
219         gl_debug (DEBUG_UI, "END");
220 }
221
222
223
224 /*
225  * Local Variables:       -- emacs
226  * mode: C                -- emacs
227  * c-basic-offset: 8      -- emacs
228  * tab-width: 8           -- emacs
229  * indent-tabs-mode: nil  -- emacs
230  * End:                   -- emacs
231  */