Implement support for listing and merging branches.
[anjuta-git-plugin.git] / libanjuta / anjuta-shell.c
blob459d5462c954104fc8f7b26db246ddd843aedbb7
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 ("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_remove_widget:
298 * @shell: A #AnjutaShell interface
299 * @widget: The widget to remove
300 * @error: Error propagation object
302 * Removes the widget from shell. The widget should have been added before
303 * with #anjuta_shell_add_widget.
305 void
306 anjuta_shell_remove_widget (AnjutaShell *shell,
307 GtkWidget *widget,
308 GError **error)
310 GQueue *queue;
311 gboolean found_in_queue;
313 g_return_if_fail (shell != NULL);
314 g_return_if_fail (ANJUTA_IS_SHELL (shell));
315 g_return_if_fail (widget != NULL);
316 g_return_if_fail (GTK_IS_WIDGET (widget));
318 /* If there is a queue, remove widgets from it */
319 found_in_queue = FALSE;
320 queue = g_object_get_data (G_OBJECT (shell), "__widget_queue");
321 if (queue)
323 gint i;
324 for (i = g_queue_get_length(queue) - 1; i >= 0; i--)
326 WidgetQueueData *qd;
328 qd = g_queue_peek_nth (queue, i);
329 if (qd->widget == widget)
331 g_queue_remove (queue, qd);
332 on_widget_data_free (qd);
333 found_in_queue = TRUE;
334 break;
338 if (!found_in_queue)
339 ANJUTA_SHELL_GET_IFACE (shell)->remove_widget (shell, widget, error);
343 * anjuta_shell_present_widget:
344 * @shell: A #AnjutaShell interface
345 * @widget: The widget to present
346 * @error: Error propagation object
348 * Make sure the widget is visible to user. If the widget is hidden, it will
349 * be shown. If it is not visible to user, it will be made visible.
351 void
352 anjuta_shell_present_widget (AnjutaShell *shell,
353 GtkWidget *widget,
354 GError **error)
356 GQueue *queue;
357 gboolean found_in_queue;
359 g_return_if_fail (shell != NULL);
360 g_return_if_fail (ANJUTA_IS_SHELL (shell));
361 g_return_if_fail (widget != NULL);
362 g_return_if_fail (GTK_IS_WIDGET (widget));
364 /* If there is a queue and the widget is in the queue, there is no
365 * way we can 'present' the widget */
366 found_in_queue = FALSE;
367 queue = g_object_get_data (G_OBJECT (shell), "__widget_queue");
368 if (queue)
370 gint i;
371 for (i = g_queue_get_length(queue) - 1; i >= 0; i--)
373 WidgetQueueData *qd;
375 qd = g_queue_peek_nth (queue, i);
376 if (qd->widget == widget)
378 found_in_queue = TRUE;
379 break;
383 if (!found_in_queue)
384 ANJUTA_SHELL_GET_IFACE (shell)->present_widget (shell, widget, error);
388 * anjuta_shell_add_value:
389 * @shell: A #AnjutaShell interface
390 * @name: Name of the value
391 * @value: Value to add
392 * @error: Error propagation object
394 * Sets a value in the shell with the given name. Any previous value will
395 * be overridden. "value_added" signal will be emitted. Objects connecting
396 * to this signal can then update their data according to the new value.
398 void
399 anjuta_shell_add_value (AnjutaShell *shell,
400 const char *name,
401 const GValue *value,
402 GError **error)
404 g_return_if_fail (shell != NULL);
405 g_return_if_fail (ANJUTA_IS_SHELL (shell));
406 g_return_if_fail (name != NULL);
407 g_return_if_fail (value != NULL);
409 ANJUTA_SHELL_GET_IFACE (shell)->add_value (shell, name, value, error);
413 * anjuta_shell_add_valist:
414 * @shell: A #AnjutaShell interface
415 * @first_name: First value name
416 * @first_type: First value type
417 * @var_args: First value, Second value name, Second value type ....
419 * Adds a valist of values in the shell. The valist should be in the order -
420 * value1, name2, type2, value2,... "value_added" signal will be emitted
421 * for each of the value.
423 void
424 anjuta_shell_add_valist (AnjutaShell *shell,
425 const char *first_name,
426 GType first_type,
427 va_list var_args)
429 const char *name;
430 GType type;
432 g_return_if_fail (shell != NULL);
433 g_return_if_fail (ANJUTA_IS_SHELL (shell));
434 g_return_if_fail (first_name != NULL);
436 name = first_name;
437 type = first_type;
439 while (name) {
440 GValue value = {0, };
441 GError *err = NULL;
442 char *error;
444 g_value_init (&value, type);
446 G_VALUE_COLLECT (&value, var_args, 0, &error);
448 if (error){
449 g_warning ("%s: %s", G_STRLOC, error);
450 g_free (error);
451 break;
454 anjuta_shell_add_value (shell, name, &value, &err);
456 g_value_unset (&value);
458 if (err) {
459 g_warning ("Could not set value: %s\n", err->message);
460 g_error_free (err);
461 break;
464 name = va_arg (var_args, char *);
465 if (name) {
466 type = va_arg (var_args, GType);
472 * anjuta_shell_add:
473 * @shell: A #AnjutaShell interface
474 * @first_name: First value name
475 * @first_type: First value type
476 * @...: First value, Second value name, Second value type .... NULL
478 * Adds a list of values in the shell. The list should be NULL terminated
479 * and should be in the order - name1, type1, value1, name2, type2, value2,
480 * ..., NULL. "value_added" signal will be emitted for each of the value.
482 void
483 anjuta_shell_add (AnjutaShell *shell,
484 const char *first_name,
485 GType first_type,
486 ...)
488 va_list var_args;
490 g_return_if_fail (shell != NULL);
491 g_return_if_fail (ANJUTA_IS_SHELL (shell));
492 g_return_if_fail (first_name != NULL);
494 va_start (var_args, first_type);
495 anjuta_shell_add_valist (shell, first_name, first_type, var_args);
496 va_end (var_args);
500 * anjuta_shell_get_value:
501 * @shell: A #AnjutaShell interface
502 * @name: Name of the value to get
503 * @value: Value to get
504 * @error: Error propagation object
506 * Gets a value from the shell with the given name. The value will be set
507 * in the passed value pointer.
509 void
510 anjuta_shell_get_value (AnjutaShell *shell,
511 const char *name,
512 GValue *value,
513 GError **error)
515 g_return_if_fail (shell != NULL);
516 g_return_if_fail (ANJUTA_IS_SHELL (shell));
517 g_return_if_fail (name != NULL);
518 g_return_if_fail (value != NULL);
520 ANJUTA_SHELL_GET_IFACE (shell)->get_value (shell, name, value, error);
524 * anjuta_shell_get_valist:
525 * @shell: A #AnjutaShell interface
526 * @first_name: First value name
527 * @first_type: First value type
528 * @var_args: First value holder, Second value name, Second value type ....
530 * Gets a valist of values from the shell. The valist should be in the order -
531 * value1, name2, type2, value2,...
533 void
534 anjuta_shell_get_valist (AnjutaShell *shell,
535 const char *first_name,
536 GType first_type,
537 va_list var_args)
539 const char *name;
540 GType type;
542 g_return_if_fail (shell != NULL);
543 g_return_if_fail (ANJUTA_IS_SHELL (shell));
544 g_return_if_fail (first_name != NULL);
546 name = first_name;
547 type = first_type;
549 while (name) {
550 GValue value = {0, };
551 GError *err = NULL;
552 char *error;
554 g_value_init (&value, type);
556 anjuta_shell_get_value (shell, name, &value, &err);
558 if (err) {
559 g_warning ("Could not get value: %s", err->message);
560 g_error_free (err);
561 break;
564 G_VALUE_LCOPY (&value, var_args, 0, &error);
566 if (error){
567 g_warning ("%s: %s", G_STRLOC, error);
568 g_free (error);
569 break;
572 g_value_unset (&value);
574 name = va_arg (var_args, char *);
575 if (name) {
576 type = va_arg (var_args, GType);
582 * anjuta_shell_get:
583 * @shell: A #AnjutaShell interface
584 * @first_name: First value name
585 * @first_type: First value type
586 * @...: First value holder, Second value name, Second value type .... NULL
588 * Gets a list of values in the shell. The list should be NULL terminated
589 * and should be in the order - name1, type1, value1, name2, type2, value2,
590 * ..., NULL.
592 void
593 anjuta_shell_get (AnjutaShell *shell,
594 const char *first_name,
595 GType first_type,
596 ...)
598 va_list var_args;
600 g_return_if_fail (shell != NULL);
601 g_return_if_fail (ANJUTA_IS_SHELL (shell));
602 g_return_if_fail (first_name != NULL);
604 va_start (var_args, first_type);
605 anjuta_shell_get_valist (shell, first_name, first_type, var_args);
606 va_end (var_args);
610 * anjuta_shell_remove_value:
611 * @shell: A #AnjutaShell interface
612 * @name: Name of the value to remove
613 * @error: Error propagation object
615 * Removes a value from the shell with the given name. "value_removed" signal
616 * will be emitted. Objects connecting to this signal can then update their
617 * data/internal-state accordingly.
619 void
620 anjuta_shell_remove_value (AnjutaShell *shell,
621 const char *name,
622 GError **error)
624 g_return_if_fail (shell != NULL);
625 g_return_if_fail (ANJUTA_IS_SHELL (shell));
626 g_return_if_fail (name != NULL);
628 ANJUTA_SHELL_GET_IFACE (shell)->remove_value (shell, name, error);
632 * anjuta_shell_get_object:
633 * @shell: A #AnjutaShell interface
634 * @iface_name: The interface implemented by the object to be found
635 * @error: Error propagation.
637 * Searches the currently available plugins to find the one which
638 * implements the given interface as primary interface and returns it. If
639 * the plugin is not yet loaded, it will be loaded and activated.
640 * The returned object is garanteed to be an implementor of the
641 * interface (as exported by the plugin metafile). It only searches
642 * from the pool of plugin objects loaded in this shell and can only search
643 * by primary interface. If there are more objects implementing this primary
644 * interface, user might be prompted to select one from them (and might give
645 * the option to use it as default for future queries). A typical usage of this
646 * function is:
647 * <programlisting>
648 * GObject *docman =
649 * anjuta_plugins_get_object (shell, "IAnjutaDocumentManager", error);
650 * </programlisting>
651 * Notice that this function takes the interface name string as string, unlike
652 * anjuta_plugins_get_interface() which takes the type directly.
654 * Return value: A plugin object implementing the primary interface or NULL.
656 GObject*
657 anjuta_shell_get_object (AnjutaShell *shell, const gchar *iface_name,
658 GError **error)
660 g_return_val_if_fail (shell != NULL, NULL);
661 g_return_val_if_fail (iface_name != NULL, NULL);
662 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
664 return ANJUTA_SHELL_GET_IFACE (shell)->get_object (shell, iface_name, error);
668 * anjuta_shell_get_status:
669 * @shell: A #AnjutaShell interface
670 * @error: Error propagation object
672 * Retrieves the #AnjutaStatus object associated with the shell.
674 * Return value: The #AnjutaStatus object.
676 AnjutaStatus*
677 anjuta_shell_get_status (AnjutaShell *shell, GError **error)
679 g_return_val_if_fail (shell != NULL, NULL);
680 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
682 return ANJUTA_SHELL_GET_IFACE (shell)->get_status (shell, error);
686 * anjuta_shell_get_ui:
687 * @shell: A #AnjutaShell interface
688 * @error: Error propagation object
690 * Retrieves the #AnjutaUI object associated with the shell.
692 * Return value: The #AnjutaUI object.
694 AnjutaUI*
695 anjuta_shell_get_ui (AnjutaShell *shell, GError **error)
697 g_return_val_if_fail (shell != NULL, NULL);
698 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
700 return ANJUTA_SHELL_GET_IFACE (shell)->get_ui (shell, error);
704 * anjuta_shell_get_preferences:
705 * @shell: A #AnjutaShell interface
706 * @error: Error propagation object
708 * Retrieves the #AnjutaPreferences object associated with the shell.
710 * Return value: The #AnjutaPreferences object.
712 AnjutaPreferences*
713 anjuta_shell_get_preferences (AnjutaShell *shell, GError **error)
715 g_return_val_if_fail (shell != NULL, NULL);
716 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
718 return ANJUTA_SHELL_GET_IFACE (shell)->get_preferences (shell, error);
722 * anjuta_shell_get_plugin_manager:
723 * @shell: A #AnjutaShell interface
724 * @error: Error propagation object
726 * Retrieves the #AnjutaPluginManager object associated with the shell.
728 * Return value: The #AnjutaPluginManager object.
730 AnjutaPluginManager*
731 anjuta_shell_get_plugin_manager (AnjutaShell *shell, GError **error)
733 g_return_val_if_fail (shell != NULL, NULL);
734 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
736 return ANJUTA_SHELL_GET_IFACE (shell)->get_plugin_manager (shell, error);
740 * anjuta_shell_get_profile_manager:
741 * @shell: A #AnjutaShell interface
742 * @error: Error propagation object
744 * Retrieves the #AnjutaProfileManager object associated with the shell.
746 * Return value: The #AnjutaProfileManager object.
748 AnjutaProfileManager*
749 anjuta_shell_get_profile_manager (AnjutaShell *shell, GError **error)
751 g_return_val_if_fail (shell != NULL, NULL);
752 g_return_val_if_fail (ANJUTA_IS_SHELL (shell), NULL);
754 return ANJUTA_SHELL_GET_IFACE (shell)->get_profile_manager (shell, error);
757 void
758 anjuta_shell_session_save (AnjutaShell *shell, const gchar *session_directory,
759 GError **error)
761 AnjutaSession *session;
763 g_return_if_fail (ANJUTA_IS_SHELL (shell));
764 g_return_if_fail (session_directory != NULL);
766 session = anjuta_session_new (session_directory);
767 anjuta_session_clear (session);
768 g_signal_emit_by_name (G_OBJECT (shell), "save_session",
769 ANJUTA_SESSION_PHASE_FIRST, session);
770 g_signal_emit_by_name (G_OBJECT (shell), "save_session",
771 ANJUTA_SESSION_PHASE_NORMAL, session);
772 g_signal_emit_by_name (G_OBJECT (shell), "save_session",
773 ANJUTA_SESSION_PHASE_LAST, session);
774 anjuta_session_sync (session);
775 g_object_unref (session);
778 void
779 anjuta_shell_session_load (AnjutaShell *shell, const gchar *session_directory,
780 GError **error)
782 AnjutaSession *session;
784 g_return_if_fail (ANJUTA_IS_SHELL (shell));
785 g_return_if_fail (session_directory != NULL);
787 /* Do not allow multiple session loadings at once. Could be a trouble */
788 if (g_object_get_data (G_OBJECT (shell), "__session_loading"))
790 /* DEBUG_PRINT ("A session load is requested in the middle of another!!"); */
791 return;
793 g_object_set_data (G_OBJECT (shell), "__session_loading", "1");
795 session = anjuta_session_new (session_directory);
796 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
797 ANJUTA_SESSION_PHASE_START, session);
798 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
799 ANJUTA_SESSION_PHASE_FIRST, session);
800 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
801 ANJUTA_SESSION_PHASE_NORMAL, session);
802 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
803 ANJUTA_SESSION_PHASE_LAST, session);
804 g_signal_emit_by_name (G_OBJECT (shell), "load_session",
805 ANJUTA_SESSION_PHASE_END, session);
806 g_object_unref (session);
808 g_object_set_data (G_OBJECT (shell), "__session_loading", NULL);
811 void
812 anjuta_shell_save_prompt (AnjutaShell *shell,
813 AnjutaSavePrompt *save_prompt,
814 GError **error)
816 g_return_if_fail (ANJUTA_IS_SHELL (shell));
817 g_return_if_fail (ANJUTA_IS_SAVE_PROMPT (save_prompt));
818 g_signal_emit_by_name (shell, "save-prompt", save_prompt);
821 void
822 anjuta_shell_notify_exit (AnjutaShell *shell,
823 GError **error)
825 g_return_if_fail (ANJUTA_IS_SHELL (shell));
826 g_signal_emit_by_name (shell, "exiting");
829 static void
830 anjuta_shell_base_init (gpointer gclass)
832 static gboolean initialized = FALSE;
834 if (!initialized) {
835 g_signal_new ("value-added",
836 ANJUTA_TYPE_SHELL,
837 G_SIGNAL_RUN_LAST,
838 G_STRUCT_OFFSET (AnjutaShellIface, value_added),
839 NULL, NULL,
840 anjuta_cclosure_marshal_VOID__STRING_BOXED,
841 G_TYPE_NONE, 2,
842 G_TYPE_STRING, G_TYPE_VALUE);
844 g_signal_new ("value-removed",
845 ANJUTA_TYPE_SHELL,
846 G_SIGNAL_RUN_LAST,
847 G_STRUCT_OFFSET (AnjutaShellIface, value_removed),
848 NULL, NULL,
849 anjuta_cclosure_marshal_VOID__STRING,
850 G_TYPE_NONE, 1,
851 G_TYPE_STRING);
852 g_signal_new ("save-session",
853 ANJUTA_TYPE_SHELL,
854 G_SIGNAL_RUN_LAST,
855 G_STRUCT_OFFSET (AnjutaShellIface, save_session),
856 NULL, NULL,
857 anjuta_cclosure_marshal_VOID__INT_OBJECT,
858 G_TYPE_NONE, 2,
859 G_TYPE_INT,
860 G_TYPE_OBJECT);
861 g_signal_new ("load-session",
862 ANJUTA_TYPE_SHELL,
863 G_SIGNAL_RUN_LAST,
864 G_STRUCT_OFFSET (AnjutaShellIface, load_session),
865 NULL, NULL,
866 anjuta_cclosure_marshal_VOID__INT_OBJECT,
867 G_TYPE_NONE, 2,
868 G_TYPE_INT,
869 G_TYPE_OBJECT);
870 g_signal_new ("save-prompt",
871 ANJUTA_TYPE_SHELL,
872 G_SIGNAL_RUN_LAST,
873 G_STRUCT_OFFSET (AnjutaShellIface, save_prompt),
874 NULL, NULL,
875 anjuta_cclosure_marshal_VOID__OBJECT,
876 G_TYPE_NONE, 1,
877 G_TYPE_OBJECT);
878 g_signal_new ("exiting",
879 ANJUTA_TYPE_SHELL,
880 G_SIGNAL_RUN_LAST,
881 G_STRUCT_OFFSET (AnjutaShellIface, exiting),
882 NULL, NULL,
883 anjuta_cclosure_marshal_VOID__VOID,
884 G_TYPE_NONE, 0);
885 initialized = TRUE;
889 GType
890 anjuta_shell_get_type (void)
892 static GType type = 0;
894 if (!type) {
895 static const GTypeInfo info = {
896 sizeof (AnjutaShellIface),
897 anjuta_shell_base_init,
898 NULL,
899 NULL,
900 NULL,
901 NULL,
904 NULL
907 type = g_type_register_static (G_TYPE_INTERFACE,
908 "AnjutaShell",
909 &info,
912 g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
915 return type;