[evolution/wip/webkit-composer: 130/372] Port EMailSignatureEditor to EEditor



commit d77da99d6cfda01f94ddff88e8bb3cb4c709a3ac
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 697ba10..27b35cf 100644
--- a/e-util/e-mail-signature-editor.c
+++ b/e-util/e-mail-signature-editor.c
@@ -15,15 +15,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 \
@@ -39,6 +43,8 @@ struct _EMailSignatureEditorPrivate {
        ESource *source;
        gchar *original_name;
 
+       EEditor *editor;
+
        GtkWidget *entry;               /* not referenced */
        GtkWidget *alert_bar;           /* not referenced */
 };
@@ -82,7 +88,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))
@@ -106,6 +112,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;
@@ -147,25 +155,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);
@@ -191,14 +189,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) {
@@ -480,7 +480,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;
@@ -495,9 +495,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
@@ -516,11 +517,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);
@@ -529,7 +529,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);
@@ -539,6 +553,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);
@@ -554,16 +569,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.
         *
@@ -573,16 +578,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;
@@ -604,10 +609,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.
@@ -633,30 +635,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)
 {
@@ -688,7 +666,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));
 
@@ -699,12 +676,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,
@@ -764,7 +735,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);
 }
@@ -864,23 +834,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;
@@ -890,7 +859,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);
@@ -927,3 +896,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 7de6841..25a2b8d 100644
--- a/e-util/e-mail-signature-editor.h
+++ b/e-util/e-mail-signature-editor.h
@@ -22,9 +22,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 */
@@ -53,12 +53,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
@@ -80,6 +80,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 f3a9549..b342e22 100644
--- a/e-util/e-mail-signature-manager.c
+++ b/e-util/e-mail-signature-manager.c
@@ -401,13 +401,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);
@@ -438,6 +444,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 d493bc0..9f0a8d6 100644
--- a/e-util/e-mail-signature-preview.c
+++ b/e-util/e-mail-signature-preview.c
@@ -156,12 +156,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]