archrelease: copy trunk to community-x86_64
[ArchLinux/community.git] / xiphos / trunk / disable-webkit-editor.patch
blob61cf907154251584dcd382a258e1f6eb9669d1d4
1 From: Bastian Germann <bage@debian.org>
2 Date: Sat, 27 Jun 2020 19:36:25 +0200
3 Subject: Disable webkit editor
5 ---
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
14 @@ -23,7 +23,7 @@
15 #include <config.h>
16 #endif
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
27 @@ -29,7 +29,6 @@
28 #include <ctype.h>
30 #include <glib.h>
31 -#include <webkit/webkit.h>
33 #include <libintl.h>
34 #include <locale.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,
44 G_MODULE_EXPORT void
45 action_about_activate_cb(GtkWidget *widget, EDITOR *e)
47 - GtkWidget *about;
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);
63 G_MODULE_EXPORT void
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);
70 G_MODULE_EXPORT void
71 action_decrease_indent_activate_cb(GtkWidget *widget, EDITOR *e)
73 - editor_execute_script("document.execCommand('Outdent', false, false);", e);
76 G_MODULE_EXPORT void
77 action_insert_rule_activate_cb(GtkWidget *widget, EDITOR *e)
79 - editor_insert_html("<hr>", e);
82 G_MODULE_EXPORT void
83 @@ -158,141 +138,80 @@ action_insert_table_activate_cb(GtkWidget *widget, EDITOR *e)
84 G_MODULE_EXPORT void
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, \"\");");
93 G_MODULE_EXPORT void
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",
99 - NULL,
100 - GTK_FILE_CHOOSER_ACTION_OPEN,
101 -#if GTK_CHECK_VERSION(3, 10, 0)
102 - "_Cancel", GTK_RESPONSE_CANCEL,
103 - "_OK", GTK_RESPONSE_ACCEPT,
104 -#else
105 - GTK_STOCK_CANCEL,
106 - GTK_RESPONSE_CANCEL,
107 - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
108 -#endif
109 - NULL);
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);
115 - g_free(script);
118 - if (filename)
119 - g_free(filename);
120 - gtk_widget_destroy(dialog);
123 G_MODULE_EXPORT void
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);
129 G_MODULE_EXPORT void
130 action_justify_right_activate_cb(GtkWidget *widget, EDITOR *e)
132 - editor_execute_script("document.execCommand('justifyright', false, false);", e);
135 G_MODULE_EXPORT void
136 action_justify_left_activate_cb(GtkWidget *widget, EDITOR *e)
138 - editor_execute_script("document.execCommand('justifyleft', false, false);", e);
141 G_MODULE_EXPORT void
142 action_justify_center_activate_cb(GtkWidget *widget, EDITOR *e)
144 - editor_execute_script("document.execCommand('justifycenter', false, false);", e);
147 G_MODULE_EXPORT void
148 action_justify_full_activate_cb(GtkWidget *widget, EDITOR *e)
150 - editor_execute_script("document.execCommand('justifyfull', false, false);", e);
153 G_MODULE_EXPORT void
154 action_bold_activate_cb(GtkWidget *widget, EDITOR *e)
156 - if (buttons_state.nochange)
157 - return;
159 - editor_execute_script("document.execCommand('bold',false,false);", e);
162 G_MODULE_EXPORT void
163 action_italic_activate_cb(GtkWidget *widget, EDITOR *e)
165 - //extern BUTTONS_STATE buttons_state;
166 - if (buttons_state.nochange)
167 - return;
169 - editor_execute_script("document.execCommand('italic',false,false);", e);
172 G_MODULE_EXPORT void
173 action_undo_activate_cb(GtkWidget *widget, EDITOR *e)
175 - editor_execute_script("document.execCommand('undo',false,false);", e);
178 G_MODULE_EXPORT void
179 action_redo_activate_cb(GtkWidget *widget, EDITOR *e)
181 - editor_execute_script("document.execCommand('redo',false,false);", e);
184 G_MODULE_EXPORT void
185 action_underline_activate_cb(GtkWidget *widget, EDITOR *e)
187 - //extern BUTTONS_STATE buttons_state;
188 - if (buttons_state.nochange)
189 - return;
191 - editor_execute_script("document.execCommand('underline', false, false);", e);
194 G_MODULE_EXPORT void
195 action_strikethrough_activate_cb(GtkWidget *widget, EDITOR *e)
197 - //extern BUTTONS_STATE buttons_state;
198 - if (buttons_state.nochange)
199 - return;
201 - editor_execute_script("document.execCommand('strikethrough', false, false);", e);
204 G_MODULE_EXPORT void action_cut_activate_cb(GtkWidget *widget, EDITOR *e)
206 - editor_cut(e);
209 G_MODULE_EXPORT void
210 action_copy_activate_cb(GtkWidget *widget, EDITOR *e)
212 - if (editor_copy(e))
213 - XI_message(("%s", "copy success"));
214 - else
215 - XI_message(("%s", "copy failed"));
218 G_MODULE_EXPORT void
219 action_paste_activate_cb(GtkWidget *widget, EDITOR *e)
221 - editor_paste(e);
224 G_MODULE_EXPORT void
225 @@ -303,737 +222,93 @@ action_delete_activate_cb(GtkWidget *widget, EDITOR *e)
226 G_MODULE_EXPORT void
227 action_delete_item_activate_cb(GtkWidget *widget, EDITOR *e)
229 - if (e->studypad)
230 - return;
232 - gchar *buf =
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)
238 - "dialog-warning"
239 -#else
240 - GTK_STOCK_DIALOG_WARNING
241 -#endif
242 - )) {
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);
250 - g_free(fname);
252 - if (text && strlen(text)) {
253 - webkit_web_view_load_string((WebKitWebView *)
254 - e->html_widget,
255 - text,
256 - "application/xhtml+xml", "utf_8",
257 - "file://");
259 - if (text)
260 - g_free(text);
263 - g_free(buf);
264 - e->is_changed = FALSE;
267 void set_button_state(BUTTONS_STATE state, EDITOR *e)
269 -#if GTK_CHECK_VERSION(3, 4, 0)
270 - GdkRGBA rgba;
271 -#else
272 - GdkColor color;
273 -#endif
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);
280 - if (state.color) {
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,
286 - &rgba);
287 -#else
288 - if (gdk_color_parse(state.color, &color))
289 - gtk_color_button_set_color((GtkColorButton *)
290 - e->toolitems.color,
291 - &color);
292 -#endif
296 G_MODULE_EXPORT void
297 colorbutton1_color_set_cb(GtkColorButton *widget, EDITOR *e)
299 -#if GTK_CHECK_VERSION(3, 4, 0)
300 - GdkRGBA color;
301 -#else
302 - GdkColor color;
303 -#endif
304 - gchar *color_str;
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);
310 -#else
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);
314 -#endif
315 - forecolor = g_strdup_printf("document.execCommand('forecolor', null, '%s');", color_str);
316 - editor_execute_script(forecolor, e);
317 - g_free(forecolor);
318 - g_free(color_str);
321 G_MODULE_EXPORT void
322 colorbutton_highlight_color_set_cb(GtkColorButton *widget, EDITOR *e)
325 -#if GTK_CHECK_VERSION(3, 4, 0)
326 - GdkRGBA color;
327 -#else
328 - GdkColor color;
329 -#endif
330 - gchar *color_str;
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);
336 -#else
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);
340 -#endif
341 - highlightcolor = g_strdup_printf("document.execCommand('backColor', null, '%s');", color_str);
342 - editor_execute_script(highlightcolor, e);
343 - g_free(highlightcolor);
344 - g_free(color_str);
347 -static gchar *get_font_size_from_name(GString *fontname)
349 - gchar buf[80];
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];
359 - buf[j + 1] = '\0';
360 - j++;
363 - return g_strdup(buf);
366 -G_MODULE_EXPORT void
367 -action_font_activate_cb(GtkWidget *widget, EDITOR *e)
369 - GtkWidget *dialog;
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,
375 -#else
376 - dialog = gtk_font_selection_dialog_new("Select font");
377 - gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)
378 - dialog,
379 -#endif
380 - "Droid Sans 14");
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);
385 -#else
386 - const gchar *fontname = gtk_font_selection_dialog_get_font_name((GtkFontSelectionDialog *)dialog);
387 -#endif
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 *)
396 - dialog);
397 - fontname = pango_font_description_get_family(font_description);
398 -#else
399 - PangoFontDescription *font_description =
400 - pango_font_description_from_string(fontname);
401 - fontname = pango_font_description_get_family(font_description);
402 -#endif
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);
408 - g_free(script);
410 - if (size)
411 - g_free(size);
412 - if (selected_text)
413 - g_free(selected_text);
414 - gtk_widget_destroy(dialog);
417 G_MODULE_EXPORT void
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);
423 - break;
424 - case 1:
425 - editor_find_string((gchar *)
426 - gtk_entry_get_text(GTK_ENTRY(find_dialog.find_entry)),
427 - e);
428 - break;
429 - case 2:
430 - editor_replace_string((gchar *)
431 - gtk_entry_get_text(GTK_ENTRY(find_dialog.find_entry)),
432 - (gchar *)
433 - gtk_entry_get_text(GTK_ENTRY(find_dialog.replace_entry)),
434 - e);
435 - break;
436 - default:
437 - gtk_widget_hide(find_dialog.window);
438 - break;
442 G_MODULE_EXPORT void
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);
450 G_MODULE_EXPORT void
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)
468 - if (e->filename) {
469 - g_free(e->filename);
471 - if (e->module) {
472 - g_free(e->module);
474 - if (e->key) {
475 - g_free(e->key);
477 - if (e->window)
478 - gtk_widget_destroy(e->window);
479 - g_free(e);
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));
487 - if (e->filename)
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);
520 - return result;
523 -static gint open_dialog(EDITOR *e)
525 - GtkWidget *dialog;
526 - gint response;
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,
533 -#else
534 - GTK_STOCK_CANCEL,
535 - GTK_RESPONSE_CANCEL,
536 - GTK_STOCK_OPEN,
537 - GTK_RESPONSE_ACCEPT,
538 -#endif
539 - NULL);
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);
555 - return response;
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)
577 - open_dialog(e);
580 G_MODULE_EXPORT void action_save_activate_cb(GtkWidget *widget, EDITOR *e)
582 - switch (e->type) {
583 - case STUDYPAD_EDITOR:
584 - _save_file(e);
585 - break;
586 - case NOTE_EDITOR:
587 - _save_note(e);
588 - break;
589 - case BOOK_EDITOR:
590 - _save_book(e);
591 - break;
592 - default:
593 - XI_message(("\naction_save_cb oops!\n"));
594 - break;
598 G_MODULE_EXPORT void action_new_activate_cb(GtkWidget *widget, EDITOR *e)
599 { /* for studypad only */
600 - gchar *filename = NULL;
602 - if (e->is_changed)
603 - ask_about_saving(e);
605 - filename = g_strdup_printf("%s/%s", settings.gSwordDir, "studypad.spt");
607 - _load_file(e, filename);
609 - if (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;
619 G_MODULE_EXPORT void
620 action_insert_sword_link_activate_cb(GtkWidget *widget, gpointer data)
622 - editor_link_dialog(data); //editor_insert_sword_link();
625 G_MODULE_EXPORT void
626 action_insert_link_activate_cb(GtkWidget *widget, EDITOR *e)
628 - editor_link_dialog(e);
631 G_MODULE_EXPORT void
632 action_save_as_activate_cb(GtkWidget *widget, EDITOR *e)
634 - if (e->filename)
635 - g_free(e->filename);
636 - e->filename = NULL;
637 - _save_file(e);
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)
648 - return;
650 - switch (choice) {
651 - case 0: /* Normal */
652 - script = "document.execCommand('formatBlock', false, \"div\");";
653 - break;
655 - case 1: /* H1 */
656 - script = "document.execCommand('formatBlock', null, \"H1\");";
657 - break;
659 - case 2: /* H2 */
660 - script = "document.execCommand('formatBlock', null, \"H2\");";
661 - break;
663 - case 3: /* H3 */
664 - script = "document.execCommand('formatBlock', null, \"H3\");";
665 - break;
667 - case 4: /* H4 */
668 - script = "document.execCommand('formatBlock', null, \"H4\");";
669 - break;
671 - case 5: /* H5 */
672 - script = "document.execCommand('formatBlock', null, \"H5\");";
673 - break;
675 - case 6: /* H6 */
676 - script = "document.execCommand('formatBlock', null, \"H6\");";
677 - break;
679 - case 7: /* Address */
680 - script = "document.execCommand('formatBlock', null, \"ADDRESS\");";
681 - break;
683 - case 8: /* Preformatted */
684 - script = "document.execCommand('formatBlock', null, \"PRE\");";
685 - break;
687 - case 9: /* Bulleted List insertUnorderedList */
688 - script = "document.execCommand('insertUnorderedList', null, \"\");";
689 - break;
691 - case 10: /* Roman Numeral List */
692 - script = "document.execCommand('insertHTML', null, \"<OL type=I><LI> </LI></OL> \");";
693 - break;
695 - case 11: /* Numbered List insertOrderedList */
696 - script = "document.execCommand('insertOrderedList', null, \"\");";
697 - break;
699 - case 12: /* Alphabetical List */
700 - script = "document.execCommand('insertHTML', null, \"<OL type=A><LI> </LI></OL> \");";
701 - break;
703 - default:
704 - break;
707 - if (script) {
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)
716 - GtkWidget *window;
717 - GtkWidget *scrollwindow;
718 - GtkWidget *statusbar;
719 - GtkBuilder *builder;
720 - gchar *gbuilder_file;
721 - GError *error = NULL;
722 - GtkMenuItem *item;
723 - GtkWidget *recent_item;
725 - buttons_state.nochange = 1;
727 - gbuilder_file = gui_general_user_file(
728 -#ifdef USE_GTK_3
729 - "gtk_webedit.ui"
730 -#else
731 - "gtk2_webedit.ui"
732 -#endif
734 - FALSE);
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",
739 - error->message);
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"));
765 - switch (e->type) {
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);
773 - break;
774 - case NOTE_EDITOR:
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));
778 - break;
779 - case BOOK_EDITOR:
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));
783 - break;
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);
804 - return window;
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)
840 - "_OK",
841 - GTK_RESPONSE_OK,
842 - "_Cancel",
843 - GTK_RESPONSE_CANCEL,
844 -#else
845 - GTK_STOCK_OK,
846 - GTK_RESPONSE_OK,
847 - GTK_STOCK_CANCEL,
848 - GTK_RESPONSE_CANCEL,
849 -#endif
850 - NULL);
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);
864 - } else {
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)
879 - char *text = NULL;
880 - GtkRecentManager *rm = NULL;
882 - rm = gtk_recent_manager_get_default();
883 - gtk_recent_manager_add_item(rm, filename);
885 - if (e->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)
896 - ? filename + 5
897 - : filename);
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://");
903 - g_free(text);
904 - e->is_changed = FALSE;
907 gboolean editor_is_dirty(EDITOR *e)
909 - return e->is_changed;
910 + return FALSE;
913 void editor_save_book(EDITOR *e)
915 - if (editor_is_dirty(e))
916 - _save_book(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);
931 - else
932 - text = g_strdup(e->module);
934 - if ((text == NULL) || strlen(text) == 0) {
935 - if (text)
936 - g_free(text);
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);
942 - g_free(fname);
945 - if (text && strlen(text)) {
946 - webkit_web_view_load_string((WebKitWebView *)
947 - e->html_widget,
948 - text,
949 - "application/xhtml+xml", "utf_8",
950 - "file://");
953 - if (text)
954 - g_free(text);
956 - title = g_strdup_printf("%s", e->module);
957 - change_window_title(e->window, title);
958 - g_free(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)
968 - GList *tmp = NULL;
970 - tmp = g_list_first(editors_all);
971 - while (tmp != NULL) {
972 - EDITOR *e = (EDITOR *)tmp->data;
974 - switch (e->type) {
975 - case STUDYPAD_EDITOR:
976 - case BOOK_EDITOR:
977 - break;
978 - case NOTE_EDITOR:
979 - if (e->sync)
980 - editor_load_note(e, NULL,
981 - settings.currentverse);
982 - break;
984 - tmp = g_list_next(tmp);
988 void
989 editor_load_note(EDITOR *e, const gchar *module_name, const gchar *key)
991 - gchar *title = NULL, *text = NULL;
993 - if (e->is_changed)
994 - _save_note(e);
996 - if (module_name) {
997 - if (e->module)
998 - g_free(e->module);
999 - e->module = g_strdup(module_name);
1001 - if (key) {
1002 - if (e->key)
1003 - g_free(e->key);
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) {
1010 - if (text)
1011 - g_free(text);
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);
1017 - g_free(fname);
1020 - if (text && strlen(text)) {
1021 - webkit_web_view_load_string((WebKitWebView *)
1022 - e->html_widget,
1023 - text,
1024 - "application/xhtml+xml", "utf_8",
1025 - "file://");
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);
1034 - if (text)
1035 - g_free(text);
1037 - title = g_strdup_printf("%s - %s", e->module, e->key);
1038 - change_window_title(e->window, title);
1039 - g_free(title);
1042 G_MODULE_EXPORT int
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 */
1048 - break;
1050 - case GS_NO: /* exit without saving */
1051 - break;
1053 - case GS_CANCEL:
1054 - return TRUE;
1057 - editors_all = g_list_remove(editors_all, e);
1058 - do_exit(e);
1059 return FALSE;
1062 -gint ask_about_saving(EDITOR *e)
1064 - gint test;
1065 - GS_DIALOG *info;
1066 - gchar *buf = NULL;
1067 - gchar *buf1 = NULL;
1068 - gchar *buf2 = NULL;
1069 - gchar *buf3 = NULL;
1070 - gint retval = FALSE;
1072 - switch (e->type) {
1073 - case BOOK_EDITOR:
1074 - case NOTE_EDITOR:
1075 - info = gui_new_dialog();
1076 - info->stock_icon =
1077 -#if GTK_CHECK_VERSION(3, 10, 0)
1078 - "dialog-warning";
1079 -#else
1080 - GTK_STOCK_DIALOG_WARNING;
1081 -#endif
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>",
1087 - buf1, buf, buf2);
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);
1095 - retval = test;
1097 - if (test == GS_YES) {
1098 - if (e->type == NOTE_EDITOR) {
1099 - /* save notes and prayer lists */
1100 - _save_note(e);
1102 - } else {
1103 - /* save notes and prayer lists */
1104 - _save_book(e);
1107 - g_free(info);
1108 - g_free(buf);
1109 - g_free(buf3);
1110 - break;
1112 - case STUDYPAD_EDITOR:
1113 - info = gui_new_dialog();
1114 - info->stock_icon =
1115 -#if GTK_CHECK_VERSION(3, 10, 0)
1116 - "dialog-warning";
1117 -#else
1118 - GTK_STOCK_DIALOG_WARNING;
1119 -#endif
1120 - if (settings.studypadfilename)
1121 - buf = settings.studypadfilename;
1122 - else
1123 - buf = N_("File");
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>",
1127 - buf1, buf, buf2);
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);
1135 - retval = test;
1136 - if (test == GS_YES) {
1137 - _save_file(e);
1139 - g_free(info);
1140 - g_free(buf3);
1141 - break;
1143 - sync_windows();
1144 - return retval;
1147 -static gint _create_new(const gchar *filename, const gchar *key,
1148 - gint editor_type)
1150 - EDITOR *editor;
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);
1168 - if (filename) {
1169 - editor->filename = g_strdup(filename);
1170 - _load_file(editor, g_strdup(filename));
1172 - break;
1173 - case NOTE_EDITOR:
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,
1187 - 0);
1189 - editor_load_note(editor, NULL, NULL);
1190 - break;
1191 - case BOOK_EDITOR:
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);
1200 - GtkWidget *box;
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),
1210 - TRUE, TRUE);
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 *)
1215 - scrollbar,
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);
1228 -#else
1229 - gtk_widget_reparent(editor->box, box);
1230 -#endif
1232 - gtk_container_add(GTK_CONTAINER(editor->window), hpaned1);
1234 - editor_load_book(editor);
1236 - break;
1238 - editor->is_changed = FALSE;
1239 - editors_all = g_list_append(editors_all, (EDITOR *)editor);
1240 - return 1;
1243 /******************************************************************************
1244 * Name
1245 * editor_create_new
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,
1248 gint editor_type)
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))
1259 - _save_file(e);
1260 - if (e->filename)
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));
1267 - return 1;
1269 - break;
1270 - case NOTE_EDITOR:
1271 - if (!e->noteeditor)
1272 - break;
1273 - if (editor_is_dirty(e))
1274 - _save_note(e);
1275 - if (e->module)
1276 - g_free(e->module);
1277 - e->module = g_strdup(filename);
1278 - if (e->key)
1279 - g_free(e->key);
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);
1286 - return 1;
1287 - break;
1288 - case BOOK_EDITOR:
1289 - if (!e->bookeditor)
1290 - break;
1291 - if (editor_is_dirty(e))
1292 - _save_book(e);
1293 - if (e->module)
1294 - g_free(e->module);
1295 - e->module = g_strdup(filename);
1296 - if (e->key)
1297 - g_free(e->key);
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),
1302 - e->module);
1303 - editor_load_book(e);
1305 - return 1;
1306 - break;
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);
1314 + return 1;
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);
1328 - tmp = tmp2;
1332 #endif /* USE_WEBKIT_EDITOR */