libanjuta: set the info for the default value of a property
[anjuta.git] / libanjuta / anjuta-shell.c
blob4fc5187e9f9f157309313cb5a8ef42f0d6888b1c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta-shell.c
4 * Copyright (C) Naba Kumar <naba@gnome.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 /**
22 * SECTION:anjuta-shell
23 * @title: AnjutaShell
24 * @short_description: Application shell interface
25 * @see_also:
26 * @stability: Unstable
27 * @include: libanjuta/anjuta-shell.h
29 * Shell is the playground where plugins are loaded and their UI
30 * widgets shown. It is also a place where plugins export objects for letting
31 * other pluings to use. Plugins are loaded into shell on demand, but some
32 * plugins are loaded on startup (such as help and text editor plugin).
33 * Demand to load a plugin can be made by requesting for a primary inferface
34 * using anjuta_shell_get_interface() or anjuta_shell_get_object().
36 * Plugins can add widgets in shell with
37 * anjuta_shell_add_widget() and remove with anjuta_shell_remove_widget()
38 * functions.
40 * In Anjuta, shell is implemented using an advanced widget docking system,
41 * allowing plugin widgets to dock, undock and layout in any fashion. Dock
42 * layout is also maintained internally and is transparent to plugin
43 * implementations.
45 * #AnjutaShell allows plugins to export arbitrary objects as <emphasis>
46 * values</emphasis> in its <emphasis>Values System</emphasis>. "value_added"
47 * and "value_removed" signals are emitted when a value is added to or
48 * removed from the <emphasis>Values System</emphasis>, hence notifying
49 * plugins of its state. However, plugins should really not connect directly
50 * to these signals, because they are emitted for all values
51 * and not just for the values the plugin is interested in. Instead,
52 * to monitor specific <emphasis>Values</emphasis>, plugins should
53 * setup watches using anjuta_plugin_add_watch().
55 * <emphasis>Values</emphasis> are added, get or removed with
56 * anjuta_shell_add_value() and anjuta_shell_get_value() or
57 * anjuta_shell_remove_value(). There multi-valued equivalent functions
58 * can be used to manipulate multiple values at once.
60 * <emphasis>Values</emphasis> are identified with names. Since <emphasis>
61 * Values</emphasis> are effectively variables, their names should follow
62 * the standard GNOME variable naming convention and should be as descriptive
63 * as possible (e.g project_root_directory, project_name etc.). It is also
64 * essential that meaningful prefix be given to names so that <emphasis>
65 * Values</emphasis> are easily grouped (e.g all values exported by a
66 * project manager should start with project_ prefix).
68 * Plugins can find other plugins with anjuta_shell_get_object() or
69 * anjuta_shell_get_interface() based on their primary interfaces.
72 #include <config.h>
73 #include <string.h>
74 #include <gobject/gvaluecollector.h>
75 #include "anjuta-shell.h"
76 #include "anjuta-marshal.h"
77 #include "anjuta-debug.h"
79 typedef struct {
80 GtkWidget *widget;
81 gchar *name;
82 gchar *title;
83 gchar *stock_id;
84 AnjutaShellPlacement placement;
85 gboolean locked;
86 } WidgetQueueData;
88 static void
89 on_widget_data_free (WidgetQueueData *data)
91 g_object_unref (data->widget);
92 g_free (data->name);
93 g_free (data->title);
94 g_free (data->stock_id);
95 g_free (data);
98 static void
99 on_widget_data_add (WidgetQueueData *data, AnjutaShell *shell)
101 ANJUTA_SHELL_GET_IFACE (shell)->add_widget_full (shell, data->widget,
102 data->name,
103 data->title,
104 data->stock_id,
105 data->placement,
106 data->locked,
107 NULL);
110 static void
111 on_destroy_widget_queue (gpointer data)
113 GQueue *queue = (GQueue*)data;
114 g_queue_foreach (queue, (GFunc)on_widget_data_free, NULL);
115 g_queue_free (queue);
118 GQuark
119 anjuta_shell_error_quark (void)
121 static GQuark quark = 0;
123 if (quark == 0) {
124 quark = g_quark_from_static_string ("anjuta-shell-quark");
127 return quark;
131 * anjuta_shell_freeze:
132 * @shell: A #AnjutaShell interface.
133 * @error: Error propagation object.
135 * Freezes addition of any UI elements (widgets) in the shell. All widget
136 * additions are queued for later additions when freeze count reaches 0.
137 * Any number of this function can be called and each call will increase
138 * the freeze count. anjuta_shell_thaw() will reduce the freeze count by
139 * 1 and real thawing happens when the count reaches 0.
141 void
142 anjuta_shell_freeze (AnjutaShell *shell, GError **error)
144 gint freeze_count;
146 g_return_if_fail (shell != NULL);
147 freeze_count = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (shell),
148 "__freeze_count"));
149 freeze_count++;
150 g_object_set_data (G_OBJECT (shell), "__freeze_count",
151 GINT_TO_POINTER (freeze_count));
155 * anjuta_shell_thaw:
156 * @shell: A #AnjutaShell interface.
157 * @error: Error propagation object.
159 * Reduces the freeze count by one and performs pending widget additions
160 * when the count reaches 0.
162 void
163 anjuta_shell_thaw (AnjutaShell *shell, GError **error)
165 gint freeze_count;
167 g_return_if_fail (shell != NULL);
168 freeze_count = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (shell),
169 "__freeze_count"));
170 freeze_count--;
171 if (freeze_count < 0)
172 freeze_count = 0;
173 g_object_set_data (G_OBJECT (shell), "__freeze_count",
174 GINT_TO_POINTER (freeze_count));
176 if (freeze_count <= 0)
178 /* Add all pending widgets */
179 /* DEBUG_PRINT ("%s", "Thawing shell ..."); */
181 GQueue *queue;
182 queue = g_object_get_data (G_OBJECT (shell), "__widget_queue");
183 if (queue)
185 g_queue_reverse (queue);
186 g_queue_foreach (queue, (GFunc)on_widget_data_add, shell);
187 g_object_set_data (G_OBJECT (shell), "__widget_queue", NULL);
193 * anjuta_shell_add_widget:
194 * @shell: A #AnjutaShell interface.
195 * @widget: Then widget to add
196 * @name: Name of the widget. None translated string used to identify it in
197 * the shell.
198 * @stock_id: Icon stock ID. Could be null.
199 * @title: Translated string which is displayed along side the widget when
200 * required (eg. as window title or notebook tab label).
201 * @placement: Placement of the widget in shell.
202 * @error: Error propagation object.
204 * Adds @widget in the shell. The @placement tells where the widget should
205 * appear, but generally it will be overridden by the container
206 * (dock, notebook, GtkContainer etc.) saved layout.
208 void
209 anjuta_shell_add_widget (AnjutaShell *shell,
210 GtkWidget *widget,
211 const char *name,
212 const char *title,
213 const char *stock_id,
214 AnjutaShellPlacement placement,
215 GError **error)
217 anjuta_shell_add_widget_full(shell, widget, name, title,
218 stock_id, placement, FALSE, error);
222 * anjuta_shell_add_widget_full:
223 * @shell: A #AnjutaShell interface.
224 * @widget: Then widget to add
225 * @name: Name of the widget. None translated string used to identify it in
226 * the shell.
227 * @stock_id: Icon stock ID. Could be null.
228 * @title: Translated string which is displayed along side the widget when
229 * required (eg. as window title or notebook tab label).
230 * @placement: Placement of the widget in shell.
231 * @locked: Whether to lock that widget (do not use this, it's only
232 * useful to some stock plugins
233 * @error: Error propagation object.
235 * Adds @widget in the shell. The @placement tells where the widget should
236 * appear, but generally it will be overridden by the container
237 * (dock, notebook, GtkContainer etc.) saved layout.
239 * Normally just use anjuta_shell_add_widget() because you do not
240 * use locking.
242 void
243 anjuta_shell_add_widget_full (AnjutaShell *shell,
244 GtkWidget *widget,
245 const char *name,
246 const char *title,
247 const char *stock_id,
248 AnjutaShellPlacement placement,
249 gboolean locked,
250 GError **error)
252 GQueue *widget_queue;
253 gint freeze_count;
255 g_return_if_fail (shell != NULL);
256 g_return_if_fail (ANJUTA_IS_SHELL (shell));
257 g_return_if_fail (widget != NULL);
258 g_return_if_fail (GTK_IS_WIDGET (widget));
259 g_return_if_fail (name != NULL);
260 g_return_if_fail (title != NULL);
262 freeze_count = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (shell),
263 "__freeze_count"));
264 if (freeze_count <= 0)
266 ANJUTA_SHELL_GET_IFACE (shell)->add_widget_full (shell, widget, name,
267 title, stock_id,
268 placement, locked, error);
270 else
272 /* Queue the operation */
273 WidgetQueueData *qd;
275 widget_queue = g_object_get_data (G_OBJECT (shell), "__widget_queue");
276 if (!widget_queue)
278 widget_queue = g_queue_new ();
279 g_object_set_data_full (G_OBJECT (shell), "__widget_queue",
280 widget_queue, on_destroy_widget_queue);
282 qd = g_new0(WidgetQueueData, 1);
283 g_object_ref (G_OBJECT (widget));
284 qd->widget = widget;
285 qd->name = g_strdup (name);
286 qd->title = g_strdup (title);
287 qd->locked = locked;
288 if (stock_id)
289 qd->stock_id = g_strdup (stock_id);
290 qd->placement = placement;
292 g_queue_push_head (widget_queue, qd);
297 * anjuta_shell_add_widget_custom:
298 * @shell: A #AnjutaShell interface.
299 * @widget: Then widget to add
300 * @name: Name of the widget. None translated string used to identify it in
301 * the shell.
302 * @title: title of the widget (translated)
303 * @stock_id: Icon stock ID. Could be null.
304 * @label: Label widget to use
305 * @placement: Placement of the widget in shell.
306 * @error: Error propagation object.
308 * Adds @widget in the shell. The @placement tells where the widget should
309 * appear, but generally it will be overridden by the container
310 * (dock, notebook, GtkContainer etc.) saved layout.
312 * Using this method you can pass a custom widget as label.
314 void anjuta_shell_add_widget_custom (AnjutaShell *shell,
315 GtkWidget *widget,
316 const char *name,
317 const char *title,
318 const char *stock_id,
319 GtkWidget *label,
320 AnjutaShellPlacement placement,
321 GError **error)
323 ANJUTA_SHELL_GET_IFACE (shell)->add_widget_custom (shell, widget, name, title, stock_id, label,
324 placement, error);
328 * anjuta_shell_remove_widget:
329 * @shell: A #AnjutaShell interface
330 * @widget: The widget to remove
331 * @error: Error propagation object
333 * Removes the widget from shell. The widget should have been added before
334 * with #anjuta_shell_add_widget.
336 void
337 anjuta_shell_remove_widget (AnjutaShell *shell,
338 GtkWidget *widget,
339 GError **error)
341 GQueue *queue;
342 gboolean found_in_queue;
344 g_return_if_fail (shell != NULL);
345 g_return_if_fail (ANJUTA_IS_SHELL (shell));
346 g_return_if_fail (widget != NULL);
347 g_return_if_fail (GTK_IS_WIDGET (widget));
349 /* If there is a queue, remove widgets from it */
350 found_in_queue = FALSE;
351 queue = g_object_get_data (G_OBJECT (shell), "__widget_queue");
352 if (queue)
354 gint i;
355 for (i = g_queue_get_length(queue) - 1; i >= 0; i--)
357 WidgetQueueData *qd;
359 qd = g_queue_peek_nth (queue, i);
360 if (qd->widget == widget)
362 g_queue_remove (queue, qd);
363 on_widget_data_free (qd);
364 found_in_queue = TRUE;
365 break;
369 if (!found_in_queue)
370 ANJUTA_SHELL_GET_IFACE (shell)->remove_widget (shell, widget, error);
374 * anjuta_shell_present_widget:
375 * @shell: A #AnjutaShell interface
376 * @widget: The widget to present
377 * @error: Error propagation object
379 * Make sure the widget is visible to user. If the widget is hidden, it will
380 * be shown. If it is not visible to user, it will be made visible.
382 void
383 anjuta_shell_present_widget (AnjutaShell *shell,
384 GtkWidget *widget,
385 GError **error)
387 GQueue *queue;
388 gboolean found_in_queue;
390 g_return_if_fail (shell != NULL);
391 g_return_if_fail (ANJUTA_IS_SHELL (shell));
392 g_return_if_fail (widget != NULL);
393 g_return_if_fail (GTK_IS_WIDGET (widget));
395 /* If there is a queue and the widget is in the queue, there is no
396 * way we can 'present' the widget */
397 found_in_queue = FALSE;
398 queue = g_object_get_data (G_OBJECT (shell), "__widget_queue");
399 if (queue)
401 gint i;
402 for (i = g_queue_get_length(queue) - 1; i >= 0; i--)
404 WidgetQueueData *qd;
406 qd = g_queue_peek_nth (queue, i);
407 if (qd->widget == widget)
409 found_in_queue = TRUE;
410 break;
414 if (!found_in_queue)
415 ANJUTA_SHELL_GET_IFACE (shell)->present_widget (shell, widget, error);
419 * anjuta_shell_iconify_dockable_widget:
420 * @shell: A #AnjutaShell interface.
421 * @widget: a #GtkWidget to iconify.
422 * @error: Error propagation object.
424 * If the widget is dockable, it iconifies it.
426 void anjuta_shell_iconify_dockable_widget (AnjutaShell *shell,
427 GtkWidget *widget,
428 GError **error)
430 ANJUTA_SHELL_GET_IFACE (shell)->iconify_dockable_widget (shell, widget, error);
434 * anjuta_shell_hide_dockable_widget:
435 * @shell: A #AnjutaShell interface.
436 * @widget: a #GtkWidget to hide.
437 * @error: Error propagation object.
439 * If the widget is dockable, it hides it.
441 void anjuta_shell_hide_dockable_widget (AnjutaShell *shell,
442 GtkWidget *widget,
443 GError **error)
445 ANJUTA_SHELL_GET_IFACE (shell)->hide_dockable_widget (shell, widget, error);
449 * anjuta_shell_show_dockable_widget:
450 * @shell: A #AnjutaShell interface.
451 * @widget: a #GtkWidget to show.
452 * @error: Error propagation object.
454 * If the widget was hidden or iconified, it will make it visible.
456 void anjuta_shell_show_dockable_widget (AnjutaShell *shell,
457 GtkWidget *widget,
458 GError **error)
460 ANJUTA_SHELL_GET_IFACE (shell)->show_dockable_widget (shell, widget, error);
464 * anjuta_shell_maximize_widget:
465 * @shell: A #AnjutaShell interface.
466 * @widget_name: Name of the widget to be maximized.
467 * @error: Error propagation object.
469 * Maximizes a widget so it will occupy all the possible space.
471 void anjuta_shell_maximize_widget (AnjutaShell *shell,
472 const char *widget_name,
473 GError **error)
475 ANJUTA_SHELL_GET_IFACE (shell)->maximize_widget (shell, widget_name, error);
479 * anjuta_shell_unmaximize:
480 * @shell: A #AnjutaShell interface.
481 * @error: Error propagation object.
483 * Unmaximizes the UI which was previously maximized by
484 * #anjuta_shell_maximize_widget
486 void anjuta_shell_unmaximize (AnjutaShell *shell,
487 GError **error)
489 ANJUTA_SHELL_GET_IFACE (shell)->unmaximize (shell, error);
493 * anjuta_shell_add_value:
494 * @shell: A #AnjutaShell interface
495 * @name: Name of the value
496 * @value: Value to add
497 * @error: Error propagation object
499 * Sets a value in the shell with the given name. Any previous value will
500 * be overridden. "value_added" signal will be emitted. Objects connecting
501 * to this signal can then update their data according to the new value.
503 void
504 anjuta_shell_add_value (AnjutaShell *shell,
505 const char *name,
506 const GValue *value,
507 GError **error)
509 g_return_if_fail (shell != NULL);
510 g_return_if_fail (ANJUTA_IS_SHELL (shell));
511 g_return_if_fail (name != NULL);
512 g_return_if_fail (value != NULL);
514 ANJUTA_SHELL_GET_IFACE (shell)->add_value (shell, name, value, error);
518 * anjuta_shell_add_valist:
519 * @shell: A #AnjutaShell interface
520 * @first_name: First value name
521 * @first_type: First value type
522 * @var_args: First value, Second value name, Second value type ....
524 * Adds a valist of values in the shell. The valist should be in the order -
525 * value1, name2, type2, value2,... "value_added" signal will be emitted
526 * for each of the value.
528 void
529 anjuta_shell_add_valist (AnjutaShell *shell,
530 const char *first_name,
531 GType first_type,
532 va_list var_args)
534 const char *name;
535 GType type;
537 g_return_if_fail (shell != NULL);
538 g_return_if_fail (ANJUTA_IS_SHELL (shell));
539 g_return_if_fail (first_name != NULL);
541 name = first_name;
542 type = first_type;
544 while (name) {
545 GValue value = {0, };
546 GError *err = NULL;
547 char *error;
549 g_value_init (&value, type);
551 G_VALUE_COLLECT (&value, var_args, 0, &error);
553 if (error){
554 g_warning ("%s: %s", G_STRLOC, error);
555 g_free (error);
556 break;
559 anjuta_shell_add_value (shell, name, &value, &err);
561 g_value_unset (&value);
563 if (err) {
564 g_warning ("Could not set value: %s\n", err->message);
565 g_error_free (err);
566 break;
569 name = va_arg (var_args, char *);
570 if (name) {
571 type = va_arg (var_args, GType);
577 * anjuta_shell_add:
578 * @shell: A #AnjutaShell interface
579 * @first_name: First value name
580 * @first_type: First value type
581 * @...: First value, Second value name, Second value type .... NULL
583 * Adds a list of values in the shell. The list should be NULL terminated
584 * and should be in the order - name1, type1, value1, name2, type2, value2,
585 * ..., NULL. "value_added" signal will be emitted for each of the value.
587 void
588 anjuta_shell_add (AnjutaShell *shell,
589 const char *first_name,
590 GType first_type,
591 ...)
593 va_list var_args;
595 g_return_if_fail (shell != NULL);
596 g_return_if_fail (ANJUTA_IS_SHELL (shell));
597 g_return_if_fail (first_name != NULL);
599 va_start (var_args, first_type);
600 anjuta_shell_add_valist (shell, first_name, first_type, var_args);
601 va_end (var_args);
605 * anjuta_shell_get_value:
606 * @shell: A #AnjutaShell interface
607 * @name: Name of the value to get
608 * @value: Value to get
609 * @error: Error propagation object
611 * Gets a value from the shell with the given name. The value will be set
612 * in the passed value pointer.
614 void
615 anjuta_shell_get_value (AnjutaShell *shell,
616 const char *name,
617 GValue *value,
618 GError **error)
620 g_return_if_fail (shell != NULL);
621 g_return_if_fail (ANJUTA_IS_SHELL (shell));
622 g_return_if_fail (name != NULL);
623 g_return_if_fail (value != NULL);
625 ANJUTA_SHELL_GET_IFACE (shell)->get_value (shell, name, value, error);
629 * anjuta_shell_get_valist:
630 * @shell: A #AnjutaShell interface
631 * @first_name: First value name
632 * @first_type: First value type
633 * @var_args: First value holder, Second value name, Second value type ....
635 * Gets a valist of values from the shell. The valist should be in the order -
636 * value1, name2, type2, value2,...
638 void
639 anjuta_shell_get_valist (AnjutaShell *shell,
640 const char *first_name,
641 GType first_type,
642 va_list var_args)
644 const char *name;
645 GType type;
647 g_return_if_fail (shell != NULL);
648 g_return_if_fail (ANJUTA_IS_SHELL (shell));
649 g_return_if_fail (first_name != NULL);
651 name = first_name;
652 type = first_type;
654 while (name) {
655 GValue value = {0, };
656 GError *err = NULL;
657 char *error;
659 g_value_init (&value, type);
661 anjuta_shell_get_value (shell, name, &value, &err);
663 if (err) {
664 g_warning ("Could not get value: %s", err->message);
665 g_error_free (err);
666 break;
669 G_VALUE_LCOPY (&value, var_args, 0, &error);
671 if (error){
672 g_warning ("%s: %s", G_STRLOC, error);
673 g_free (error);
674 break;
677 g_value_unset (&value);
679 name = va_arg (var_args, char *);
680 if (name) {
681 type = va_arg (var_args, GType);
687 * anjuta_shell_get:
688 * @shell: A #AnjutaShell interface
689 * @first_name: First value name
690 * @first_type: First value type
691 * @...: First value holder, Second value name, Second value type .... NULL
693 * Gets a list of values in the shell. The list should be NULL terminated
694 * and should be in the order - name1, type1, value1, name2, type2, value2,
695 * ..., NULL.
697 void
698 anjuta_shell_get (AnjutaShell *shell,
699 const char *first_name,
700 GType first_type,
701 ...)
703 va_list var_args;
705 g_return_if_fail (shell != NULL);
706 g_return_if_fail (ANJUTA_IS_SHELL (shell));
707 g_return_if_fail (first_name != NULL);
709 va_start (var_args, first_type);
710 anjuta_shell_get_valist (shell, first_name, first_type, var_args);
711 va_end (var_args);
715 * anjuta_shell_remove_value:
716 * @shell: A #AnjutaShell interface
717 * @name: Name of the value to remove
718 * @error: Error propagation object
720 * Removes a value from the shell with the given name. "value_removed" signal
721 * will be emitted. Objects connecting to this signal can then update their
722 * data/internal-state accordingly.
724 void
725 anjuta_shell_remove_value (AnjutaShell *shell,
726 const char *name,
727 GError **error)
729 g_return_if_fail (shell != NULL);
730 g_return_if_fail (ANJUTA_IS_SHELL (shell));
731 g_return_if_fail (name != NULL);
733 ANJUTA_SHELL_GET_IFACE (shell)->remove_value (shell, name, error);
737 * anjuta_shell_get_object:
738 * @shell: A #AnjutaShell interface
739 * @iface_name: The interface implemented by the object to be found
740 * @error: Error propagation.
742 * Searches the currently available plugins to find the one which
743 * implements the given interface as primary interface and returns it. If
744 * the plugin is not yet loaded, it will be loaded and activated.
745 * The returned object is garanteed to be an implementor of the
746 * interface (as exported by the plugin metafile). It only searches
747 * from the pool of plugin objects loaded in this shell and can only search
748 * by primary interface. If there are more objects implementing this primary
749 * interface, user might be prompted to select one from them (and might give
750 * the option to use it as default for future queries). A typical usage of this
751 * function is:
752 * <programlisting>
753 * GObject *docman =
754 * anjuta_plugins_get_object (shell, "IAnjutaDocumentManager", error);
755 * </programlisting>
756 * Notice that this function takes the interface name string as string, unlike
757 * anjuta_plugins_get_interface() which takes the type directly.
759 * Return value: (transfer none): A plugin object implementing the primary interface or NULL.
761 GObject*
762 anjuta_shell_get_object (AnjutaShell *shell, const gchar *iface_name,
763 GError **error)
765 g_return_val_if_fail (shell != NULL, NULL);
766 g_return_val_if_fail (iface_name != NULL, NULL);
767 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
769 return ANJUTA_SHELL_GET_IFACE (shell)->get_object (shell, iface_name, error);
773 * anjuta_shell_get_status:
774 * @shell: A #AnjutaShell interface
775 * @error: Error propagation object
777 * Retrieves the #AnjutaStatus object associated with the shell.
779 * Return value: The #AnjutaStatus object.
781 AnjutaStatus*
782 anjuta_shell_get_status (AnjutaShell *shell, GError **error)
784 g_return_val_if_fail (shell != NULL, NULL);
785 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
787 return ANJUTA_SHELL_GET_IFACE (shell)->get_status (shell, error);
791 * anjuta_shell_get_ui:
792 * @shell: A #AnjutaShell interface
793 * @error: Error propagation object
795 * Retrieves the #AnjutaUI object associated with the shell.
797 * Return value: The #AnjutaUI object.
799 AnjutaUI*
800 anjuta_shell_get_ui (AnjutaShell *shell, GError **error)
802 g_return_val_if_fail (shell != NULL, NULL);
803 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
805 return ANJUTA_SHELL_GET_IFACE (shell)->get_ui (shell, error);
809 * anjuta_shell_get_preferences:
810 * @shell: A #AnjutaShell interface
811 * @error: Error propagation object
813 * Retrieves the #AnjutaPreferences object associated with the shell.
815 * Return value: The #AnjutaPreferences object.
817 AnjutaPreferences*
818 anjuta_shell_get_preferences (AnjutaShell *shell, GError **error)
820 g_return_val_if_fail (shell != NULL, NULL);
821 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
823 return ANJUTA_SHELL_GET_IFACE (shell)->get_preferences (shell, error);
827 * anjuta_shell_get_plugin_manager:
828 * @shell: A #AnjutaShell interface
829 * @error: Error propagation object
831 * Retrieves the #AnjutaPluginManager object associated with the shell.
833 * Return value: The #AnjutaPluginManager object.
835 AnjutaPluginManager*
836 anjuta_shell_get_plugin_manager (AnjutaShell *shell, GError **error)
838 g_return_val_if_fail (shell != NULL, NULL);
839 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
841 return ANJUTA_SHELL_GET_IFACE (shell)->get_plugin_manager (shell, error);
845 * anjuta_shell_get_profile_manager:
846 * @shell: A #AnjutaShell interface
847 * @error: Error propagation object
849 * Retrieves the #AnjutaProfileManager object associated with the shell.
851 * Return value: The #AnjutaProfileManager object.
853 AnjutaProfileManager*
854 anjuta_shell_get_profile_manager (AnjutaShell *shell, GError **error)
856 g_return_val_if_fail (shell != NULL, NULL);
857 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
859 return ANJUTA_SHELL_GET_IFACE (shell)->get_profile_manager (shell, error);
863 * anjuta_shell_saving_push:
864 * @shell: A #AnjutaShell interface
866 * Increase the count of files that need to be saved
869 void anjuta_shell_saving_push (AnjutaShell* shell)
871 g_return_if_fail (ANJUTA_IS_SHELL (shell));
873 ANJUTA_SHELL_GET_IFACE (shell)->saving_push (shell);
877 * anjuta_shell_saving_push:
878 * @shell: A #AnjutaShell interface
880 * Decrease the count of files that need to be saved
883 void anjuta_shell_saving_pop (AnjutaShell* shell)
885 g_return_if_fail (ANJUTA_IS_SHELL (shell));
887 ANJUTA_SHELL_GET_IFACE (shell)->saving_pop (shell);
890 void
891 anjuta_shell_session_save (AnjutaShell *shell, const gchar *session_directory,
892 GError **error)
894 AnjutaSession *session;
896 g_return_if_fail (ANJUTA_IS_SHELL (shell));
897 g_return_if_fail (session_directory != NULL);
899 session = anjuta_session_new (session_directory);
900 anjuta_session_clear (session);
901 g_signal_emit_by_name (G_OBJECT (shell), "save_session",
902 ANJUTA_SESSION_PHASE_FIRST, session);
903 g_signal_emit_by_name (G_OBJECT (shell), "save_session",
904 ANJUTA_SESSION_PHASE_NORMAL, session);
905 g_signal_emit_by_name (G_OBJECT (shell), "save_session",
906 ANJUTA_SESSION_PHASE_LAST, session);
907 anjuta_session_sync (session);
908 g_object_unref (session);
911 void
912 anjuta_shell_session_load (AnjutaShell *shell, const gchar *session_directory,
913 GError **error)
915 AnjutaSession *session;
917 g_return_if_fail (ANJUTA_IS_SHELL (shell));
918 g_return_if_fail (session_directory != NULL);
920 /* Do not allow multiple session loadings at once. Could be a trouble */
921 if (g_object_get_data (G_OBJECT (shell), "__session_loading"))
923 /* DEBUG_PRINT ("%s", "A session load is requested in the middle of another!!"); */
924 return;
926 g_object_set_data (G_OBJECT (shell), "__session_loading", "1");
928 session = anjuta_session_new (session_directory);
929 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
930 ANJUTA_SESSION_PHASE_START, session);
931 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
932 ANJUTA_SESSION_PHASE_FIRST, session);
933 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
934 ANJUTA_SESSION_PHASE_NORMAL, session);
935 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
936 ANJUTA_SESSION_PHASE_LAST, session);
937 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
938 ANJUTA_SESSION_PHASE_END, session);
939 g_object_unref (session);
941 g_object_set_data (G_OBJECT (shell), "__session_loading", NULL);
944 void
945 anjuta_shell_save_prompt (AnjutaShell *shell,
946 AnjutaSavePrompt *save_prompt,
947 GError **error)
949 g_return_if_fail (ANJUTA_IS_SHELL (shell));
950 g_return_if_fail (ANJUTA_IS_SAVE_PROMPT (save_prompt));
951 g_signal_emit_by_name (shell, "save-prompt", save_prompt);
954 void
955 anjuta_shell_notify_exit (AnjutaShell *shell,
956 GError **error)
958 g_return_if_fail (ANJUTA_IS_SHELL (shell));
959 g_signal_emit_by_name (shell, "exiting");
962 static void
963 anjuta_shell_base_init (gpointer gclass)
965 static gboolean initialized = FALSE;
967 if (!initialized) {
968 g_signal_new ("value-added",
969 ANJUTA_TYPE_SHELL,
970 G_SIGNAL_RUN_LAST,
971 G_STRUCT_OFFSET (AnjutaShellIface, value_added),
972 NULL, NULL,
973 anjuta_cclosure_marshal_VOID__STRING_BOXED,
974 G_TYPE_NONE, 2,
975 G_TYPE_STRING, G_TYPE_VALUE);
977 g_signal_new ("value-removed",
978 ANJUTA_TYPE_SHELL,
979 G_SIGNAL_RUN_LAST,
980 G_STRUCT_OFFSET (AnjutaShellIface, value_removed),
981 NULL, NULL,
982 anjuta_cclosure_marshal_VOID__STRING,
983 G_TYPE_NONE, 1,
984 G_TYPE_STRING);
985 g_signal_new ("save-session",
986 ANJUTA_TYPE_SHELL,
987 G_SIGNAL_RUN_LAST,
988 G_STRUCT_OFFSET (AnjutaShellIface, save_session),
989 NULL, NULL,
990 anjuta_cclosure_marshal_VOID__INT_OBJECT,
991 G_TYPE_NONE, 2,
992 G_TYPE_INT,
993 G_TYPE_OBJECT);
994 g_signal_new ("load-session",
995 ANJUTA_TYPE_SHELL,
996 G_SIGNAL_RUN_LAST,
997 G_STRUCT_OFFSET (AnjutaShellIface, load_session),
998 NULL, NULL,
999 anjuta_cclosure_marshal_VOID__INT_OBJECT,
1000 G_TYPE_NONE, 2,
1001 G_TYPE_INT,
1002 G_TYPE_OBJECT);
1003 g_signal_new ("save-prompt",
1004 ANJUTA_TYPE_SHELL,
1005 G_SIGNAL_RUN_LAST,
1006 G_STRUCT_OFFSET (AnjutaShellIface, save_prompt),
1007 NULL, NULL,
1008 anjuta_cclosure_marshal_VOID__OBJECT,
1009 G_TYPE_NONE, 1,
1010 G_TYPE_OBJECT);
1011 g_signal_new ("exiting",
1012 ANJUTA_TYPE_SHELL,
1013 G_SIGNAL_RUN_LAST,
1014 G_STRUCT_OFFSET (AnjutaShellIface, exiting),
1015 NULL, NULL,
1016 anjuta_cclosure_marshal_VOID__VOID,
1017 G_TYPE_NONE, 0);
1018 initialized = TRUE;
1022 GType
1023 anjuta_shell_get_type (void)
1025 static GType type = 0;
1027 if (!type) {
1028 static const GTypeInfo info = {
1029 sizeof (AnjutaShellIface),
1030 anjuta_shell_base_init,
1031 NULL,
1032 NULL,
1033 NULL,
1034 NULL,
1037 NULL
1040 type = g_type_register_static (G_TYPE_INTERFACE,
1041 "AnjutaShell",
1042 &info,
1045 g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
1048 return type;