static void _load_file(EDITOR *e, const gchar *filename) { //GtkWidget *choser; if (e->filename) g_free(e->filename); e->filename = g_strdup(filename); XI_message(("_load_file filename: %s", filename)); xml_set_value("Xiphos", "studypad", "lastfile", e->filename); settings.studypadfilename = xml_get_value("studypad", "lastfile"); change_window_title(e->window, e->filename); char *contents; char *etag_out; gsize length; GFile *file; file = g_file_new_for_path(filename); gtkhtml_editor_set_filename(GTKHTML_EDITOR(e->window), e->filename); if (g_file_load_contents(file, NULL, &contents, &length, &etag_out, NULL)) gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window), contents, length); gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window)); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE); return; }
static void _save_book(EDITOR *e) { GString *string; string = g_string_sized_new(4096); gtk_html_export(gtkhtml_editor_get_html(GTKHTML_EDITOR(e->window)), "text/html", (GtkHTMLSaveReceiverFn)_save_receiver, string); main_treekey_save_book_text(e->module, e->key, string->str); g_string_free(string, TRUE); gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window)); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE); }
static void action_close_cb (GtkAction *action, ESignatureEditor *editor) { gboolean something_changed = FALSE; const gchar *original_name; const gchar *signature_name; original_name = editor->priv->original_name; signature_name = gtk_entry_get_text (GTK_ENTRY (editor->priv->entry)); something_changed |= gtkhtml_editor_has_undo (GTKHTML_EDITOR (editor)); something_changed |= (strcmp (signature_name, original_name) != 0); if (something_changed) { gint response; response = e_error_run ( GTK_WINDOW (editor), "mail:ask-signature-changed", NULL); if (response == GTK_RESPONSE_YES) { GtkActionGroup *action_group; action_group = editor->priv->action_group; action = gtk_action_group_get_action ( action_group, "save-and-close"); gtk_action_activate (action); return; } else if (response == GTK_RESPONSE_CANCEL) return; } gtk_widget_destroy (GTK_WIDGET (editor)); }
gboolean e_plugin_ui_init (GtkUIManager *ui_manager, EMsgComposer *composer) { GtkhtmlEditor *editor; static GtkToggleActionEntry entries[] = { { "face-plugin", NULL, N_("Include _Face"), NULL, NULL, G_CALLBACK (action_toggle_face_cb), FALSE } }; if (get_include_face_by_default ()) { gchar *face = get_face_base64 (); /* activate it only if has a face image available */ entries[0].is_active = face && *face; g_free (face); } editor = GTKHTML_EDITOR (composer); /* Add actions to the "composer" action group. */ gtk_action_group_add_toggle_actions ( gtkhtml_editor_get_action_group (editor, "composer"), entries, G_N_ELEMENTS (entries), composer); return TRUE; }
static void enable_disable_composer (EMsgComposer *composer, gboolean enable) { GtkhtmlEditor *editor; GtkAction *action; GtkActionGroup *action_group; g_return_if_fail (E_IS_MSG_COMPOSER (composer)); editor = GTKHTML_EDITOR (composer); if (enable) gtkhtml_editor_run_command (editor, "editable-on"); else gtkhtml_editor_run_command (editor, "editable-off"); action = GTKHTML_EDITOR_ACTION_EDIT_MENU (composer); gtk_action_set_sensitive (action, enable); action = GTKHTML_EDITOR_ACTION_FORMAT_MENU (composer); gtk_action_set_sensitive (action, enable); action = GTKHTML_EDITOR_ACTION_INSERT_MENU (composer); gtk_action_set_sensitive (action, enable); action_group = gtkhtml_editor_get_action_group (editor, "composer"); gtk_action_group_set_sensitive (action_group, enable); }
gboolean e_plugin_ui_init (GtkUIManager *manager, EMsgComposer *composer) { GtkhtmlEditor *editor; EWebViewGtkHTML *web_view; editor = GTKHTML_EDITOR (composer); /* Add actions to the "composer" action group. */ gtk_action_group_add_actions ( gtkhtml_editor_get_action_group (editor, "composer"), entries, G_N_ELEMENTS (entries), composer); web_view = e_msg_composer_get_web_view (composer); g_signal_connect ( web_view, "key_press_event", G_CALLBACK (key_press_cb), composer); g_signal_connect ( web_view, "delete-event", G_CALLBACK (delete_cb), composer); return TRUE; }
gboolean eex_ui_composer_actions (GtkUIManager *manager, EMsgComposer *composer) { static GtkActionEntry entries[] = { { "eex-send-options", NULL, N_("_Send Options"), NULL, N_("Insert Send options"), G_CALLBACK (action_send_options_cb) } }; GtkhtmlEditor *editor; EComposerHeaderTable *headers; EComposerHeader *header; editor = GTKHTML_EDITOR (composer); /* Add actions to the "composer" action group. */ e_action_group_add_actions_localized ( gtkhtml_editor_get_action_group (editor, "composer"), GETTEXT_PACKAGE, entries, G_N_ELEMENTS (entries), composer); headers = e_msg_composer_get_header_table (composer); header = e_composer_header_table_get_header (headers, E_COMPOSER_HEADER_FROM); from_changed_cb (E_COMPOSER_FROM_HEADER (header), composer); g_signal_connect (G_OBJECT (header), "changed", G_CALLBACK (from_changed_cb), composer); return TRUE; }
static void action_save_as_cb(GtkAction *action, EDITOR *e) { const gchar *filename; gboolean as_html; GError *error = NULL; if (save_dialog(GTKHTML_EDITOR(e->window), e) == GTK_RESPONSE_CANCEL) return; filename = gtkhtml_editor_get_filename(GTKHTML_EDITOR(e->window)); as_html = gtkhtml_editor_get_html_mode(GTKHTML_EDITOR(e->window)); gtkhtml_editor_save(GTKHTML_EDITOR(e->window), filename, as_html, &error); handle_error(&error); }
static void action_new_cb(GtkAction *action, EDITOR *e) { /* for studypad only */ if (editor_is_dirty(e)) _save_file(e); _load_file(e, g_strdup_printf("%s/%s", settings.gSwordDir, "template.pad")); if (e->filename) g_free(e->filename); e->filename = g_strdup(_("Untitled document")); xml_set_value("Xiphos", "studypad", "lastfile", e->filename); settings.studypadfilename = xml_get_value("studypad", "lastfile"); change_window_title(e->window, e->filename); gtkhtml_editor_set_filename(GTKHTML_EDITOR(e->window), NULL); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), TRUE); }
static void signature_manager_add_signature (ESignatureManager *manager) { ESignatureTreeView *tree_view; GtkWidget *editor; tree_view = e_signature_manager_get_tree_view (manager); editor = e_signature_editor_new (); gtkhtml_editor_set_html_mode ( GTKHTML_EDITOR (editor), manager->priv->prefer_html); signature_manager_emit_editor_created (manager, editor); gtk_widget_grab_focus (GTK_WIDGET (tree_view)); }
static gint open_dialog(EDITOR *e) { GtkWidget *dialog; gint response; #if 0 const gchar *filename; #endif dialog = gtk_file_chooser_dialog_new(_("Open"), GTK_WINDOW(e->window), GTK_FILE_CHOOSER_ACTION_OPEN, #ifdef HAVE_GTK_310 "_Cancel", GTK_RESPONSE_CANCEL, "_Open", GTK_RESPONSE_ACCEPT, #else GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, #endif NULL); /*gtk_file_chooser_set_do_overwrite_confirmation ( GTK_FILE_CHOOSER (dialog), TRUE); */ #if 0 filename = gtkhtml_editor_get_filename(GTKHTML_EDITOR(e->window)); #endif gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), settings.studypaddir); response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_ACCEPT) { gchar *new_filename; new_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); //gtkhtml_editor_set_filename (e->window, new_filename); _load_file(e, new_filename); g_free(new_filename); } gtk_widget_destroy(dialog); return response; }
static void from_changed_cb (EComposerFromHeader *header, EMsgComposer *composer) { GtkActionGroup *group; GtkAction *action; g_return_if_fail (header != NULL); g_return_if_fail (composer != NULL); group = gtkhtml_editor_get_action_group (GTKHTML_EDITOR (composer), "composer"); g_return_if_fail (group != NULL); action = gtk_action_group_get_action (group, "eex-send-options"); g_return_if_fail (action != NULL); gtk_action_set_visible (action, account_is_exchange (e_composer_from_header_get_active (header))); }
void face_handle_send (EPlugin *ep, EMEventTargetComposer *target) { GtkhtmlEditor *editor; GtkAction *action; editor = GTKHTML_EDITOR (target->composer); action = gtkhtml_editor_get_action (editor, "face-plugin"); g_return_if_fail (action != NULL); if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) { gchar *face = get_face_base64 (); if (face) e_msg_composer_set_header (target->composer, "Face", face); g_free (face); } }
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 action_delete_cb(GtkAction *action, EDITOR *e) { /* for note only */ gchar *buf; if (e->studypad) return; buf = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s %s?</span>", _("Are you sure you want to delete the note for"), e->key); if (gui_yes_no_dialog(buf, #ifdef HAVE_GTK_310 "dialog-warning" #else GTK_STOCK_DIALOG_WARNING #endif )) { main_delete_note(e->module, e->key); gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window), "", strlen("")); } g_free(buf); }
static void _save_file(EDITOR *e) { const gchar *filename; gboolean as_html; GError *error = NULL; if (gtkhtml_editor_get_filename(GTKHTML_EDITOR(e->window)) == NULL) if (save_dialog(GTKHTML_EDITOR(e->window), e) == GTK_RESPONSE_CANCEL) return; filename = gtkhtml_editor_get_filename(GTKHTML_EDITOR(e->window)); as_html = gtkhtml_editor_get_html_mode(GTKHTML_EDITOR(e->window)); XI_message(("\n_save_file filename: %s\n", filename)); gtkhtml_editor_save(GTKHTML_EDITOR(e->window), filename, as_html, &error); handle_error(&error); gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window)); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE); }
/* save if needed is done in treeky-editor.c before calling editor_load_book() */ void editor_load_book(EDITOR *e) { gchar *title = NULL; gchar *text = NULL; if (!g_ascii_isdigit(e->key[0])) return; /* make sure is a number (offset) */ title = g_strdup_printf("%s", e->module); XI_message(("book: %s\noffset :%s", e->module, e->key)); if (atol(e->key) != 0) text = main_get_book_raw_text(e->module, e->key); else text = g_strdup(e->module); 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 (text) g_free(text); if (title) g_free(title); }
GtkWidget *editor_new(const gchar *title, EDITOR *e) { GtkActionGroup *action_group; GtkUIManager *manager; GtkWidget *editor; GError *error = NULL; editor = gtkhtml_editor_new(); e->window = editor; e->html_widget = GTK_WIDGET(gtkhtml_editor_get_html(GTKHTML_EDITOR(editor))); gtk_window_set_title(GTK_WINDOW(editor), title); set_window_icon(GTK_WINDOW(editor)); manager = gtkhtml_editor_get_ui_manager(GTKHTML_EDITOR(editor)); if (e->type == STUDYPAD_EDITOR) gtk_ui_manager_add_ui_from_string(manager, file_ui, -1, &error); else gtk_ui_manager_add_ui_from_string(manager, note_file_ui, -1, &error); handle_error(&error); gtk_ui_manager_add_ui_from_string(manager, view_ui, -1, &error); handle_error(&error); if (e->type == STUDYPAD_EDITOR) gtk_ui_manager_add_ui_from_string(manager, main_ui_studypad, -1, &error); else gtk_ui_manager_add_ui_from_string(manager, main_ui_note, -1, &error); handle_error(&error); action_group = gtk_action_group_new("file"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, file_entries, G_N_ELEMENTS(file_entries), e); gtk_ui_manager_insert_action_group(manager, action_group, 0); action_group = gtk_action_group_new("view"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, view_entries, G_N_ELEMENTS(view_entries), editor); gtk_ui_manager_insert_action_group(manager, action_group, 0); action_group = gtk_action_group_new("main"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, main_entries, G_N_ELEMENTS(main_entries), e); gtk_ui_manager_insert_action_group(manager, action_group, 0); action_group = gtk_action_group_new("context-menu"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, test_entries, G_N_ELEMENTS(test_entries), e); gtk_ui_manager_insert_action_group(manager, action_group, 0); gtk_ui_manager_ensure_update(manager); gtk_widget_show(editor); gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window)); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE); g_signal_connect(editor, "delete-event", G_CALLBACK(app_delete_cb), (EDITOR *)e); return editor; }
static void action_print_preview_cb(GtkAction *action, EDITOR *e) { print(GTKHTML_EDITOR(e->window), GTK_PRINT_OPERATION_ACTION_PREVIEW); }
static gpointer external_editor_thread (gpointer user_data) { EMsgComposer *composer = user_data; gchar *filename = NULL; gint status = 0; GSettings *settings; gchar *editor_cmd_line = NULL, *editor_cmd = NULL, *content; gint fd, position = -1, offset = -1; /* prefix temp files with evo so .*vimrc can be setup to recognize them */ fd = g_file_open_tmp ("evoXXXXXX", &filename, NULL); if (fd > 0) { gsize length = 0; close (fd); d (printf ("\n\aTemporary-file Name is : [%s] \n\a", filename)); /* Push the text (if there is one) from the composer to the file */ content = gtkhtml_editor_get_text_plain (GTKHTML_EDITOR (composer), &length); g_file_set_contents (filename, content, length, NULL); } else { struct run_error_dialog_data *data; data = g_new0 (struct run_error_dialog_data, 1); data->composer = composer; data->text = "org.gnome.evolution.plugins.external-editor:no-temp-file"; g_warning ("Temporary file fd is null"); /* run_error_dialog also calls enable_composer */ g_idle_add ((GSourceFunc) run_error_dialog, data); goto finished; } settings = g_settings_new ("org.gnome.evolution.plugin.external-editor"); editor_cmd = g_settings_get_string (settings, "command"); if (!editor_cmd) { if (!(editor_cmd = g_strdup (g_getenv ("EDITOR")))) /* Make gedit the default external editor, * if the default schemas are not installed * and no $EDITOR is set. */ editor_cmd = g_strdup ("gedit"); } g_object_unref (settings); if (g_strrstr (editor_cmd, "vim") != NULL && gtk_html_get_cursor_pos ( gtkhtml_editor_get_html ( GTKHTML_EDITOR (composer)), &position, &offset) && position >= 0 && offset >= 0) { gchar *tmp = editor_cmd; gint lineno; gboolean set_nofork; set_nofork = g_strrstr (editor_cmd, "gvim") != NULL; /* Increment 1 so that entering vim insert mode places you * in the same entry position you were at in the html. */ offset++; /* calculate the line number that the cursor is in */ lineno = numlines (content, position); editor_cmd = g_strdup_printf ( "%s \"+call cursor(%d,%d)\"%s%s", tmp, lineno, offset, set_nofork ? " " : "", set_nofork ? "--nofork" : ""); g_free (tmp); } g_free (content); editor_cmd_line = g_strconcat (editor_cmd, " ", filename, NULL); if (!g_spawn_command_line_sync (editor_cmd_line, NULL, NULL, &status, NULL)) { struct run_error_dialog_data *data; g_warning ("Unable to launch %s: ", editor_cmd_line); data = g_new0 (struct run_error_dialog_data, 1); data->composer = composer; data->text = "org.gnome.evolution.plugins.external-editor:editor-not-launchable"; /* run_error_dialog also calls enable_composer */ g_idle_add ((GSourceFunc) run_error_dialog, data); g_free (filename); g_free (editor_cmd_line); g_free (editor_cmd); goto finished; } g_free (editor_cmd_line); g_free (editor_cmd); #ifdef HAVE_SYS_WAIT_H if (WEXITSTATUS (status) != 0) { #else if (status) { #endif d (printf ("\n\nsome problem here with external editor\n\n")); g_idle_add ((GSourceFunc) enable_composer, composer); goto finished; } else { gchar *buf; if (g_file_get_contents (filename, &buf, NULL, NULL)) { gchar *htmltext; GArray *array; htmltext = camel_text_to_html ( buf, CAMEL_MIME_FILTER_TOHTML_PRE, 0); array = g_array_sized_new ( TRUE, TRUE, sizeof (gpointer), 2 * sizeof (gpointer)); array = g_array_append_val (array, composer); array = g_array_append_val (array, htmltext); g_idle_add ((GSourceFunc) update_composer_text, array); /* We no longer need that temporary file */ if (g_remove (filename) == -1) g_warning ( "%s: Failed to remove file '%s': %s", G_STRFUNC, filename, g_strerror (errno)); g_free (filename); } } finished: g_mutex_lock (&external_editor_running_lock); external_editor_running = FALSE; g_mutex_unlock (&external_editor_running_lock); return NULL; } static void launch_editor (GtkAction *action, EMsgComposer *composer) { d (printf ("\n\nexternal_editor plugin is launched \n\n")); if (editor_running ()) { d (printf ("not opening editor, because it's still running\n")); return; } disable_composer (composer); g_mutex_lock (&external_editor_running_lock); external_editor_running = TRUE; g_mutex_unlock (&external_editor_running_lock); editor_thread = g_thread_new ( NULL, external_editor_thread, composer); g_thread_unref (editor_thread); }
gboolean editor_is_dirty(EDITOR *e) { return gtkhtml_editor_get_changed(GTKHTML_EDITOR(e->window)); }
static void action_save_and_close_cb (GtkAction *action, ESignatureEditor *editor) { GtkWidget *entry; ESignatureList *signature_list; ESignature *signature; ESignature *same_name; const gchar *filename; gchar *signature_name; gboolean html; GError *error = NULL; entry = editor->priv->entry; html = gtkhtml_editor_get_html_mode (GTKHTML_EDITOR (editor)); if (editor->priv->signature == NULL) signature = mail_config_signature_new (NULL, FALSE, html); else { signature = g_object_ref (editor->priv->signature); signature->html = html; } filename = signature->filename; gtkhtml_editor_save (GTKHTML_EDITOR (editor), filename, html, &error); if (error != NULL) { e_error_run ( GTK_WINDOW (editor), "mail:no-save-signature", error->message, NULL); g_clear_error (&error); return; } signature_list = mail_config_get_signatures (); signature_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); g_strstrip (signature_name); /* Make sure the signature name is not blank. */ if (*signature_name == '\0') { e_error_run ( GTK_WINDOW (editor), "mail:blank-signature", NULL); gtk_widget_grab_focus (entry); g_free (signature_name); return; } /* Don't overwrite an existing signature of the same name. * XXX ESignatureList misuses const. */ same_name = (ESignature *) e_signature_list_find ( signature_list, E_SIGNATURE_FIND_NAME, signature_name); if (same_name != NULL && strcmp (signature->uid, same_name->uid) != 0) { e_error_run ( GTK_WINDOW (editor), "mail:signature-already-exists", signature_name, NULL); gtk_widget_grab_focus (entry); g_free (signature_name); return; } g_free (signature->name); signature->name = signature_name; if (editor->priv->signature != NULL) e_signature_list_change (signature_list, signature); else mail_config_add_signature (signature); gtk_widget_destroy (GTK_WIDGET (editor)); }
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; }
static void action_print_cb(GtkAction *action, EDITOR *e) { print(GTKHTML_EDITOR(e->window), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); }
static gint _create_new(const gchar *filename, const gchar *key, gint editor_type) { EDITOR *editor; GtkWidget *vbox = NULL; GtkWidget *toolbar_nav = NULL; editor = g_new(EDITOR, 1); editor->html_widget = NULL; editor->sync = FALSE; editor->type = editor_type; switch (editor_type) { case STUDYPAD_EDITOR: editor->studypad = TRUE; editor->bookeditor = FALSE; editor->noteeditor = FALSE; editor->module = NULL; editor->key = NULL; editor->filename = NULL; widgets.studypad_dialog = editor_new(_("StudyPad"), editor); if (filename) { editor->filename = g_strdup(filename); _load_file(editor, g_strdup(filename)); } break; case NOTE_EDITOR: editor->noteeditor = TRUE; editor->bookeditor = FALSE; editor->studypad = FALSE; editor->filename = NULL; editor->module = g_strdup(filename); editor->key = g_strdup(key); editor->navbar.key = NULL; editor_new(_("Note Editor"), editor); vbox = GTKHTML_EDITOR(editor->window)->vbox; toolbar_nav = gui_navbar_versekey_editor_new(editor); gtk_widget_show(toolbar_nav); gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(toolbar_nav), FALSE, TRUE, 0); gtk_box_reorder_child(GTK_BOX(vbox), GTK_WIDGET(toolbar_nav), 1); editor_load_note(editor, NULL, NULL); break; case BOOK_EDITOR: editor->bookeditor = TRUE; editor->noteeditor = FALSE; editor->studypad = FALSE; editor->filename = NULL; editor->module = g_strdup(filename); editor->key = g_strdup(key); editor_new(_("Prayer List/Journal Editor"), editor); GtkWidget *box; UI_VBOX(box, TRUE, 0); gtk_widget_show(box); GtkWidget *hpaned1 = UI_HPANE(); gtk_widget_show(hpaned1); gtk_paned_pack2(GTK_PANED(hpaned1), box, TRUE, TRUE); GtkWidget *scrollbar = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(scrollbar); gtk_paned_pack1(GTK_PANED(hpaned1), GTK_WIDGET(scrollbar), TRUE, TRUE); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type((GtkScrolledWindow *) scrollbar, settings.shadow_type); editor->treeview = gui_create_editor_tree(editor); gtk_widget_show(editor->treeview); gtk_container_add(GTK_CONTAINER(scrollbar), editor->treeview); gtk_paned_set_position(GTK_PANED(hpaned1), 125); gtk_tree_view_collapse_all((GtkTreeView *) editor->treeview); // then we should expand on the item to which we've opened for edit. vbox = GTKHTML_EDITOR(editor->window)->vbox; gtk_widget_reparent(vbox, box); gtk_container_add(GTK_CONTAINER(editor->window), hpaned1); editor_load_book(editor); break; } editor->is_changed = FALSE; editors_all = g_list_append(editors_all, (EDITOR *)editor); return 1; }
gboolean e_composer_autosave_snapshot (EMsgComposer *composer) { GtkhtmlEditor *editor; CamelMimeMessage *message; AutosaveState *state; CamelStream *stream; gint camelfd; const gchar *errmsg; g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), FALSE); editor = GTKHTML_EDITOR (composer); /* If the contents are unchanged, exit early. */ if (!gtkhtml_editor_get_changed (editor)) return TRUE; state = g_object_get_data (G_OBJECT (composer), "autosave"); g_return_val_if_fail (state != NULL, FALSE); /* Open the autosave file on-demand. */ if (!composer_autosave_state_open (state, NULL)) { errmsg = _("Could not open autosave file"); goto fail; } /* Extract a MIME message from the composer. */ message = e_msg_composer_get_message_draft (composer); if (message == NULL) { errmsg = _("Unable to retrieve message from editor"); goto fail; } /* Move to the beginning of the autosave file. */ if (lseek (state->fd, (off_t) 0, SEEK_SET) < 0) { camel_object_unref (message); errmsg = g_strerror (errno); goto fail; } /* Destroy the contents of the autosave file. */ if (ftruncate (state->fd, (off_t) 0) < 0) { camel_object_unref (message); errmsg = g_strerror (errno); goto fail; } /* Duplicate the file descriptor for Camel. */ if ((camelfd = dup (state->fd)) < 0) { camel_object_unref (message); errmsg = g_strerror (errno); goto fail; } /* Open a CamelStream to the autosave file. */ stream = camel_stream_fs_new_with_fd (camelfd); /* Write the message to the CamelStream. */ if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream) < 0) { camel_object_unref (message); camel_object_unref (stream); errmsg = g_strerror (errno); goto fail; } /* Close the CamelStream. */ if (camel_stream_close (CAMEL_STREAM (stream)) < 0) { camel_object_unref (message); camel_object_unref (stream); errmsg = g_strerror (errno); goto fail; } /* Snapshot was successful; set various flags. */ gtkhtml_editor_set_changed (editor, FALSE); e_composer_autosave_set_saved (composer, TRUE); camel_object_unref (message); camel_object_unref (stream); return TRUE; fail: e_error_run ( GTK_WINDOW (composer), "mail-composer:no-autosave", (state->filename != NULL) ? state->filename : "", errmsg, NULL); return FALSE; }