void on_save_all1_activate(GtkMenuItem *menuitem, gpointer user_data) { guint i, max = (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); GeanyDocument *doc, *cur_doc = document_get_current(); guint count = 0; /* iterate over documents in tabs order */ for (i = 0; i < max; i++) { doc = document_get_from_page(i); if (! doc->changed) continue; if (document_save_file(doc, FALSE)) count++; } if (!count) return; ui_set_statusbar(FALSE, ngettext("%d file saved.", "%d files saved.", count), count); /* saving may have changed window title, sidebar for another doc, so update */ document_show_tab(cur_doc); sidebar_update_tag_list(cur_doc, TRUE); ui_set_window_title(cur_doc); }
static void instantsave_document_new_cb(GObject *obj, GeanyDocument *doc, gpointer user_data) { if (enable_instantsave && doc->file_name == NULL) { gchar *new_filename; gint fd; GeanyFiletype *ft = doc->file_type; fd = g_file_open_tmp("gis_XXXXXX", &new_filename, NULL); if (fd != -1) close(fd); /* close the returned file descriptor as we only need the filename */ if (ft == NULL || ft->id == GEANY_FILETYPES_NONE) /* ft is NULL when a new file without template was opened, so use the * configured default file type */ ft = filetypes_lookup_by_name(instantsave_default_ft); if (ft != NULL) /* add the filetype's default extension to the new filename */ SETPTR(new_filename, g_strconcat(new_filename, ".", ft->extension, NULL)); doc->file_name = new_filename; if (doc->file_type->id == GEANY_FILETYPES_NONE) document_set_filetype(doc, filetypes_lookup_by_name(instantsave_default_ft)); /* force saving the file to enable all the related actions(tab name, filetype, etc.) */ document_save_file(doc, TRUE); } }
static gboolean on_save(gboolean force) { GeanyDocument *doc = document_get_current(); if (doc != NULL) return document_save_file(doc, force); return TRUE; }
static gboolean on_save_all(gboolean force) { gint i; gboolean success = TRUE; foreach_document(i) success = success && document_save_file(documents[i], force); return success; }
void on_save1_activate(GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); if (doc != NULL) { document_save_file(doc, ui_prefs.allow_always_save); } }
/* Save when focus out * * @param pointer ref to the current doc (struct GeanyDocument *) * * @return always FALSE = Just a one shot execution * */ static gboolean save_on_focus_out_idle(gpointer p_cur_doc) { GeanyDocument *cur_doc = p_cur_doc; if (DOC_VALID(cur_doc) && (cur_doc->file_name != NULL)) document_save_file(cur_doc, FALSE); return FALSE; }
static void on_build_start(GObject *obj, gpointer user_data) { guint i; foreach_document(i) { if (prjorg_project_is_in_project(documents[i]->file_name)) document_save_file(documents[i], FALSE); } }
static gboolean auto_save(gpointer data) { GeanyDocument *doc; GeanyDocument *cur_doc = document_get_current(); gint i, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(geany->main_widgets->notebook)); gint saved_files = 0; if (cur_doc == NULL) return TRUE; if (autosave_save_all) { for (i = 0; i < max; i++) { doc = document_get_from_page(i); /* skip current file (save it last), skip files without name */ if (doc != cur_doc && doc->file_name != NULL) if (document_save_file(doc, FALSE)) saved_files++; } } /* finally save current file, do it after all other files to get correct window title and * symbol list */ if (cur_doc->file_name != NULL) if (document_save_file(cur_doc, FALSE)) saved_files++; if (saved_files > 0 && autosave_print_msg) ui_set_statusbar(FALSE, ngettext( "Autosave: Saved %d file automatically.", "Autosave: Saved %d files automatically.", saved_files), saved_files); return TRUE; }
static PyObject* Document_save_file(Document *self, PyObject *args, PyObject *kwargs) { gboolean result; gint force = 0; static gchar *kwlist[] = { "force", NULL }; if (PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &force)) { result = document_save_file(self->doc, (gboolean) force); if (result) Py_RETURN_TRUE; else Py_RETURN_FALSE; } Py_RETURN_NONE; }
/* (tries to) refresh the tag list to the file's current state */ static void refresh_tag_list (TMSourceFile *tm_wo, ScintillaObject *sci, GeanyDocument *doc) { /* gint len; guchar *buf; len = sci_get_length (sci); buf = g_malloc (len + 1); sci_get_text (sci, len + 1, (gchar *)buf); tm_source_file_buffer_update (tm_wo, buf, len, TRUE); g_free (buf); //*/ if (GGD_OPT_save_to_refresh) { document_save_file (doc, FALSE); } }
/* Callback for sending file as attachment */ static void send_as_attachment(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { GeanyDocument *doc; gchar *locale_filename = NULL; gchar *command = NULL; GError *error = NULL; GString *cmd_str = NULL; gchar *data; doc = document_get_current(); if (doc->file_name == NULL) { dialogs_show_save_as(); } else { document_save_file(doc, FALSE); } if (doc->file_name != NULL) { if (mailer) { locale_filename = utils_get_locale_from_utf8(doc->file_name); cmd_str = g_string_new(mailer); if ((use_address_dialog == TRUE) && (g_strrstr(mailer, "%r") != NULL)) { GKeyFile *config = NULL; gchar *config_dir = NULL; gchar *input = dialogs_show_input(_("Recipient's Address"), GTK_WINDOW(geany->main_widgets->window), _("Enter the recipient's e-mail address:"), address); if (input) { config = g_key_file_new(); g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_free(address); address = input; g_key_file_set_string(config, "tools", "address", address); } else { g_string_free(cmd_str, TRUE); g_free(locale_filename); return; } config_dir = g_path_get_dirname(config_file); if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, data); g_free(data); } g_key_file_free(config); g_free(config_dir); } if (! utils_string_replace_all(cmd_str, "%f", locale_filename)) ui_set_statusbar(FALSE, _("Filename placeholder not found. The executed command might have failed.")); if (use_address_dialog == TRUE && address != NULL) { if (! utils_string_replace_all(cmd_str, "%r", address)) ui_set_statusbar(FALSE, _("Recipient address placeholder not found. The executed command might have failed.")); } else { /* Removes %r if option was not activ but was included into command */ utils_string_replace_all(cmd_str, "%r", ""); } utils_string_replace_all(cmd_str, "%b", g_path_get_basename(locale_filename)); command = g_string_free(cmd_str, FALSE); g_spawn_command_line_async(command, &error); if (error != NULL) { ui_set_statusbar(FALSE, _("Could not execute mailer. Please check your configuration.")); g_error_free(error); } g_free(locale_filename); g_free(command); } else { ui_set_statusbar(FALSE, _("Please define a mail client first.")); } } else { ui_set_statusbar(FALSE, _("File has to be saved before sending.")); } }