void editor_load_note(EDITOR *e, const gchar *module_name, const gchar *key) { gchar *title = NULL, *text = NULL; if (e->is_changed) _save_note(e); if (module_name) { if (e->module) g_free(e->module); e->module = g_strdup(module_name); } if (key) { if (e->key) g_free(e->key); e->key = g_strdup(key); } text = main_get_raw_text((gchar *)e->module, (gchar *)e->key); if ((text == NULL) || strlen(text) == 0) { if (text) g_free(text); /* new empty document from template */ gchar *fname = g_build_filename(settings.gSwordDir, "studypad.spt", NULL); XI_message(("editor load NOTE [%s]", fname)); text = inhale_text_from_file(fname); g_free(fname); } if (text && strlen(text)) { webkit_web_view_load_string((WebKitWebView *) e->html_widget, text, "text/html", "utf_8", "file://"); } e->is_changed = FALSE; if (e->type == NOTE_EDITOR) { e->navbar.valid_key = TRUE; main_navbar_versekey_set(e->navbar, e->key); } if (text) g_free(text); title = g_strdup_printf("%s - %s", e->module, e->key); change_window_title(e->window, title); g_free(title); }
static void action_save_cb(GtkAction *action, EDITOR *e) { switch (e->type) { case STUDYPAD_EDITOR: _save_file(e); break; case NOTE_EDITOR: _save_note(e); break; case BOOK_EDITOR: _save_book(e); break; default: XI_message(("\naction_save_cb oops!\n")); break; } }
void editor_load_note(EDITOR *e, const gchar *module_name, const gchar *key) { gchar *title; gchar *text; if (editor_is_dirty(e)) _save_note(e); if (module_name) { if (e->module) g_free(e->module); e->module = g_strdup(module_name); } if (key) { if (e->key) g_free(e->key); e->key = g_strdup(key); } title = g_strdup_printf("%s - %s", e->module, e->key); text = main_get_raw_text((gchar *)e->module, (gchar *)e->key); if (strlen(text)) { gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window), text, strlen(text)); gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window)); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE); } else { gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window), "", strlen("")); gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window)); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE); } change_window_title(e->window, title); if (e->type == NOTE_EDITOR) main_navbar_versekey_set(e->navbar, e->key); if (text) g_free(text); if (title) g_free(title); }
G_MODULE_EXPORT void action_save_activate_cb(GtkWidget *widget, EDITOR *e) { switch (e->type) { case STUDYPAD_EDITOR: _save_file(e); break; case NOTE_EDITOR: _save_note(e); break; case BOOK_EDITOR: _save_book(e); break; default: XI_message(("\naction_save_cb oops!\n")); break; } }
gint editor_create_new(const gchar *filename, const gchar *key, gint editor_type) { GList *tmp = NULL; tmp = g_list_first(editors_all); while (tmp != NULL) { EDITOR *e = (EDITOR *)tmp->data; switch (editor_type) { case STUDYPAD_EDITOR: if (e->studypad) { if (editor_is_dirty(e)) _save_file(e); if (e->filename) g_free(e->filename); e->filename = g_strdup(filename); gtk_widget_show(e->window); gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window))); _load_file(e, g_strdup(filename)); return 1; } break; case NOTE_EDITOR: if (!e->noteeditor) break; if (editor_is_dirty(e)) _save_note(e); if (e->module) g_free(e->module); e->module = g_strdup(filename); if (e->key) g_free(e->key); e->key = g_strdup(key); gtk_widget_show(e->window); gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window))); editor_load_note(e, NULL, NULL); return 1; break; case BOOK_EDITOR: if (!e->bookeditor) break; if (editor_is_dirty(e)) _save_book(e); if (e->module) g_free(e->module); e->module = g_strdup(filename); if (e->key) g_free(e->key); e->key = g_strdup(key); gtk_widget_show(e->window); gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window))); main_load_book_tree_in_editor(GTK_TREE_VIEW(e->treeview), e->module); editor_load_book(e); return 1; break; } tmp = g_list_next(tmp); } XI_message(("filename %s, key %s", (filename ? filename : "-null-"), (key ? key : "-null-"))); return _create_new(filename, key, editor_type); }
static gint ask_about_saving(EDITOR *e) { gint test; GS_DIALOG *info; gchar *buf = NULL; gchar *buf1 = NULL; gchar *buf2 = NULL; gchar *buf3 = NULL; gint retval = FALSE; switch (e->type) { case BOOK_EDITOR: case NOTE_EDITOR: info = gui_new_dialog(); info->stock_icon = GTK_STOCK_DIALOG_WARNING; buf = g_strdup_printf("%s: %s", e->module, e->key); buf1 = _("Save the changes to document"); buf2 = _("before closing?"); buf3 = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s %s %s</span>", buf1, buf, buf2); info->label_top = buf3; info->label2 = _("If you don't save, changes will be permanently lost."); info->save = TRUE; info->cancel = TRUE; info->no_save = TRUE; test = gui_alert_dialog(info); retval = test; if (test == GS_YES) { if (e->type == NOTE_EDITOR) { /* save notes and prayer lists */ _save_note(e); } else { /* save notes and prayer lists */ _save_book(e); } } g_free(info); g_free(buf); g_free(buf3); break; case STUDYPAD_EDITOR: info = gui_new_dialog(); info->stock_icon = #ifdef HAVE_GTK_310 "dialog-warning"; #else GTK_STOCK_DIALOG_WARNING; #endif if (settings.studypadfilename) buf = settings.studypadfilename; else buf = N_("File"); buf1 = _("Save the changes to document"); buf2 = _("before closing?"); buf3 = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s %s %s</span>", buf1, buf, buf2); info->label_top = buf3; info->label2 = _("If you don't save, changes will be permanently lost."); info->save = TRUE; info->cancel = TRUE; info->no_save = TRUE; test = gui_alert_dialog(info); retval = test; if (test == GS_YES) { if (e->filename) gtkhtml_editor_save(GTKHTML_EDITOR(e->window), e->filename, TRUE, NULL); /*else open_or_save_as_dialog(e, OP_SAVE_THROUGH_PERSIST_FILE); */ } g_free(info); g_free(buf3); break; } sync_windows(); return retval; }