1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * anjuta
4  * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
5  *
6  * git-shell-test is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * git-shell-test is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "anjuta-dock-pane.h"
21 
22 /**
23  * SECTION: anjuta-dock-pane
24  * @short_description: Wrapper class for #AnjutaDock panes
25  * @see_also: #AnjutaDock
26  * @include: libanjuta/anjuta-dock-pane.h
27  *
28  * AnjutaDockPane is an abstract wrapper class for panes in an
29  * #AnjutaDock.
30  *
31  * Using AnjutaDockPane is especially helpful for those panes that show data
32  * from extenal sources that must be refreshed frequently, or panes that are
33  * exceptionally complex.
34  */
35 
36 enum
37 {
38 	ANJUTA_DOCK_PANE_PLUGIN = 1
39 };
40 
41 enum
42 {
43 	SINGLE_SELECTION_CHANGED,
44 	MULTIPLE_SELECTION_CHANGED,
45 
46 	LAST_SIGNAL
47 };
48 
49 static guint anjuta_dock_pane_signals[LAST_SIGNAL] = { 0 };
50 
51 struct _AnjutaDockPanePriv
52 {
53 	AnjutaPlugin *plugin;
54 };
55 
56 G_DEFINE_ABSTRACT_TYPE (AnjutaDockPane, anjuta_dock_pane, G_TYPE_OBJECT);
57 
58 static void
anjuta_dock_pane_init(AnjutaDockPane * self)59 anjuta_dock_pane_init (AnjutaDockPane *self)
60 {
61 	self->priv = g_new0 (AnjutaDockPanePriv, 1);
62 }
63 
64 static void
anjuta_dock_pane_finalize(GObject * object)65 anjuta_dock_pane_finalize (GObject *object)
66 {
67 	AnjutaDockPane *self;
68 
69 	self = ANJUTA_DOCK_PANE (object);
70 
71 	g_free (self->priv);
72 
73 	G_OBJECT_CLASS (anjuta_dock_pane_parent_class)->finalize (object);
74 }
75 
76 static void
anjuta_dock_pane_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * param_spec)77 anjuta_dock_pane_set_property (GObject *object, guint property_id,
78                                const GValue *value, GParamSpec *param_spec)
79 {
80 	AnjutaDockPane *self;
81 
82 	self = ANJUTA_DOCK_PANE (object);
83 
84 	switch (property_id)
85 	{
86 		case ANJUTA_DOCK_PANE_PLUGIN:
87 			self->priv->plugin = ANJUTA_PLUGIN (g_value_get_object (value));
88 			break;
89 		default:
90 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, param_spec);
91 			break;
92 	}
93 }
94 
95 static void
anjuta_dock_pane_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * param_spec)96 anjuta_dock_pane_get_property (GObject *object, guint property_id,
97                                GValue *value, GParamSpec *param_spec)
98 {
99 	AnjutaDockPane *self;
100 
101 	self = ANJUTA_DOCK_PANE (object);
102 
103 	switch (property_id)
104 	{
105 		case ANJUTA_DOCK_PANE_PLUGIN:
106 			g_value_set_object (value, self->priv->plugin);
107 			break;
108 		default:
109 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, param_spec);
110 			break;
111 	}
112 }
113 
114 static void
anjuta_dock_pane_single_selection_changed(AnjutaDockPane * pane)115 anjuta_dock_pane_single_selection_changed (AnjutaDockPane *pane)
116 {
117 }
118 
119 static void
anjuta_dock_pane_multiple_selection_changed(AnjutaDockPane * pane)120 anjuta_dock_pane_multiple_selection_changed (AnjutaDockPane *pane)
121 {
122 }
123 
124 static void
anjuta_dock_pane_class_init(AnjutaDockPaneClass * klass)125 anjuta_dock_pane_class_init (AnjutaDockPaneClass *klass)
126 {
127 	GObjectClass* object_class = G_OBJECT_CLASS (klass);
128 	GParamSpec *param_spec;
129 
130 	object_class->finalize = anjuta_dock_pane_finalize;
131 	object_class->set_property = anjuta_dock_pane_set_property;
132 	object_class->get_property = anjuta_dock_pane_get_property;
133 	klass->refresh = NULL;
134 	klass->get_widget = NULL;
135 	klass->single_selection_changed = anjuta_dock_pane_single_selection_changed;
136 	klass->multiple_selection_changed = anjuta_dock_pane_multiple_selection_changed;
137 
138 	param_spec = g_param_spec_object ("plugin", "Plugin",
139 	                                  "Plugin object associated with this pane.",
140 	                                  ANJUTA_TYPE_PLUGIN,
141 	                                  G_PARAM_READWRITE);
142 	g_object_class_install_property (object_class, ANJUTA_DOCK_PANE_PLUGIN,
143 	                                 param_spec);
144 
145 	/**
146 	 * AnjutaDockPane::single-selection-changed:
147 	 * @pane: An AnjutaDockPane
148 	 *
149 	 * This signal is emitted by pane subclasses to notify clients that
150 	 * the user has selected an item. This signal should be used when users are
151 	 * expected to only select one item at a time.
152 	 */
153 	anjuta_dock_pane_signals[SINGLE_SELECTION_CHANGED] =
154 		g_signal_new ("single-selection-changed",
155 		              G_OBJECT_CLASS_TYPE (klass),
156 		              G_SIGNAL_RUN_FIRST,
157 		              G_STRUCT_OFFSET (AnjutaDockPaneClass, single_selection_changed),
158 		              NULL,
159 		              NULL,
160 		              g_cclosure_marshal_VOID__VOID,
161 		              G_TYPE_NONE,
162 		              0);
163 
164 	/**
165 	 * AnjutaDockPane::multiple-selection-changed:
166 	 * @pane: An AnjutaDockPane
167 	 *
168 	 * This signal is emitted by pane subclasses to notify clients that the set
169 	 * of selected items in the pane has changed.
170 	 */
171 	anjuta_dock_pane_signals[MULTIPLE_SELECTION_CHANGED] =
172 		g_signal_new ("multiple-selection-changed",
173 		              G_OBJECT_CLASS_TYPE (klass),
174 		              G_SIGNAL_RUN_FIRST,
175 		              G_STRUCT_OFFSET (AnjutaDockPaneClass, multiple_selection_changed),
176 		              NULL,
177 		              NULL,
178 		              g_cclosure_marshal_VOID__VOID,
179 		              G_TYPE_NONE,
180 		              0);
181 
182 }
183 
184 /**
185  * anjuta_dock_pane_refresh:
186  * @self: An AnjutaDockPane
187  *
188  * Refreshes the given pane. Subclasses only need to override this method if
189  * needed.
190  */
191 void
anjuta_dock_pane_refresh(AnjutaDockPane * self)192 anjuta_dock_pane_refresh (AnjutaDockPane *self)
193 {
194 	AnjutaDockPaneClass *klass;
195 
196 	klass = ANJUTA_DOCK_PANE_GET_CLASS (self);
197 
198 	if (klass->refresh)
199 		klass->refresh (self);
200 }
201 
202 /**
203  * anjuta_dock_pane_get_widget:
204  * @self: An AnjutaDockPane
205  *
206  * Returns: The widget associated with the given pane. The returned widget is
207  * owned by the pane and should not be destroyed or modified.
208  */
209 GtkWidget *
anjuta_dock_pane_get_widget(AnjutaDockPane * self)210 anjuta_dock_pane_get_widget (AnjutaDockPane *self)
211 {
212 	return ANJUTA_DOCK_PANE_GET_CLASS (self)->get_widget (self);
213 }
214 
215 
216 /**
217  * anjuta_dock_pane_get_plugin:
218  * @self: An AnjutaDockPane
219  *
220  * Returns: The plugin object associated with this pane.
221  */
222 AnjutaPlugin *
anjuta_dock_pane_get_plugin(AnjutaDockPane * self)223 anjuta_dock_pane_get_plugin (AnjutaDockPane *self)
224 {
225 	return self->priv->plugin;
226 }
227 
228 /**
229  * anjuta_dock_pane_notify_single_selection_changed:
230  * @self: An AnjutaDockPane
231  *
232  * Emits the single-selection-changed signal.
233  */
234 void
anjuta_dock_pane_notify_single_selection_changed(AnjutaDockPane * self)235 anjuta_dock_pane_notify_single_selection_changed (AnjutaDockPane *self)
236 {
237 	g_signal_emit_by_name (self, "single-selection-changed", NULL);
238 }
239 
240 /**
241  * anjuta_dock_pane_notify_multiple_selection_changed:
242  * @self: An AnjutaDockPane
243  *
244  * Emits the multiple-selection-changed signal.
245  */
246 void
anjuta_dock_pane_notify_multiple_selection_changed(AnjutaDockPane * self)247 anjuta_dock_pane_notify_multiple_selection_changed (AnjutaDockPane *self)
248 {
249 	g_signal_emit_by_name (self, "multiple-selection-changed", NULL);
250 }