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
34 #include <sys/types.h>
38 #include <libanjuta/anjuta-plugin-manager.h>
39 #include <libanjuta/anjuta-marshal.h>
40 #include <libanjuta/anjuta-debug.h>
41 #include <libanjuta/anjuta-plugin-handle.h>
42 #include <libanjuta/anjuta-plugin.h>
43 #include <libanjuta/anjuta-c-plugin-factory.h>
44 #include <libanjuta/interfaces/ianjuta-plugin-factory.h>
45 #include <libanjuta/interfaces/ianjuta-preferences.h>
55 PROP_AVAILABLE_PLUGINS
,
56 PROP_ACTIVATED_PLUGINS
71 struct _AnjutaPluginManagerPriv
76 GList
*available_plugins
;
78 /* Indexes => plugin handles */
79 GHashTable
*plugins_by_interfaces
;
80 GHashTable
*plugins_by_name
;
81 GHashTable
*plugins_by_description
;
83 /* Plugins that are currently activated */
84 GHashTable
*activated_plugins
;
86 /* Plugins that have been previously loaded but current deactivated */
87 GHashTable
*plugins_cache
;
89 /* Remember plugin selection */
90 GHashTable
*remember_plugins
;
93 GHashTable
*disable_plugins
;
96 /* Available plugins page treeview */
106 /* Remembered plugins page treeview */
114 /* Plugin class types */
116 static AnjutaCPluginFactory
*anjuta_plugin_factory
= NULL
;
118 static GObjectClass
* parent_class
= NULL
;
119 static guint plugin_manager_signals
[LAST_SIGNAL
] = { 0 };
121 static void plugin_set_update (AnjutaPluginManager
*plugin_manager
,
122 AnjutaPluginHandle
* selected_plugin
,
125 static IAnjutaPluginFactory
* get_plugin_factory (AnjutaPluginManager
*plugin_manager
,
126 const gchar
*language
, GError
**error
);
129 anjuta_plugin_manager_error_quark (void)
131 static GQuark quark
= 0;
134 quark
= g_quark_from_static_string ("anjuta-plugin-manager-quark");
139 /* Dependency Resolution */
142 collect_cycle (AnjutaPluginManager
*plugin_manager
,
143 AnjutaPluginHandle
*base_plugin
, AnjutaPluginHandle
*cur_plugin
,
146 AnjutaPluginManagerPriv
*priv
;
149 priv
= plugin_manager
->priv
;
151 for (l
= anjuta_plugin_handle_get_dependency_names (cur_plugin
);
152 l
!= NULL
; l
= l
->next
)
154 AnjutaPluginHandle
*dep
= g_hash_table_lookup (priv
->plugins_by_name
,
158 if (dep
== base_plugin
)
160 *cycle
= g_list_prepend (NULL
, dep
);
161 /* DEBUG_PRINT ("%s", anjuta_plugin_handle_get_name (dep)); */
166 if (collect_cycle (plugin_manager
, base_plugin
, dep
, cycle
))
168 *cycle
= g_list_prepend (*cycle
, dep
);
169 /* DEBUG_PRINT ("%s", anjuta_plugin_handle_get_name (dep)); */
179 add_dependency (AnjutaPluginHandle
*dependent
, AnjutaPluginHandle
*dependency
)
181 g_hash_table_insert (anjuta_plugin_handle_get_dependents (dependency
),
182 dependent
, dependency
);
183 g_hash_table_insert (anjuta_plugin_handle_get_dependencies (dependent
),
184 dependency
, dependent
);
188 child_dep_foreach_cb (gpointer key
, gpointer value
, gpointer user_data
)
190 add_dependency (ANJUTA_PLUGIN_HANDLE (user_data
),
191 ANJUTA_PLUGIN_HANDLE (key
));
194 /* Resolves dependencies for a single module recursively. Shortcuts if
195 * the module has already been resolved. Returns a list representing
196 * any cycles found, or NULL if no cycles are found. If a cycle is found,
197 * the graph is left unresolved.
200 resolve_for_module (AnjutaPluginManager
*plugin_manager
,
201 AnjutaPluginHandle
*plugin
, int pass
)
203 AnjutaPluginManagerPriv
*priv
;
207 priv
= plugin_manager
->priv
;
209 if (anjuta_plugin_handle_get_checked (plugin
))
214 if (anjuta_plugin_handle_get_resolve_pass (plugin
) == pass
)
217 g_warning ("cycle found: %s on pass %d",
218 anjuta_plugin_handle_get_name (plugin
),
219 anjuta_plugin_handle_get_resolve_pass (plugin
));
220 collect_cycle (plugin_manager
, plugin
, plugin
, &cycle
);
224 if (anjuta_plugin_handle_get_resolve_pass (plugin
) != -1)
229 anjuta_plugin_handle_set_can_load (plugin
, TRUE
);
230 anjuta_plugin_handle_set_resolve_pass (plugin
, pass
);
232 for (l
= anjuta_plugin_handle_get_dependency_names (plugin
);
233 l
!= NULL
; l
= l
->next
)
236 AnjutaPluginHandle
*child
=
237 g_hash_table_lookup (priv
->plugins_by_name
, dep
);
240 ret
= resolve_for_module (plugin_manager
, child
, pass
);
246 /* Add the dependency's dense dependency list
247 * to the current module's dense dependency list */
248 g_hash_table_foreach (anjuta_plugin_handle_get_dependencies (child
),
249 child_dep_foreach_cb
, plugin
);
250 add_dependency (plugin
, child
);
252 /* If the child can't load due to dependency problems,
253 * the current module can't either */
254 anjuta_plugin_handle_set_can_load (plugin
,
255 anjuta_plugin_handle_get_can_load (child
));
257 g_warning ("Dependency %s not found.\n", dep
);
258 anjuta_plugin_handle_set_can_load (plugin
, FALSE
);
262 anjuta_plugin_handle_set_checked (plugin
, TRUE
);
267 /* Clean up the results of a resolving run */
269 unresolve_dependencies (AnjutaPluginManager
*plugin_manager
)
271 AnjutaPluginManagerPriv
*priv
;
274 priv
= plugin_manager
->priv
;
276 for (l
= priv
->available_plugins
; l
!= NULL
; l
= l
->next
)
278 AnjutaPluginHandle
*plugin
= l
->data
;
279 anjuta_plugin_handle_unresolve_dependencies (plugin
);
286 prune_modules (AnjutaPluginManager
*plugin_manager
, GList
*modules
)
288 AnjutaPluginManagerPriv
*priv
;
291 priv
= plugin_manager
->priv
;
293 for (l
= modules
; l
!= NULL
; l
= l
->next
) {
294 AnjutaPluginHandle
*plugin
= l
->data
;
296 g_hash_table_remove (priv
->plugins_by_name
,
297 anjuta_plugin_handle_get_id (plugin
));
298 priv
->available_plugins
= g_list_remove (priv
->available_plugins
, plugin
);
303 dependency_compare (AnjutaPluginHandle
*plugin_a
,
304 AnjutaPluginHandle
*plugin_b
)
306 int a
= g_hash_table_size (anjuta_plugin_handle_get_dependencies (plugin_a
));
307 int b
= g_hash_table_size (anjuta_plugin_handle_get_dependencies (plugin_b
));
312 /* Resolves the dependencies of the priv->available_plugins list. When this
313 * function is complete, the following will be true:
315 * 1) The dependencies and dependents hash tables of the modules will
318 * 2) Cycles in the graph will be removed.
320 * 3) Modules which cannot be loaded due to failed dependencies will
323 * 4) priv->available_plugins will be sorted such that no module depends on a
326 * If a cycle in the graph is found, it is pruned from the tree and
327 * returned as a list stored in the cycles list.
330 resolve_dependencies (AnjutaPluginManager
*plugin_manager
, GList
**cycles
)
332 AnjutaPluginManagerPriv
*priv
;
336 priv
= plugin_manager
->priv
;
339 /* Try resolving dependencies. If there is a cycle, prune the
340 * cycle and try to resolve again */
345 for (l
= priv
->available_plugins
; l
!= NULL
&& !cycle
; l
= l
->next
) {
346 cycle
= resolve_for_module (plugin_manager
, l
->data
, pass
++);
350 *cycles
= g_list_prepend (*cycles
, cycle
);
351 prune_modules (plugin_manager
, cycle
);
352 unresolve_dependencies (plugin_manager
);
356 /* Now that there is a fully resolved dependency tree, sort
357 * priv->available_plugins to create a valid load order */
358 priv
->available_plugins
= g_list_sort (priv
->available_plugins
,
359 (GCompareFunc
)dependency_compare
);
362 /* Plugins loading */
365 str_has_suffix (const char *haystack
, const char *needle
)
369 if (needle
== NULL
) {
372 if (haystack
== NULL
) {
373 return needle
[0] == '\0';
376 /* Eat one character at a time. */
377 h
= haystack
+ strlen(haystack
);
378 n
= needle
+ strlen(needle
);
386 } while (*--h
== *--n
);
391 load_plugin (AnjutaPluginManager
*plugin_manager
,
392 const gchar
*plugin_desc_path
)
394 AnjutaPluginManagerPriv
*priv
;
395 AnjutaPluginHandle
*plugin_handle
;
397 g_return_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
));
398 priv
= plugin_manager
->priv
;
400 plugin_handle
= anjuta_plugin_handle_new (plugin_desc_path
);
403 if (g_hash_table_lookup (priv
->plugins_by_name
,
404 anjuta_plugin_handle_get_id (plugin_handle
)))
406 g_object_unref (plugin_handle
);
411 /* Available plugin */
412 priv
->available_plugins
= g_list_prepend (priv
->available_plugins
,
415 g_hash_table_insert (priv
->plugins_by_name
,
416 (gchar
*)anjuta_plugin_handle_get_id (plugin_handle
),
419 /* Index by description */
420 g_hash_table_insert (priv
->plugins_by_description
,
421 anjuta_plugin_handle_get_description (plugin_handle
),
424 /* Index by interfaces exported by this plugin */
425 node
= anjuta_plugin_handle_get_interfaces (plugin_handle
);
434 objs
= (GList
*)g_hash_table_lookup (priv
->plugins_by_interfaces
, iface
);
440 if (obj_node
->data
== plugin_handle
)
445 obj_node
= g_list_next (obj_node
);
449 g_hash_table_steal (priv
->plugins_by_interfaces
, iface
);
450 objs
= g_list_prepend (objs
, plugin_handle
);
451 g_hash_table_insert (priv
->plugins_by_interfaces
, iface
, objs
);
453 node
= g_list_next (node
);
461 load_plugins_from_directory (AnjutaPluginManager
* plugin_manager
,
462 const gchar
*dirname
)
465 struct dirent
*entry
;
467 dir
= opendir (dirname
);
474 for (entry
= readdir (dir
); entry
!= NULL
; entry
= readdir (dir
))
476 if (str_has_suffix (entry
->d_name
, ".plugin"))
479 pathname
= g_strdup_printf ("%s/%s", dirname
, entry
->d_name
);
480 load_plugin (plugin_manager
,pathname
);
487 /* Plugin activation and deactivation */
490 on_plugin_activated (AnjutaPlugin
*plugin_object
, AnjutaPluginHandle
*plugin
)
492 AnjutaPluginManager
*plugin_manager
;
493 AnjutaPluginManagerPriv
*priv
;
495 /* FIXME: Pass plugin_manager directly in signal arguments */
496 plugin_manager
= anjuta_shell_get_plugin_manager (plugin_object
->shell
, NULL
);
498 g_return_if_fail(plugin_manager
!= NULL
);
500 priv
= plugin_manager
->priv
;
502 g_hash_table_insert (priv
->activated_plugins
, plugin
,
503 g_object_ref (plugin_object
));
504 g_hash_table_remove (priv
->plugins_cache
, plugin
);
506 g_signal_emit_by_name (plugin_manager
, "plugin-activated",
512 on_plugin_deactivated (AnjutaPlugin
*plugin_object
, AnjutaPluginHandle
*plugin
)
514 AnjutaPluginManager
*plugin_manager
;
515 AnjutaPluginManagerPriv
*priv
;
517 /* FIXME: Pass plugin_manager directly in signal arguments */
518 plugin_manager
= anjuta_shell_get_plugin_manager (plugin_object
->shell
, NULL
);
520 g_return_if_fail (plugin_manager
!= NULL
);
522 priv
= plugin_manager
->priv
;
524 g_hash_table_insert (priv
->plugins_cache
, plugin
, g_object_ref (plugin_object
));
525 g_hash_table_remove (priv
->activated_plugins
, plugin
);
527 g_signal_emit_by_name (plugin_manager
, "plugin-deactivated",
533 activate_plugin (AnjutaPluginManager
*plugin_manager
,
534 AnjutaPluginHandle
*handle
, GError
**error
)
536 AnjutaPluginManagerPriv
*priv
;
537 IAnjutaPluginFactory
* factory
;
538 AnjutaPlugin
*plugin
;
539 const gchar
*language
;
541 priv
= plugin_manager
->priv
;
543 language
= anjuta_plugin_handle_get_language (handle
);
545 factory
= get_plugin_factory (plugin_manager
, language
, error
);
546 if (factory
== NULL
) return NULL
;
548 plugin
= ianjuta_plugin_factory_new_plugin (factory
, handle
, ANJUTA_SHELL (priv
->shell
), error
);
554 g_signal_connect (plugin
, "activated",
555 G_CALLBACK (on_plugin_activated
), handle
);
556 g_signal_connect (plugin
, "deactivated",
557 G_CALLBACK (on_plugin_deactivated
), handle
);
563 * anjuta_plugin_manager_unload_all_plugins:
564 * @plugin_manager: A #AnjutaPluginManager object
566 * Unload all plugins. Do not take care of the dependencies because all plugins
567 * are unloaded anyway.
570 anjuta_plugin_manager_unload_all_plugins (AnjutaPluginManager
*plugin_manager
)
572 AnjutaPluginManagerPriv
*priv
;
574 priv
= plugin_manager
->priv
;
575 if (g_hash_table_size (priv
->activated_plugins
) > 0 ||
576 g_hash_table_size (priv
->plugins_cache
) > 0)
578 if (g_hash_table_size (priv
->activated_plugins
) > 0)
581 for (node
= g_list_last (priv
->available_plugins
); node
; node
= g_list_previous (node
))
583 AnjutaPluginHandle
*selected_plugin
= node
->data
;
584 AnjutaPlugin
*plugin
;
586 plugin
= g_hash_table_lookup (priv
->activated_plugins
, selected_plugin
);
589 DEBUG_PRINT ("Deactivating plugin: %s",
590 anjuta_plugin_handle_get_id (selected_plugin
));
591 anjuta_plugin_deactivate (plugin
);
594 g_hash_table_remove_all (priv
->activated_plugins
);
596 if (g_hash_table_size (priv
->plugins_cache
) > 0)
600 for (node
= g_list_last (priv
->available_plugins
); node
; node
= g_list_previous (node
))
602 AnjutaPluginHandle
*selected_plugin
= node
->data
;
604 g_hash_table_remove (priv
->plugins_cache
, selected_plugin
);
606 g_hash_table_remove_all (priv
->plugins_cache
);
611 /* Return true if plugin should be unloaded when plugin_to_unloaded is unloaded.
612 * It can be because plugin is or need plugin_to_unload. */
614 should_unload (GHashTable
*activated_plugins
, AnjutaPluginHandle
*plugin_to_unload
,
615 AnjutaPluginHandle
*plugin
)
617 GObject
*plugin_obj
= g_hash_table_lookup (activated_plugins
, plugin
);
622 if (plugin_to_unload
== plugin
)
626 GPOINTER_TO_INT (g_hash_table_lookup (anjuta_plugin_handle_get_dependents (plugin_to_unload
),
631 /* Return true if plugin should be loaded when plugin_to_loaded is loaded.
632 * It can be because plugin_to_load is or need plugin. */
634 should_load (GHashTable
*activated_plugins
, AnjutaPluginHandle
*plugin_to_load
,
635 AnjutaPluginHandle
*plugin
)
637 GObject
*plugin_obj
= g_hash_table_lookup (activated_plugins
, plugin
);
642 if (plugin_to_load
== plugin
)
643 return anjuta_plugin_handle_get_can_load (plugin
);
645 gboolean dependency
=
646 GPOINTER_TO_INT (g_hash_table_lookup (anjuta_plugin_handle_get_dependencies (plugin_to_load
),
648 return (dependency
&& anjuta_plugin_handle_get_can_load (plugin
));
651 static AnjutaPluginHandle
*
652 plugin_for_iter (GtkListStore
*store
, GtkTreeIter
*iter
)
654 AnjutaPluginHandle
*plugin
;
656 gtk_tree_model_get (GTK_TREE_MODEL (store
), iter
, COL_PLUGIN
, &plugin
, -1);
661 update_enabled (GtkTreeModel
*model
, GHashTable
*activated_plugins
)
665 if (gtk_tree_model_get_iter_first (model
, &iter
)) {
667 AnjutaPluginHandle
*plugin
;
671 plugin
= plugin_for_iter(GTK_LIST_STORE(model
), &iter
);
672 plugin_obj
= g_hash_table_lookup (activated_plugins
, plugin
);
673 installed
= (plugin_obj
!= NULL
) ? TRUE
: FALSE
;
674 gtk_tree_model_get (model
, &iter
, COL_PLUGIN
, &plugin
, -1);
675 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
676 COL_ENABLED
, installed
, -1);
677 } while (gtk_tree_model_iter_next (model
, &iter
));
682 plugin_set_update (AnjutaPluginManager
*plugin_manager
,
683 AnjutaPluginHandle
* selected_plugin
,
686 AnjutaPluginManagerPriv
*priv
;
690 priv
= plugin_manager
->priv
;
692 /* Plugins can be loaded or unloaded implicitely because they need or are
693 * needed by another plugin so it is possible that we try to load or unload
694 * respectively an already loaded or already unloaded plugin. */
695 loaded
= g_hash_table_lookup (priv
->activated_plugins
, selected_plugin
) != NULL
;
696 if ((load
&& loaded
) || (!load
&& !loaded
)) return;
699 anjuta_status_busy_push (priv
->status
);
703 /* visit priv->available_plugins in reverse order when unloading, so
704 * that plugins are unloaded in the right order */
705 for (l
= g_list_last(priv
->available_plugins
); l
!= NULL
; l
= l
->prev
)
707 AnjutaPluginHandle
*plugin
= l
->data
;
708 if (should_unload (priv
->activated_plugins
, selected_plugin
, plugin
))
710 AnjutaPlugin
*plugin_obj
= ANJUTA_PLUGIN (g_hash_table_lookup (priv
->activated_plugins
, plugin
));
711 if (!anjuta_plugin_deactivate (plugin_obj
))
713 anjuta_util_dialog_info (GTK_WINDOW (priv
->shell
),
714 dgettext (GETTEXT_PACKAGE
, "Plugin '%s' does not want to be deactivated"),
715 anjuta_plugin_handle_get_name (plugin
));
722 for (l
= priv
->available_plugins
; l
!= NULL
; l
= l
->next
)
724 AnjutaPluginHandle
*plugin
= l
->data
;
725 if (should_load (priv
->activated_plugins
, selected_plugin
, plugin
))
727 AnjutaPlugin
*plugin_obj
;
728 GError
*error
= NULL
;
729 plugin_obj
= g_hash_table_lookup (priv
->plugins_cache
, plugin
);
731 g_object_ref (plugin_obj
);
734 plugin_obj
= activate_plugin (plugin_manager
, plugin
,
740 anjuta_plugin_activate (ANJUTA_PLUGIN (plugin_obj
));
741 g_object_unref (plugin_obj
);
747 gchar
* message
= g_strdup_printf (dgettext (GETTEXT_PACKAGE
, "Could not load %s\n"
748 "This usually means that your installation is corrupted. The "
749 "error message leading to this was:\n%s"),
750 anjuta_plugin_handle_get_name (selected_plugin
),
752 anjuta_util_dialog_error (GTK_WINDOW(plugin_manager
->priv
->shell
),
754 g_error_free (error
);
762 anjuta_status_busy_pop (priv
->status
);
768 plugin_toggled (GtkCellRendererToggle
*cell
, char *path_str
, gpointer data
)
770 AnjutaPluginManager
*plugin_manager
;
771 AnjutaPluginManagerPriv
*priv
;
772 GtkListStore
*store
= GTK_LIST_STORE (data
);
775 AnjutaPluginHandle
*plugin
;
777 GList
*activated_plugins
;
779 AnjutaPlugin
* plugin_object
;
781 path
= gtk_tree_path_new_from_string (path_str
);
783 plugin_manager
= g_object_get_data (G_OBJECT (store
), "plugin-manager");
784 priv
= plugin_manager
->priv
;
786 gtk_tree_model_get_iter (GTK_TREE_MODEL (store
), &iter
, path
);
787 gtk_tree_model_get (GTK_TREE_MODEL (store
), &iter
,
788 COL_ENABLED
, &enabled
,
792 /* Activate one plugin can force the loading of other ones, instead of
793 * searching which plugins have to be activated, we just unmerge all
794 * current plugins and merge all plugins after the modification */
796 /* unmerge all plugins */
797 activated_plugins
= g_hash_table_get_values (priv
->activated_plugins
);
798 for (node
= g_list_first (activated_plugins
); node
!= NULL
; node
= g_list_next (node
))
800 plugin_object
= (AnjutaPlugin
*)node
->data
;
802 IANJUTA_IS_PREFERENCES(plugin_object
))
804 ianjuta_preferences_unmerge (IANJUTA_PREFERENCES (plugin_object
),
805 anjuta_shell_get_preferences (ANJUTA_SHELL (priv
->shell
), NULL
),
809 g_list_free (activated_plugins
);
811 plugin_set_update (plugin_manager
, plugin
, !enabled
);
813 /* Make sure that it appears in the preferences. This method
814 can only be called when the preferences dialog is active so
817 activated_plugins
= g_hash_table_get_values (priv
->activated_plugins
);
818 for (node
= g_list_first (activated_plugins
); node
!= NULL
; node
= g_list_next (node
))
820 plugin_object
= (AnjutaPlugin
*)node
->data
;
822 IANJUTA_IS_PREFERENCES(plugin_object
))
824 ianjuta_preferences_merge (IANJUTA_PREFERENCES (plugin_object
),
825 anjuta_shell_get_preferences (ANJUTA_SHELL (priv
->shell
), NULL
),
829 g_list_free (activated_plugins
);
831 update_enabled (GTK_TREE_MODEL (store
), priv
->activated_plugins
);
832 gtk_tree_path_free (path
);
837 selection_changed (GtkTreeSelection
*selection
, GtkListStore
*store
)
841 if (gtk_tree_selection_get_selected (selection
, NULL
,
843 GtkTextBuffer
*buffer
;
845 GtkWidget
*txt
= g_object_get_data (G_OBJECT (store
),
848 GtkWidget
*image
= g_object_get_data (G_OBJECT (store
),
850 AnjutaPluginHandle
*plugin
= plugin_for_iter (store
, &iter
);
852 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (txt
));
853 gtk_text_buffer_set_text (buffer
, plugin
->about
, -1);
855 if (plugin
->icon_path
) {
856 gtk_image_set_from_file (GTK_IMAGE (image
),
858 gtk_widget_show (GTK_WIDGET (image
));
860 gtk_widget_hide (GTK_WIDGET (image
));
867 create_plugin_tree (void)
871 GtkCellRenderer
*renderer
;
872 GtkTreeViewColumn
*column
;
874 store
= gtk_list_store_new (N_COLS
,
880 tree
= gtk_tree_view_new_with_model (GTK_TREE_MODEL (store
));
882 renderer
= gtk_cell_renderer_toggle_new ();
883 g_signal_connect (G_OBJECT (renderer
), "toggled",
884 G_CALLBACK (plugin_toggled
), store
);
885 column
= gtk_tree_view_column_new_with_attributes (dgettext (GETTEXT_PACKAGE
, "Load"),
892 gtk_tree_view_append_column (GTK_TREE_VIEW (tree
), column
);
893 gtk_tree_view_column_set_sizing (column
,
894 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
896 column
= gtk_tree_view_column_new ();
897 renderer
= gtk_cell_renderer_pixbuf_new ();
898 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
899 gtk_tree_view_column_add_attribute (column
, renderer
, "pixbuf",
901 renderer
= gtk_cell_renderer_text_new ();
902 g_object_set(renderer
, "ellipsize", PANGO_ELLIPSIZE_END
, NULL
);
903 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
904 gtk_tree_view_column_add_attribute (column
, renderer
, "markup",
906 gtk_tree_view_column_set_sizing (column
,
907 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
908 gtk_tree_view_column_set_title (column
, dgettext (GETTEXT_PACKAGE
, "Available Plugins"));
909 gtk_tree_view_append_column (GTK_TREE_VIEW (tree
), column
);
910 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (tree
), column
);
912 g_object_unref (store
);
916 /* Sort function for plugins */
918 sort_plugins(gconstpointer a
, gconstpointer b
)
920 g_return_val_if_fail (a
!= NULL
, 0);
921 g_return_val_if_fail (b
!= NULL
, 0);
923 AnjutaPluginHandle
* plugin_a
= ANJUTA_PLUGIN_HANDLE (a
);
924 AnjutaPluginHandle
* plugin_b
= ANJUTA_PLUGIN_HANDLE (b
);
926 return strcmp (anjuta_plugin_handle_get_name (plugin_a
),
927 anjuta_plugin_handle_get_name (plugin_b
));
930 /* If show_all == FALSE, show only user activatable plugins
931 * If show_all == TRUE, show all plugins
934 populate_plugin_model (AnjutaPluginManager
*plugin_manager
,
936 GHashTable
*plugins_to_show
,
937 GHashTable
*activated_plugins
,
940 AnjutaPluginManagerPriv
*priv
;
941 GList
*sorted_plugins
, *l
;
943 priv
= plugin_manager
->priv
;
944 gtk_list_store_clear (store
);
946 sorted_plugins
= g_list_copy (priv
->available_plugins
);
947 sorted_plugins
= g_list_sort (sorted_plugins
, sort_plugins
);
949 for (l
= sorted_plugins
; l
!= NULL
; l
= l
->next
)
951 AnjutaPluginHandle
*plugin
= l
->data
;
953 /* If plugins to show is NULL, show all available plugins */
954 if (plugins_to_show
== NULL
||
955 g_hash_table_lookup (plugins_to_show
, plugin
))
958 gboolean enable
= FALSE
;
959 if (g_hash_table_lookup (activated_plugins
, plugin
))
962 if (anjuta_plugin_handle_get_name (plugin
) &&
963 anjuta_plugin_handle_get_description (plugin
) &&
964 (anjuta_plugin_handle_get_user_activatable (plugin
) ||
966 (g_hash_table_lookup (plugin_manager
->priv
->disable_plugins
, plugin
) == NULL
))
971 text
= g_markup_printf_escaped ("<span size=\"larger\" weight=\"bold\">%s</span>\n%s",
972 anjuta_plugin_handle_get_name (plugin
),
973 anjuta_plugin_handle_get_about (plugin
));
975 gtk_list_store_append (store
, &iter
);
976 gtk_list_store_set (store
, &iter
,
978 anjuta_plugin_handle_get_user_activatable (plugin
),
983 if (anjuta_plugin_handle_get_icon_path (plugin
))
986 icon
= gdk_pixbuf_new_from_file_at_size (anjuta_plugin_handle_get_icon_path (plugin
),
989 gtk_list_store_set (store
, &iter
,
991 g_object_unref (icon
);
999 g_list_free (sorted_plugins
);
1003 create_remembered_plugins_tree (void)
1005 GtkListStore
*store
;
1007 GtkCellRenderer
*renderer
;
1008 GtkTreeViewColumn
*column
;
1010 store
= gtk_list_store_new (N_REM_COLS
, GDK_TYPE_PIXBUF
, G_TYPE_STRING
,
1012 tree
= gtk_tree_view_new_with_model (GTK_TREE_MODEL (store
));
1014 column
= gtk_tree_view_column_new ();
1015 renderer
= gtk_cell_renderer_pixbuf_new ();
1016 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
1017 gtk_tree_view_column_add_attribute (column
, renderer
, "pixbuf",
1019 renderer
= gtk_cell_renderer_text_new ();
1020 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
1021 gtk_tree_view_column_add_attribute (column
, renderer
, "markup",
1023 gtk_tree_view_column_set_sizing (column
,
1024 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
1025 gtk_tree_view_column_set_title (column
, dgettext (GETTEXT_PACKAGE
, "Preferred plugins"));
1026 gtk_tree_view_append_column (GTK_TREE_VIEW (tree
), column
);
1027 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (tree
), column
);
1029 g_object_unref (store
);
1034 foreach_remembered_plugin (gpointer key
, gpointer value
, gpointer user_data
)
1036 AnjutaPluginHandle
*handle
= (AnjutaPluginHandle
*) value
;
1037 GtkListStore
*store
= GTK_LIST_STORE (user_data
);
1039 if (anjuta_plugin_handle_get_name (handle
) &&
1040 anjuta_plugin_handle_get_description (handle
))
1045 text
= g_markup_printf_escaped ("<span size=\"larger\" weight=\"bold\">%s</span>\n%s",
1046 anjuta_plugin_handle_get_name (handle
),
1047 anjuta_plugin_handle_get_about (handle
));
1049 gtk_list_store_append (store
, &iter
);
1050 gtk_list_store_set (store
, &iter
,
1052 COL_REM_PLUGIN_KEY
, key
,
1054 if (anjuta_plugin_handle_get_icon_path (handle
))
1057 icon
= gdk_pixbuf_new_from_file_at_size (anjuta_plugin_handle_get_icon_path (handle
),
1060 gtk_list_store_set (store
, &iter
,
1061 COL_REM_ICON
, icon
, -1);
1062 g_object_unref (icon
);
1070 populate_remembered_plugins_model (AnjutaPluginManager
*plugin_manager
,
1071 GtkListStore
*store
)
1073 AnjutaPluginManagerPriv
*priv
= plugin_manager
->priv
;
1074 gtk_list_store_clear (store
);
1075 g_hash_table_foreach (priv
->remember_plugins
, foreach_remembered_plugin
,
1080 on_show_all_plugins_toggled (GtkToggleButton
*button
, GtkListStore
*store
)
1082 AnjutaPluginManager
*plugin_manager
;
1084 plugin_manager
= g_object_get_data (G_OBJECT (button
), "__plugin_manager");
1086 populate_plugin_model (plugin_manager
, store
, NULL
,
1087 plugin_manager
->priv
->activated_plugins
,
1088 !gtk_toggle_button_get_active (button
));
1092 on_forget_plugin_clicked (GtkWidget
*button
, GtkTreeView
*view
)
1095 GtkTreeModel
*model
;
1096 GtkTreeSelection
*selection
= gtk_tree_view_get_selection (view
);
1097 if (gtk_tree_selection_get_selected (selection
, &model
, &iter
))
1100 AnjutaPluginManager
*manager
= g_object_get_data (G_OBJECT (model
),
1102 gtk_tree_model_get (model
, &iter
, COL_REM_PLUGIN_KEY
, &plugin_key
, -1);
1103 g_hash_table_remove (manager
->priv
->remember_plugins
, plugin_key
);
1104 gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
1105 g_free (plugin_key
);
1110 on_forget_plugin_sel_changed (GtkTreeSelection
*selection
,
1115 if (gtk_tree_selection_get_selected (selection
, NULL
, &iter
))
1116 gtk_widget_set_sensitive (button
, TRUE
);
1118 gtk_widget_set_sensitive (button
, FALSE
);
1122 anjuta_plugin_manager_get_plugins_page (AnjutaPluginManager
*plugin_manager
)
1125 GtkWidget
*checkbutton
;
1127 GtkWidget
*scrolled
;
1129 GtkToolItem
*toolitem
;
1130 GtkListStore
*store
;
1133 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
1134 gtk_container_set_border_width (GTK_CONTAINER (vbox
), 6);
1136 scrolled
= gtk_scrolled_window_new (NULL
, NULL
);
1137 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled
),
1139 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled
),
1141 GTK_POLICY_AUTOMATIC
);
1142 gtk_style_context_set_junction_sides (gtk_widget_get_style_context (scrolled
), GTK_JUNCTION_BOTTOM
);
1143 gtk_box_pack_start (GTK_BOX (vbox
), scrolled
, TRUE
, TRUE
, 0);
1145 toolbar
= gtk_toolbar_new ();
1146 gtk_style_context_add_class (gtk_widget_get_style_context (toolbar
), GTK_STYLE_CLASS_INLINE_TOOLBAR
);
1147 gtk_style_context_set_junction_sides (gtk_widget_get_style_context (toolbar
), GTK_JUNCTION_TOP
);
1148 gtk_box_pack_start (GTK_BOX (vbox
), toolbar
, FALSE
, FALSE
, 0);
1149 gtk_widget_show (toolbar
);
1151 toolitem
= gtk_tool_item_new ();
1152 gtk_toolbar_insert (GTK_TOOLBAR (toolbar
), GTK_TOOL_ITEM (toolitem
), 0);
1153 gtk_widget_show (GTK_WIDGET(toolitem
));
1155 checkbutton
= gtk_check_button_new_with_label (dgettext (GETTEXT_PACKAGE
, "Only show user activatable plugins"));
1156 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton
), TRUE
);
1157 gtk_container_add (GTK_CONTAINER (toolitem
), checkbutton
);
1159 tree
= create_plugin_tree ();
1160 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree
), TRUE
);
1161 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree
), FALSE
);
1162 store
= GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (tree
)));
1164 populate_plugin_model (plugin_manager
, store
, NULL
,
1165 plugin_manager
->priv
->activated_plugins
, FALSE
);
1167 gtk_container_add (GTK_CONTAINER (scrolled
), tree
);
1168 g_object_set_data (G_OBJECT (store
), "plugin-manager", plugin_manager
);
1171 g_object_set_data (G_OBJECT (checkbutton
), "__plugin_manager", plugin_manager
);
1172 g_signal_connect (G_OBJECT (checkbutton
), "toggled",
1173 G_CALLBACK (on_show_all_plugins_toggled
),
1175 gtk_widget_show_all (vbox
);
1180 anjuta_plugin_manager_get_remembered_plugins_page (AnjutaPluginManager
*plugin_manager
)
1184 GtkWidget
*scrolled
;
1185 GtkListStore
*store
;
1187 GtkWidget
*display_label
;
1188 GtkWidget
*forget_button
;
1189 GtkTreeSelection
*selection
;
1191 /* Remembered plugin */
1192 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 10);
1193 gtk_container_set_border_width (GTK_CONTAINER (vbox
), 10);
1195 display_label
= gtk_label_new (dgettext (GETTEXT_PACKAGE
, "These are the plugins selected by you "
1196 "when you have been prompted to choose one of "
1197 "many suitable plugins. Removing the "
1198 "preferred plugin will let you "
1199 "choose a different plugin."));
1200 gtk_label_set_line_wrap (GTK_LABEL (display_label
), TRUE
);
1201 gtk_box_pack_start (GTK_BOX (vbox
), display_label
, FALSE
, FALSE
, 0);
1203 scrolled
= gtk_scrolled_window_new (NULL
, NULL
);
1204 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled
),
1206 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled
),
1207 GTK_POLICY_AUTOMATIC
,
1208 GTK_POLICY_AUTOMATIC
);
1209 gtk_box_pack_start (GTK_BOX (vbox
), scrolled
, TRUE
, TRUE
, 0);
1211 tree
= create_remembered_plugins_tree ();
1212 store
= GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (tree
)));
1214 gtk_container_add (GTK_CONTAINER (scrolled
), tree
);
1215 g_object_set_data (G_OBJECT (store
), "plugin-manager", plugin_manager
);
1216 populate_remembered_plugins_model (plugin_manager
, store
);
1218 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
1219 gtk_container_set_border_width (GTK_CONTAINER (hbox
), 5);
1220 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
1221 forget_button
= gtk_button_new_with_label (dgettext (GETTEXT_PACKAGE
, "Forget selected plugin"));
1222 gtk_widget_set_sensitive (forget_button
, FALSE
);
1223 gtk_box_pack_end (GTK_BOX (hbox
), forget_button
, FALSE
, FALSE
, 0);
1225 g_signal_connect (forget_button
, "clicked",
1226 G_CALLBACK (on_forget_plugin_clicked
),
1228 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (tree
));
1229 g_signal_connect (selection
, "changed",
1230 G_CALLBACK (on_forget_plugin_sel_changed
),
1232 gtk_widget_show_all (vbox
);
1237 property_to_list (const char *value
)
1243 split_str
= g_strsplit (value
, ",", -1);
1244 for (p
= split_str
; *p
!= NULL
; p
++) {
1245 l
= g_list_prepend (l
, g_strdup (g_strstrip (*p
)));
1247 g_strfreev (split_str
);
1251 static IAnjutaPluginFactory
*
1252 get_plugin_factory (AnjutaPluginManager
*plugin_manager
,
1253 const gchar
*language
,
1256 AnjutaPluginManagerPriv
*priv
;
1257 AnjutaPluginHandle
*plugin
;
1258 GList
*loader_plugins
, *node
;
1259 GList
*valid_plugins
;
1260 GObject
*obj
= NULL
;
1262 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), G_TYPE_INVALID
);
1265 if ((language
== NULL
) || (g_ascii_strcasecmp (language
, "C") == 0))
1267 /* Support of C plugin is built-in */
1268 return IANJUTA_PLUGIN_FACTORY (anjuta_plugin_factory
);
1271 priv
= plugin_manager
->priv
;
1274 /* Find all plugins implementing the IAnjutaPluginLoader interface. */
1275 loader_plugins
= g_hash_table_lookup (priv
->plugins_by_interfaces
, "IAnjutaPluginLoader");
1277 /* Create a list of loader supporting this language */
1278 node
= loader_plugins
;
1279 valid_plugins
= NULL
;
1282 AnjutaPluginDescription
*desc
;
1288 plugin
= node
->data
;
1290 desc
= anjuta_plugin_handle_get_description (plugin
);
1291 if (anjuta_plugin_description_get_string (desc
, "Plugin Loader", "SupportedLanguage", &val
))
1295 vals
= property_to_list (val
);
1304 if (!found
&& (g_ascii_strcasecmp (l_node
->data
, language
) == 0))
1308 g_free (l_node
->data
);
1309 l_node
= g_list_next (l_node
);
1315 valid_plugins
= g_list_prepend (valid_plugins
, plugin
);
1318 node
= g_list_next (node
);
1321 /* Find the first installed plugin from the valid plugins */
1322 node
= valid_plugins
;
1325 plugin
= node
->data
;
1326 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1328 node
= g_list_next (node
);
1331 /* If no plugin is installed yet, do something */
1332 if ((obj
== NULL
) && valid_plugins
&& g_list_length (valid_plugins
) == 1)
1334 /* If there is just one plugin, consider it selected */
1335 plugin
= valid_plugins
->data
;
1337 /* Install and return it */
1338 plugin_set_update (plugin_manager
, plugin
, TRUE
);
1339 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1341 else if ((obj
== NULL
) && valid_plugins
)
1343 /* Prompt the user to select one of these plugins */
1345 GList
*handles
= NULL
;
1346 node
= valid_plugins
;
1349 plugin
= node
->data
;
1350 handles
= g_list_prepend (handles
, plugin
);
1351 node
= g_list_next (node
);
1353 handles
= g_list_reverse (handles
);
1354 obj
= anjuta_plugin_manager_select_and_activate (plugin_manager
,
1355 dgettext (GETTEXT_PACKAGE
, "Select a plugin"),
1356 dgettext (GETTEXT_PACKAGE
, "Please select a plugin to activate"),
1358 g_list_free (handles
);
1360 g_list_free (valid_plugins
);
1364 return IANJUTA_PLUGIN_FACTORY (obj
);
1367 /* No plugin implementing this interface found */
1368 g_set_error (error
, ANJUTA_PLUGIN_MANAGER_ERROR
,
1369 ANJUTA_PLUGIN_MANAGER_MISSING_FACTORY
,
1370 dgettext (GETTEXT_PACKAGE
, "No plugin is able to load other plugins in %s"), language
);
1376 on_is_active_plugins_foreach (gpointer key
, gpointer data
, gpointer user_data
)
1378 AnjutaPluginHandle
*handle
= ANJUTA_PLUGIN_HANDLE (key
);
1379 gchar
const **search_iface
= (gchar
const **)user_data
;
1381 if (*search_iface
!= NULL
)
1386 interfaces
= anjuta_plugin_handle_get_interfaces (handle
);
1388 for (found
= g_list_first (interfaces
); found
!= NULL
; found
= g_list_next (found
))
1392 found
= g_list_find_custom (interfaces
, *search_iface
, (GCompareFunc
)strcmp
);
1394 if (found
!= NULL
) *search_iface
= NULL
;
1399 * anjuta_plugin_manager_is_active_plugin:
1400 * @plugin_manager: A #AnjutaPluginManager object
1401 * @iface_name: The interface implemented by the object to be found
1403 * Searches if a currently loaded plugins implements
1404 * the given interface.
1406 * Return value: %TRUE is the plugin is currently loaded.
1410 anjuta_plugin_manager_is_active_plugin (AnjutaPluginManager
*plugin_manager
,
1411 const gchar
*iface_name
)
1413 const gchar
*search_iface
= iface_name
;
1415 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), FALSE
);
1417 g_hash_table_foreach (plugin_manager
->priv
->activated_plugins
,
1418 on_is_active_plugins_foreach
,
1421 return search_iface
== NULL
;
1425 * anjuta_plugin_manager_get_plugin:
1426 * @plugin_manager: A #AnjutaPluginManager object
1427 * @iface_name: The interface implemented by the object to be found
1429 * Searches the currently available plugins to find the one which
1430 * implements the given interface as primary interface and returns it. If
1431 * the plugin is not yet loaded, it will be loaded and activated.
1433 * from the pool of plugin objects loaded in this shell and can only search
1434 * by primary interface. If there are more objects implementing this primary
1435 * interface, user might be prompted to select one from them (and might give
1436 * the option to use it as default for future queries). A typical usage of this
1440 * anjuta_plugin_manager_get_plugin (plugin_manager, "IAnjutaDocumentManager", error);
1442 * Notice that this function takes the interface name string as string, unlike
1443 * anjuta_plugins_get_interface() which takes the type directly.
1444 * If no plugin implementing this interface can be found, returns %NULL.
1446 * Return value: The plugin object (subclass of #AnjutaPlugin) which implements
1447 * the given interface or %NULL. See #AnjutaPlugin for more detail on interfaces
1448 * implemented by plugins.
1451 anjuta_plugin_manager_get_plugin (AnjutaPluginManager
*plugin_manager
,
1452 const gchar
*iface_name
)
1454 AnjutaPluginManagerPriv
*priv
;
1455 AnjutaPluginHandle
*plugin
;
1456 GList
*valid_plugins
, *node
;
1458 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1459 g_return_val_if_fail (iface_name
!= NULL
, NULL
);
1461 priv
= plugin_manager
->priv
;
1464 /* Find all plugins implementing this (primary) interface. */
1465 valid_plugins
= g_hash_table_lookup (priv
->plugins_by_interfaces
, iface_name
);
1467 /* Find the first installed plugin from the valid plugins */
1468 node
= valid_plugins
;
1472 plugin
= node
->data
;
1473 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1476 node
= g_list_next (node
);
1479 /* Filter disable plugins */
1480 valid_plugins
= g_list_copy (valid_plugins
);
1481 node
= valid_plugins
;
1484 GList
*next
= g_list_next (node
);
1486 if ((g_hash_table_lookup (priv
->disable_plugins
, node
->data
) != NULL
) &&
1487 (g_hash_table_lookup (priv
->activated_plugins
, node
->data
) == NULL
))
1490 valid_plugins
= g_list_delete_link (valid_plugins
, node
);
1495 /* If no plugin is installed yet, do something */
1496 if (valid_plugins
&&
1497 (g_list_length (valid_plugins
) == 1))
1499 /* If there is just one plugin, consider it selected */
1501 plugin
= valid_plugins
->data
;
1502 g_list_free (valid_plugins
);
1504 /* Install and return it */
1505 plugin_set_update (plugin_manager
, plugin
, TRUE
);
1506 obj
= g_hash_table_lookup (priv
->activated_plugins
, plugin
);
1510 else if (valid_plugins
)
1512 /* Prompt the user to select one of these plugins */
1514 obj
= anjuta_plugin_manager_select_and_activate (plugin_manager
,
1515 dgettext (GETTEXT_PACKAGE
, "Select a plugin"),
1516 dgettext (GETTEXT_PACKAGE
, "<b>Please select a plugin to activate</b>"),
1518 g_list_free (valid_plugins
);
1522 /* No plugin implementing this interface found */
1527 * anjuta_plugin_manager_get_plugin_by_handle:
1528 * @plugin_manager: A #AnjutaPluginManager object
1529 * @handle: A #AnjutaPluginHandle
1531 * Searches the currently available plugins to find the one with the
1532 * specified handle. If the plugin is not yet loaded, it will be loaded
1535 * Return value: The plugin object (subclass of #AnjutaPlugin)
1538 anjuta_plugin_manager_get_plugin_by_handle (AnjutaPluginManager
*plugin_manager
,
1539 AnjutaPluginHandle
*handle
)
1541 AnjutaPluginManagerPriv
*priv
;
1544 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1545 g_return_val_if_fail (handle
!= NULL
, NULL
);
1547 priv
= plugin_manager
->priv
;
1548 obj
= g_hash_table_lookup (priv
->activated_plugins
, handle
);
1551 plugin_set_update (plugin_manager
, handle
, TRUE
);
1552 obj
= g_hash_table_lookup (priv
->activated_plugins
, handle
);
1559 on_activated_plugins_foreach (gpointer key
, gpointer data
, gpointer user_data
)
1561 AnjutaPluginHandle
*plugin
= ANJUTA_PLUGIN_HANDLE (key
);
1562 GList
**active_plugins
= (GList
**)user_data
;
1563 *active_plugins
= g_list_prepend (*active_plugins
,
1568 on_activated_plugin_objects_foreach (gpointer key
, gpointer data
, gpointer user_data
)
1570 GList
**active_plugins
= (GList
**)user_data
;
1571 *active_plugins
= g_list_prepend (*active_plugins
,
1576 anjuta_plugin_manager_get_active_plugins (AnjutaPluginManager
*plugin_manager
)
1578 GList
*active_plugins
= NULL
;
1580 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1581 g_hash_table_foreach (plugin_manager
->priv
->activated_plugins
,
1582 on_activated_plugins_foreach
,
1584 return g_list_reverse (active_plugins
);
1588 anjuta_plugin_manager_get_active_plugin_objects (AnjutaPluginManager
*plugin_manager
)
1590 GList
*active_plugins
= NULL
;
1592 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1593 g_hash_table_foreach (plugin_manager
->priv
->activated_plugins
,
1594 on_activated_plugin_objects_foreach
,
1596 return g_list_reverse (active_plugins
);
1600 * anjuta_plugin_manager_unload_plugin_by_handle:
1601 * @plugin_manager: A #AnjutaPluginManager object
1602 * @handle: A #AnjutaPluginHandle
1604 * Unload the plugin corresponding to the given handle. If the plugin is
1605 * already unloaded, nothing will be done.
1607 * Return value: %TRUE is the plugin is unloaded. %FALSE if a corresponding
1608 * plugin does not exist or if the plugin cannot be unloaded.
1611 anjuta_plugin_manager_unload_plugin_by_handle (AnjutaPluginManager
*plugin_manager
,
1612 AnjutaPluginHandle
*handle
)
1614 AnjutaPluginManagerPriv
*priv
;
1616 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), FALSE
);
1617 g_return_val_if_fail (handle
!= NULL
, FALSE
);
1619 priv
= plugin_manager
->priv
;
1620 plugin_set_update (plugin_manager
, handle
, FALSE
);
1622 /* Check if the plugin has been indeed unloaded */
1623 return g_hash_table_lookup (priv
->activated_plugins
, handle
) == NULL
;
1627 find_plugin_for_object (gpointer key
, gpointer value
, gpointer data
)
1631 g_object_set_data (G_OBJECT (data
), "__plugin_plugin", key
);
1638 * anjuta_plugin_manager_unload_plugin:
1639 * @plugin_manager: A #AnjutaPluginManager object
1640 * @plugin_object: A #AnjutaPlugin object
1642 * Unload the corresponding plugin. The plugin has to be loaded.
1644 * Return value: %TRUE if the plugin has been unloaded. %FALSE if the plugin is
1645 * already or cannot be unloaded.
1648 anjuta_plugin_manager_unload_plugin (AnjutaPluginManager
*plugin_manager
,
1649 GObject
*plugin_object
)
1651 AnjutaPluginManagerPriv
*priv
;
1652 AnjutaPluginHandle
*plugin
;
1654 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), FALSE
);
1655 g_return_val_if_fail (ANJUTA_IS_PLUGIN (plugin_object
), FALSE
);
1657 priv
= plugin_manager
->priv
;
1661 /* Find the plugin that correspond to this plugin object */
1662 g_hash_table_find (priv
->activated_plugins
, find_plugin_for_object
,
1664 plugin
= g_object_get_data (G_OBJECT (plugin_object
), "__plugin_plugin");
1668 plugin_set_update (plugin_manager
, plugin
, FALSE
);
1670 /* Check if the plugin has been indeed unloaded */
1671 if (!g_hash_table_lookup (priv
->activated_plugins
, plugin
))
1676 g_warning ("No plugin found with object \"%p\".", plugin_object
);
1681 anjuta_plugin_manager_list_query (AnjutaPluginManager
*plugin_manager
,
1686 AnjutaPluginManagerPriv
*priv
;
1687 GList
*selected_plugins
= NULL
;
1690 const gchar
*avalue
;
1693 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
1695 priv
= plugin_manager
->priv
;
1696 available
= priv
->available_plugins
;
1700 /* If no query is given, select all plugins */
1703 AnjutaPluginHandle
*plugin
= available
->data
;
1704 if ((g_hash_table_lookup (plugin_manager
->priv
->disable_plugins
, plugin
) == NULL
) ||
1705 (g_hash_table_lookup (plugin_manager
->priv
->activated_plugins
, plugin
) != NULL
))
1706 selected_plugins
= g_list_prepend (selected_plugins
, plugin
);
1707 available
= g_list_next (available
);
1709 return g_list_reverse (selected_plugins
);
1712 g_return_val_if_fail (secs
!= NULL
, NULL
);
1713 g_return_val_if_fail (anames
!= NULL
, NULL
);
1714 g_return_val_if_fail (avalues
!= NULL
, NULL
);
1716 for (;available
; available
= g_list_next (available
))
1718 GList
* s_node
= secs
;
1719 GList
* n_node
= anames
;
1720 GList
* v_node
= avalues
;
1722 gboolean satisfied
= FALSE
;
1724 AnjutaPluginHandle
*plugin
= available
->data
;
1725 AnjutaPluginDescription
*desc
=
1726 anjuta_plugin_handle_get_description (plugin
);
1728 if ((g_hash_table_lookup (plugin_manager
->priv
->disable_plugins
, plugin
) != NULL
) &&
1729 (g_hash_table_lookup (plugin_manager
->priv
->activated_plugins
, plugin
) == NULL
))
1737 gboolean found
= FALSE
;
1742 aname
= n_node
->data
;
1743 avalue
= v_node
->data
;
1745 if (!anjuta_plugin_description_get_string (desc
, sec
, aname
, &val
))
1751 vals
= property_to_list (val
);
1757 if (strchr(node
->data
, '*') != NULL
)
1762 const gchar
*cursor
;
1764 segments
= g_strsplit (node
->data
, "*", -1);
1768 while (*seg_ptr
!= NULL
)
1770 if (strlen (*seg_ptr
) > 0) {
1771 cursor
= strstr (cursor
, *seg_ptr
);
1775 cursor
+= strlen (*seg_ptr
);
1778 if (*seg_ptr
== NULL
)
1780 g_strfreev (segments
);
1782 else if (g_ascii_strcasecmp (node
->data
, avalue
) == 0)
1787 g_free (node
->data
);
1788 node
= g_list_next (node
);
1796 s_node
= g_list_next (s_node
);
1797 n_node
= g_list_next (n_node
);
1798 v_node
= g_list_next (v_node
);
1802 selected_plugins
= g_list_prepend (selected_plugins
, plugin
);
1803 /* DEBUG_PRINT ("Satisfied, Adding %s",
1804 anjuta_plugin_handle_get_name (plugin));*/
1808 return g_list_reverse (selected_plugins
);
1812 anjuta_plugin_manager_query (AnjutaPluginManager
*plugin_manager
,
1813 const gchar
*section_name
,
1814 const gchar
*attribute_name
,
1815 const gchar
*attribute_value
,
1820 GList
*anames
= NULL
;
1821 GList
*avalues
= NULL
;
1824 const gchar
*avalue
;
1825 GList
*selected_plugins
;
1828 if (section_name
== NULL
)
1830 /* If no query is given, select all plugins */
1831 return anjuta_plugin_manager_list_query (plugin_manager
, NULL
, NULL
, NULL
);
1834 g_return_val_if_fail (section_name
!= NULL
, NULL
);
1835 g_return_val_if_fail (attribute_name
!= NULL
, NULL
);
1836 g_return_val_if_fail (attribute_value
!= NULL
, NULL
);
1838 secs
= g_list_prepend (secs
, g_strdup (section_name
));
1839 anames
= g_list_prepend (anames
, g_strdup (attribute_name
));
1840 avalues
= g_list_prepend (avalues
, g_strdup (attribute_value
));
1842 va_start (var_args
, attribute_value
);
1845 sec
= va_arg (var_args
, const gchar
*);
1848 aname
= va_arg (var_args
, const gchar
*);
1851 avalue
= va_arg (var_args
, const gchar
*);
1854 secs
= g_list_prepend (secs
, g_strdup (sec
));
1855 anames
= g_list_prepend (anames
, g_strdup (aname
));
1856 avalues
= g_list_prepend (avalues
, g_strdup (avalue
));
1864 secs
= g_list_reverse (secs
);
1865 anames
= g_list_reverse (anames
);
1866 avalues
= g_list_reverse (avalues
);
1868 selected_plugins
= anjuta_plugin_manager_list_query (plugin_manager
,
1873 anjuta_util_glist_strings_free (secs
);
1874 anjuta_util_glist_strings_free (anames
);
1875 anjuta_util_glist_strings_free (avalues
);
1877 return selected_plugins
;
1883 PLUGIN_HANDLE_COLUMN
,
1888 on_plugin_list_row_activated (GtkTreeView
*tree_view
,
1890 GtkTreeViewColumn
*column
,
1893 gtk_dialog_response (dialog
, GTK_RESPONSE_OK
);
1898 on_plugin_list_show (GtkTreeView
*view
,
1899 GtkDirectionType direction
,
1902 GtkTreeSelection
*selection
;
1903 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (view
));
1905 g_signal_emit_by_name (G_OBJECT (selection
), "changed", GTK_DIALOG(dialog
), NULL
);
1910 on_plugin_list_selection_changed (GtkTreeSelection
*tree_selection
,
1913 GtkContainer
*action_area
;
1915 GtkButton
*bt
= NULL
;
1917 action_area
= GTK_CONTAINER (gtk_dialog_get_action_area (dialog
));
1918 list
= gtk_container_get_children (action_area
);
1919 for (; list
; list
= list
->next
) {
1921 if (!strcmp("gtk-ok", gtk_button_get_label (bt
)))
1924 if (bt
&& gtk_tree_selection_get_selected (tree_selection
, NULL
, NULL
))
1925 gtk_widget_set_sensitive ((GtkWidget
*) bt
, TRUE
);
1927 gtk_widget_set_sensitive ((GtkWidget
*) bt
, FALSE
);
1932 * anjuta_plugin_manager_select:
1933 * @plugin_manager: #AnjutaPluginManager object
1934 * @title: Title of the dialog
1935 * @description: label shown on the dialog
1936 * @plugin_handles: List of #AnjutaPluginHandle
1938 * Show a dialog where the user can choose between the given plugins
1940 * Returns: The chosen plugin handle
1942 AnjutaPluginHandle
*
1943 anjuta_plugin_manager_select (AnjutaPluginManager
*plugin_manager
,
1944 gchar
*title
, gchar
*description
,
1945 GList
*plugin_handles
)
1947 AnjutaPluginManagerPriv
*priv
;
1949 AnjutaPluginHandle
*handle
;
1951 GtkTreeModel
*model
;
1953 GtkTreeViewColumn
*column
;
1954 GtkCellRenderer
*renderer
;
1957 GtkWidget
*content_area
;
1959 GtkWidget
*remember_checkbox
;
1961 GtkTreeIter selected
;
1962 GtkTreeSelection
*selection
;
1963 GtkTreeModel
*store
;
1964 GList
*selection_ids
= NULL
;
1965 GString
*remember_key
= g_string_new ("");
1967 g_return_val_if_fail (title
!= NULL
, NULL
);
1968 g_return_val_if_fail (description
!= NULL
, NULL
);
1969 g_return_val_if_fail (plugin_handles
!= NULL
, NULL
);
1971 priv
= plugin_manager
->priv
;
1973 plugin_count
= g_list_length (plugin_handles
);
1974 if (plugin_count
<= 0)
1977 dlg
= gtk_dialog_new_with_buttons (title
, GTK_WINDOW (priv
->shell
),
1978 GTK_DIALOG_DESTROY_WITH_PARENT
,
1980 GTK_RESPONSE_CANCEL
,
1981 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
1982 GTK_STOCK_HELP
, GTK_RESPONSE_HELP
,
1984 gtk_window_set_default_size (GTK_WINDOW (dlg
), 520, 200 + (plugin_count
> 6 ? 300 : plugin_count
* 60));
1986 label
= gtk_label_new (description
);
1987 gtk_label_set_use_markup (GTK_LABEL (label
), TRUE
);
1988 gtk_widget_show (label
);
1989 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (dlg
));
1990 gtk_box_pack_start (GTK_BOX (content_area
), label
,
1993 sc
= gtk_scrolled_window_new (NULL
, NULL
);
1994 gtk_widget_show (sc
);
1995 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sc
),
1997 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sc
),
1998 GTK_POLICY_AUTOMATIC
,
1999 GTK_POLICY_AUTOMATIC
);
2001 gtk_box_pack_start (GTK_BOX (content_area
), sc
,
2004 model
= GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS
, GDK_TYPE_PIXBUF
,
2005 G_TYPE_STRING
, G_TYPE_POINTER
));
2006 view
= gtk_tree_view_new_with_model (model
);
2007 gtk_widget_show (view
);
2008 gtk_container_add (GTK_CONTAINER (sc
), view
);
2010 column
= gtk_tree_view_column_new ();
2011 gtk_tree_view_column_set_sizing (column
,
2012 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
2013 gtk_tree_view_column_set_title (column
, dgettext (GETTEXT_PACKAGE
, "Available Plugins"));
2015 renderer
= gtk_cell_renderer_pixbuf_new ();
2016 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
2017 gtk_tree_view_column_add_attribute (column
, renderer
, "pixbuf",
2020 renderer
= gtk_cell_renderer_text_new ();
2021 g_object_set (G_OBJECT (renderer
), "wrap-mode", PANGO_WRAP_WORD_CHAR
,
2022 "wrap-width", 450, NULL
);
2023 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
2024 gtk_tree_view_column_add_attribute (column
, renderer
, "markup",
2027 gtk_tree_view_append_column (GTK_TREE_VIEW (view
), column
);
2028 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (view
), column
);
2030 g_signal_connect (view
, "row-activated",
2031 G_CALLBACK (on_plugin_list_row_activated
),
2033 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (view
));
2034 g_signal_connect(selection
, "changed",
2035 G_CALLBACK(on_plugin_list_selection_changed
),
2037 g_signal_connect(view
, "focus",
2038 G_CALLBACK(on_plugin_list_show
),
2042 gtk_check_button_new_with_label (dgettext (GETTEXT_PACKAGE
, "Remember this selection"));
2043 gtk_container_set_border_width (GTK_CONTAINER (remember_checkbox
), 10);
2044 gtk_widget_show (remember_checkbox
);
2045 gtk_box_pack_start (GTK_BOX (content_area
), remember_checkbox
,
2048 node
= plugin_handles
;
2051 const gchar
*filename
;
2052 GdkPixbuf
*icon_pixbuf
= NULL
;
2053 const gchar
*name
= NULL
;
2054 AnjutaPluginDescription
*desc
;
2056 handle
= (AnjutaPluginHandle
*)node
->data
;
2058 filename
= anjuta_plugin_handle_get_icon_path (handle
);
2059 if (filename
!= NULL
)
2061 icon_pixbuf
= gdk_pixbuf_new_from_file (filename
, NULL
);
2063 g_warning ("Plugin does not define Icon: No such file %s",
2068 g_warning ("Plugin does not define Icon attribute");
2071 name
= anjuta_plugin_handle_get_name (handle
);
2072 desc
= anjuta_plugin_handle_get_description (handle
);
2073 if ((name
!= NULL
) && (desc
!= NULL
))
2079 if (!anjuta_plugin_description_get_locale_string (desc
,
2084 g_warning ("Plugin does not define Description attribute");
2086 text
= g_markup_printf_escaped ("<span size=\"larger\" weight=\"bold\">%s</span>\n%s", name
, plugin_desc
);
2087 g_free (plugin_desc
);
2089 gtk_list_store_append (GTK_LIST_STORE (model
), &iter
);
2090 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
2091 PLUGIN_COLUMN
, text
,
2092 PLUGIN_HANDLE_COLUMN
, handle
, -1);
2094 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
2095 PIXBUF_COLUMN
, icon_pixbuf
, -1);
2099 selection_ids
= g_list_prepend (selection_ids
, (gpointer
)anjuta_plugin_handle_get_id (handle
));
2103 g_warning ("Plugin does not define Name attribute");
2107 g_object_unref (icon_pixbuf
);
2109 node
= g_list_next (node
);
2112 /* Prepare remembering key */
2113 selection_ids
= g_list_sort (selection_ids
,
2114 (GCompareFunc
)strcmp
);
2115 node
= selection_ids
;
2118 g_string_append (remember_key
, (gchar
*)node
->data
);
2119 g_string_append (remember_key
, ",");
2120 node
= g_list_next (node
);
2122 g_list_free (selection_ids
);
2124 /* Find if the selection is remembered */
2125 handle
= g_hash_table_lookup (priv
->remember_plugins
, remember_key
->str
);
2128 g_string_free (remember_key
, TRUE
);
2129 gtk_widget_destroy (dlg
);
2134 response
= gtk_dialog_run (GTK_DIALOG (dlg
));
2137 case GTK_RESPONSE_OK
:
2138 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (view
));
2139 if (gtk_tree_selection_get_selected (selection
, &store
,
2142 gtk_tree_model_get (model
, &selected
,
2143 PLUGIN_HANDLE_COLUMN
, &handle
, -1);
2146 /* Remember selection */
2147 if (gtk_toggle_button_get_active
2148 (GTK_TOGGLE_BUTTON (remember_checkbox
)))
2150 /* DEBUG_PRINT ("Remembering selection '%s'",
2151 remember_key->str);*/
2152 g_hash_table_insert (priv
->remember_plugins
,
2153 g_strdup (remember_key
->str
), handle
);
2155 g_string_free (remember_key
, TRUE
);
2156 gtk_widget_destroy (dlg
);
2162 g_string_free (remember_key
, TRUE
);
2163 gtk_widget_destroy (dlg
);
2168 anjuta_plugin_manager_select_and_activate (AnjutaPluginManager
*plugin_manager
,
2171 GList
*plugin_handles
)
2173 AnjutaPluginHandle
*handle
;
2174 GObject
*plugin
= NULL
;
2176 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), NULL
);
2178 handle
= anjuta_plugin_manager_select (plugin_manager
, title
, description
,
2180 plugin
= anjuta_plugin_manager_get_plugin_by_handle (plugin_manager
, handle
);
2186 * anjuta_plugin_manager_get_plugin_handle:
2187 * @plugin_manager: #AnjutaPluginManager object
2188 * @plugin: #AnjutaPlugin object
2190 * Get the handle corresponding to the plugin or %NULL if the plugin is not
2193 * Returns: (transfer none) (allow-none): A #AnjutaPluginHandle or %NULL.
2196 anjuta_plugin_manager_get_plugin_handle (AnjutaPluginManager
*plugin_manager
,
2199 GHashTableIter iter
;
2200 gpointer key
, value
;
2202 g_hash_table_iter_init (&iter
, plugin_manager
->priv
->activated_plugins
);
2203 while (g_hash_table_iter_next (&iter
, &key
, &value
))
2205 if (G_OBJECT(value
) == plugin
)
2207 return ANJUTA_PLUGIN_HANDLE (key
);
2215 /* Plugin manager */
2218 anjuta_plugin_manager_init (AnjutaPluginManager
*object
)
2220 object
->priv
= g_new0 (AnjutaPluginManagerPriv
, 1);
2221 object
->priv
->plugins_by_name
= g_hash_table_new (g_str_hash
, g_str_equal
);
2222 object
->priv
->plugins_by_interfaces
= g_hash_table_new_full (g_str_hash
,
2225 (GDestroyNotify
) g_list_free
);
2226 object
->priv
->plugins_by_description
= g_hash_table_new (g_direct_hash
,
2228 object
->priv
->activated_plugins
= g_hash_table_new_full (g_direct_hash
, g_direct_equal
,
2229 NULL
, g_object_unref
);
2230 object
->priv
->plugins_cache
= g_hash_table_new_full (g_direct_hash
, g_direct_equal
,
2231 NULL
, g_object_unref
);
2232 object
->priv
->remember_plugins
= g_hash_table_new_full (g_str_hash
,
2235 object
->priv
->disable_plugins
= g_hash_table_new (g_direct_hash
,
2240 anjuta_plugin_manager_dispose (GObject
*object
)
2242 AnjutaPluginManagerPriv
*priv
;
2243 priv
= ANJUTA_PLUGIN_MANAGER (object
)->priv
;
2245 if (priv
->available_plugins
)
2247 g_list_foreach (priv
->available_plugins
, (GFunc
)g_object_unref
, NULL
);
2248 g_list_free (priv
->available_plugins
);
2249 priv
->available_plugins
= NULL
;
2251 if (priv
->activated_plugins
)
2253 g_hash_table_destroy (priv
->activated_plugins
);
2254 priv
->activated_plugins
= NULL
;
2256 if (priv
->plugins_cache
)
2258 g_hash_table_destroy (priv
->plugins_cache
);
2259 priv
->plugins_cache
= NULL
;
2261 if (priv
->disable_plugins
)
2263 g_hash_table_destroy (priv
->disable_plugins
);
2264 priv
->disable_plugins
= NULL
;
2266 if (priv
->plugins_by_name
)
2268 g_hash_table_destroy (priv
->plugins_by_name
);
2269 priv
->plugins_by_name
= NULL
;
2271 if (priv
->plugins_by_description
)
2273 g_hash_table_destroy (priv
->plugins_by_description
);
2274 priv
->plugins_by_description
= NULL
;
2276 if (priv
->plugins_by_interfaces
)
2278 g_hash_table_destroy (priv
->plugins_by_interfaces
);
2279 priv
->plugins_by_interfaces
= NULL
;
2281 if (priv
->plugin_dirs
)
2283 g_list_foreach (priv
->plugin_dirs
, (GFunc
)g_free
, NULL
);
2284 g_list_free (priv
->plugin_dirs
);
2285 priv
->plugin_dirs
= NULL
;
2288 if (anjuta_c_plugin_factory
)
2290 g_object_unref (anjuta_c_plugin_factory
);
2291 anjuta_c_plugin_factory
= NULL
;
2294 G_OBJECT_CLASS (parent_class
)->dispose (object
);
2298 anjuta_plugin_manager_set_property (GObject
*object
, guint prop_id
,
2299 const GValue
*value
, GParamSpec
*pspec
)
2301 AnjutaPluginManagerPriv
*priv
;
2303 g_return_if_fail (ANJUTA_IS_PLUGIN_MANAGER (object
));
2304 priv
= ANJUTA_PLUGIN_MANAGER (object
)->priv
;
2309 priv
->status
= g_value_get_object (value
);
2312 priv
->shell
= g_value_get_object (value
);
2315 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
2321 anjuta_plugin_manager_get_property (GObject
*object
, guint prop_id
,
2322 GValue
*value
, GParamSpec
*pspec
)
2324 AnjutaPluginManagerPriv
*priv
;
2326 g_return_if_fail (ANJUTA_IS_PLUGIN_MANAGER (object
));
2327 priv
= ANJUTA_PLUGIN_MANAGER (object
)->priv
;
2332 g_value_set_object (value
, priv
->shell
);
2335 g_value_set_object (value
, priv
->status
);
2337 case PROP_AVAILABLE_PLUGINS
:
2338 g_value_set_pointer (value
, priv
->available_plugins
);
2340 case PROP_ACTIVATED_PLUGINS
:
2341 g_value_set_pointer (value
, priv
->activated_plugins
);
2344 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
2349 anjuta_plugin_manager_plugin_activated (AnjutaPluginManager
*self
,
2350 AnjutaPluginHandle
* handle
,
2353 /* TODO: Add default signal handler implementation here */
2357 anjuta_plugin_manager_plugin_deactivated (AnjutaPluginManager
*self
,
2358 AnjutaPluginHandle
* handle
,
2361 /* TODO: Add default signal handler implementation here */
2365 anjuta_plugin_manager_class_init (AnjutaPluginManagerClass
*klass
)
2367 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
2368 parent_class
= G_OBJECT_CLASS (g_type_class_peek_parent (klass
));
2370 object_class
->dispose
= anjuta_plugin_manager_dispose
;
2371 object_class
->set_property
= anjuta_plugin_manager_set_property
;
2372 object_class
->get_property
= anjuta_plugin_manager_get_property
;
2374 klass
->plugin_activated
= anjuta_plugin_manager_plugin_activated
;
2375 klass
->plugin_deactivated
= anjuta_plugin_manager_plugin_deactivated
;
2377 g_object_class_install_property (object_class
,
2379 g_param_spec_pointer ("profiles",
2380 dgettext (GETTEXT_PACKAGE
, "Profiles"),
2381 dgettext (GETTEXT_PACKAGE
, "Current stack of profiles"),
2383 g_object_class_install_property (object_class
,
2384 PROP_AVAILABLE_PLUGINS
,
2385 g_param_spec_pointer ("available-plugins",
2386 dgettext (GETTEXT_PACKAGE
, "Available plugins"),
2387 dgettext (GETTEXT_PACKAGE
, "Currently available plugins found in plugin paths"),
2390 g_object_class_install_property (object_class
,
2391 PROP_ACTIVATED_PLUGINS
,
2392 g_param_spec_pointer ("activated-plugins",
2393 dgettext (GETTEXT_PACKAGE
, "Activated plugins"),
2394 dgettext (GETTEXT_PACKAGE
, "Currently activated plugins"),
2396 g_object_class_install_property (object_class
,
2398 g_param_spec_object ("shell",
2399 dgettext (GETTEXT_PACKAGE
, "Anjuta Shell"),
2400 dgettext (GETTEXT_PACKAGE
, "Anjuta shell for which the plugins are made"),
2404 G_PARAM_CONSTRUCT
));
2405 g_object_class_install_property (object_class
,
2407 g_param_spec_object ("status",
2408 dgettext (GETTEXT_PACKAGE
, "Anjuta Status"),
2409 dgettext (GETTEXT_PACKAGE
, "Anjuta status to use in loading and unloading of plugins"),
2413 G_PARAM_CONSTRUCT
));
2415 plugin_manager_signals
[PLUGIN_ACTIVATED
] =
2416 g_signal_new ("plugin-activated",
2417 G_OBJECT_CLASS_TYPE (klass
),
2419 G_STRUCT_OFFSET (AnjutaPluginManagerClass
,
2422 anjuta_cclosure_marshal_VOID__POINTER_OBJECT
,
2424 G_TYPE_POINTER
, ANJUTA_TYPE_PLUGIN
);
2426 plugin_manager_signals
[PLUGIN_DEACTIVATED
] =
2427 g_signal_new ("plugin-deactivated",
2428 G_OBJECT_CLASS_TYPE (klass
),
2430 G_STRUCT_OFFSET (AnjutaPluginManagerClass
,
2431 plugin_deactivated
),
2433 anjuta_cclosure_marshal_VOID__POINTER_OBJECT
,
2435 G_TYPE_POINTER
, ANJUTA_TYPE_PLUGIN
);
2439 anjuta_plugin_manager_get_type (void)
2441 static GType our_type
= 0;
2445 static const GTypeInfo our_info
=
2447 sizeof (AnjutaPluginManagerClass
), /* class_size */
2448 (GBaseInitFunc
) NULL
, /* base_init */
2449 (GBaseFinalizeFunc
) NULL
, /* base_finalize */
2450 (GClassInitFunc
) anjuta_plugin_manager_class_init
, /* class_init */
2451 (GClassFinalizeFunc
) NULL
, /* class_finalize */
2452 NULL
/* class_data */,
2453 sizeof (AnjutaPluginManager
), /* instance_size */
2454 0, /* n_preallocs */
2455 (GInstanceInitFunc
) anjuta_plugin_manager_init
, /* instance_init */
2456 NULL
/* value_table */
2458 our_type
= g_type_register_static (G_TYPE_OBJECT
,
2459 "AnjutaPluginManager",
2466 AnjutaPluginManager
*
2467 anjuta_plugin_manager_new (GObject
*shell
, AnjutaStatus
*status
,
2468 GList
* plugins_directories
)
2470 GObject
*manager_object
;
2471 AnjutaPluginManager
*plugin_manager
;
2472 GList
*cycles
= NULL
;
2473 const char *gnome2_path
;
2477 GList
*plugin_dirs
= NULL
;
2479 /* Initialize the anjuta plugin system */
2480 manager_object
= g_object_new (ANJUTA_TYPE_PLUGIN_MANAGER
,
2481 "shell", shell
, "status", status
, NULL
);
2482 plugin_manager
= ANJUTA_PLUGIN_MANAGER (manager_object
);
2484 if (anjuta_plugin_factory
== NULL
)
2486 anjuta_plugin_factory
= anjuta_c_plugin_factory_new ();
2489 gnome2_path
= g_getenv ("GNOME2_PATH");
2491 pathv
= g_strsplit (gnome2_path
, ":", 1);
2493 for (p
= pathv
; *p
!= NULL
; p
++) {
2494 char *path
= g_strdup (*p
);
2495 plugin_dirs
= g_list_prepend (plugin_dirs
, path
);
2500 node
= plugins_directories
;
2504 char *path
= g_strdup (node
->data
);
2505 plugin_dirs
= g_list_prepend (plugin_dirs
, path
);
2506 node
= g_list_next (node
);
2508 plugin_dirs
= g_list_reverse (plugin_dirs
);
2509 /* load_plugins (); */
2514 load_plugins_from_directory (plugin_manager
, (char*)node
->data
);
2515 node
= g_list_next (node
);
2517 resolve_dependencies (plugin_manager
, &cycles
);
2518 g_list_foreach(plugin_dirs
, (GFunc
) g_free
, NULL
);
2519 g_list_free(plugin_dirs
);
2520 return plugin_manager
;
2524 anjuta_plugin_manager_activate_plugins (AnjutaPluginManager
*plugin_manager
,
2525 GList
*plugins_to_activate
)
2527 AnjutaPluginManagerPriv
*priv
;
2530 priv
= plugin_manager
->priv
;
2532 /* Freeze shell operations */
2533 anjuta_shell_freeze (ANJUTA_SHELL (priv
->shell
), NULL
);
2534 if (plugins_to_activate
)
2536 anjuta_status_progress_add_ticks (ANJUTA_STATUS (priv
->status
),
2537 g_list_length (plugins_to_activate
));
2539 node
= plugins_to_activate
;
2542 AnjutaPluginHandle
*handle
;
2543 const gchar
*filename
;
2544 GdkPixbuf
*icon_pixbuf
= NULL
;
2548 handle
= node
->data
;
2550 filename
= anjuta_plugin_handle_get_icon_path (handle
);
2551 if (filename
!= NULL
)
2553 icon_pixbuf
= gdk_pixbuf_new_from_file (filename
, NULL
);
2555 g_warning ("Plugin does not define Icon: No such file %s",
2559 name
= anjuta_plugin_handle_get_name (handle
);
2562 label
= g_strconcat (dgettext (GETTEXT_PACKAGE
, "Loading:"), " ", name
, "...", NULL
);
2565 anjuta_status_progress_tick (ANJUTA_STATUS (priv
->status
),
2566 icon_pixbuf
, label
);
2569 g_object_unref (icon_pixbuf
);
2571 /* Activate the plugin */
2572 anjuta_plugin_manager_get_plugin_by_handle (plugin_manager
, handle
);
2574 node
= g_list_next (node
);
2577 /* Thaw shell operations */
2578 anjuta_shell_thaw (ANJUTA_SHELL (priv
->shell
), NULL
);
2582 on_collect (gpointer key
, gpointer value
, gpointer user_data
)
2585 gchar
*query
= (gchar
*) key
;
2586 AnjutaPluginHandle
*handle
= (AnjutaPluginHandle
*) value
;
2587 GString
*write_buffer
= (GString
*) user_data
;
2589 id
= anjuta_plugin_handle_get_id (handle
);
2590 g_string_append_printf (write_buffer
, "%s=%s;", query
, id
);
2594 * anjuta_plugin_manager_get_remembered_plugins:
2595 * @plugin_manager: A #AnjutaPluginManager object
2597 * Get the list of plugins loaded when there is a choice between several
2598 * ones without asking the user.
2600 * The list format is returned as a string with the format detailed in
2601 * anjuta_plugin_manager_set_remembered_plugins().
2603 * Return value: (transfer full): a newly-allocated string that must be freed
2608 anjuta_plugin_manager_get_remembered_plugins (AnjutaPluginManager
*plugin_manager
)
2610 AnjutaPluginManagerPriv
*priv
;
2611 GString
*write_buffer
= g_string_new ("");
2613 g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
), FALSE
);
2615 priv
= plugin_manager
->priv
;
2616 g_hash_table_foreach (priv
->remember_plugins
, on_collect
,
2618 return g_string_free (write_buffer
, FALSE
);
2622 * anjuta_plugin_manager_set_remembered_plugins:
2623 * @plugin_manager: A #AnjutaPluginManager object
2624 * @remembered_plugins: A list of prefered plugins
2626 * Set the list of plugins loaded when there is a choice between several
2627 * ones without asking the user.
2628 * The list is a string composed of elements separated by ';'. Each element
2629 * is defined with "key=value", where key is the list of possible plugins and
2630 * the value is the choosen plugin.
2632 * By the example the following element
2634 * anjuta-symbol-browser:SymbolBrowserPlugin,anjuta-symbol-db:SymbolDBPlugin,=anjuta-symbol-db:SymbolDBPlugin;
2636 * means if Anjuta has to choose between SymbolBrowserPlugin and
2637 * SymbolDBPlugin, it will choose SymbolDBPlugin.
2640 anjuta_plugin_manager_set_remembered_plugins (AnjutaPluginManager
*plugin_manager
,
2641 const gchar
*remembered_plugins
)
2643 AnjutaPluginManagerPriv
*priv
;
2644 gchar
**strv_lines
, **line_idx
;
2646 g_return_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager
));
2647 g_return_if_fail (remembered_plugins
!= NULL
);
2649 priv
= plugin_manager
->priv
;
2651 g_hash_table_remove_all (priv
->remember_plugins
);
2653 strv_lines
= g_strsplit (remembered_plugins
, ";", -1);
2654 line_idx
= strv_lines
;
2657 gchar
**strv_keyvals
;
2658 strv_keyvals
= g_strsplit (*line_idx
, "=", -1);
2659 if (strv_keyvals
&& strv_keyvals
[0] && strv_keyvals
[1])
2661 AnjutaPluginHandle
*handle
;
2662 handle
= g_hash_table_lookup (priv
->plugins_by_name
,
2666 g_hash_table_insert (priv
->remember_plugins
,
2667 g_strdup (strv_keyvals
[0]), handle
);
2669 g_strfreev (strv_keyvals
);
2673 g_strfreev (strv_lines
);
2677 * anjuta_plugin_manager_set_disable_plugins:
2678 * @plugin_manager: A #AnjutaPluginManager object
2679 * @plugin_handles: A list of plugins to disable or reenable
2680 * @disable: %TRUE to disable, %FALSE to re-enable plugins in the list
2682 * Disable or re-enable plugins. By default, all plugins are enabled but they
2683 * can be disabled and they will not be proposed when a plugin is requested.
2686 anjuta_plugin_manager_set_disable_plugins (AnjutaPluginManager
*plugin_manager
,
2687 GList
*plugin_handles
,
2694 for (item
= g_list_first (plugin_handles
); item
!= NULL
; item
= g_list_next (item
))
2696 g_hash_table_add (plugin_manager
->priv
->disable_plugins
, item
->data
);
2701 for (item
= g_list_first (plugin_handles
); item
!= NULL
; item
= g_list_next (item
))
2703 g_hash_table_remove (plugin_manager
->priv
->disable_plugins
, item
->data
);