1 From: Bastian Germann <bage@debian.org>
2 Date: Sat, 27 Jun 2020 19:36:25 +0200
3 Subject: Disable webkit editor
6 src/editor/editor.c | 2 +-
7 src/editor/webkit_editor.c | 1065 +-----------------------------------
8 2 files changed, 3 insertions(+), 1064 deletions(-)
10 diff --git a/src/editor/editor.c b/src/editor/editor.c
11 index 0a7cab4..006eeeb 100644
12 --- a/src/editor/editor.c
13 +++ b/src/editor/editor.c
18 -#ifdef USE_WEBKIT_EDITOR
19 +#ifndef USE_WEBKIT_EDITOR
21 /* X keyboard #definitions, to handle shortcuts */
22 /* we must define the categories of #definitions we need. */
23 diff --git a/src/editor/webkit_editor.c b/src/editor/webkit_editor.c
24 index 8299d23..8507f64 100644
25 --- a/src/editor/webkit_editor.c
26 +++ b/src/editor/webkit_editor.c
31 -#include <webkit/webkit.h>
35 @@ -93,7 +92,6 @@ static void
36 on_about_dialog_response(GtkDialog *dialog,
37 gint response_id, gpointer user_data)
39 - gtk_widget_destroy(GTK_WIDGET(dialog));
42 /******************************************************************************
43 @@ -115,39 +113,21 @@ on_about_dialog_response(GtkDialog *dialog,
45 action_about_activate_cb(GtkWidget *widget, EDITOR *e)
48 - GdkPixbuf *about_logo;
50 - about_logo = pixbuf_finder("xiphos-button-125.png", 0, NULL);
51 - about = gtk_about_dialog_new();
53 - g_signal_connect(about, "response",
54 - G_CALLBACK(on_about_dialog_response), NULL);
55 - gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(about), "WebKit editor, Xiphos");
56 - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), (gchar *)VERSION);
57 - gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), "Replacement for gtkhtml editor");
58 - gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about), about_logo);
59 - set_window_icon(GTK_WINDOW(about));
60 - gtk_widget_show(about);
64 action_increase_indent_activate_cb(GtkWidget *widget, EDITOR *e)
66 - editor_execute_script("document.execCommand('Indent', false, false);", e);
67 - editor_insert_new_outline_level(e->toolitems.outline_level, e);
71 action_decrease_indent_activate_cb(GtkWidget *widget, EDITOR *e)
73 - editor_execute_script("document.execCommand('Outdent', false, false);", e);
77 action_insert_rule_activate_cb(GtkWidget *widget, EDITOR *e)
79 - editor_insert_html("<hr>", e);
83 @@ -158,141 +138,80 @@ action_insert_table_activate_cb(GtkWidget *widget, EDITOR *e)
85 action_insert_emoticon_activate_cb(GtkWidget *widget, EDITOR *e)
87 - // This is stupid, if we don't have emoticons working, then we sould
88 - // remove the button users see.
90 - //script = g_strdup ("document.execCommand('', null, \"\");");
94 action_insert_image_activate_cb(GtkWidget *widget, EDITOR *e)
96 - gchar *filename = NULL;
98 - GtkWidget *dialog = gtk_file_chooser_dialog_new("Select an image file",
100 - GTK_FILE_CHOOSER_ACTION_OPEN,
101 -#if GTK_CHECK_VERSION(3, 10, 0)
102 - "_Cancel", GTK_RESPONSE_CANCEL,
103 - "_OK", GTK_RESPONSE_ACCEPT,
106 - GTK_RESPONSE_CANCEL,
107 - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
111 - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
112 - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
113 - gchar *script = g_strdup_printf("document.execCommand('insertImage', null, '%s');", filename);
114 - editor_execute_script(script, e);
120 - gtk_widget_destroy(dialog);
124 action_insert_outline_activate_cb(GtkWidget *widget, EDITOR *e)
126 - editor_execute_script("document.execCommand('insertHTML', null, \"<OL CLASS=L1><LI> </LI></OL> \");", e);
130 action_justify_right_activate_cb(GtkWidget *widget, EDITOR *e)
132 - editor_execute_script("document.execCommand('justifyright', false, false);", e);
136 action_justify_left_activate_cb(GtkWidget *widget, EDITOR *e)
138 - editor_execute_script("document.execCommand('justifyleft', false, false);", e);
142 action_justify_center_activate_cb(GtkWidget *widget, EDITOR *e)
144 - editor_execute_script("document.execCommand('justifycenter', false, false);", e);
148 action_justify_full_activate_cb(GtkWidget *widget, EDITOR *e)
150 - editor_execute_script("document.execCommand('justifyfull', false, false);", e);
154 action_bold_activate_cb(GtkWidget *widget, EDITOR *e)
156 - if (buttons_state.nochange)
159 - editor_execute_script("document.execCommand('bold',false,false);", e);
163 action_italic_activate_cb(GtkWidget *widget, EDITOR *e)
165 - //extern BUTTONS_STATE buttons_state;
166 - if (buttons_state.nochange)
169 - editor_execute_script("document.execCommand('italic',false,false);", e);
173 action_undo_activate_cb(GtkWidget *widget, EDITOR *e)
175 - editor_execute_script("document.execCommand('undo',false,false);", e);
179 action_redo_activate_cb(GtkWidget *widget, EDITOR *e)
181 - editor_execute_script("document.execCommand('redo',false,false);", e);
185 action_underline_activate_cb(GtkWidget *widget, EDITOR *e)
187 - //extern BUTTONS_STATE buttons_state;
188 - if (buttons_state.nochange)
191 - editor_execute_script("document.execCommand('underline', false, false);", e);
195 action_strikethrough_activate_cb(GtkWidget *widget, EDITOR *e)
197 - //extern BUTTONS_STATE buttons_state;
198 - if (buttons_state.nochange)
201 - editor_execute_script("document.execCommand('strikethrough', false, false);", e);
204 G_MODULE_EXPORT void action_cut_activate_cb(GtkWidget *widget, EDITOR *e)
210 action_copy_activate_cb(GtkWidget *widget, EDITOR *e)
212 - if (editor_copy(e))
213 - XI_message(("%s", "copy success"));
215 - XI_message(("%s", "copy failed"));
219 action_paste_activate_cb(GtkWidget *widget, EDITOR *e)
225 @@ -303,737 +222,93 @@ action_delete_activate_cb(GtkWidget *widget, EDITOR *e)
227 action_delete_item_activate_cb(GtkWidget *widget, EDITOR *e)
233 - g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s %s?</span>",
234 - _("Are you sure you want to delete the note for"), e->key);
236 - if (gui_yes_no_dialog(buf,
237 -#if GTK_CHECK_VERSION(3, 10, 0)
240 - GTK_STOCK_DIALOG_WARNING
244 - main_delete_note(e->module, e->key);
246 - /* new empty document from template */
247 - gchar *fname = g_build_filename(settings.gSwordDir, "studypad.spt", NULL);
248 - XI_message(("action delete item [%s]", fname));
249 - gchar *text = inhale_text_from_file(fname);
252 - if (text && strlen(text)) {
253 - webkit_web_view_load_string((WebKitWebView *)
256 - "application/xhtml+xml", "utf_8",
264 - e->is_changed = FALSE;
267 void set_button_state(BUTTONS_STATE state, EDITOR *e)
269 -#if GTK_CHECK_VERSION(3, 4, 0)
274 - gtk_toggle_tool_button_set_active(e->toolitems.bold, state.bold);
275 - gtk_toggle_tool_button_set_active(e->toolitems.italic, state.italic);
276 - gtk_toggle_tool_button_set_active(e->toolitems.underline, state.underline);
277 - gtk_toggle_tool_button_set_active(e->toolitems.strike, state.strike);
278 - gtk_combo_box_set_active((GtkComboBox *)e->toolitems.cb, state.style);
281 - XI_message(("state.color: %s", state.color));
282 -#if GTK_CHECK_VERSION(3, 4, 0)
283 - if (gdk_rgba_parse(&rgba, state.color))
284 - gtk_color_chooser_set_rgba((GtkColorChooser *)
285 - e->toolitems.color,
288 - if (gdk_color_parse(state.color, &color))
289 - gtk_color_button_set_color((GtkColorButton *)
290 - e->toolitems.color,
297 colorbutton1_color_set_cb(GtkColorButton *widget, EDITOR *e)
299 -#if GTK_CHECK_VERSION(3, 4, 0)
305 - gchar *forecolor = NULL;
307 -#if GTK_CHECK_VERSION(3, 4, 0)
308 - gtk_color_chooser_get_rgba((GtkColorChooser *)widget, &color);
309 - color_str = gdk_rgba_to_string(&color);
311 - gtk_color_button_get_color((GtkColorButton *)widget, &color);
312 - /* FIXME: ugly need something better */
313 - color_str = g_strdup_printf("rgb(%u,%u,%u)", color.red >> 8, color.green >> 8, color.blue >> 8);
315 - forecolor = g_strdup_printf("document.execCommand('forecolor', null, '%s');", color_str);
316 - editor_execute_script(forecolor, e);
322 colorbutton_highlight_color_set_cb(GtkColorButton *widget, EDITOR *e)
325 -#if GTK_CHECK_VERSION(3, 4, 0)
331 - gchar *highlightcolor = NULL;
333 -#if GTK_CHECK_VERSION(3, 4, 0)
334 - gtk_color_chooser_get_rgba((GtkColorChooser *)widget, &color);
335 - color_str = gdk_rgba_to_string(&color);
337 - gtk_color_button_get_color((GtkColorButton *)widget, &color);
338 - /* FIXME: ugly need something better */
339 - color_str = g_strdup_printf("rgb(%u,%u,%u)", color.red >> 8, color.green >> 8, color.blue >> 8);
341 - highlightcolor = g_strdup_printf("document.execCommand('backColor', null, '%s');", color_str);
342 - editor_execute_script(highlightcolor, e);
343 - g_free(highlightcolor);
347 -static gchar *get_font_size_from_name(GString *fontname)
350 - gint len, i = 0, j = 0;
352 - len = fontname->len;
353 - XI_message(("\nlength: %d\n", len));
354 - for (i = 0; (i < 79 && i < len); i++) {
355 - if (isdigit(fontname->str[i])) {
356 - XI_message(("\n\nfontname->str[i]: %c",
357 - fontname->str[i]));
358 - buf[j] = fontname->str[i];
363 - return g_strdup(buf);
366 -G_MODULE_EXPORT void
367 -action_font_activate_cb(GtkWidget *widget, EDITOR *e)
370 - gchar *selected_text = NULL;
371 - gchar *size = NULL;
372 -#if GTK_CHECK_VERSION(3, 2, 0)
373 - dialog = gtk_font_chooser_dialog_new("Select font", NULL);
374 - gtk_font_chooser_set_font((GtkFontChooser *)dialog,
376 - dialog = gtk_font_selection_dialog_new("Select font");
377 - gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)
382 - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
383 -#if GTK_CHECK_VERSION(3, 2, 0)
384 - const gchar *fontname = gtk_font_chooser_get_font((GtkFontChooser *)dialog);
386 - const gchar *fontname = gtk_font_selection_dialog_get_font_name((GtkFontSelectionDialog *)dialog);
388 - GString *name = g_string_new(fontname);
389 - size = get_font_size_from_name(name);
390 - g_string_free(name, TRUE);
392 - selected_text = editor_get_selected_text(e);
393 -#if GTK_CHECK_VERSION(3, 2, 0)
394 - PangoFontDescription *font_description =
395 - gtk_font_chooser_get_font_desc((GtkFontChooser *)
397 - fontname = pango_font_description_get_family(font_description);
399 - PangoFontDescription *font_description =
400 - pango_font_description_from_string(fontname);
401 - fontname = pango_font_description_get_family(font_description);
404 - gchar *script = g_strdup_printf("<SPAN STYLE=\"font-family:%s;font-size:%spx;\">%s</SPAN>",
405 - fontname, size, selected_text);
407 - editor_insert_html(script, e);
413 - g_free(selected_text);
414 - gtk_widget_destroy(dialog);
418 find_replace_response_cb(GtkDialog *dialog, gint response_id, EDITOR *e)
420 - switch (response_id) {
421 - case GTK_RESPONSE_CANCEL:
422 - gtk_widget_hide(find_dialog.window);
425 - editor_find_string((gchar *)
426 - gtk_entry_get_text(GTK_ENTRY(find_dialog.find_entry)),
430 - editor_replace_string((gchar *)
431 - gtk_entry_get_text(GTK_ENTRY(find_dialog.find_entry)),
433 - gtk_entry_get_text(GTK_ENTRY(find_dialog.replace_entry)),
437 - gtk_widget_hide(find_dialog.window);
443 action_find_activate_cb(GtkWidget *widget, EDITOR *e)
445 - gtk_widget_show(find_dialog.window);
446 - gtk_widget_hide(find_dialog.box_replace);
447 - gtk_widget_hide(find_dialog.button_replace);
451 action_replace_activate_cb(GtkWidget *widget, EDITOR *e)
453 - gtk_widget_show(find_dialog.window);
454 - gtk_widget_show(find_dialog.box_replace);
455 - gtk_widget_show(find_dialog.button_replace);
458 -static void handle_error(GError **error)
460 - if (*error != NULL) {
461 - g_warning("%s", (*error)->message);
462 - g_clear_error(error);
466 -static void do_exit(EDITOR *e)
469 - g_free(e->filename);
478 - gtk_widget_destroy(e->window);
482 -static void recent_item_cb(GtkRecentChooser *chooser, EDITOR *e)
484 - gchar *file_uri = gtk_recent_chooser_get_current_uri(chooser);
486 - XI_message(("file_uri: %s", file_uri));
488 - g_free(e->filename);
489 - e->filename = g_strdup(file_uri);
491 - //editor_open_recent (file_uri, e);
492 - _load_file(e, file_uri);
493 - xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
494 - settings.studypadfilename = xml_get_value("studypad", "lastfile");
496 - change_window_title(e->window, e->filename);
499 -static void change_window_title(GtkWidget *window, const gchar *window_title)
501 - gtk_window_set_title(GTK_WINDOW(window), window_title);
504 -static GtkPrintOperationResult
505 -print(WebKitWebView *html, GtkPrintOperationAction action)
507 - GtkPrintOperation *operation;
508 - GtkPrintOperationResult result;
509 - GError *error = NULL;
510 - WebKitWebFrame *frame;
512 - frame = webkit_web_view_get_main_frame(html);
513 - operation = gtk_print_operation_new();
515 - result = webkit_web_frame_print_full(frame, operation, action, &error);
517 - g_object_unref(operation);
518 - handle_error(&error);
523 -static gint open_dialog(EDITOR *e)
528 - dialog = gtk_file_chooser_dialog_new(_("Open"), GTK_WINDOW(e->window),
529 - GTK_FILE_CHOOSER_ACTION_OPEN,
530 -#if GTK_CHECK_VERSION(3, 10, 0)
531 - "_Cancel", GTK_RESPONSE_CANCEL,
532 - "_Open", GTK_RESPONSE_ACCEPT,
535 - GTK_RESPONSE_CANCEL,
537 - GTK_RESPONSE_ACCEPT,
541 - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), settings.studypaddir);
543 - response = gtk_dialog_run(GTK_DIALOG(dialog));
545 - if (response == GTK_RESPONSE_ACCEPT) {
546 - gchar *new_filename;
548 - new_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
549 - _load_file(e, new_filename);
550 - g_free(new_filename);
553 - gtk_widget_destroy(dialog);
558 G_MODULE_EXPORT void action_print_cb(GtkAction *action, EDITOR *e)
560 - print(WEBKIT_WEB_VIEW(e->html_widget),
561 - GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
564 G_MODULE_EXPORT void action_print_preview_cb(GtkAction *action, EDITOR *e)
566 - print(WEBKIT_WEB_VIEW(e->html_widget),
567 - GTK_PRINT_OPERATION_ACTION_PREVIEW);
570 G_MODULE_EXPORT void action_quit_activate_cb(GtkWidget *widget, EDITOR *e)
572 - delete_event(NULL, NULL, e);
575 G_MODULE_EXPORT void action_open_activate_cb(GtkWidget *widget, EDITOR *e)
580 G_MODULE_EXPORT void action_save_activate_cb(GtkWidget *widget, EDITOR *e)
583 - case STUDYPAD_EDITOR:
593 - XI_message(("\naction_save_cb oops!\n"));
598 G_MODULE_EXPORT void action_new_activate_cb(GtkWidget *widget, EDITOR *e)
599 { /* for studypad only */
600 - gchar *filename = NULL;
603 - ask_about_saving(e);
605 - filename = g_strdup_printf("%s/%s", settings.gSwordDir, "studypad.spt");
607 - _load_file(e, filename);
610 - g_free(e->filename);
611 - e->filename = g_strdup(_("Untitled document"));
613 - xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
614 - settings.studypadfilename = xml_get_value("studypad", "lastfile");
615 - change_window_title(e->window, e->filename);
616 - e->is_changed = TRUE;
620 action_insert_sword_link_activate_cb(GtkWidget *widget, gpointer data)
622 - editor_link_dialog(data); //editor_insert_sword_link();
626 action_insert_link_activate_cb(GtkWidget *widget, EDITOR *e)
628 - editor_link_dialog(e);
632 action_save_as_activate_cb(GtkWidget *widget, EDITOR *e)
635 - g_free(e->filename);
636 - e->filename = NULL;
640 G_MODULE_EXPORT void combo_box_changed_cb(GtkComboBox *widget, EDITOR *e)
642 - gchar *script = NULL;
643 - gint choice = gtk_combo_box_get_active(widget);
644 - /* we need the line of text where the cursor is */
645 - //extern BUTTONS_STATE buttons_state;
647 - if (buttons_state.nochange)
651 - case 0: /* Normal */
652 - script = "document.execCommand('formatBlock', false, \"div\");";
656 - script = "document.execCommand('formatBlock', null, \"H1\");";
660 - script = "document.execCommand('formatBlock', null, \"H2\");";
664 - script = "document.execCommand('formatBlock', null, \"H3\");";
668 - script = "document.execCommand('formatBlock', null, \"H4\");";
672 - script = "document.execCommand('formatBlock', null, \"H5\");";
676 - script = "document.execCommand('formatBlock', null, \"H6\");";
679 - case 7: /* Address */
680 - script = "document.execCommand('formatBlock', null, \"ADDRESS\");";
683 - case 8: /* Preformatted */
684 - script = "document.execCommand('formatBlock', null, \"PRE\");";
687 - case 9: /* Bulleted List insertUnorderedList */
688 - script = "document.execCommand('insertUnorderedList', null, \"\");";
691 - case 10: /* Roman Numeral List */
692 - script = "document.execCommand('insertHTML', null, \"<OL type=I><LI> </LI></OL> \");";
695 - case 11: /* Numbered List insertOrderedList */
696 - script = "document.execCommand('insertOrderedList', null, \"\");";
699 - case 12: /* Alphabetical List */
700 - script = "document.execCommand('insertHTML', null, \"<OL type=A><LI> </LI></OL> \");";
708 - XI_message(("%s", script));
709 - editor_execute_script(script, e);
713 -/* need note toolbars when type is note */
714 -static GtkWidget *editor_new(const gchar *title, EDITOR *e)
717 - GtkWidget *scrollwindow;
718 - GtkWidget *statusbar;
719 - GtkBuilder *builder;
720 - gchar *gbuilder_file;
721 - GError *error = NULL;
723 - GtkWidget *recent_item;
725 - buttons_state.nochange = 1;
727 - gbuilder_file = gui_general_user_file(
735 - builder = gtk_builder_new();
737 - if (!gtk_builder_add_from_file(builder, gbuilder_file, &error)) {
738 - g_warning("Couldn't load builder file: %s",
740 - g_error_free(error);
743 - window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
744 - e->window = window;
745 - gtk_window_set_title(GTK_WINDOW(window), title);
747 - statusbar = GTK_WIDGET(gtk_builder_get_object(builder, "statusbar1"));
748 - gtk_widget_hide(statusbar);
750 - e->toolitems.outline_level = 0;
751 - e->toolitems.bold = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "toolbutton_bold"));
752 - e->toolitems.italic = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "toolbutton_italic"));
753 - e->toolitems.underline = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "toolbuttonunderline"));
754 - e->toolitems.strike = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "toolbutton_strikethrough"));
755 - e->toolitems.open = GTK_TOOL_BUTTON(gtk_builder_get_object(builder, "toolbutton_open"));
756 - e->toolitems.newdoc = GTK_TOOL_BUTTON(gtk_builder_get_object(builder, "toolbutton_new"));
757 - e->toolitems.deletedoc = GTK_TOOL_BUTTON(gtk_builder_get_object(builder, "toolbutton_delete"));
758 - e->toolitems.color = GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "colorbutton1"));
759 - e->toolitems.cb = GTK_COMBO_BOX_TEXT(gtk_builder_get_object(builder, "comboboxtext1"));
761 - gtk_combo_box_set_active((GtkComboBox *)e->toolitems.cb, 0);
763 - item = GTK_MENU_ITEM(gtk_builder_get_object(builder, "menuitem_recent"));
766 - case STUDYPAD_EDITOR:
767 - gtk_widget_hide(GTK_WIDGET(e->toolitems.deletedoc));
769 - recent_item = gtk_recent_chooser_menu_new();
770 - g_signal_connect(G_OBJECT(recent_item), "item-activated",
771 - G_CALLBACK(recent_item_cb), e);
772 - gtk_menu_item_set_submenu(item, recent_item);
775 - gtk_widget_hide(GTK_WIDGET(e->toolitems.open));
776 - gtk_widget_hide(GTK_WIDGET(e->toolitems.newdoc));
777 - gtk_widget_hide(GTK_WIDGET(item));
780 - gtk_widget_hide(GTK_WIDGET(e->toolitems.open));
781 - gtk_widget_hide(GTK_WIDGET(e->toolitems.newdoc));
782 - gtk_widget_hide(GTK_WIDGET(item));
786 - e->navbar_box = GTK_WIDGET(gtk_builder_get_object(builder, "box_navbar"));
787 - e->box = GTK_WIDGET(gtk_builder_get_object(builder, "vbox1"));
789 - scrollwindow = GTK_WIDGET(gtk_builder_get_object(builder, "scrolledwindow1"));
790 - create_editor_window(scrollwindow, e);
791 - e->is_changed = FALSE;
793 - /* This is important */
794 - gtk_builder_connect_signals(builder, (EDITOR *)e);
796 - find_dialog.window = GTK_WIDGET(gtk_builder_get_object(builder, "dialog_find_replace"));
797 - find_dialog.find_entry = GTK_WIDGET(gtk_builder_get_object(builder, "entry1"));
798 - find_dialog.replace_entry = GTK_WIDGET(gtk_builder_get_object(builder, "entry2"));
799 - find_dialog.box_replace = GTK_WIDGET(gtk_builder_get_object(builder, "box4"));
800 - find_dialog.button_replace = GTK_WIDGET(gtk_builder_get_object(builder, "button_replace"));
802 - g_object_unref(builder);
807 -static void _save_note(EDITOR *e)
809 - GString *data = g_string_new("");
811 - editor_get_document_content(data, e);
812 - main_save_note(e->module, e->key, data->str);
813 - e->is_changed = FALSE;
814 - g_string_free(data, TRUE);
817 -static void _save_book(EDITOR *e)
819 - GString *data = g_string_new("");
821 - editor_get_document_content(data, e);
822 - main_treekey_save_book_text(e->module, e->key, data->str);
823 - e->is_changed = FALSE;
824 - g_string_free(data, TRUE);
827 -static void _save_file(EDITOR *e)
829 - GtkRecentManager *rm = NULL;
830 - GString *data = g_string_new("");
832 - editor_get_document_content(data, e);
833 - XI_message(("%s", data->str));
835 - if (!e->filename || (0 == g_strcmp0("Untitled document", e->filename)) || g_strrstr(e->filename, ".spt")) {
836 - GtkWidget *dialog = gtk_file_chooser_dialog_new("Save as", //const gchar *title,
837 - NULL, //GtkWindow *parent,
838 - GTK_FILE_CHOOSER_ACTION_SAVE, //GtkFileChooserAction action,
839 -#if GTK_CHECK_VERSION(3, 10, 0)
843 - GTK_RESPONSE_CANCEL,
848 - GTK_RESPONSE_CANCEL,
851 - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
853 - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
854 - settings.studypaddir);
855 - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
856 - gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
857 - e->filename = g_strdup(filename);
858 - GFile *gfile = g_file_parse_name(filename);
859 - g_file_replace_contents(gfile, data->str, data->len, NULL, TRUE, G_FILE_CREATE_NONE, NULL, NULL, NULL); //GError **error
861 - change_window_title(e->window, e->filename);
862 - gtk_widget_destroy(dialog);
866 - GFile *gfile = g_file_parse_name(e->filename);
867 - g_file_replace_contents(gfile, data->str, data->len, NULL, TRUE, G_FILE_CREATE_NONE, NULL, NULL, NULL); //GError **error
870 - rm = gtk_recent_manager_get_default();
871 - gtk_recent_manager_add_item(rm, e->filename);
873 - e->is_changed = FALSE;
874 - g_string_free(data, TRUE);
877 -static void _load_file(EDITOR *e, const gchar *filename)
880 - GtkRecentManager *rm = NULL;
882 - rm = gtk_recent_manager_get_default();
883 - gtk_recent_manager_add_item(rm, filename);
886 - g_free(e->filename);
887 - e->filename = g_strdup(filename);
889 - XI_message(("_load_file filename: %s", filename));
891 - xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
892 - settings.studypadfilename = xml_get_value("studypad", "lastfile");
894 - change_window_title(e->window, e->filename);
895 - text = inhale_text_from_file(!strncmp(filename, "file:", 5)
899 - XI_message(("web view load string [%s]", text));
900 - webkit_web_view_load_string(WEBKIT_WEB_VIEW(e->html_widget),
901 - text, "application/xhtml+xml", "utf_8", "file://");
904 - e->is_changed = FALSE;
907 gboolean editor_is_dirty(EDITOR *e)
909 - return e->is_changed;
913 void editor_save_book(EDITOR *e)
915 - if (editor_is_dirty(e))
919 /* save if needed is done in treeky-editor.c before calling editor_load_book() */
920 void editor_load_book(EDITOR *e)
922 - gchar *title = NULL, *text = NULL;
924 - if (!g_ascii_isdigit(e->key[0]))
925 - return; /* make sure is a number (offset) */
927 - XI_message(("book: %s\noffset :%s", e->module, e->key));
929 - if (atol(e->key) != 0)
930 - text = main_get_book_raw_text(e->module, e->key);
932 - text = g_strdup(e->module);
934 - if ((text == NULL) || strlen(text) == 0) {
938 - /* new empty document from template */
939 - gchar *fname = g_build_filename(settings.gSwordDir, "studypad.spt", NULL);
940 - XI_message(("editor load BOOK [%s]", fname));
941 - text = inhale_text_from_file(fname);
945 - if (text && strlen(text)) {
946 - webkit_web_view_load_string((WebKitWebView *)
949 - "application/xhtml+xml", "utf_8",
956 - title = g_strdup_printf("%s", e->module);
957 - change_window_title(e->window, title);
960 - e->is_changed = FALSE;
963 /******************************************************************************
964 @@ -1054,281 +329,19 @@ void editor_load_book(EDITOR *e)
966 void editor_sync_with_main(void)
970 - tmp = g_list_first(editors_all);
971 - while (tmp != NULL) {
972 - EDITOR *e = (EDITOR *)tmp->data;
975 - case STUDYPAD_EDITOR:
980 - editor_load_note(e, NULL,
981 - settings.currentverse);
984 - tmp = g_list_next(tmp);
989 editor_load_note(EDITOR *e, const gchar *module_name, const gchar *key)
991 - gchar *title = NULL, *text = NULL;
999 - e->module = g_strdup(module_name);
1004 - e->key = g_strdup(key);
1007 - text = main_get_raw_text((gchar *)e->module, (gchar *)e->key);
1009 - if ((text == NULL) || strlen(text) == 0) {
1013 - /* new empty document from template */
1014 - gchar *fname = g_build_filename(settings.gSwordDir, "studypad.spt", NULL);
1015 - XI_message(("editor load NOTE [%s]", fname));
1016 - text = inhale_text_from_file(fname);
1020 - if (text && strlen(text)) {
1021 - webkit_web_view_load_string((WebKitWebView *)
1024 - "application/xhtml+xml", "utf_8",
1028 - e->is_changed = FALSE;
1029 - if (e->type == NOTE_EDITOR) {
1030 - e->navbar.valid_key = TRUE;
1031 - main_navbar_versekey_set(e->navbar, e->key);
1037 - title = g_strdup_printf("%s - %s", e->module, e->key);
1038 - change_window_title(e->window, title);
1043 delete_event(GtkWidget *widget, GdkEvent *event, EDITOR *e)
1045 - if (e->is_changed) {
1046 - switch (ask_about_saving(e)) {
1047 - case GS_YES: /* exit saving */
1050 - case GS_NO: /* exit without saving */
1057 - editors_all = g_list_remove(editors_all, e);
1062 -gint ask_about_saving(EDITOR *e)
1066 - gchar *buf = NULL;
1067 - gchar *buf1 = NULL;
1068 - gchar *buf2 = NULL;
1069 - gchar *buf3 = NULL;
1070 - gint retval = FALSE;
1072 - switch (e->type) {
1075 - info = gui_new_dialog();
1076 - info->stock_icon =
1077 -#if GTK_CHECK_VERSION(3, 10, 0)
1080 - GTK_STOCK_DIALOG_WARNING;
1083 - buf = g_strdup_printf("%s: %s", e->module, e->key);
1084 - buf1 = _("Save the changes to document");
1085 - buf2 = _("before closing?");
1086 - buf3 = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s %s %s</span>",
1088 - info->label_top = buf3;
1089 - info->label2 = _("If you don't save, changes will be permanently lost.");
1090 - info->save = TRUE;
1091 - info->cancel = TRUE;
1092 - info->no_save = TRUE;
1094 - test = gui_alert_dialog(info);
1097 - if (test == GS_YES) {
1098 - if (e->type == NOTE_EDITOR) {
1099 - /* save notes and prayer lists */
1103 - /* save notes and prayer lists */
1112 - case STUDYPAD_EDITOR:
1113 - info = gui_new_dialog();
1114 - info->stock_icon =
1115 -#if GTK_CHECK_VERSION(3, 10, 0)
1118 - GTK_STOCK_DIALOG_WARNING;
1120 - if (settings.studypadfilename)
1121 - buf = settings.studypadfilename;
1124 - buf1 = _("Save the changes to document");
1125 - buf2 = _("before closing?");
1126 - buf3 = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s %s %s</span>",
1128 - info->label_top = buf3;
1129 - info->label2 = _("If you don't save, changes will be permanently lost.");
1130 - info->save = TRUE;
1131 - info->cancel = TRUE;
1132 - info->no_save = TRUE;
1134 - test = gui_alert_dialog(info);
1136 - if (test == GS_YES) {
1147 -static gint _create_new(const gchar *filename, const gchar *key,
1151 - GtkWidget *toolbar_nav = NULL;
1153 - editor = g_new(EDITOR, 1);
1154 - editor->html_widget = NULL;
1155 - editor->sync = FALSE;
1156 - editor->type = editor_type;
1158 - switch (editor_type) {
1159 - case STUDYPAD_EDITOR:
1160 - editor->studypad = TRUE;
1161 - editor->bookeditor = FALSE;
1162 - editor->noteeditor = FALSE;
1163 - editor->module = NULL;
1164 - editor->key = NULL;
1165 - editor->filename = NULL;
1166 - widgets.studypad_dialog = editor_new(_("StudyPad"), editor);
1169 - editor->filename = g_strdup(filename);
1170 - _load_file(editor, g_strdup(filename));
1174 - editor->noteeditor = TRUE;
1175 - editor->bookeditor = FALSE;
1176 - editor->studypad = FALSE;
1177 - editor->filename = NULL;
1178 - editor->module = g_strdup(filename);
1179 - editor->key = g_strdup(key);
1180 - editor->navbar.key = NULL;
1181 - editor_new(_("Note Editor"), editor);
1183 - toolbar_nav = gui_navbar_versekey_editor_new(editor);
1184 - gtk_widget_show(toolbar_nav);
1185 - gtk_box_pack_start(GTK_BOX(editor->navbar_box),
1186 - GTK_WIDGET(toolbar_nav), FALSE, TRUE,
1189 - editor_load_note(editor, NULL, NULL);
1192 - editor->bookeditor = TRUE;
1193 - editor->noteeditor = FALSE;
1194 - editor->studypad = FALSE;
1195 - editor->filename = NULL;
1196 - editor->module = g_strdup(filename);
1197 - editor->key = g_strdup(key);
1198 - editor_new(_("Prayer List/Journal Editor"), editor);
1201 - UI_VBOX(box, FALSE, 0);
1202 - gtk_widget_show(box);
1203 - GtkWidget *hpaned1 = UI_HPANE();
1204 - gtk_widget_show(hpaned1);
1205 - gtk_paned_pack2(GTK_PANED(hpaned1), box, TRUE, TRUE);
1207 - GtkWidget *scrollbar = gtk_scrolled_window_new(NULL, NULL);
1208 - gtk_widget_show(scrollbar);
1209 - gtk_paned_pack1(GTK_PANED(hpaned1), GTK_WIDGET(scrollbar),
1211 - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar),
1212 - GTK_POLICY_AUTOMATIC,
1213 - GTK_POLICY_AUTOMATIC);
1214 - gtk_scrolled_window_set_shadow_type((GtkScrolledWindow *)
1216 - settings.shadow_type);
1218 - editor->treeview = gui_create_editor_tree(editor);
1219 - gtk_widget_show(editor->treeview);
1220 - gtk_container_add(GTK_CONTAINER(scrollbar),
1221 - editor->treeview);
1222 - gtk_paned_set_position(GTK_PANED(hpaned1), 125);
1223 - gtk_tree_view_expand_all((GtkTreeView *)editor->treeview);
1224 -// then we should expand on the item to which we've opened for edit.
1226 -#if GTK_CHECK_VERSION(3, 10, 0)
1227 - gtk_container_add(GTK_CONTAINER(box), editor->box);
1229 - gtk_widget_reparent(editor->box, box);
1232 - gtk_container_add(GTK_CONTAINER(editor->window), hpaned1);
1234 - editor_load_book(editor);
1238 - editor->is_changed = FALSE;
1239 - editors_all = g_list_append(editors_all, (EDITOR *)editor);
1243 /******************************************************************************
1246 @@ -1348,85 +361,11 @@ static gint _create_new(const gchar *filename, const gchar *key,
1247 gint editor_create_new(const gchar *filename, const gchar *key,
1250 - GList *tmp = NULL;
1252 - tmp = g_list_first(editors_all);
1253 - while (tmp != NULL) {
1254 - EDITOR *e = (EDITOR *)tmp->data;
1255 - switch (editor_type) {
1256 - case STUDYPAD_EDITOR:
1257 - if (e->studypad) {
1258 - if (editor_is_dirty(e))
1261 - g_free(e->filename);
1262 - e->filename = g_strdup(filename);
1263 - gtk_widget_show(e->window);
1264 - gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window)));
1266 - _load_file(e, g_strdup(filename));
1271 - if (!e->noteeditor)
1273 - if (editor_is_dirty(e))
1276 - g_free(e->module);
1277 - e->module = g_strdup(filename);
1280 - e->key = g_strdup(key);
1281 - gtk_widget_show(e->window);
1282 - gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window)));
1284 - editor_load_note(e, NULL, NULL);
1289 - if (!e->bookeditor)
1291 - if (editor_is_dirty(e))
1294 - g_free(e->module);
1295 - e->module = g_strdup(filename);
1298 - e->key = g_strdup(key);
1299 - gtk_widget_show(e->window);
1300 - gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window)));
1301 - main_load_book_tree_in_editor(GTK_TREE_VIEW(e->treeview),
1303 - editor_load_book(e);
1308 - tmp = g_list_next(tmp);
1310 - XI_message(("filename %s, key %s",
1311 - (filename ? filename : "-null-"),
1312 - (key ? key : "-null-")));
1313 - return _create_new(filename, key, editor_type);
1317 void editor_maybe_save_all(void)
1319 - GList *tmp, *tmp2;
1321 - tmp = g_list_first(editors_all);
1322 - while (tmp != NULL) {
1323 - /* 2ndary list chaser:
1324 - elements will be removed by the saver. */
1325 - tmp2 = g_list_next(tmp);
1327 - delete_event(NULL, NULL, (EDITOR *)tmp->data);
1332 #endif /* USE_WEBKIT_EDITOR */