void on_git_branch_delete_activated (GtkAction *action, Git *plugin) { gchar *selected_branch; GList *branches; GitBranchDeleteCommand *delete_command; selected_branch = git_branches_pane_get_selected_branch (GIT_BRANCHES_PANE (plugin->branches_pane)); if (anjuta_util_dialog_boolean_question (NULL, FALSE, _("Are you sure you want to delete branch %s?"), selected_branch)) { branches = g_list_append (NULL, selected_branch); delete_command = git_branch_delete_command_new (plugin->project_root_directory, branches, git_branches_pane_is_selected_branch_remote (GIT_BRANCHES_PANE (plugin->branches_pane)), FALSE); g_list_free (branches); g_signal_connect (G_OBJECT (delete_command), "command-finished", G_CALLBACK (git_pane_report_errors), plugin); g_signal_connect (G_OBJECT (delete_command), "command-finished", G_CALLBACK (g_object_unref), NULL); anjuta_command_start (ANJUTA_COMMAND (delete_command)); } g_free (selected_branch); }
static BuildContext* build_save_distclean_and_execute_command (BasicAutotoolsPlugin* bplugin, BuildProgram *prog, gboolean with_view, GError **err) { BuildContext *context; gchar *root_path; gboolean same; BuildConfiguration *config; GList *vars; context = build_get_context (bplugin, prog->work_dir, with_view); root_path = g_file_get_path (bplugin->project_root_dir); same = strcmp (prog->work_dir, root_path) != 0; g_free (root_path); config = build_configuration_list_get_selected (bplugin->configurations); vars = build_configuration_get_variables (config); if (!same && directory_has_file (bplugin->project_root_dir, "config.status")) { BuildProgram *new_prog; // Need to run make clean before if (!anjuta_util_dialog_boolean_question (GTK_WINDOW (ANJUTA_PLUGIN (bplugin)->shell), _("Before using this new configuration, the default one needs to be removed. Do you want to do that ?"), NULL)) { if (err) *err = g_error_new (ianjuta_builder_error_quark (), IANJUTA_BUILDER_CANCELED, _("Command canceled by user")); return NULL; } new_prog = build_program_new_with_command (bplugin->project_root_dir, "%s", CHOOSE_COMMAND (bplugin, DISTCLEAN)); build_program_set_callback (new_prog, build_execute_after_command, prog); prog = new_prog; } build_program_add_env_list (prog, vars); build_set_command_in_context (context, prog); build_save_and_execute_command_in_context (context, NULL); return context; }
static gboolean project_import_generate_file (AnjutaPluginDescription *backend, ProjectImportDialog *import_dialog, GFile *project_file) { /* Of course we could do some more intelligent stuff here * and check which plugins are really needed */ GFile* source_file = NULL; gchar *backend_id = NULL; GError* error = NULL; if (!anjuta_plugin_description_get_string (backend, "Project", "Supported-Project-Types", &backend_id)) { if (!strcmp (backend_id, "automake")) source_file = g_file_new_for_path (AM_PROJECT_FILE); else if (!strcmp (backend_id, "make")) source_file = g_file_new_for_path (MKFILE_PROJECT_FILE); else if (!strcmp (backend_id, "directory")) source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE); } g_free (backend_id); if (source_file != NULL) { /* Use a default project file */ if (!g_file_copy (source_file, project_file, G_FILE_COPY_NONE, NULL, NULL, NULL, &error)) { if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_EXISTS) { gchar *prjfile = g_file_get_parse_name (project_file); if (anjuta_util_dialog_boolean_question (GTK_WINDOW (import_dialog), FALSE, _("A file named \"%s\" already exists. " "Do you want to replace it?"), prjfile)) { g_error_free (error); error = NULL; g_file_copy (source_file, project_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error); } g_free (prjfile); } } if (!error) { time_t ctime = time(NULL); GFileInfo* file_info = g_file_info_new(); g_file_info_set_attribute_uint64(file_info, "time::modified", ctime); g_file_info_set_attribute_uint64(file_info, "time::created", ctime); g_file_info_set_attribute_uint64(file_info, "time::access", ctime); g_file_set_attributes_from_info (project_file, file_info, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (G_OBJECT(file_info));; } } else { /* For unknown project backend we use the directory project file and * replace the backend plugin with the right one */ gchar *content; gsize length; source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE); if (g_file_load_contents (source_file, NULL, &content, &length, NULL, &error)) { GString *buffer; const gchar *pos; const gchar *plugin; const gchar *end_plugin; gssize len; buffer = g_string_new_len (content, length); pos = buffer->str; len = buffer->len; for (;;) { plugin = g_strstr_len (pos, len, "<plugin "); if (plugin == NULL) break; end_plugin = g_strstr_len (plugin, len - (plugin - pos), "</plugin>"); if (end_plugin == NULL) break; if (g_strstr_len (plugin, end_plugin - plugin, "\"IAnjutaProjectBackend\"") != NULL) break; pos = end_plugin + 9; len -= (end_plugin + 9 - pos); } if ((plugin == NULL) || (end_plugin == NULL)) { g_set_error (&error, ianjuta_project_backend_error_quark(),0, "Unable to find backend plugin"); } else { /* Replace directory backend with right one */ GString *str; GFileOutputStream *stream; gchar *name = NULL; gchar *plugin_id = NULL; anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Name", &name); anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Location", &plugin_id); str = g_string_new (NULL); g_string_printf (str, "<plugin name= \"%s\"\n" " mandatory=\"yes\">\n" " <require group=\"Anjuta Plugin\"\n" " attribute=\"Location\"\n" " value=\"%s\"/>\n" " <require group=\"Anjuta Plugin\"\n" " attribute=\"Interfaces\"\n" " value=\"IAnjutaProjectBackend\"/>\n" " ", name, plugin_id); g_string_erase (buffer, plugin - buffer->str, end_plugin - plugin); g_string_insert_len (buffer, plugin - buffer->str, str->str, str->len); g_string_free (str, TRUE); stream = g_file_create (project_file, G_FILE_CREATE_NONE, NULL, &error); if (stream == NULL && error->domain == G_IO_ERROR && error->code == G_IO_ERROR_EXISTS) { gchar *prjfile = g_file_get_parse_name (project_file); if (anjuta_util_dialog_boolean_question (GTK_WINDOW (import_dialog), FALSE, _("A file named \"%s\" already exists. " "Do you want to replace it?"), prjfile)) { g_error_free (error); error = NULL; stream = g_file_replace (project_file, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error); } g_free (prjfile); } if (stream != NULL) { gsize written; g_output_stream_write_all (G_OUTPUT_STREAM (stream), buffer->str, buffer->len, &written, NULL, &error); g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, NULL); } } g_string_free (buffer, TRUE); g_free (content); } } g_object_unref (source_file); if (error) { gchar *prjfile; prjfile = g_file_get_parse_name (project_file); /* show the dialog since it may be hidden */ gtk_widget_show (GTK_WIDGET (import_dialog)); anjuta_util_dialog_error (GTK_WINDOW (import_dialog), _("A file named \"%s\" cannot be written: %s. " "Check if you have write access to the project directory."), prjfile, error->message); g_free (prjfile); g_error_free (error); return FALSE; } return TRUE; }