gboolean anjuta_pm_project_load (AnjutaPmProject *project, GFile *file, GError **error) { AnjutaPluginManager *plugin_manager; GList *desc; IAnjutaProjectBackend *backend; gint found = 0; GValue value = {0, }; g_return_val_if_fail (file != NULL, FALSE); DEBUG_PRINT ("loading gbf backend…\n"); plugin_manager = anjuta_shell_get_plugin_manager (project->plugin->shell, NULL); if (!anjuta_plugin_manager_is_active_plugin (plugin_manager, "IAnjutaProjectBackend")) { GList *descs = NULL; descs = anjuta_plugin_manager_query (plugin_manager, "Anjuta Plugin", "Interfaces", "IAnjutaProjectBackend", NULL); backend = NULL; for (desc = g_list_first (descs); desc != NULL; desc = g_list_next (desc)) { AnjutaPluginDescription *backend_desc; gchar *location = NULL; IAnjutaProjectBackend *plugin; gint backend_val; backend_desc = (AnjutaPluginDescription *)desc->data; anjuta_plugin_description_get_string (backend_desc, "Anjuta Plugin", "Location", &location); plugin = (IAnjutaProjectBackend *)anjuta_plugin_manager_get_plugin_by_id (plugin_manager, location); g_free (location); backend_val = ianjuta_project_backend_probe (plugin, file, NULL); if (backend_val > found) { /* Backend found */; backend = plugin; found = backend_val; } } g_list_free (descs); } else { /* A backend is already loaded, use it */ backend = IANJUTA_PROJECT_BACKEND (anjuta_shell_get_object (project->plugin->shell, "IAnjutaProjectBackend", NULL)); g_object_ref (backend); } if (!backend) { /* FIXME: Set err */ g_warning ("no backend available for this project\n"); return FALSE; } DEBUG_PRINT ("%s", "Creating new gbf project\n"); project->project = ianjuta_project_backend_new_project (backend, file, NULL); if (!project->project) { /* FIXME: Set err */ g_warning ("project creation failed\n"); return FALSE; } g_signal_connect (G_OBJECT (project->project), "file-changed", G_CALLBACK (on_file_changed), project); g_signal_connect (G_OBJECT (project->project), "node-loaded", G_CALLBACK (on_node_loaded), project); g_signal_connect (G_OBJECT (project->project), "node-changed", G_CALLBACK (on_node_changed), project); project->root = ianjuta_project_get_root (project->project, NULL); /* Export project root shell variable */ g_value_init (&value, G_TYPE_OBJECT); g_value_set_object (&value, project->project); anjuta_shell_add_value (project->plugin->shell, IANJUTA_PROJECT_MANAGER_CURRENT_PROJECT, &value, NULL); g_value_unset(&value); g_value_init (&value, G_TYPE_STRING); g_value_set_string (&value, ANJUTA_PLUGIN_PROJECT_MANAGER (project->plugin)->project_root_uri); anjuta_shell_add_value (project->plugin->shell, IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI, &value, NULL); g_value_unset(&value); ianjuta_project_load_node (project->project, project->root, NULL); return TRUE; }
static gboolean project_import_import_project (AnjutaProjectImportPlugin *import_plugin, ProjectImportDialog *import_dialog, GFile *source_dir) { AnjutaPluginManager *plugin_manager; GList *descs = NULL; GList *desc; AnjutaPluginDescription *backend; gchar *name, *project_file_name; /* Search for all valid project backend */ plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN(import_plugin)->shell, NULL); descs = anjuta_plugin_manager_query (plugin_manager, "Anjuta Plugin", "Interfaces", "IAnjutaProjectBackend", NULL); for (desc = g_list_first (descs); desc != NULL;) { IAnjutaProjectBackend *plugin; gchar *location = NULL; GList *next; backend = (AnjutaPluginDescription *)desc->data; anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Location", &location); plugin = (IAnjutaProjectBackend *)anjuta_plugin_manager_get_plugin_by_id (plugin_manager, location); g_free (location); next = g_list_next (desc); /* Probe the project directory to find if the backend can handle it */ if (ianjuta_project_backend_probe (plugin, source_dir, NULL) <= 0) { /* Remove invalid backend */ descs = g_list_delete_link (descs, desc); } desc = next; } if (descs == NULL) { backend = NULL; } else if (g_list_next (descs) == NULL) { backend = (AnjutaPluginDescription *)descs->data; } else { /* Several backend are possible, ask the user to select one */ gchar *path = project_import_dialog_get_name (import_dialog); gchar* message = g_strdup_printf (_("Please select a project backend to open %s."), path); g_free (path); backend = anjuta_plugin_manager_select (plugin_manager, _("Open With"), message, descs); g_free (message); } g_list_free (descs); if (backend == NULL) { gchar *path = project_import_dialog_get_name (import_dialog); /* show the dialog since it may be hidden */ gtk_widget_show (GTK_WIDGET (import_dialog)); anjuta_util_dialog_error (GTK_WINDOW (import_dialog), _("Could not find a valid project backend for the " "given directory (%s). Please select a different " "directory, or try upgrading to a newer version of " "Anjuta."), path); g_free (path); return FALSE; } name = project_import_dialog_get_name (import_dialog); project_file_name = g_strconcat (name, ".", "anjuta", NULL); GFile *project_file = g_file_get_child (source_dir, project_file_name); g_free (name); g_free (project_file_name); IAnjutaFileLoader* loader; if (!project_import_generate_file (backend, import_dialog, project_file)) { g_object_unref (project_file); return FALSE; } loader = anjuta_shell_get_interface (ANJUTA_PLUGIN (import_plugin)->shell, IAnjutaFileLoader, NULL); if (!loader) { g_warning("No IAnjutaFileLoader interface! Cannot open project file!"); g_object_unref (project_file); return TRUE; } ianjuta_file_loader_load (loader, project_file, FALSE, NULL); g_object_unref (project_file); return TRUE; }