[evolution/webkit-composer: 64/231] Port EMailSignatureEditor to EEditor



commit 58c0ba5dca8b53bbdf3474caf57bfaba619eb632
Author: Dan Vrátil <dvratil redhat com>
Date:   Mon Aug 27 13:55:19 2012 +0200

    Port EMailSignatureEditor to EEditor

 e-util/e-mail-signature-editor.c  |  148 +++++++++++++++---------------------
 e-util/e-mail-signature-editor.h  |    8 +-
 e-util/e-mail-signature-manager.c |   11 ++-
 e-util/e-mail-signature-preview.c |    8 ++-
 4 files changed, 82 insertions(+), 93 deletions(-)
---
diff --git a/e-util/e-mail-signature-editor.c b/e-util/e-mail-signature-editor.c
index d27fec5..c4a3c44 100644
--- a/e-util/e-mail-signature-editor.c
+++ b/e-util/e-mail-signature-editor.c
@@ -16,15 +16,19 @@
  *
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include "e-mail-signature-editor.h"
 
 #include <string.h>
 #include <glib/gi18n.h>
 
-#include "e-alert-bar.h"
 #include "e-alert-dialog.h"
 #include "e-alert-sink.h"
-#include "e-web-view-gtkhtml.h"
+#include "e-alert-bar.h"
+#include "e-editor.h"
 
 #define E_MAIL_SIGNATURE_EDITOR_GET_PRIVATE(obj) \
        (G_TYPE_INSTANCE_GET_PRIVATE \
@@ -40,6 +44,8 @@ struct _EMailSignatureEditorPrivate {
        ESource *source;
        gchar *original_name;
 
+       EEditor *editor;
+
        GtkWidget *entry;               /* not referenced */
        GtkWidget *alert_bar;           /* not referenced */
 };
@@ -83,7 +89,7 @@ static void   e_mail_signature_editor_alert_sink_init
 G_DEFINE_TYPE_WITH_CODE (
        EMailSignatureEditor,
        e_mail_signature_editor,
-       GTKHTML_TYPE_EDITOR,
+       GTK_TYPE_WINDOW,
        G_IMPLEMENT_INTERFACE (
                E_TYPE_ALERT_SINK,
                e_mail_signature_editor_alert_sink_init))
@@ -107,6 +113,8 @@ mail_signature_editor_loaded_cb (GObject *object,
                                  GAsyncResult *result,
                                  gpointer user_data)
 {
+       EEditorWidget *editor_widget;
+       EEditorSelection *editor_selection;
        ESource *source;
        EMailSignatureEditor *editor;
        ESourceMailSignature *extension;
@@ -148,25 +156,15 @@ mail_signature_editor_loaded_cb (GObject *object,
        mime_type = e_source_mail_signature_get_mime_type (extension);
        is_html = (g_strcmp0 (mime_type, "text/html") == 0);
 
-       gtkhtml_editor_set_html_mode (GTKHTML_EDITOR (editor), is_html);
+       editor_widget = e_editor_get_editor_widget (editor->priv->editor);
+       e_editor_widget_set_mode (editor_widget,
+               (is_html) ? E_EDITOR_WIDGET_MODE_HTML : E_EDITOR_WIDGET_MODE_PLAIN_TEXT);
 
+       editor_selection = e_editor_widget_get_selection (editor_widget);
        if (is_html) {
-               gtkhtml_editor_insert_html (
-                       GTKHTML_EDITOR (editor), contents);
+               e_editor_selection_insert_html (editor_selection, contents);
        } else {
-               gtkhtml_editor_insert_text (
-                       GTKHTML_EDITOR (editor), contents);
-
-               gtkhtml_editor_run_command (
-                       GTKHTML_EDITOR (editor), "cursor-position-save");
-               gtkhtml_editor_run_command (
-                       GTKHTML_EDITOR (editor), "select-all");
-               gtkhtml_editor_run_command (
-                       GTKHTML_EDITOR (editor), "style-pre");
-               gtkhtml_editor_run_command (
-                       GTKHTML_EDITOR (editor), "unselect-all");
-               gtkhtml_editor_run_command (
-                       GTKHTML_EDITOR (editor), "cursor-position-restore");
+               e_editor_selection_insert_text (editor_selection, contents);
        }
 
        g_free (contents);
@@ -192,14 +190,16 @@ static void
 action_close_cb (GtkAction *action,
                  EMailSignatureEditor *editor)
 {
+       EEditorWidget *editor_widget;
        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));
+       editor_widget = e_editor_get_editor_widget (editor->priv->editor);
 
-       something_changed |= gtkhtml_editor_has_undo (GTKHTML_EDITOR (editor));
+       something_changed |= webkit_web_view_can_undo (WEBKIT_WEB_VIEW (editor_widget));
        something_changed |= (strcmp (signature_name, original_name) != 0);
 
        if (something_changed) {
@@ -481,7 +481,7 @@ mail_signature_editor_constructed (GObject *object)
        EMailSignatureEditor *editor;
        GtkActionGroup *action_group;
        EFocusTracker *focus_tracker;
-       GtkhtmlEditor *gtkhtml_editor;
+       EEditorWidget *editor_widget;
        GtkUIManager *ui_manager;
        GDBusObject *dbus_object;
        ESource *source;
@@ -496,9 +496,10 @@ mail_signature_editor_constructed (GObject *object)
                constructed (object);
 
        editor = E_MAIL_SIGNATURE_EDITOR (object);
+       editor->priv->editor = E_EDITOR (e_editor_new ());
+       editor_widget = e_editor_get_editor_widget (editor->priv->editor);
 
-       gtkhtml_editor = GTKHTML_EDITOR (editor);
-       ui_manager = gtkhtml_editor_get_ui_manager (gtkhtml_editor);
+       ui_manager = e_editor_get_ui_manager (editor->priv->editor);
 
        /* Because we are loading from a hard-coded string, there is
         * no chance of I/O errors.  Failure here implies a malformed
@@ -517,11 +518,10 @@ mail_signature_editor_constructed (GObject *object)
        editor->priv->action_group = g_object_ref (action_group);
 
        /* Hide page properties because it is not inherited in the mail. */
-       action = gtkhtml_editor_get_action (gtkhtml_editor, "properties-page");
+       action = e_editor_get_action (editor->priv->editor, "properties-page");
        gtk_action_set_visible (action, FALSE);
 
-       action = gtkhtml_editor_get_action (
-               gtkhtml_editor, "context-properties-page");
+       action = e_editor_get_action (editor->priv->editor, "context-properties-page");
        gtk_action_set_visible (action, FALSE);
 
        gtk_ui_manager_ensure_update (ui_manager);
@@ -530,7 +530,21 @@ mail_signature_editor_constructed (GObject *object)
 
        /* Construct the signature name entry. */
 
-       container = gtkhtml_editor->vbox;
+       container = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
+       gtk_container_add (GTK_CONTAINER (editor), container);
+       gtk_widget_show (container);
+
+       /* Construct the alert bar for errors. */
+       widget = e_alert_bar_new ();
+       gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
+       /* Position 5 should be between the style toolbar and editing area. */
+       gtk_box_reorder_child (GTK_BOX (container), widget, 5);
+       editor->priv->alert_bar = widget;  /* not referenced */
+       /* EAlertBar controls its own visibility. */
+
+       gtk_box_pack_end (
+               GTK_BOX (container), GTK_WIDGET (editor->priv->editor), TRUE, TRUE, 0);
+       gtk_widget_show (GTK_WIDGET (editor->priv->editor));
 
        widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
        gtk_container_set_border_width (GTK_CONTAINER (widget), 6);
@@ -540,6 +554,7 @@ mail_signature_editor_constructed (GObject *object)
        gtk_widget_show (widget);
 
        container = widget;
+       gtk_widget_show (container);
 
        widget = gtk_entry_new ();
        gtk_box_pack_end (GTK_BOX (container), widget, TRUE, TRUE, 0);
@@ -555,16 +570,6 @@ mail_signature_editor_constructed (GObject *object)
                editor, "delete-event",
                G_CALLBACK (mail_signature_editor_delete_event_cb), NULL);
 
-       /* Construct the alert bar for errors. */
-
-       container = gtkhtml_editor->vbox;
-
-       widget = e_alert_bar_new ();
-       gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
-       /* Position 5 should be between the style toolbar and editing area. */
-       gtk_box_reorder_child (GTK_BOX (container), widget, 5);
-       editor->priv->alert_bar = widget;  /* not referenced */
-       /* EAlertBar controls its own visibility. */
 
        /* Configure an EFocusTracker to manage selection actions.
         *
@@ -574,16 +579,16 @@ mail_signature_editor_constructed (GObject *object)
 
        focus_tracker = e_focus_tracker_new (GTK_WINDOW (editor));
 
-       action = gtkhtml_editor_get_action (gtkhtml_editor, "cut");
+       action = e_editor_get_action (editor->priv->editor, "cut");
        e_focus_tracker_set_cut_clipboard_action (focus_tracker, action);
 
-       action = gtkhtml_editor_get_action (gtkhtml_editor, "copy");
+       action = e_editor_get_action (editor->priv->editor, "copy");
        e_focus_tracker_set_copy_clipboard_action (focus_tracker, action);
 
-       action = gtkhtml_editor_get_action (gtkhtml_editor, "paste");
+       action = e_editor_get_action (editor->priv->editor, "paste");
        e_focus_tracker_set_paste_clipboard_action (focus_tracker, action);
 
-       action = gtkhtml_editor_get_action (gtkhtml_editor, "select-all");
+       action = e_editor_get_action (editor->priv->editor, "select-all");
        e_focus_tracker_set_select_all_action (focus_tracker, action);
 
        editor->priv->focus_tracker = focus_tracker;
@@ -605,10 +610,7 @@ mail_signature_editor_constructed (GObject *object)
        if (source == NULL) {
                gtk_widget_grab_focus (editor->priv->entry);
        } else {
-               GtkHTML *html;
-
-               html = gtkhtml_editor_get_html (gtkhtml_editor);
-               gtk_widget_grab_focus (GTK_WIDGET (html));
+               gtk_widget_grab_focus (GTK_WIDGET (editor_widget));
        }
 
        /* Load file content only for an existing signature.
@@ -634,30 +636,6 @@ mail_signature_editor_constructed (GObject *object)
 }
 
 static void
-mail_signature_editor_cut_clipboard (GtkhtmlEditor *editor)
-{
-       /* Do nothing.  EFocusTracker handles this. */
-}
-
-static void
-mail_signature_editor_copy_clipboard (GtkhtmlEditor *editor)
-{
-       /* Do nothing.  EFocusTracker handles this. */
-}
-
-static void
-mail_signature_editor_paste_clipboard (GtkhtmlEditor *editor)
-{
-       /* Do nothing.  EFocusTracker handles this. */
-}
-
-static void
-mail_signature_editor_select_all (GtkhtmlEditor *editor)
-{
-       /* Do nothing.  EFocusTracker handles this. */
-}
-
-static void
 mail_signature_editor_submit_alert (EAlertSink *alert_sink,
                                     EAlert *alert)
 {
@@ -689,7 +667,6 @@ static void
 e_mail_signature_editor_class_init (EMailSignatureEditorClass *class)
 {
        GObjectClass *object_class;
-       GtkhtmlEditorClass *editor_class;
 
        g_type_class_add_private (class, sizeof (EMailSignatureEditorPrivate));
 
@@ -700,12 +677,6 @@ e_mail_signature_editor_class_init (EMailSignatureEditorClass *class)
        object_class->finalize = mail_signature_editor_finalize;
        object_class->constructed = mail_signature_editor_constructed;
 
-       editor_class = GTKHTML_EDITOR_CLASS (class);
-       editor_class->cut_clipboard = mail_signature_editor_cut_clipboard;
-       editor_class->copy_clipboard = mail_signature_editor_copy_clipboard;
-       editor_class->paste_clipboard = mail_signature_editor_paste_clipboard;
-       editor_class->select_all = mail_signature_editor_select_all;
-
        g_object_class_install_property (
                object_class,
                PROP_FOCUS_TRACKER,
@@ -765,7 +736,6 @@ e_mail_signature_editor_new (ESourceRegistry *registry,
 
        return g_object_new (
                E_TYPE_MAIL_SIGNATURE_EDITOR,
-               "html", e_web_view_gtkhtml_new (),
                "registry", registry,
                "source", source, NULL);
 }
@@ -865,23 +835,22 @@ e_mail_signature_editor_commit (EMailSignatureEditor *editor,
        const gchar *extension_name;
        const gchar *mime_type;
        gchar *contents;
-       gboolean is_html;
-       gsize length;
+       EEditorWidget *editor_widget;
+       EEditorWidgetMode mode;
 
        g_return_if_fail (E_IS_MAIL_SIGNATURE_EDITOR (editor));
 
        registry = e_mail_signature_editor_get_registry (editor);
        source = e_mail_signature_editor_get_source (editor);
-       is_html = gtkhtml_editor_get_html_mode (GTKHTML_EDITOR (editor));
+       editor_widget = e_editor_get_editor_widget (editor->priv->editor);
+       mode = e_editor_widget_get_mode (editor_widget);
 
-       if (is_html) {
+       if (mode == E_EDITOR_WIDGET_MODE_HTML) {
                mime_type = "text/html";
-               contents = gtkhtml_editor_get_text_html (
-                       GTKHTML_EDITOR (editor), &length);
+               contents = e_editor_widget_get_text_html (editor_widget);
        } else {
                mime_type = "text/plain";
-               contents = gtkhtml_editor_get_text_plain (
-                       GTKHTML_EDITOR (editor), &length);
+               contents = e_editor_widget_get_text_plain (editor_widget);
        }
 
        extension_name = E_SOURCE_EXTENSION_MAIL_SIGNATURE;
@@ -891,7 +860,7 @@ e_mail_signature_editor_commit (EMailSignatureEditor *editor,
        async_context = g_slice_new0 (AsyncContext);
        async_context->source = g_object_ref (source);
        async_context->contents = contents;  /* takes ownership */
-       async_context->length = length;
+       async_context->length = strlen (contents);
 
        if (G_IS_CANCELLABLE (cancellable))
                async_context->cancellable = g_object_ref (cancellable);
@@ -928,3 +897,10 @@ e_mail_signature_editor_commit_finish (EMailSignatureEditor *editor,
        return !g_simple_async_result_propagate_error (simple, error);
 }
 
+EEditorWidget *
+e_mail_signature_editor_get_editor_widget (EMailSignatureEditor *editor)
+{
+       g_return_val_if_fail (E_IS_MAIL_SIGNATURE_EDITOR (editor), NULL);
+
+       return e_editor_get_editor_widget (editor->priv->editor);
+}
diff --git a/e-util/e-mail-signature-editor.h b/e-util/e-mail-signature-editor.h
index c525d5a..0d689f9 100644
--- a/e-util/e-mail-signature-editor.h
+++ b/e-util/e-mail-signature-editor.h
@@ -23,9 +23,9 @@
 #ifndef E_MAIL_SIGNATURE_EDITOR_H
 #define E_MAIL_SIGNATURE_EDITOR_H
 
-#include <gtkhtml-editor.h>
 #include <libedataserver/libedataserver.h>
 
+#include <e-util/e-editor-widget.h>
 #include <e-util/e-focus-tracker.h>
 
 /* Standard GObject macros */
@@ -54,12 +54,12 @@ typedef struct _EMailSignatureEditorClass EMailSignatureEditorClass;
 typedef struct _EMailSignatureEditorPrivate EMailSignatureEditorPrivate;
 
 struct _EMailSignatureEditor {
-       GtkhtmlEditor parent;
+       GtkWindow parent;
        EMailSignatureEditorPrivate *priv;
 };
 
 struct _EMailSignatureEditorClass {
-       GtkhtmlEditorClass parent_class;
+       GtkWindowClass parent_class;
 };
 
 GType          e_mail_signature_editor_get_type
@@ -81,6 +81,8 @@ gboolean      e_mail_signature_editor_commit_finish
                                                (EMailSignatureEditor *editor,
                                                 GAsyncResult *result,
                                                 GError **error);
+EEditorWidget *        e_mail_signature_editor_get_editor_widget
+                                               (EMailSignatureEditor *editor);
 
 G_END_DECLS
 
diff --git a/e-util/e-mail-signature-manager.c b/e-util/e-mail-signature-manager.c
index b32e9dd..937d41e 100644
--- a/e-util/e-mail-signature-manager.c
+++ b/e-util/e-mail-signature-manager.c
@@ -402,13 +402,19 @@ static void
 mail_signature_manager_add_signature (EMailSignatureManager *manager)
 {
        ESourceRegistry *registry;
+       EEditorWidget *editor_widget;
        GtkWidget *editor;
 
        registry = e_mail_signature_manager_get_registry (manager);
 
        editor = e_mail_signature_editor_new (registry, NULL);
-       gtkhtml_editor_set_html_mode (
-               GTKHTML_EDITOR (editor), manager->priv->prefer_html);
+       editor_widget = e_mail_signature_editor_get_editor_widget (
+                               E_MAIL_SIGNATURE_EDITOR (editor));
+       e_editor_widget_set_mode (
+               editor_widget,
+               manager->priv->prefer_html ?
+                       E_EDITOR_WIDGET_MODE_HTML :
+                       E_EDITOR_WIDGET_MODE_PLAIN_TEXT);
        mail_signature_manager_emit_editor_created (manager, editor);
 
        gtk_widget_grab_focus (manager->priv->tree_view);
@@ -439,6 +445,7 @@ mail_signature_manager_editor_created (EMailSignatureManager *manager,
        gtk_window_set_transient_for (GTK_WINDOW (editor), parent);
        gtk_window_set_position (GTK_WINDOW (editor), position);
        gtk_widget_show (GTK_WIDGET (editor));
+       gtk_widget_set_size_request (GTK_WIDGET (editor), 450, 300);
 }
 
 static void
diff --git a/e-util/e-mail-signature-preview.c b/e-util/e-mail-signature-preview.c
index d5e809f..a1677c5 100644
--- a/e-util/e-mail-signature-preview.c
+++ b/e-util/e-mail-signature-preview.c
@@ -157,12 +157,16 @@ mail_signature_preview_load_cb (ESource *source,
        mime_type = e_source_mail_signature_get_mime_type (extension);
 
        if (g_strcmp0 (mime_type, "text/html") == 0) {
-               e_web_view_load_string (E_WEB_VIEW (preview), contents);
+               webkit_web_view_load_string (
+                       WEBKIT_WEB_VIEW (preview), contents,
+                       "text/html", "UTF-8", "file:///");
        } else {
                gchar *string;
 
                string = g_markup_printf_escaped ("<pre>%s</pre>", contents);
-               e_web_view_load_string (E_WEB_VIEW (preview), string);
+               webkit_web_view_load_string (
+                       WEBKIT_WEB_VIEW (preview), string,
+                       "text/html", "UTF-8", "file:///");
                g_free (string);
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]