1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * anjuta-plugin-manager.c
4 * Copyright (C) Naba Kumar <naba@gnome.org>
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
22 * SECTION:anjuta-plugin-manager
23 * @short_description: Plugins management and activation
24 * @see_also: #AnjutaPlugin, #AnjutaProfileManager
25 * @stability: Unstable
26 * @include: libanjuta/anjuta-plugin-manager.h
30 #include <sys/types.h>
34 #include <libanjuta/anjuta-plugin-manager.h>
35 #include <libanjuta/anjuta-marshal.h>
36 #include <libanjuta/anjuta-debug.h>
37 #include <libanjuta/anjuta-plugin-handle.h>
38 #include <libanjuta/anjuta-plugin.h>
39 #include <libanjuta/anjuta-c-plugin-factory.h>
40 #include <libanjuta/interfaces/ianjuta-plugin-factory.h>
41 #include <libanjuta/interfaces/ianjuta-preferences.h>
51 PROP_AVAILABLE_PLUGINS
,
52 PROP_ACTIVATED_PLUGINS
67 struct _AnjutaPluginManagerPriv
72 GList
*available_plugins
;
74 /* Indexes => plugin handles */
75 GHashTable
*plugins_by_interfaces
;
76 GHashTable
*plugins_by_name
;
77 GHashTable
*plugins_by_description
;
79 /* Plugins that are currently activated */
80 GHashTable
*activated_plugins
;
82 /* Plugins that have been previously loaded but current deactivated */
83 GHashTable
*plugins_cache
;
85 /* Remember plugin selection */
86 GHashTable
*remember_plugins
;
89 /* Available plugins page treeview */
99 /* Remembered plugins page treeview */
107 /* Plugin class types */
109 static AnjutaCPluginFactory
*anjuta_plugin_factory
= NULL
;
111 static GObjectClass
* parent_class
= NULL
;
112 static guint plugin_manager_signals
[LAST_SIGNAL
] = { 0 };
114 static GHashTable
* plugin_set_update (AnjutaPluginManager
*plugin_manager
,
115 AnjutaPluginHandle
* selected_plugin
,
118 static IAnjutaPluginFactory
* get_plugin_factory (AnjutaPluginManager
*plugin_manager
,
119 const gchar
*language
, GError
**error
);
122 anjuta_plugin_manager_error_quark (void)
124 static GQuark quark
= 0;
127 quark
= g_quark_from_static_string ("anjuta-plugin-manager-quark");
132 /** Dependency Resolution **/
135 collect_cycle (AnjutaPluginManager
*plugin_manager
,
136 AnjutaPluginHandle
*base_plugin
, AnjutaPluginHandle
*cur_plugin
,
139 AnjutaPluginManagerPriv
*priv
;
142 priv
= plugin_manager
->priv
;
144 for (l
= anjuta_plugin_handle_get_dependency_names (cur_plugin
);
145 l
!= NULL
; l
= l
->next
)
147 AnjutaPluginHandle
*dep
= g_hash_table_lookup (priv
->plugins_by_name
,
151 if (dep
== base_plugin
)
153 *cycle
= g_list_prepend (NULL
, dep
);
154 /* DEBUG_PRINT ("%s", anjuta_plugin_handle_get_name (dep)); */
159 if (collect_cycle (plugin_manager
, base_plugin
, dep
, cycle
))
161 *cycle
= g_list_prepend (*cycle
, dep
);
162 /* DEBUG_PRINT ("%s", anjuta_plugin_handle_get_name (dep)); */
172 add_dependency (AnjutaPluginHandle
*dependent
, AnjutaPluginHandle
*dependency
)
174 g_hash_table_insert (anjuta_plugin_handle_get_dependents (dependency
),
175 dependent
, dependency
);
176 g_hash_table_insert (anjuta_plugin_handle_get_dependencies (dependent
),
177 dependency
, dependent
);
181 child_dep_foreach_cb (gpointer key
, gpointer value
, gpointer user_data
)
183 add_dependency (ANJUTA_PLUGIN_HANDLE (user_data
),
184 ANJUTA_PLUGIN_HANDLE (key
));
187 /* Resolves dependencies for a single module recursively. Shortcuts if
188 * the module has already been resolved. Returns a list representing
189 * any cycles found, or NULL if no cycles are found. If a cycle is found,
190 * the graph is left unresolved.
193 resolve_for_module (AnjutaPluginManager
*plugin_manager
,
194 AnjutaPluginHandle
*plugin
, int pass
)
196 AnjutaPluginManagerPriv
*priv
;
200 priv
= plugin_manager
->priv
;
202 if (anjuta_plugin_handle_get_checked (plugin
))
207 if (anjuta_plugin_handle_get_resolve_pass (plugin
) == pass
)
210 g_warning ("cycle found: %s on pass %d",
211 anjuta_plugin_handle_get_name (plugin
),
212 anjuta_plugin_handle_get_resolve_pass (plugin
));
213 collect_cycle (plugin_manager
, plugin
, plugin
, &cycle
);
217 if (anjuta_plugin_handle_get_resolve_pass (plugin
) != -1)
222 anjuta_plugin_handle_set_can_load (plugin
, TRUE
);
223 anjuta_plugin_handle_set_resolve_pass (plugin
, pass
);
225 for (l
= anjuta_plugin_handle_get_dependency_names (plugin
);
226 l
!= NULL
; l
= l
->next
)
229 AnjutaPluginHandle
*child
=
230 g_hash_table_lookup (priv
->plugins_by_name
, dep
);
233 ret
= resolve_for_module (plugin_manager
, child
, pass
);
239 /* Add the dependency's dense dependency list
240 * to the current module's dense dependency list */
241 g_hash_table_foreach (anjuta_plugin_handle_get_dependencies (child
),
242 child_dep_foreach_cb
, plugin
);
243 add_dependency (plugin
, child
);
245 /* If the child can't load due to dependency problems,
246 * the current module can't either */
247 anjuta_plugin_handle_set_can_load (plugin
,
248 anjuta_plugin_handle_get_can_load (child
));
250 g_warning ("Dependency %s not found.\n", dep
);
251 anjuta_plugin_handle_set_can_load (plugin
, FALSE
);
255 anjuta_plugin_handle_set_checked (plugin
, TRUE
);
260 /* Clean up the results of a resolving run */
262 unresolve_dependencies (AnjutaPluginManager
*plugin_manager
)
264 AnjutaPluginManagerPriv
*priv
;
267 priv
= plugin_manager
->priv
;
269 for (l
= priv
->available_plugins
; l
!= NULL
; l
= l
->next
)
271 AnjutaPluginHandle
*plugin
= l
->data
;
272 anjuta_plugin_handle_unresolve_dependencies (plugin
);
279 prune_modules (AnjutaPluginManager
*plugin_manager
, GList
*modules
)
281 AnjutaPluginManagerPriv
*priv
;
284 priv
= plugin_manager
->priv
;
286 for (l
= modules
; l
!= NULL
; l
= l
->next
) {
287 AnjutaPluginHandle
*plugin
= l
->data
;
289 g_hash_table_remove (priv
->plugins_by_name
,
290 anjuta_plugin_handle_get_id (plugin
));
291 priv
->available_plugins
= g_list_remove (priv
->available_plugins
, plugin
);
296 dependency_compare (AnjutaPluginHandle
*plugin_a
,
297 AnjutaPluginHandle
*plugin_b
)
299 int a
= g_hash_table_size (anjuta_plugin_handle_get_dependencies (plugin_a
));
300 int b
= g_hash_table_size (anjuta_plugin_handle_get_dependencies (plugin_b
));
305 /* Resolves the dependencies of the priv->available_plugins list. When this
306 * function is complete, the following will be true:
308 * 1) The dependencies and dependents hash tables of the modules will
311 * 2) Cycles in the graph will be removed.
313 * 3) Modules which cannot be loaded due to failed dependencies will
316 * 4) priv->available_plugins will be sorted such that no module depends on a
319 * If a cycle in the graph is found, it is pruned from the tree and
320 * returned as a list stored in the cycles list.
323 resolve_dependencies (AnjutaPluginManager
*plugin_manager
, GList
**cycles
)
325 AnjutaPluginManagerPriv
*priv
;
329 priv
= plugin_manager
->priv
;
332 /* Try resolving dependencies. If there is a cycle, prune the
333 * cycle and try to resolve again */
338 for (l
= priv
->available_plugins
; l
!= NULL
&& !cycle
; l
= l
->next
) {
339 cycle
= resolve_for_module (plugin_manager
, l
->data
, pass
++);
343 *cycles
= g_list_prepend (*cycles
, cycle
);
344 prune_modules (plugin_manager
, cycle
);
345 unresolve_dependencies (plugin_manager
);
349 /* Now that there is a fully resolved dependency tree, sort
350 * priv->available_plugins to create a valid load order */
351 priv
->available_plugins
= g_list_sort (priv
->available_plugins
,
352 (GCompareFunc
)dependency_compare
);
355 /* Plugins loading */
358 str_has_suffix (const char *haystack
, const char *needle
)
362 if (needle
== NULL
) {
365 if (haystack
== NULL
) {
366 return needle
[0] == '\0';
369 /* Eat one character at a time. */
370 h
= haystack
+ strlen(haystack
);
371 n
= needle
+ strlen(needle
);
379 } while (*--h
== *--n
);
384 load_plugin (AnjutaPluginManager
*plugin_manager
,
385 const gchar
*plugin_desc_path
)
387 AnjutaPluginManagerPriv
*priv
;
388 AnjutaPluginHandle
*plugin_handle
;
390 g_return_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
));
391 priv
= plugin_manager
->priv
;
393 plugin_handle
= anjuta_plugin_handle_new (plugin_desc_path
);
396 if (g_hash_table_lookup (priv
->plugins_by_name
,
397 anjuta_plugin_handle_get_id (plugin_handle
)))
399 g_object_unref (plugin_handle
);
404 /* Available plugin */
405 priv
->available_plugins
= g_list_prepend (priv
->available_plugins
,
408 g_hash_table_insert (priv
->plugins_by_name
,
409 (gchar
*)anjuta_plugin_handle_get_id (plugin_handle
),
412 /* Index by description */
413 g_hash_table_insert (priv
->plugins_by_description
,
414 anjuta_plugin_handle_get_description (plugin_handle
),
417 /* Index by interfaces exported by this plugin */
418 node
= anjuta_plugin_handle_get_interfaces (plugin_handle
);
427 objs
= (GList
*)g_hash_table_lookup (priv
->plugins_by_interfaces
, iface
);
433 if (obj_node
->data
== plugin_handle
)
438 obj_node
= g_list_next (obj_node
);
442 g_hash_table_steal (priv
->plugins_by_interfaces
, iface
);
443 objs
= g_list_prepend (objs
, plugin_handle
);
444 g_hash_table_insert (priv
->plugins_by_interfaces
, iface
, objs
);
446 node
= g_list_next (node
);
454 load_plugins_from_directory (AnjutaPluginManager
* plugin_manager
,
455 const gchar
*dirname
)
458 struct dirent
*entry
;
460 dir
= opendir (dirname
);
467 for (entry
= readdir (dir
); entry
!= NULL
; entry
= readdir (dir
))
469 if (str_has_suffix (entry
->d_name
, ".plugin"))
472 pathname
= g_strdup_printf ("%s/%s", dirname
, entry
->d_name
);
473 load_plugin (plugin_manager
,pathname
);
480 /* Plugin activation and deactivation */
483 on_plugin_activated (AnjutaPlugin
*plugin_object
, AnjutaPluginHandle
*plugin
)
485 AnjutaPluginManager
*plugin_manager
;
486 AnjutaPluginManagerPriv
*priv
;
488 /* FIXME: Pass plugin_manager directly in signal arguments */
489 plugin_manager
= anjuta_shell_get_plugin_manager (plugin_object
->shell
, NULL
);
491 g_return_if_fail(plugin_manager
!= NULL
);
493 priv
= plugin_manager
->priv
;
495 g_hash_table_insert (priv
->activated_plugins
, plugin
,
496 G_OBJECT (plugin_object
));
497 if (g_hash_table_lookup (priv
->plugins_cache
, plugin
))
498 g_hash_table_remove (priv
->plugins_cache
, plugin
);
500 g_signal_emit_by_name (plugin_manager
, "plugin-activated",
501 anjuta_plugin_handle_get_description (plugin
),
506 on_plugin_deactivated (AnjutaPlugin
*plugin_object
, AnjutaPluginHandle
*plugin
)
508 AnjutaPluginManager
*plugin_manager
;
509 AnjutaPluginManagerPriv
*priv
;
511 /* FIXME: Pass plugin_manager directly in signal arguments */
512 plugin_manager
= anjuta_shell_get_plugin_manager (plugin_object
->shell
, NULL
);
514 g_return_if_fail (plugin_manager
!= NULL
);
516 priv
= plugin_manager
->priv
;
518 g_hash_table_insert (priv
->plugins_cache
, plugin
, G_OBJECT (plugin_object
));
519 g_hash_table_remove (priv
->activated_plugins
, plugin
);
521 g_signal_emit_by_name (plugin_manager
, "plugin-deactivated",
522 anjuta_plugin_handle_get_description (plugin
),
527 activate_plugin (AnjutaPluginManager
*plugin_manager
,
528 AnjutaPluginHandle
*handle
, GError
**error
)
530 AnjutaPluginManagerPriv
*priv
;
531 IAnjutaPluginFactory
* factory
;
532 AnjutaPlugin
*plugin
;
533 const gchar
*plugin_id
;
534 const gchar
*language
;
537 priv
= plugin_manager
->priv
;
539 plugin_id
= anjuta_plugin_handle_get_id (handle
);
541 resident
= anjuta_plugin_handle_get_resident (handle
);
542 language
= anjuta_plugin_handle_get_language (handle
);
544 factory
= get_plugin_factory (plugin_manager
, language
, error
);
545 if (factory
== NULL
) return NULL
;
547 plugin
= ianjuta_plugin_factory_new_plugin (factory
, handle
, ANJUTA_SHELL (priv
->shell
), error
);
553 g_signal_connect (plugin
, "activated",
554 G_CALLBACK (on_plugin_activated
), handle
);
555 g_signal_connect (plugin
, "deactivated",
556 G_CALLBACK (on_plugin_deactivated
), handle
);
562 g_hashtable_foreach_true (gpointer key
, gpointer value
, gpointer user_data
)
568 anjuta_plugin_manager_unload_all_plugins (AnjutaPluginManager
*plugin_manager
)
570 AnjutaPluginManagerPriv
*priv
;
572 priv
= plugin_manager
->priv
;
573 if (g_hash_table_size (priv
->activated_plugins
) > 0 ||
574 g_hash_table_size (priv
->plugins_cache
) > 0)
576 priv
->available_plugins
= g_list_reverse (priv
->available_plugins
);
577 if (g_hash_table_size (priv
->activated_plugins
) > 0)
580 node
= priv
->available_plugins
;
583 AnjutaPluginHandle
*selected_plugin
= node
->data
;
584 if (g_hash_table_lookup (priv
->activated_plugins
, selected_plugin
))
586 plugin_set_update (plugin_manager
, selected_plugin
, FALSE
);
587 /* DEBUG_PRINT ("Unloading plugin: %s",
588 anjuta_plugin_handle_get_id (selected_plugin));
591 node
= g_list_next (node
);
593 g_hash_table_foreach_remove (priv
->activated_plugins
,
594 g_hashtable_foreach_true
, NULL
);
596 if (g_hash_table_size (priv
->plugins_cache
) > 0)
599 node
= priv
->available_plugins
;
603 AnjutaPluginHandle
*selected_plugin
= node
->data
;
605 plugin_obj
= g_hash_table_lookup (priv
->plugins_cache
,
609 /* DEBUG_PRINT ("Destroying plugin: %s",
610 anjuta_plugin_handle_get_id (selected_plugin));
612 g_object_unref (plugin_obj
);
614 node
= g_list_next (node
);
616 g_hash_table_foreach_remove (priv
->plugins_cache
,
617 g_hashtable_foreach_true
, NULL
);
619 priv
->available_plugins
= g_list_reverse (priv
->available_plugins
);
624 should_unload (GHashTable
*activated_plugins
, AnjutaPluginHandle
*plugin_to_unload
,
625 AnjutaPluginHandle
*plugin
)
627 GObject
*plugin_obj
= g_hash_table_lookup (activated_plugins
, plugin
);
632 if (plugin_to_unload
== plugin
)
636 GPOINTER_TO_INT (g_hash_table_lookup (anjuta_plugin_handle_get_dependents (plugin
),
642 should_load (GHashTable
*activated_plugins
, AnjutaPluginHandle
*plugin_to_load
,
643 AnjutaPluginHandle
*plugin
)
645 GObject
*plugin_obj
= g_hash_table_lookup (activated_plugins
, plugin
);
650 if (plugin_to_load
== plugin
)
651 return anjuta_plugin_handle_get_can_load (plugin
);
653 gboolean dependency
=
654 GPOINTER_TO_INT (g_hash_table_lookup (anjuta_plugin_handle_get_dependencies (plugin_to_load
),
656 return (dependency
&& anjuta_plugin_handle_get_can_load (plugin
));
659 static AnjutaPluginHandle
*
660 plugin_for_iter (GtkListStore
*store
, GtkTreeIter
*iter
)
662 AnjutaPluginHandle
*plugin
;
664 gtk_tree_model_get (GTK_TREE_MODEL (store
), iter
, COL_PLUGIN
, &plugin
, -1);
669 update_enabled (GtkTreeModel
*model
, GHashTable
*activated_plugins
)
673 if (gtk_tree_model_get_iter_first (model
, &iter
)) {
675 AnjutaPluginHandle
*plugin
;
679 plugin
= plugin_for_iter(GTK_LIST_STORE(model
), &iter
);
680 plugin_obj
= g_hash_table_lookup (activated_plugins
, plugin
);
681 installed
= (plugin_obj
!= NULL
) ? TRUE
: FALSE
;
682 gtk_tree_model_get (model
, &iter
, COL_PLUGIN
, &plugin
, -1);
683 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
684 COL_ENABLED
, installed
, -1);
685 } while (gtk_tree_model_iter_next (model
, &iter
));
690 plugin_set_update (AnjutaPluginManager
*plugin_manager
,
691 AnjutaPluginHandle
* selected_plugin
,
694 AnjutaPluginManagerPriv
*priv
;
698 priv
= plugin_manager
->priv
;
699 plugin_obj
= g_hash_table_lookup (priv
->activated_plugins
, selected_plugin
);
701 if (plugin_obj
&& load
)
703 g_warning ("Trying to install already installed plugin '%s'",
704 anjuta_plugin_handle_get_name (selected_plugin
));
705 return priv
->activated_plugins
;
707 if (!plugin_obj
&& !load
)
709 g_warning ("Trying to uninstall a not installed plugin '%s'",
710 anjuta_plugin_handle_get_name (selected_plugin
));
711 return priv
->activated_plugins
;
715 anjuta_status_busy_push (priv
->status
);
719 /* reverse priv->available_plugins when unloading, so that plugins are
720 * unloaded in the right order */
721 priv
->available_plugins
= g_list_reverse (priv
->available_plugins
);
723 for (l
= priv
->available_plugins
; l
!= NULL
; l
= l
->next
)
725 AnjutaPluginHandle
*plugin
= l
->data
;
726 if (should_unload (priv
->activated_plugins
, selected_plugin
, plugin
))
728 /* FIXME: Unload the class and sharedlib if possible */
729 AnjutaPlugin
*anjuta_plugin
= ANJUTA_PLUGIN (plugin_obj
);
730 if (!anjuta_plugin_deactivate (ANJUTA_PLUGIN (anjuta_plugin
)))
732 anjuta_util_dialog_info (GTK_WINDOW (priv
->shell
),
733 _("Plugin '%s' does not want to be deactivated"),
734 anjuta_plugin_handle_get_name (plugin
));
738 priv
->available_plugins
= g_list_reverse (priv
->available_plugins
);
742 for (l
= priv
->available_plugins
; l
!= NULL
; l
= l
->next
)
744 AnjutaPluginHandle
*plugin
= l
->data
;
745 if (should_load (priv
->activated_plugins
, selected_plugin
, plugin
))
747 AnjutaPlugin
*plugin_obj
;
748 GError
*error
= NULL
;
749 plugin_obj
= g_hash_table_lookup (priv
->plugins_cache
, plugin
);
752 plugin_obj
= activate_plugin (plugin_manager
, plugin
,
758 anjuta_plugin_activate (ANJUTA_PLUGIN (plugin_obj
));
764 gchar
* message
= g_strdup_printf (_("Could not load %s\n"
765 "This usually means that your installation is corrupted. The "
766 "error message leading to this was:\n%s"),
767 anjuta_plugin_handle_get_name (selected_plugin
),
769 anjuta_util_dialog_error (GTK_WINDOW(plugin_manager
->priv
->shell
),
771 g_error_free (error
);
779 anjuta_status_busy_pop (priv
->status
);
780 return priv
->activated_plugins
;
784 plugin_toggled (GtkCellRendererToggle
*cell
, char *path_str
, gpointer data
)
786 AnjutaPluginManager
*plugin_manager
;
787 AnjutaPluginManagerPriv
*priv
;
788 GtkListStore
*store
= GTK_LIST_STORE (data
);
791 AnjutaPluginHandle
*plugin
;
793 GList
*activated_plugins
;
795 AnjutaPlugin
* plugin_object
;
797 path
= gtk_tree_path_new_from_string (path_str
);
799 plugin_manager
= g_object_get_data (G_OBJECT (store
), "plugin-manager");
800 priv
= plugin_manager
->priv
;
802 gtk_tree_model_get_iter (GTK_TREE_MODEL (store
), &iter
, path
);
803 gtk_tree_model_get (GTK_TREE_MODEL (store
), &iter
,
804 COL_ENABLED
, &enabled
,
808 /* Activate one plugin can force the loading of other ones, instead of
809 * searching which plugins have to be activated, we just unmerge all
810 * current plugins and merge all plugins after the modification */
812 /* unmerge all plugins */
813 activated_plugins
= g_hash_table_get_values (priv
->activated_plugins
);
814 for (node
= g_list_first (activated_plugins
); node
!= NULL
; node
= g_list_next (node
))
816 plugin_object
= (AnjutaPlugin
*)node
->data
;
818 IANJUTA_IS_PREFERENCES(plugin_object
))
820 ianjuta_preferences_unmerge (IANJUTA_PREFERENCES (plugin_object
),
821 anjuta_shell_get_preferences (ANJUTA_SHELL (priv
->shell
), NULL
),
825 g_list_free (activated_plugins
);
827 plugin_set_update (plugin_manager
, plugin
, !enabled
);
829 /* Make sure that it appears in the preferences. This method
830 can only be called when the preferences dialog is active so
833 activated_plugins
= g_hash_table_get_values (priv
->activated_plugins
);
834 for (node
= g_list_first (activated_plugins
); node
!= NULL
; node
= g_list_next (node
))
836 plugin_object
= (AnjutaPlugin
*)node
->data
;
838 IANJUTA_IS_PREFERENCES(plugin_object
))
840 ianjuta_preferences_merge (IANJUTA_PREFERENCES (plugin_object
),
841 anjuta_shell_get_preferences (ANJUTA_SHELL (priv
->shell
), NULL
),
845 g_list_free (activated_plugins
);
847 update_enabled (GTK_TREE_MODEL (store
), priv
->activated_plugins
);
848 gtk_tree_path_free (path
);
853 selection_changed (GtkTreeSelection
*selection
, GtkListStore
*store
)
857 if (gtk_tree_selection_get_selected (selection
, NULL
,
859 GtkTextBuffer
*buffer
;
861 GtkWidget
*txt
= g_object_get_data (G_OBJECT (store
),
864 GtkWidget
*image
= g_object_get_data (G_OBJECT (store
),
866 AnjutaPluginHandle
*plugin
= plugin_for_iter (store
, &iter
);
868 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (txt
));
869 gtk_text_buffer_set_text (buffer
, plugin
->about
, -1);
871 if (plugin
->icon_path
) {
872 gtk_image_set_from_file (GTK_IMAGE (image
),
874 gtk_widget_show (GTK_WIDGET (image
));
876 gtk_widget_hide (GTK_WIDGET (image
));
883 create_plugin_tree (void)
887 GtkCellRenderer
*renderer
;
888 GtkTreeViewColumn
*column
;
890 store
= gtk_list_store_new (N_COLS
,
896 tree
= gtk_tree_view_new_with_model (GTK_TREE_MODEL (store
));
898 renderer
= gtk_cell_renderer_toggle_new ();
899 g_signal_connect (G_OBJECT (renderer
), "toggled",
900 G_CALLBACK (plugin_toggled
), store
);
901 column
= gtk_tree_view_column_new_with_attributes (_("Load"),
908 gtk_tree_view_append_column (GTK_TREE_VIEW (tree
), column
);
909 gtk_tree_view_column_set_sizing (column
,
910 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
912 column
= gtk_tree_view_column_new ();
913 renderer
= gtk_cell_renderer_pixbuf_new ();
914 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
915 gtk_tree_view_column_add_attribute (column
, renderer
, "pixbuf",
917 renderer
= gtk_cell_renderer_text_new ();
918 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
919 gtk_tree_view_column_add_attribute (column
, renderer
, "markup",
921 gtk_tree_view_column_set_sizing (column
,
922 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
923 gtk_tree_view_column_set_title (column
, _("Available Plugins"));
924 gtk_tree_view_append_column (GTK_TREE_VIEW (tree
), column
);
925 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (tree
), column
);
927 g_object_unref (store
);
931 /* Sort function for plugins */
933 sort_plugins(gconstpointer a
, gconstpointer b
)
935 g_return_val_if_fail (a
!= NULL
, 0);
936 g_return_val_if_fail (b
!= NULL
, 0);
938 AnjutaPluginHandle
* plugin_a
= ANJUTA_PLUGIN_HANDLE (a
);
939 AnjutaPluginHandle
* plugin_b
= ANJUTA_PLUGIN_HANDLE (b
);
941 return strcmp (anjuta_plugin_handle_get_name (plugin_a
),
942 anjuta_plugin_handle_get_name (plugin_b
));
945 /* If show_all == FALSE, show only user activatable plugins
946 * If show_all == TRUE, show all plugins
949 populate_plugin_model (AnjutaPluginManager
*plugin_manager
,
951 GHashTable
*plugins_to_show
,
952 GHashTable
*activated_plugins
,
955 AnjutaPluginManagerPriv
*priv
;
958 priv
= plugin_manager
->priv
;
959 gtk_list_store_clear (store
);
961 priv
->available_plugins
= g_list_sort (priv
->available_plugins
, sort_plugins
);
963 for (l
= priv
->available_plugins
; l
!= NULL
; l
= l
->next
)
965 AnjutaPluginHandle
*plugin
= l
->data
;
967 /* If plugins to show is NULL, show all available plugins */
968 if (plugins_to_show
== NULL
||
969 g_hash_table_lookup (plugins_to_show
, plugin
))
972 gboolean enable
= FALSE
;
973 if (g_hash_table_lookup (activated_plugins
, plugin
))
976 if (anjuta_plugin_handle_get_name (plugin
) &&
977 anjuta_plugin_handle_get_description (plugin
) &&
978 (anjuta_plugin_handle_get_user_activatable (plugin
) ||
984 text
= g_markup_printf_escaped ("<span size=\"larger\" weight=\"bold\">%s</span>\n%s",
985 anjuta_plugin_handle_get_name (plugin
),
986 anjuta_plugin_handle_get_about (plugin
));
988 gtk_list_store_append (store
, &iter
);
989 gtk_list_store_set (store
, &iter
,
991 anjuta_plugin_handle_get_user_activatable (plugin
),
996 if (anjuta_plugin_handle_get_icon_path (plugin
))
999 icon
= gdk_pixbuf_new_from_file_at_size (anjuta_plugin_handle_get_icon_path (plugin
),
1002 gtk_list_store_set (store
, &iter
,
1003 COL_ICON
, icon
, -1);
1004 g_object_unref (icon
);
1014 create_remembered_plugins_tree (void)
1016 GtkListStore
*store
;
1018 GtkCellRenderer
*renderer
;
1019 GtkTreeViewColumn
*column
;
1021 store
= gtk_list_store_new (N_REM_COLS
, GDK_TYPE_PIXBUF
, G_TYPE_STRING
,
1023 tree
= gtk_tree_view_new_with_model (GTK_TREE_MODEL (store
));
1025 column
= gtk_tree_view_column_new ();
1026 renderer
= gtk_cell_renderer_pixbuf_new ();
1027 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
1028 gtk_tree_view_column_add_attribute (column
, renderer
, "pixbuf",
1030 renderer
= gtk_cell_renderer_text_new ();
1031 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
1032 gtk_tree_view_column_add_attribute (column
, renderer
, "markup",
1034 gtk_tree_view_column_set_sizing (column
,
1035 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
1036 gtk_tree_view_column_set_title (column
, _("Preferred plugins"));
1037 gtk_tree_view_append_column (GTK_TREE_VIEW (tree
), column
);
1038 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (tree
), column
);
1040 g_object_unref (store
);
1045 foreach_remembered_plugin (gpointer key
, gpointer value
, gpointer user_data
)
1047 AnjutaPluginDescription
*desc
= (AnjutaPluginDescription
*) value
;
1048 GtkListStore
*store
= GTK_LIST_STORE (user_data
);
1049 AnjutaPluginManager
*manager
= g_object_get_data (G_OBJECT (store
),
1051 AnjutaPluginHandle
*plugin
=
1052 g_hash_table_lookup (manager
->priv
->plugins_by_description
, desc
);
1053 g_return_if_fail (plugin
!= NULL
);
1055 if (anjuta_plugin_handle_get_name (plugin
) &&
1056 anjuta_plugin_handle_get_description (plugin
))
1061 text
= g_markup_printf_escaped ("<span size=\"larger\" weight=\"bold\">%s</span>\n%s",
1062 anjuta_plugin_handle_get_name (plugin
),
1063 anjuta_plugin_handle_get_about (plugin
));
1065 gtk_list_store_append (store
, &iter
);
1066 gtk_list_store_set (store
, &iter
,
1068 COL_REM_PLUGIN_KEY
, key
,
1070 if (anjuta_plugin_handle_get_icon_path (plugin
))
1073 icon
= gdk_pixbuf_new_from_file_at_size (anjuta_plugin_handle_get_icon_path (plugin
),
1076 gtk_list_store_set (store
, &iter
,
1077 COL_REM_ICON
, icon
, -1);
1078 g_object_unref (icon
);
1086 populate_remembered_plugins_model (AnjutaPluginManager
*plugin_manager
,
1087 GtkListStore
*store
)
1089 AnjutaPluginManagerPriv
*priv
= plugin_manager
->priv
;
1090 gtk_list_store_clear (store
);
1091 g_hash_table_foreach (priv
->remember_plugins
, foreach_remembered_plugin
,
1096 on_show_all_plugins_toggled (GtkToggleButton
*button
, GtkListStore
*store
)
1098 AnjutaPluginManager
*plugin_manager
;
1100 plugin_manager
= g_object_get_data (G_OBJECT (button
), "__plugin_manager");
1102 populate_plugin_model (plugin_manager
, store
, NULL
,
1103 plugin_manager
->priv
->activated_plugins
,
1104 !gtk_toggle_button_get_active (button
));
1108 on_forget_plugin_clicked (GtkWidget
*button
, GtkTreeView
*view
)
1111 GtkTreeModel
*model
;
1112 GtkTreeSelection
*selection
= gtk_tree_view_get_selection (view
);
1113 if (gtk_tree_selection_get_selected (selection
, &model
, &iter
))
1116 AnjutaPluginManager
*manager
= g_object_get_data (G_OBJECT (model
),
1118 gtk_tree_model_get (model
, &iter
, COL_REM_PLUGIN_KEY
, &plugin_key
, -1);
1119 g_hash_table_remove (manager
->priv
->remember_plugins
, plugin_key
);
1120 gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
1121 g_free (plugin_key
);
1126 on_forget_plugin_sel_changed (GtkTreeSelection
*selection
,
1131 if (gtk_tree_selection_get_selected (selection
, NULL
, &iter
))
1132 gtk_widget_set_sensitive (button
, TRUE
);
1134 gtk_widget_set_sensitive (button
, FALSE
);
1138 anjuta_plugin_manager_get_plugins_page (AnjutaPluginManager
*plugin_manager
)
1141 GtkWidget
*checkbutton
;
1143 GtkWidget
*scrolled
;
1144 GtkListStore
*store
;
1147 vbox
= gtk_vbox_new (FALSE
, 0);
1148 gtk_container_set_border_width (GTK_CONTAINER (vbox
), 10);
1150 checkbutton
= gtk_check_button_new_with_label (_("Only show user activatable plugins"));
1151 gtk_container_set_border_width (GTK_CONTAINER (checkbutton
), 10);
1152 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton
), TRUE
);
1153 gtk_box_pack_start (GTK_BOX (vbox
), checkbutton
, FALSE
, FALSE
, 0);
1155 scrolled
= gtk_scrolled_window_new (NULL
, NULL
);
1156 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled
),
1158 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled
),
1159 GTK_POLICY_AUTOMATIC
,
1160 GTK_POLICY_AUTOMATIC
);
1161 gtk_box_pack_start (GTK_BOX (vbox
), scrolled
, TRUE
, TRUE
, 0);
1163 tree
= create_plugin_tree ();
1164 store
= GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (tree
)));
1166 populate_plugin_model (plugin_manager
, store
, NULL
,
1167 plugin_manager
->priv
->activated_plugins
, FALSE
);
1169 gtk_container_add (GTK_CONTAINER (scrolled
), tree
);
1170 g_object_set_data (G_OBJECT (store
), "plugin-manager", plugin_manager
);
1173 g_object_set_data (G_OBJECT (checkbutton
), "__plugin_manager", plugin_manager
);
1174 g_signal_connect (G_OBJECT (checkbutton
), "toggled",
1175 G_CALLBACK (on_show_all_plugins_toggled
),
1177 gtk_widget_show_all (vbox
);
1182 anjuta_plugin_manager_get_remembered_plugins_page (AnjutaPluginManager
*plugin_manager
)
1186 GtkWidget
*scrolled
;
1187 GtkListStore
*store
;
1189 GtkWidget
*display_label
;
1190 GtkWidget
*forget_button
;
1191 GtkTreeSelection
*selection
;
1193 /* Remembered plugin */
1194 vbox
= gtk_vbox_new (FALSE
, 10);
1195 gtk_container_set_border_width (GTK_CONTAINER (vbox
), 10);
1197 display_label
= gtk_label_new (_("These are the plugins selected by you "
1198 "when Anjuta prompted to choose one of "
1199 "many suitable plugins. Removing the "
1200 "preferred plugin will let Anjuta prompt "
1201 "you again to choose different plugin."));
1202 gtk_label_set_line_wrap (GTK_LABEL (display_label
), TRUE
);
1203 gtk_box_pack_start (GTK_BOX (vbox
), display_label
, FALSE
, FALSE
, 0);
1205 scrolled
= gtk_scrolled_window_new (NULL
, NULL
);
1206 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled
),
1208 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled
),
1209 GTK_POLICY_AUTOMATIC
,
1210 GTK_POLICY_AUTOMATIC
);
1211 gtk_box_pack_start (GTK_BOX (vbox
), scrolled
, TRUE
, TRUE
, 0);
1213 tree
= create_remembered_plugins_tree ();
1214 store
= GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (tree
)));
1216 gtk_container_add (GTK_CONTAINER (scrolled
), tree
);
1217 g_object_set_data (G_OBJECT (store
), "plugin-manager", plugin_manager
);
1218 populate_remembered_plugins_model (plugin_manager
, store
);
1220 hbox
= gtk_hbox_new (FALSE
, 0);
1221 gtk_container_set_border_width (GTK_CONTAINER (hbox
), 5);
1222 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
1223 forget_button
= gtk_button_new_with_label (_("Forget selected plugin"));
1224 gtk_widget_set_sensitive (forget_button
, FALSE
);
1225 gtk_box_pack_end (GTK_BOX (hbox
), forget_button
, FALSE
, FALSE
, 0);
1227 g_signal_connect (forget_button
, "clicked",
1228 G_CALLBACK (on_forget_plugin_clicked
),
1230 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (tree
));
1231 g_signal_connect (selection
, "changed",
1232 G_CALLBACK (on_forget_plugin_sel_changed
),
1234 gtk_widget_show_all (vbox
);
1239 property_to_list (const char *value
)
1245 split_str
= g_strsplit (value
, ",", -1);
1246 for (p
= split_str
; *p
!= NULL
; p
++) {
1247 l
= g_list_prepend (l
, g_strdup (g_strstrip (*p
)));
1249 g_strfreev (split_str
);
1253 static IAnjutaPluginFactory
*
1254 get_plugin_factory (AnjutaPluginManager
*plugin_manager
,
1255 const gchar
*language
,
1258 AnjutaPluginManagerPriv
*priv
;
1259 AnjutaPluginHandle
*plugin
;
1260 GList
*loader_plugins
, *node
;
1261 GList
*valid_plugins
;
1262 GObject
*obj
= NULL
;
1264 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), G_TYPE_INVALID
);
1267 if ((language
== NULL
) || (g_ascii_strcasecmp (language
, "C") == 0))
1269 /* Support of C plugin is built-in */
1270 return IANJUTA_PLUGIN_FACTORY (anjuta_plugin_factory
);
1273 priv
= plugin_manager
->priv
;
1276 /* Find all plugins implementing the IAnjutaPluginLoader interface. */
1277 loader_plugins
= g_hash_table_lookup (priv
->plugins_by_interfaces
, "IAnjutaPluginLoader");
1279 /* Create a list of loader supporting this language */
1280 node
= loader_plugins
;
1281 valid_plugins
= NULL
;
1284 AnjutaPluginDescription
*desc
;
1290 plugin
= node
->data
;
1292 desc
= anjuta_plugin_handle_get_description (plugin
);
1293 if (anjuta_plugin_description_get_string (desc
, "Plugin Loader", "SupportedLanguage", &val
))
1297 vals
= property_to_list (val
);
1306 if (!found
&& (g_ascii_strcasecmp (l_node
->data
, language
) == 0))
1310 g_free (l_node
->data
);
1311 l_node
= g_list_next (l_node
);
1317 valid_plugins
= g_list_prepend (valid_plugins
, plugin
);
1320 node
= g_list_next (node
);
1323 /* Find the first installed plugin from the valid plugins */
1324 node
= valid_plugins
;
1327 plugin
= node
->data
;
1328 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1330 node
= g_list_next (node
);
1333 /* If no plugin is installed yet, do something */
1334 if ((obj
== NULL
) && valid_plugins
&& g_list_length (valid_plugins
) == 1)
1336 /* If there is just one plugin, consider it selected */
1337 plugin
= valid_plugins
->data
;
1339 /* Install and return it */
1340 plugin_set_update (plugin_manager
, plugin
, TRUE
);
1341 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1343 else if ((obj
== NULL
) && valid_plugins
)
1345 /* Prompt the user to select one of these plugins */
1347 GList
*descs
= NULL
;
1348 node
= valid_plugins
;
1351 plugin
= node
->data
;
1352 descs
= g_list_prepend (descs
, anjuta_plugin_handle_get_description (plugin
));
1353 node
= g_list_next (node
);
1355 descs
= g_list_reverse (descs
);
1356 obj
= anjuta_plugin_manager_select_and_activate (plugin_manager
,
1357 _("Select a plugin"),
1358 _("<b>Please select a plugin to activate</b>"),
1360 g_list_free (descs
);
1362 g_list_free (valid_plugins
);
1366 return IANJUTA_PLUGIN_FACTORY (obj
);
1369 /* No plugin implementing this interface found */
1370 g_set_error (error
, ANJUTA_PLUGIN_MANAGER_ERROR
,
1371 ANJUTA_PLUGIN_MANAGER_MISSING_FACTORY
,
1372 _("No plugin is able to load other plugins in %s"), language
);
1378 on_is_active_plugins_foreach (gpointer key
, gpointer data
, gpointer user_data
)
1380 AnjutaPluginHandle
*handle
= ANJUTA_PLUGIN_HANDLE (key
);
1381 gchar
const **search_iface
= (gchar
const **)user_data
;
1383 if (*search_iface
!= NULL
)
1388 interfaces
= anjuta_plugin_handle_get_interfaces (handle
);
1390 for (found
= g_list_first (interfaces
); found
!= NULL
; found
= g_list_next (found
))
1394 found
= g_list_find_custom (interfaces
, *search_iface
, (GCompareFunc
)strcmp
);
1396 if (found
!= NULL
) *search_iface
= NULL
;
1401 * anjuta_plugin_manager_is_active_plugin:
1402 * @plugin_manager: A #AnjutaPluginManager object
1403 * @iface_name: The interface implemented by the object to be found
1405 * Searches if a currently loaded plugins implements
1406 * the given interface.
1408 * Return value: True is the plugin is currently loaded.
1412 anjuta_plugin_manager_is_active_plugin (AnjutaPluginManager
*plugin_manager
,
1413 const gchar
*iface_name
)
1415 const gchar
*search_iface
= iface_name
;
1417 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), FALSE
);
1419 g_hash_table_foreach (plugin_manager
->priv
->activated_plugins
,
1420 on_is_active_plugins_foreach
,
1423 return search_iface
== NULL
;
1427 * anjuta_plugin_manager_get_plugin:
1428 * @plugin_manager: A #AnjutaPluginManager object
1429 * @iface_name: The interface implemented by the object to be found
1431 * Searches the currently available plugins to find the one which
1432 * implements the given interface as primary interface and returns it. If
1433 * the plugin is not yet loaded, it will be loaded and activated.
1435 * from the pool of plugin objects loaded in this shell and can only search
1436 * by primary interface. If there are more objects implementing this primary
1437 * interface, user might be prompted to select one from them (and might give
1438 * the option to use it as default for future queries). A typical usage of this
1442 * anjuta_plugin_manager_get_plugin (plugin_manager, "IAnjutaDocumentManager", error);
1444 * Notice that this function takes the interface name string as string, unlike
1445 * anjuta_plugins_get_interface() which takes the type directly.
1446 * If no plugin implementing this interface can be found, returns NULL.
1448 * Return value: The plugin object (subclass of #AnjutaPlugin) which implements
1449 * the given interface or NULL. See #AnjutaPlugin for more detail on interfaces
1450 * implemented by plugins.
1453 anjuta_plugin_manager_get_plugin (AnjutaPluginManager
*plugin_manager
,
1454 const gchar
*iface_name
)
1456 AnjutaPluginManagerPriv
*priv
;
1457 AnjutaPluginHandle
*plugin
;
1458 GList
*valid_plugins
, *node
;
1460 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1461 g_return_val_if_fail (iface_name
!= NULL
, NULL
);
1463 priv
= plugin_manager
->priv
;
1466 /* Find all plugins implementing this (primary) interface. */
1467 valid_plugins
= g_hash_table_lookup (priv
->plugins_by_interfaces
, iface_name
);
1469 /* Find the first installed plugin from the valid plugins */
1470 node
= valid_plugins
;
1474 plugin
= node
->data
;
1475 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1478 node
= g_list_next (node
);
1481 /* If no plugin is installed yet, do something */
1482 if (valid_plugins
&& g_list_length (valid_plugins
) == 1)
1484 /* If there is just one plugin, consider it selected */
1486 plugin
= valid_plugins
->data
;
1488 /* Install and return it */
1489 plugin_set_update (plugin_manager
, plugin
, TRUE
);
1490 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1494 else if (valid_plugins
)
1496 /* Prompt the user to select one of these plugins */
1498 GList
*descs
= NULL
;
1499 node
= valid_plugins
;
1502 plugin
= node
->data
;
1503 descs
= g_list_prepend (descs
, anjuta_plugin_handle_get_description (plugin
));
1504 node
= g_list_next (node
);
1506 descs
= g_list_reverse (descs
);
1507 obj
= anjuta_plugin_manager_select_and_activate (plugin_manager
,
1508 _("Select a plugin"),
1509 _("<b>Please select a plugin to activate</b>"),
1511 g_list_free (descs
);
1515 /* No plugin implementing this interface found */
1520 anjuta_plugin_manager_get_plugin_by_id (AnjutaPluginManager
*plugin_manager
,
1521 const gchar
*plugin_id
)
1523 AnjutaPluginManagerPriv
*priv
;
1524 AnjutaPluginHandle
*plugin
;
1526 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1527 g_return_val_if_fail (plugin_id
!= NULL
, NULL
);
1529 priv
= plugin_manager
->priv
;
1530 plugin
= g_hash_table_lookup (priv
->plugins_by_name
, plugin_id
);
1534 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1540 plugin_set_update (plugin_manager
, plugin
, TRUE
);
1541 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1545 g_warning ("No plugin found with id \"%s\".", plugin_id
);
1550 on_activated_plugins_foreach (gpointer key
, gpointer data
, gpointer user_data
)
1552 AnjutaPluginHandle
*plugin
= ANJUTA_PLUGIN_HANDLE (key
);
1553 GList
**active_plugins
= (GList
**)user_data
;
1554 *active_plugins
= g_list_prepend (*active_plugins
,
1555 anjuta_plugin_handle_get_description (plugin
));
1559 on_activated_plugin_objects_foreach (gpointer key
, gpointer data
, gpointer user_data
)
1561 GList
**active_plugins
= (GList
**)user_data
;
1562 *active_plugins
= g_list_prepend (*active_plugins
,
1567 anjuta_plugin_manager_get_active_plugins (AnjutaPluginManager
*plugin_manager
)
1569 GList
*active_plugins
= NULL
;
1571 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1572 g_hash_table_foreach (plugin_manager
->priv
->activated_plugins
,
1573 on_activated_plugins_foreach
,
1575 return g_list_reverse (active_plugins
);
1579 anjuta_plugin_manager_get_active_plugin_objects (AnjutaPluginManager
*plugin_manager
)
1581 GList
*active_plugins
= NULL
;
1583 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1584 g_hash_table_foreach (plugin_manager
->priv
->activated_plugins
,
1585 on_activated_plugin_objects_foreach
,
1587 return g_list_reverse (active_plugins
);
1591 anjuta_plugin_manager_unload_plugin_by_id (AnjutaPluginManager
*plugin_manager
,
1592 const gchar
*plugin_id
)
1594 AnjutaPluginManagerPriv
*priv
;
1595 AnjutaPluginHandle
*plugin
;
1597 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), FALSE
);
1598 g_return_val_if_fail (plugin_id
!= NULL
, FALSE
);
1600 priv
= plugin_manager
->priv
;
1602 plugin
= g_hash_table_lookup (priv
->plugins_by_name
, plugin_id
);
1605 plugin_set_update (plugin_manager
, plugin
, FALSE
);
1607 /* Check if the plugin has been indeed unloaded */
1608 if (!g_hash_table_lookup (priv
->activated_plugins
, plugin
))
1613 g_warning ("No plugin found with id \"%s\".", plugin_id
);
1618 find_plugin_for_object (gpointer key
, gpointer value
, gpointer data
)
1622 g_object_set_data (G_OBJECT (data
), "__plugin_plugin", key
);
1629 anjuta_plugin_manager_unload_plugin (AnjutaPluginManager
*plugin_manager
,
1630 GObject
*plugin_object
)
1632 AnjutaPluginManagerPriv
*priv
;
1633 AnjutaPluginHandle
*plugin
;
1635 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), FALSE
);
1636 g_return_val_if_fail (ANJUTA_IS_PLUGIN (plugin_object
), FALSE
);
1638 priv
= plugin_manager
->priv
;
1642 /* Find the plugin that correspond to this plugin object */
1643 g_hash_table_find (priv
->activated_plugins
, find_plugin_for_object
,
1645 plugin
= g_object_get_data (G_OBJECT (plugin_object
), "__plugin_plugin");
1649 plugin_set_update (plugin_manager
, plugin
, FALSE
);
1651 /* Check if the plugin has been indeed unloaded */
1652 if (!g_hash_table_lookup (priv
->activated_plugins
, plugin
))
1657 g_warning ("No plugin found with object \"%p\".", plugin_object
);
1662 anjuta_plugin_manager_list_query (AnjutaPluginManager
*plugin_manager
,
1667 AnjutaPluginManagerPriv
*priv
;
1668 GList
*selected_plugins
= NULL
;
1671 const gchar
*avalue
;
1674 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1676 priv
= plugin_manager
->priv
;
1677 available
= priv
->available_plugins
;
1681 /* If no query is given, select all plugins */
1684 AnjutaPluginHandle
*plugin
= available
->data
;
1685 AnjutaPluginDescription
*desc
=
1686 anjuta_plugin_handle_get_description (plugin
);
1687 selected_plugins
= g_list_prepend (selected_plugins
, desc
);
1688 available
= g_list_next (available
);
1690 return g_list_reverse (selected_plugins
);
1693 g_return_val_if_fail (secs
!= NULL
, NULL
);
1694 g_return_val_if_fail (anames
!= NULL
, NULL
);
1695 g_return_val_if_fail (avalues
!= NULL
, NULL
);
1699 GList
* s_node
= secs
;
1700 GList
* n_node
= anames
;
1701 GList
* v_node
= avalues
;
1703 gboolean satisfied
= FALSE
;
1705 AnjutaPluginHandle
*plugin
= available
->data
;
1706 AnjutaPluginDescription
*desc
=
1707 anjuta_plugin_handle_get_description (plugin
);
1714 gboolean found
= FALSE
;
1719 aname
= n_node
->data
;
1720 avalue
= v_node
->data
;
1722 if (!anjuta_plugin_description_get_string (desc
, sec
, aname
, &val
))
1728 vals
= property_to_list (val
);
1734 if (strchr(node
->data
, '*') != NULL
)
1739 const gchar
*cursor
;
1741 segments
= g_strsplit (node
->data
, "*", -1);
1745 while (*seg_ptr
!= NULL
)
1747 if (strlen (*seg_ptr
) > 0) {
1748 cursor
= strstr (cursor
, *seg_ptr
);
1752 cursor
+= strlen (*seg_ptr
);
1755 if (*seg_ptr
== NULL
)
1757 g_strfreev (segments
);
1759 else if (g_ascii_strcasecmp (node
->data
, avalue
) == 0)
1764 g_free (node
->data
);
1765 node
= g_list_next (node
);
1773 s_node
= g_list_next (s_node
);
1774 n_node
= g_list_next (n_node
);
1775 v_node
= g_list_next (v_node
);
1779 selected_plugins
= g_list_prepend (selected_plugins
, desc
);
1780 /* DEBUG_PRINT ("Satisfied, Adding %s",
1781 anjuta_plugin_handle_get_name (plugin));*/
1783 available
= g_list_next (available
);
1786 return g_list_reverse (selected_plugins
);
1790 anjuta_plugin_manager_query (AnjutaPluginManager
*plugin_manager
,
1791 const gchar
*section_name
,
1792 const gchar
*attribute_name
,
1793 const gchar
*attribute_value
,
1798 GList
*anames
= NULL
;
1799 GList
*avalues
= NULL
;
1802 const gchar
*avalue
;
1803 GList
*selected_plugins
;
1806 if (section_name
== NULL
)
1808 /* If no query is given, select all plugins */
1809 return anjuta_plugin_manager_list_query (plugin_manager
, NULL
, NULL
, NULL
);
1812 g_return_val_if_fail (section_name
!= NULL
, NULL
);
1813 g_return_val_if_fail (attribute_name
!= NULL
, NULL
);
1814 g_return_val_if_fail (attribute_value
!= NULL
, NULL
);
1816 secs
= g_list_prepend (secs
, g_strdup (section_name
));
1817 anames
= g_list_prepend (anames
, g_strdup (attribute_name
));
1818 avalues
= g_list_prepend (avalues
, g_strdup (attribute_value
));
1820 va_start (var_args
, attribute_value
);
1823 sec
= va_arg (var_args
, const gchar
*);
1826 aname
= va_arg (var_args
, const gchar
*);
1829 avalue
= va_arg (var_args
, const gchar
*);
1832 secs
= g_list_prepend (secs
, g_strdup (sec
));
1833 anames
= g_list_prepend (anames
, g_strdup (aname
));
1834 avalues
= g_list_prepend (avalues
, g_strdup (avalue
));
1842 secs
= g_list_reverse (secs
);
1843 anames
= g_list_reverse (anames
);
1844 avalues
= g_list_reverse (avalues
);
1846 selected_plugins
= anjuta_plugin_manager_list_query (plugin_manager
,
1851 anjuta_util_glist_strings_free (secs
);
1852 anjuta_util_glist_strings_free (anames
);
1853 anjuta_util_glist_strings_free (avalues
);
1855 return selected_plugins
;
1861 PLUGIN_DESCRIPTION_COLUMN
,
1866 on_plugin_list_row_activated (GtkTreeView
*tree_view
,
1868 GtkTreeViewColumn
*column
,
1871 gtk_dialog_response (dialog
, GTK_RESPONSE_OK
);
1876 on_plugin_list_show (GtkTreeView
*view
,
1879 GtkTreeSelection
*selection
;
1880 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (view
));
1882 g_signal_emit_by_name (G_OBJECT (selection
), "changed", GTK_DIALOG(dialog
), NULL
);
1887 on_plugin_list_selection_changed (GtkTreeSelection
*tree_selection
,
1890 GtkContainer
*action_area
;
1892 GtkButton
*bt
= NULL
;
1894 action_area
= GTK_CONTAINER (gtk_dialog_get_action_area (dialog
));
1895 list
= gtk_container_get_children (action_area
);
1896 for (; list
; list
= list
->next
) {
1898 if (!strcmp("gtk-ok", gtk_button_get_label (bt
)))
1901 if (bt
&& gtk_tree_selection_get_selected (tree_selection
, NULL
, NULL
))
1902 gtk_widget_set_sensitive ((GtkWidget
*) bt
, TRUE
);
1904 gtk_widget_set_sensitive ((GtkWidget
*) bt
, FALSE
);
1909 * anjuta_plugin_manager_select:
1910 * @plugin_manager: #AnjutaPluginManager object
1911 * @title: Title of the dialog
1912 * @description: label shown on the dialog
1913 * @plugin_descriptions: List of #AnjutaPluginDescription
1915 * Show a dialog where the user can choose between the given plugins
1917 * Returns: The chosen plugin description
1919 AnjutaPluginDescription
*
1920 anjuta_plugin_manager_select (AnjutaPluginManager
*plugin_manager
,
1921 gchar
*title
, gchar
*description
,
1922 GList
*plugin_descriptions
)
1924 AnjutaPluginDescription
*desc
;
1925 AnjutaPluginManagerPriv
*priv
;
1927 GtkTreeModel
*model
;
1929 GtkTreeViewColumn
*column
;
1930 GtkCellRenderer
*renderer
;
1933 GtkWidget
*content_area
;
1935 GtkWidget
*remember_checkbox
;
1937 GtkTreeIter selected
;
1938 GtkTreeSelection
*selection
;
1939 GtkTreeModel
*store
;
1940 GList
*selection_ids
= NULL
;
1941 GString
*remember_key
= g_string_new ("");
1943 g_return_val_if_fail (title
!= NULL
, NULL
);
1944 g_return_val_if_fail (description
!= NULL
, NULL
);
1945 g_return_val_if_fail (plugin_descriptions
!= NULL
, NULL
);
1947 priv
= plugin_manager
->priv
;
1949 if (g_list_length (plugin_descriptions
) <= 0)
1952 dlg
= gtk_dialog_new_with_buttons (title
, GTK_WINDOW (priv
->shell
),
1953 GTK_DIALOG_DESTROY_WITH_PARENT
,
1955 GTK_RESPONSE_CANCEL
,
1956 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
1958 gtk_window_set_default_size (GTK_WINDOW (dlg
), 400, 300);
1960 label
= gtk_label_new (description
);
1961 gtk_label_set_use_markup (GTK_LABEL (label
), TRUE
);
1962 gtk_widget_show (label
);
1963 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (dlg
));
1964 gtk_box_pack_start (GTK_BOX (content_area
), label
,
1967 sc
= gtk_scrolled_window_new (NULL
, NULL
);
1968 gtk_widget_show (sc
);
1969 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sc
),
1971 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sc
),
1972 GTK_POLICY_AUTOMATIC
,
1973 GTK_POLICY_AUTOMATIC
);
1975 gtk_box_pack_start (GTK_BOX (content_area
), sc
,
1978 model
= GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS
, GDK_TYPE_PIXBUF
,
1979 G_TYPE_STRING
, G_TYPE_POINTER
));
1980 view
= gtk_tree_view_new_with_model (model
);
1981 gtk_widget_show (view
);
1982 gtk_container_add (GTK_CONTAINER (sc
), view
);
1984 column
= gtk_tree_view_column_new ();
1985 gtk_tree_view_column_set_sizing (column
,
1986 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
1987 gtk_tree_view_column_set_title (column
, _("Available Plugins"));
1989 renderer
= gtk_cell_renderer_pixbuf_new ();
1990 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
1991 gtk_tree_view_column_add_attribute (column
, renderer
, "pixbuf",
1994 renderer
= gtk_cell_renderer_text_new ();
1995 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
1996 gtk_tree_view_column_add_attribute (column
, renderer
, "markup",
1999 gtk_tree_view_append_column (GTK_TREE_VIEW (view
), column
);
2000 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (view
), column
);
2002 g_signal_connect (view
, "row-activated",
2003 G_CALLBACK (on_plugin_list_row_activated
),
2005 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (view
));
2006 g_signal_connect(selection
, "changed",
2007 G_CALLBACK(on_plugin_list_selection_changed
),
2009 g_signal_connect(view
, "focus",
2010 G_CALLBACK(on_plugin_list_show
),
2014 gtk_check_button_new_with_label (_("Remember this selection"));
2015 gtk_container_set_border_width (GTK_CONTAINER (remember_checkbox
), 10);
2016 gtk_widget_show (remember_checkbox
);
2017 gtk_box_pack_start (GTK_BOX (content_area
), remember_checkbox
,
2020 node
= plugin_descriptions
;
2023 GdkPixbuf
*icon_pixbuf
= NULL
;
2024 gchar
*plugin_name
= NULL
;
2025 gchar
*plugin_desc
= NULL
;
2026 gchar
*icon_filename
= NULL
;
2027 gchar
*location
= NULL
;
2029 desc
= (AnjutaPluginDescription
*)node
->data
;
2031 if (anjuta_plugin_description_get_string (desc
,
2036 gchar
*icon_path
= NULL
;
2037 icon_path
= g_strconcat (PACKAGE_PIXMAPS_DIR
"/",
2038 icon_filename
, NULL
);
2039 g_free (icon_filename
);
2040 /* DEBUG_PRINT ("Icon: %s", icon_path); */
2042 gdk_pixbuf_new_from_file (icon_path
, NULL
);
2043 if (icon_pixbuf
== NULL
)
2045 g_warning ("Plugin pixmap not found: %s", plugin_name
);
2051 g_warning ("Plugin does not define Icon attribute");
2053 if (!anjuta_plugin_description_get_locale_string (desc
,
2058 g_warning ("Plugin does not define Name attribute");
2060 if (!anjuta_plugin_description_get_locale_string (desc
,
2065 g_warning ("Plugin does not define Description attribute");
2067 if (plugin_name
&& plugin_desc
)
2072 if (!anjuta_plugin_description_get_string (desc
,
2077 g_warning ("Plugin does not define Location attribute");
2081 text
= g_markup_printf_escaped ("<span size=\"larger\" weight=\"bold\">%s</span>\n%s", plugin_name
, plugin_desc
);
2083 gtk_list_store_append (GTK_LIST_STORE (model
), &iter
);
2084 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
2085 PLUGIN_COLUMN
, text
,
2086 PLUGIN_DESCRIPTION_COLUMN
, desc
, -1);
2088 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
2089 PIXBUF_COLUMN
, icon_pixbuf
, -1);
2090 g_object_unref (icon_pixbuf
);
2094 selection_ids
= g_list_prepend (selection_ids
, location
);
2096 g_free (plugin_name
);
2097 g_free (plugin_desc
);
2098 node
= g_list_next (node
);
2101 /* Prepare remembering key */
2102 selection_ids
= g_list_sort (selection_ids
,
2103 (GCompareFunc
)strcmp
);
2104 node
= selection_ids
;
2107 g_string_append (remember_key
, (gchar
*)node
->data
);
2108 g_string_append (remember_key
, ",");
2109 node
= g_list_next (node
);
2111 g_list_foreach (selection_ids
, (GFunc
) g_free
, NULL
);
2112 g_list_free (selection_ids
);
2114 /* Find if the selection is remembered */
2115 desc
= g_hash_table_lookup (priv
->remember_plugins
, remember_key
->str
);
2118 g_string_free (remember_key
, TRUE
);
2119 gtk_widget_destroy (dlg
);
2124 response
= gtk_dialog_run (GTK_DIALOG (dlg
));
2127 case GTK_RESPONSE_OK
:
2128 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (view
));
2129 if (gtk_tree_selection_get_selected (selection
, &store
,
2132 gtk_tree_model_get (model
, &selected
,
2133 PLUGIN_DESCRIPTION_COLUMN
, &desc
, -1);
2136 /* Remember selection */
2137 if (gtk_toggle_button_get_active
2138 (GTK_TOGGLE_BUTTON (remember_checkbox
)))
2140 /* DEBUG_PRINT ("Remembering selection '%s'",
2141 remember_key->str);*/
2142 g_hash_table_insert (priv
->remember_plugins
,
2143 g_strdup (remember_key
->str
), desc
);
2145 g_string_free (remember_key
, TRUE
);
2146 gtk_widget_destroy (dlg
);
2152 g_string_free (remember_key
, TRUE
);
2153 gtk_widget_destroy (dlg
);
2158 anjuta_plugin_manager_select_and_activate (AnjutaPluginManager
*plugin_manager
,
2161 GList
*plugin_descriptions
)
2163 AnjutaPluginDescription
*d
;
2165 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
2167 d
= anjuta_plugin_manager_select (plugin_manager
, title
, description
,
2168 plugin_descriptions
);
2171 GObject
*plugin
= NULL
;
2172 gchar
*location
= NULL
;
2174 anjuta_plugin_description_get_string (d
,
2178 g_return_val_if_fail (location
!= NULL
, NULL
);
2180 anjuta_plugin_manager_get_plugin_by_id (plugin_manager
, location
);
2187 /* Plugin manager */
2190 anjuta_plugin_manager_init (AnjutaPluginManager
*object
)
2192 object
->priv
= g_new0 (AnjutaPluginManagerPriv
, 1);
2193 object
->priv
->plugins_by_name
= g_hash_table_new (g_str_hash
, g_str_equal
);
2194 object
->priv
->plugins_by_interfaces
= g_hash_table_new_full (g_str_hash
,
2197 (GDestroyNotify
) g_list_free
);
2198 object
->priv
->plugins_by_description
= g_hash_table_new (g_direct_hash
,
2200 object
->priv
->activated_plugins
= g_hash_table_new (g_direct_hash
,
2202 object
->priv
->plugins_cache
= g_hash_table_new (g_direct_hash
,
2204 object
->priv
->remember_plugins
= g_hash_table_new_full (g_str_hash
,
2210 anjuta_plugin_manager_finalize (GObject
*object
)
2212 AnjutaPluginManagerPriv
*priv
;
2213 priv
= ANJUTA_PLUGIN_MANAGER (object
)->priv
;
2214 if (priv
->available_plugins
)
2216 /* anjuta_plugin_manager_unload_all_plugins (ANJUTA_PLUGIN_MANAGER (object)); */
2217 g_list_foreach (priv
->available_plugins
, (GFunc
)g_object_unref
, NULL
);
2218 g_list_free (priv
->available_plugins
);
2219 priv
->available_plugins
= NULL
;
2221 if (priv
->activated_plugins
)
2223 g_hash_table_destroy (priv
->activated_plugins
);
2224 priv
->activated_plugins
= NULL
;
2226 if (priv
->plugins_cache
)
2228 g_hash_table_destroy (priv
->plugins_cache
);
2229 priv
->plugins_cache
= NULL
;
2231 if (priv
->plugins_by_name
)
2233 g_hash_table_destroy (priv
->plugins_by_name
);
2234 priv
->plugins_by_name
= NULL
;
2236 if (priv
->plugins_by_description
)
2238 g_hash_table_destroy (priv
->plugins_by_description
);
2239 priv
->plugins_by_description
= NULL
;
2241 if (priv
->plugins_by_interfaces
)
2243 g_hash_table_destroy (priv
->plugins_by_interfaces
);
2244 priv
->plugins_by_interfaces
= NULL
;
2246 if (priv
->plugin_dirs
)
2248 g_list_foreach (priv
->plugin_dirs
, (GFunc
)g_free
, NULL
);
2249 g_list_free (priv
->plugin_dirs
);
2250 priv
->plugin_dirs
= NULL
;
2253 if (anjuta_c_plugin_factory
)
2255 g_object_unref (anjuta_c_plugin_factory
);
2256 anjuta_c_plugin_factory
= NULL
;
2259 G_OBJECT_CLASS (parent_class
)->finalize (object
);
2263 anjuta_plugin_manager_set_property (GObject
*object
, guint prop_id
,
2264 const GValue
*value
, GParamSpec
*pspec
)
2266 AnjutaPluginManagerPriv
*priv
;
2268 g_return_if_fail (ANJUTA_IS_PLUGIN_MANAGER (object
));
2269 priv
= ANJUTA_PLUGIN_MANAGER (object
)->priv
;
2274 priv
->status
= g_value_get_object (value
);
2277 priv
->shell
= g_value_get_object (value
);
2280 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
2286 anjuta_plugin_manager_get_property (GObject
*object
, guint prop_id
,
2287 GValue
*value
, GParamSpec
*pspec
)
2289 AnjutaPluginManagerPriv
*priv
;
2291 g_return_if_fail (ANJUTA_IS_PLUGIN_MANAGER (object
));
2292 priv
= ANJUTA_PLUGIN_MANAGER (object
)->priv
;
2297 g_value_set_object (value
, priv
->shell
);
2300 g_value_set_object (value
, priv
->status
);
2302 case PROP_AVAILABLE_PLUGINS
:
2303 g_value_set_pointer (value
, priv
->available_plugins
);
2305 case PROP_ACTIVATED_PLUGINS
:
2306 g_value_set_pointer (value
, priv
->activated_plugins
);
2309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
2314 anjuta_plugin_manager_plugin_activated (AnjutaPluginManager
*self
,
2315 AnjutaPluginDescription
* plugin_desc
,
2318 /* TODO: Add default signal handler implementation here */
2322 anjuta_plugin_manager_plugin_deactivated (AnjutaPluginManager
*self
,
2323 AnjutaPluginDescription
* plugin_desc
,
2326 /* TODO: Add default signal handler implementation here */
2330 anjuta_plugin_manager_class_init (AnjutaPluginManagerClass
*klass
)
2332 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
2333 parent_class
= G_OBJECT_CLASS (g_type_class_peek_parent (klass
));
2335 object_class
->finalize
= anjuta_plugin_manager_finalize
;
2336 object_class
->set_property
= anjuta_plugin_manager_set_property
;
2337 object_class
->get_property
= anjuta_plugin_manager_get_property
;
2339 klass
->plugin_activated
= anjuta_plugin_manager_plugin_activated
;
2340 klass
->plugin_deactivated
= anjuta_plugin_manager_plugin_deactivated
;
2342 g_object_class_install_property (object_class
,
2344 g_param_spec_pointer ("profiles",
2346 _("Current stack of profiles"),
2348 g_object_class_install_property (object_class
,
2349 PROP_AVAILABLE_PLUGINS
,
2350 g_param_spec_pointer ("available-plugins",
2351 _("Available plugins"),
2352 _("Currently available plugins found in plugin paths"),
2355 g_object_class_install_property (object_class
,
2356 PROP_ACTIVATED_PLUGINS
,
2357 g_param_spec_pointer ("activated-plugins",
2358 _("Activated plugins"),
2359 _("Currently activated plugins"),
2361 g_object_class_install_property (object_class
,
2363 g_param_spec_object ("shell",
2365 _("Anjuta shell for which the plugins are made"),
2369 G_PARAM_CONSTRUCT
));
2370 g_object_class_install_property (object_class
,
2372 g_param_spec_object ("status",
2374 _("Anjuta status to use in loading and unloading of plugins"),
2378 G_PARAM_CONSTRUCT
));
2380 plugin_manager_signals
[PLUGIN_ACTIVATED
] =
2381 g_signal_new ("plugin-activated",
2382 G_OBJECT_CLASS_TYPE (klass
),
2384 G_STRUCT_OFFSET (AnjutaPluginManagerClass
,
2387 anjuta_cclosure_marshal_VOID__POINTER_OBJECT
,
2389 G_TYPE_POINTER
, ANJUTA_TYPE_PLUGIN
);
2391 plugin_manager_signals
[PLUGIN_DEACTIVATED
] =
2392 g_signal_new ("plugin-deactivated",
2393 G_OBJECT_CLASS_TYPE (klass
),
2395 G_STRUCT_OFFSET (AnjutaPluginManagerClass
,
2396 plugin_deactivated
),
2398 anjuta_cclosure_marshal_VOID__POINTER_OBJECT
,
2400 G_TYPE_POINTER
, ANJUTA_TYPE_PLUGIN
);
2404 anjuta_plugin_manager_get_type (void)
2406 static GType our_type
= 0;
2410 static const GTypeInfo our_info
=
2412 sizeof (AnjutaPluginManagerClass
), /* class_size */
2413 (GBaseInitFunc
) NULL
, /* base_init */
2414 (GBaseFinalizeFunc
) NULL
, /* base_finalize */
2415 (GClassInitFunc
) anjuta_plugin_manager_class_init
, /* class_init */
2416 (GClassFinalizeFunc
) NULL
, /* class_finalize */
2417 NULL
/* class_data */,
2418 sizeof (AnjutaPluginManager
), /* instance_size */
2419 0, /* n_preallocs */
2420 (GInstanceInitFunc
) anjuta_plugin_manager_init
, /* instance_init */
2421 NULL
/* value_table */
2423 our_type
= g_type_register_static (G_TYPE_OBJECT
,
2424 "AnjutaPluginManager",
2431 AnjutaPluginManager
*
2432 anjuta_plugin_manager_new (GObject
*shell
, AnjutaStatus
*status
,
2433 GList
* plugins_directories
)
2435 GObject
*manager_object
;
2436 AnjutaPluginManager
*plugin_manager
;
2437 GList
*cycles
= NULL
;
2438 const char *gnome2_path
;
2442 GList
*plugin_dirs
= NULL
;
2444 /* Initialize the anjuta plugin system */
2445 manager_object
= g_object_new (ANJUTA_TYPE_PLUGIN_MANAGER
,
2446 "shell", shell
, "status", status
, NULL
);
2447 plugin_manager
= ANJUTA_PLUGIN_MANAGER (manager_object
);
2449 if (anjuta_plugin_factory
== NULL
)
2451 anjuta_plugin_factory
= anjuta_c_plugin_factory_new ();
2454 gnome2_path
= g_getenv ("GNOME2_PATH");
2456 pathv
= g_strsplit (gnome2_path
, ":", 1);
2458 for (p
= pathv
; *p
!= NULL
; p
++) {
2459 char *path
= g_strdup (*p
);
2460 plugin_dirs
= g_list_prepend (plugin_dirs
, path
);
2465 node
= plugins_directories
;
2469 char *path
= g_strdup (node
->data
);
2470 plugin_dirs
= g_list_prepend (plugin_dirs
, path
);
2471 node
= g_list_next (node
);
2473 plugin_dirs
= g_list_reverse (plugin_dirs
);
2474 /* load_plugins (); */
2479 load_plugins_from_directory (plugin_manager
, (char*)node
->data
);
2480 node
= g_list_next (node
);
2482 resolve_dependencies (plugin_manager
, &cycles
);
2483 g_list_foreach(plugin_dirs
, (GFunc
) g_free
, NULL
);
2484 g_list_free(plugin_dirs
);
2485 return plugin_manager
;
2489 anjuta_plugin_manager_activate_plugins (AnjutaPluginManager
*plugin_manager
,
2490 GList
*plugins_to_activate
)
2492 AnjutaPluginManagerPriv
*priv
;
2493 GdkPixbuf
*icon_pixbuf
;
2496 priv
= plugin_manager
->priv
;
2498 /* Freeze shell operations */
2499 anjuta_shell_freeze (ANJUTA_SHELL (priv
->shell
), NULL
);
2500 if (plugins_to_activate
)
2502 anjuta_status_progress_add_ticks (ANJUTA_STATUS (priv
->status
),
2503 g_list_length (plugins_to_activate
));
2505 node
= plugins_to_activate
;
2508 AnjutaPluginDescription
*d
;
2510 gchar
*icon_filename
, *label
;
2511 gchar
*icon_path
= NULL
;
2517 if (anjuta_plugin_description_get_string (d
, "Anjuta Plugin",
2521 gchar
*title
/*, *description */;
2522 anjuta_plugin_description_get_locale_string (d
, "Anjuta Plugin",
2526 anjuta_plugin_description_get_locale_string (d, "Anjuta Plugin",
2530 icon_path
= g_strconcat (PACKAGE_PIXMAPS_DIR
"/",
2531 icon_filename
, NULL
);
2532 /* DEBUG_PRINT ("Icon: %s", icon_path); */
2533 /* Avoid space in translated string */
2534 label
= g_strconcat (_("Loaded:"), " ", title
, "...", NULL
);
2535 icon_pixbuf
= gdk_pixbuf_new_from_file (icon_path
, NULL
);
2537 g_warning ("Plugin does not define Icon: No such file %s",
2540 g_free (icon_filename
);
2544 if (anjuta_plugin_description_get_string (d
, "Anjuta Plugin",
2545 "Location", &plugin_id
))
2547 GObject
*plugin_obj
;
2550 anjuta_plugin_manager_get_plugin_by_id (plugin_manager
,
2554 anjuta_status_progress_tick (ANJUTA_STATUS (priv
->status
),
2555 icon_pixbuf
, label
);
2558 g_object_unref (icon_pixbuf
);
2560 node
= g_list_next (node
);
2563 /* Thaw shell operations */
2564 anjuta_shell_thaw (ANJUTA_SHELL (priv
->shell
), NULL
);
2568 on_collect (gpointer key
, gpointer value
, gpointer user_data
)
2571 gchar
*query
= (gchar
*) key
;
2572 AnjutaPluginDescription
*desc
= (AnjutaPluginDescription
*) value
;
2573 GString
*write_buffer
= (GString
*) user_data
;
2575 anjuta_plugin_description_get_string (desc
, "Anjuta Plugin", "Location",
2577 g_string_append_printf (write_buffer
, "%s=%s;", query
, id
);
2582 * anjuta_plugin_manager_get_remembered_plugins:
2583 * @plugin_manager: A #AnjutaPluginManager object
2585 * Get the list of plugins loaded when there is a choice between several
2586 * ones without asking the user.
2588 * The list format is returned as a string with the format detailed in
2589 * anjuta_plugin_manager_set_remembered_plugins().
2591 * Return value: a newly-allocated string that must be freed with g_free().
2595 anjuta_plugin_manager_get_remembered_plugins (AnjutaPluginManager
*plugin_manager
)
2597 AnjutaPluginManagerPriv
*priv
;
2598 GString
*write_buffer
= g_string_new ("");
2600 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), FALSE
);
2602 priv
= plugin_manager
->priv
;
2603 g_hash_table_foreach (priv
->remember_plugins
, on_collect
,
2605 return g_string_free (write_buffer
, FALSE
);
2609 on_foreach_remove_true (gpointer k
, gpointer v
, gpointer d
)
2615 * anjuta_plugin_manager_set_remembered_plugins:
2616 * @plugin_manager: A #AnjutaPluginManager object
2617 * @remembered_plugins: A list of prefered plugins
2619 * Set the list of plugins loaded when there is a choice between several
2620 * ones without asking the user.
2621 * The list is a string composed of elements separated by ';'. Each element
2622 * is defined with "key=value", where key is the list of possible plugins and
2623 * the value is the choosen plugin.
2625 * By the example the following element
2627 * anjuta-symbol-browser:SymbolBrowserPlugin,anjuta-symbol-db:SymbolDBPlugin,=anjuta-symbol-db:SymbolDBPlugin;
2629 * means if Anjuta has to choose between SymbolBrowserPlugin and
2630 * SymbolDBPlugin, it will choose SymbolDBPlugin.
2633 anjuta_plugin_manager_set_remembered_plugins (AnjutaPluginManager
*plugin_manager
,
2634 const gchar
*remembered_plugins
)
2636 AnjutaPluginManagerPriv
*priv
;
2637 gchar
**strv_lines
, **line_idx
;
2639 g_return_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
));
2640 g_return_if_fail (remembered_plugins
!= NULL
);
2642 priv
= plugin_manager
->priv
;
2644 g_hash_table_foreach_remove (priv
->remember_plugins
,
2645 on_foreach_remove_true
, NULL
);
2647 strv_lines
= g_strsplit (remembered_plugins
, ";", -1);
2648 line_idx
= strv_lines
;
2651 gchar
**strv_keyvals
;
2652 strv_keyvals
= g_strsplit (*line_idx
, "=", -1);
2653 if (strv_keyvals
&& strv_keyvals
[0] && strv_keyvals
[1])
2655 AnjutaPluginHandle
*plugin
;
2656 plugin
= g_hash_table_lookup (priv
->plugins_by_name
,
2660 AnjutaPluginDescription
*desc
;
2661 desc
= anjuta_plugin_handle_get_description (plugin
);
2663 DEBUG_PRINT ("Restoring remember plugin: %s=%s",
2667 g_hash_table_insert (priv
->remember_plugins
,
2668 g_strdup (strv_keyvals
[0]), desc
);
2670 g_strfreev (strv_keyvals
);
2674 g_strfreev (strv_lines
);