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); }
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); }
static void on_entry_activate(GtkEntry *entry, EDITOR *editor) { const gchar *buf = gtk_entry_get_text(entry); if (buf == NULL) return; /* handle potential subsection anchor */ if ((settings.special_anchor = strchr(buf, '#')) || /* thml */ (settings.special_anchor = strchr(buf, '!'))) /* osisref */ *settings.special_anchor = '\0'; const gchar *gkey = main_get_valid_key(settings.MainWindowModule, (gchar *)buf); // we got a valid key. but was it really a valid key within v11n? // for future use in determining whether to show normal navbar content. editor->navbar.valid_key = main_is_Bible_key(settings.MainWindowModule, gkey); if (settings.special_anchor) *settings.special_anchor = '#'; /* put it back. */ if (gkey == NULL) return; gchar *url = g_strdup_printf("sword:///%s%s", gkey, (settings.special_anchor ? settings.special_anchor : "")); editor->navbar.module_name = g_string_assign(editor->navbar.module_name, settings.MainWindowModule); main_navbar_versekey_set(editor->navbar, gkey); editor_load_note(editor, NULL, gkey); if (url) g_free(url); if (gkey) g_free((gchar *)gkey); }