static void on_dialog_response(GtkDialog* dialog, gint response_id, gpointer user_data) { QuickOpenPlugin* self = user_data; gtk_widget_hide(GTK_WIDGET(dialog)); if (response_id == GTK_RESPONSE_ACCEPT) { GObject* object; object = quick_open_dialog_get_selected_object(self->dialog); if (!object) return; if (IANJUTA_IS_DOCUMENT(object)) { ianjuta_document_manager_set_current_document(self->docman, IANJUTA_DOCUMENT(object), NULL); } else if (G_IS_FILE(object)) { IAnjutaFileLoader* loader; loader = anjuta_shell_get_interface (ANJUTA_PLUGIN (self)->shell, IAnjutaFileLoader, NULL); g_return_if_fail (loader != NULL); ianjuta_file_loader_load (loader, G_FILE(object), FALSE, NULL); } g_object_unref(object); } }
void on_recent_project_activated (GtkListBox *box, GtkListBoxRow *row, gpointer user_data) { GFile *file; IAnjutaFileLoader *loader; loader = anjuta_shell_get_interface (anjuta_plugin_get_shell (ANJUTA_PLUGIN (user_data)), IAnjutaFileLoader, NULL); file = g_file_new_for_uri ((const char*) g_object_get_data (G_OBJECT (row), URI_KEY)); ianjuta_file_loader_load (IANJUTA_FILE_LOADER (loader), file, FALSE, NULL); }
static void on_file_view_open_file (AnjutaFileView* view, GFile* file, AnjutaFileManager* file_manager) { IAnjutaFileLoader *loader; g_return_if_fail (file != NULL); loader = anjuta_shell_get_interface (ANJUTA_PLUGIN (file_manager)->shell, IAnjutaFileLoader, NULL); g_return_if_fail (loader != NULL); ianjuta_file_loader_load (loader, file, FALSE, NULL); }
static void recent_project_clicked_cb (GtkButton *button, Starter *wcm) { GFile *file; IAnjutaFileLoader *loader = anjuta_shell_get_interface (wcm->priv->shell, IAnjutaFileLoader, NULL); file = g_object_get_data (G_OBJECT (button), "file"); ianjuta_file_loader_load (IANJUTA_FILE_LOADER (loader), file, FALSE, NULL); }
static void ifile_open (IAnjutaFile *ifile, GFile* file, GError **err) { AnjutaProjectImportPlugin* plugin = ANJUTA_PLUGIN_PROJECT_IMPORT (ifile); gchar *mime_type; g_return_if_fail (G_IS_FILE (file)); mime_type = anjuta_util_get_file_mime_type (file); if (g_strcmp0 (mime_type,"application/x-anjuta-old") == 0) { /* Automatically import old Anjuta project */ gchar *ext, *project_name; GFile *dir; ProjectImportDialog* pi; AnjutaPluginManager *plugin_manager; dir = g_file_get_parent (file); project_name = g_file_get_basename (file); ext = strrchr (project_name, '.'); if (ext) *ext = '\0'; plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN (plugin)->shell, NULL); pi = project_import_dialog_new (plugin_manager, project_name, dir); g_signal_connect (pi, "response", G_CALLBACK (import_dialog_response), plugin); gtk_widget_show (GTK_WIDGET (pi)); g_object_unref (dir); g_free (project_name); } else if (g_strcmp0 (mime_type,"inode/directory") == 0) { GFileEnumerator *dir; dir = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (dir) { /* Look for anjuta project file in the directory */ GFileInfo *info; for (info = g_file_enumerator_next_file (dir, NULL, NULL); info != NULL; info = g_file_enumerator_next_file (dir, NULL, NULL)) { gchar *mime_type = anjuta_util_get_file_info_mime_type (info); if (g_strcmp0 (mime_type, "application/x-anjuta") == 0) { /* Open the first anjuta project file */ IAnjutaFileLoader *loader; loader = anjuta_shell_get_interface(ANJUTA_PLUGIN (plugin)->shell, IAnjutaFileLoader, NULL); if (loader != NULL) { GFile* project_file = g_file_get_child (file, g_file_info_get_name(info)); ianjuta_file_loader_load(loader, project_file, FALSE, NULL); g_object_unref (project_file); } g_free (mime_type); g_object_unref (info); break; } g_free (mime_type); g_object_unref (info); } if (info == NULL) { /* Else import the directory */ ProjectImportDialog* pi; AnjutaPluginManager *plugin_manager; gchar *basename; plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN (plugin)->shell, NULL); basename = g_file_get_basename (file); pi = project_import_dialog_new (plugin_manager, basename, file); g_free (basename); g_signal_connect (pi, "response", G_CALLBACK (import_dialog_response), plugin); gtk_widget_show (GTK_WIDGET (pi)); } g_object_unref (dir); } } g_free (mime_type); }
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; }