3 * Copyright (C) 2003-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
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.
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.
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/>.
23 #include "ui-sidebar.h"
25 #include <glib/gi18n.h>
28 #include "object-editor.h"
34 /*===========================================================================*/
35 /* Private macros and constants. */
36 /*===========================================================================*/
38 #define DEFAULT_SIDEBAR_WIDTH 340
41 /*===========================================================================*/
42 /* Private data types */
43 /*===========================================================================*/
45 struct _glUISidebarPrivate {
50 GtkWidget *empty_child;
53 /*===========================================================================*/
55 /*===========================================================================*/
58 /*===========================================================================*/
59 /* Local function prototypes */
60 /*===========================================================================*/
62 static void gl_ui_sidebar_finalize (GObject *object);
64 static void gl_ui_sidebar_construct (glUISidebar *sidebar);
66 static void selection_changed_cb (glView *view,
67 glUISidebar *sidebar);
70 /****************************************************************************/
71 /* Boilerplate Object stuff. */
72 /****************************************************************************/
73 G_DEFINE_TYPE (glUISidebar, gl_ui_sidebar, GTK_TYPE_VBOX);
77 gl_ui_sidebar_class_init (glUISidebarClass *class)
79 GObjectClass *object_class = G_OBJECT_CLASS (class);
81 gl_debug (DEBUG_UI, "START");
83 gl_ui_sidebar_parent_class = g_type_class_peek_parent (class);
85 object_class->finalize = gl_ui_sidebar_finalize;
87 gl_debug (DEBUG_UI, "END");
92 gl_ui_sidebar_init (glUISidebar *sidebar)
94 gl_debug (DEBUG_UI, "START");
96 sidebar->priv = g_new0 (glUISidebarPrivate, 1);
98 gl_debug (DEBUG_UI, "END");
103 gl_ui_sidebar_finalize (GObject *object)
105 glUISidebar *sidebar = GL_UI_SIDEBAR (object);
107 gl_debug (DEBUG_UI, "START");
109 g_return_if_fail (object != NULL);
110 g_return_if_fail (GL_IS_UI_SIDEBAR (object));
112 if (sidebar->priv->view) {
113 g_object_unref (G_OBJECT(sidebar->priv->view));
115 g_free (sidebar->priv);
117 G_OBJECT_CLASS (gl_ui_sidebar_parent_class)->finalize (object);
119 gl_debug (DEBUG_UI, "END");
123 /****************************************************************************/
124 /* Create a NEW sidebar. */
125 /****************************************************************************/
127 gl_ui_sidebar_new (void)
129 glUISidebar *sidebar;
131 gl_debug (DEBUG_UI, "START");
133 sidebar = g_object_new (gl_ui_sidebar_get_type (), NULL);
135 gtk_widget_set_size_request (GTK_WIDGET (sidebar), DEFAULT_SIDEBAR_WIDTH, -1);
137 gl_ui_sidebar_construct (sidebar);
139 gl_debug (DEBUG_UI, "END");
141 return GTK_WIDGET(sidebar);
145 /******************************************************************************/
146 /* Initialize property toolbar. */
147 /******************************************************************************/
149 gl_ui_sidebar_construct (glUISidebar *sidebar)
151 gl_debug (DEBUG_UI, "START");
153 sidebar->priv->empty_child = gl_object_editor_new (GL_STOCK_PROPERTIES,
154 _("Object properties"),
156 GL_OBJECT_EDITOR_EMPTY,
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);
163 gtk_widget_set_sensitive (GTK_WIDGET (sidebar), FALSE);
165 gl_debug (DEBUG_UI, "END");
169 /****************************************************************************/
170 /* Set view associated with sidebar. */
171 /****************************************************************************/
173 gl_ui_sidebar_set_view (glUISidebar *sidebar,
176 gl_debug (DEBUG_UI, "START");
178 g_return_if_fail (view && GL_IS_VIEW (view));
180 gtk_widget_set_sensitive (GTK_WIDGET (sidebar), TRUE);
182 sidebar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
184 g_signal_connect (G_OBJECT(view), "selection_changed",
185 G_CALLBACK(selection_changed_cb), sidebar);
187 gl_debug (DEBUG_UI, "END");
191 /*---------------------------------------------------------------------------*/
192 /* PRIVATE. View "selection state changed" callback. */
193 /*---------------------------------------------------------------------------*/
195 selection_changed_cb (glView *view,
196 glUISidebar *sidebar)
198 gl_debug (DEBUG_UI, "START");
200 g_return_if_fail (view && GL_IS_VIEW (view));
201 g_return_if_fail (sidebar && GL_IS_UI_SIDEBAR (sidebar));
203 gtk_container_remove (GTK_CONTAINER(sidebar), sidebar->priv->child);
205 if (gl_view_is_selection_empty (view) || !gl_view_is_selection_atomic (view)) {
207 sidebar->priv->child = g_object_ref (sidebar->priv->empty_child);
211 sidebar->priv->child = g_object_ref (gl_view_get_editor (view));
215 gtk_widget_show (sidebar->priv->child);
217 gtk_box_pack_start (GTK_BOX(sidebar), sidebar->priv->child, TRUE, TRUE, 0);
219 gl_debug (DEBUG_UI, "END");
225 * Local Variables: -- emacs
227 * c-basic-offset: 8 -- emacs
228 * tab-width: 8 -- emacs
229 * indent-tabs-mode: nil -- emacs