[evolution/wip/webkit-composer: 79/372] Make Undo and Redo buttons work



commit 0d07dcf3808c21e4c88247b0812ade08bfc8a4d2
Author: Dan Vrátil <dvratil redhat com>
Date:   Mon Jul 30 19:09:14 2012 +0200

    Make Undo and Redo buttons work
    
    Undo and Redo actions now perform expected actions
    and their sensitivity is automatically controlled
    through EEditorWidget properties

 e-util/e-editor-actions.c |   11 ++++++++
 e-util/e-editor-actions.h |    4 +++
 e-util/e-editor-widget.c  |   59 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 1 deletions(-)
---
diff --git a/e-util/e-editor-actions.c b/e-util/e-editor-actions.c
index 74f89f3..5aef1a9 100644
--- a/e-util/e-editor-actions.c
+++ b/e-util/e-editor-actions.c
@@ -2322,6 +2322,7 @@ editor_actions_init (EEditor *editor)
        GtkActionGroup *action_group;
        GtkUIManager *manager;
        const gchar *domain;
+       EEditorWidget *editor_widget;
 
        g_return_if_fail (E_IS_EDITOR (editor));
 
@@ -2434,5 +2435,15 @@ editor_actions_init (EEditor *editor)
                "short-label", _("_Table"), NULL);
 
        gtk_action_set_sensitive (ACTION (UNINDENT), FALSE);
+
+       editor_widget = e_editor_get_editor_widget (editor);
+       g_object_bind_property (
+               editor_widget, "can-redo",
+               ACTION (REDO), "sensitive",
+               G_BINDING_SYNC_CREATE);
+       g_object_bind_property (
+               editor_widget, "can-undo",
+               ACTION (UNDO), "sensitive",
+               G_BINDING_SYNC_CREATE);
 }
  
diff --git a/e-util/e-editor-actions.h b/e-util/e-editor-actions.h
index 3f84b13..52b8199 100644
--- a/e-util/e-editor-actions.h
+++ b/e-util/e-editor-actions.h
@@ -116,6 +116,8 @@
        E_EDITOR_ACTION ((editor), "properties-rule")
 #define E_EDITOR_ACTION_PROPERTIES_TABLE(editor) \
        E_EDITOR_ACTION ((editor), "properties-table")
+#define E_EDITOR_ACTION_REDO(editor) \
+       E_EDITOR_ACTION ((editor), "redo")
 #define E_EDITOR_ACTION_SHOW_FIND(editor) \
        E_EDITOR_ACTION ((editor), "show-find")
 #define E_EDITOR_ACTION_SHOW_REPLACE(editor) \
@@ -146,6 +148,8 @@
        E_EDITOR_ACTION ((editor), "test-url")
 #define E_EDITOR_ACTION_UNDERLINE(editor) \
        E_EDITOR_ACTION ((editor), "underline")
+#define E_EDITOR_ACTION_UNDO(editor) \
+       E_EDITOR_ACTION ((editor), "undo")
 #define E_EDITOR_ACTION_UNINDENT(editor) \
        E_EDITOR_ACTION ((editor), "unindent")
 
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index 1c9add6..b88ef8d 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -30,6 +30,8 @@ struct _EEditorWidgetPrivate {
        gint inline_spelling    : 1;
        gint magic_links        : 1;
        gint magic_smileys      : 1;
+       gint can_redo           : 1;
+       gint can_undo           : 1;
 
        /* FIXME WEBKIT Is this in widget's competence? */
        GList *spelling_langs;
@@ -48,11 +50,33 @@ enum {
        PROP_INLINE_SPELLING,
        PROP_MAGIC_LINKS,
        PROP_MAGIC_SMILEYS,
-       PROP_SPELL_LANGUAGES
+       PROP_SPELL_LANGUAGES,
+       PROP_CAN_REDO,
+       PROP_CAN_UNDO
 };
 
 
 static void
+editor_widget_user_changed_contents_cb (EEditorWidget *widget,
+                                       gpointer user_data)
+{
+       gboolean can_redo, can_undo;
+       e_editor_widget_set_changed (widget, TRUE);
+
+       can_redo = webkit_web_view_can_redo (WEBKIT_WEB_VIEW (widget));
+       if ((widget->priv->can_redo ? TRUE : FALSE) != (can_redo ? TRUE : FALSE)) {
+               widget->priv->can_redo = can_redo;
+               g_object_notify (G_OBJECT (widget), "can-redo");
+       }
+
+       can_undo = webkit_web_view_can_undo (WEBKIT_WEB_VIEW (widget));
+       if ((widget->priv->can_undo ? TRUE : FALSE) != (can_undo ? TRUE : FALSE)) {
+               widget->priv->can_undo = can_undo;
+               g_object_notify (G_OBJECT (widget), "can-undo");
+       }
+}
+
+static void
 e_editor_widget_get_property (GObject *object,
                              guint property_id,
                              GValue *value,
@@ -88,6 +112,16 @@ e_editor_widget_get_property (GObject *object,
                                value, e_editor_widget_get_changed (
                                E_EDITOR_WIDGET (object)));
                        return;
+               case PROP_CAN_REDO:
+                       g_value_set_boolean (
+                               value, webkit_web_view_can_redo (
+                               WEBKIT_WEB_VIEW (object)));
+                       return;
+               case PROP_CAN_UNDO:
+                       g_value_set_boolean (
+                               value, webkit_web_view_can_undo (
+                               WEBKIT_WEB_VIEW (object)));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -204,6 +238,26 @@ e_editor_widget_class_init (EEditorWidgetClass *klass)
                        _("Whether editor changed"),
                        FALSE,
                        G_PARAM_READWRITE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_CAN_REDO,
+               g_param_spec_boolean (
+                       "can-redo",
+                       "Can Redo",
+                       NULL,
+                       FALSE,
+                       G_PARAM_READABLE));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_CAN_UNDO,
+               g_param_spec_boolean (
+                       "can-undo",
+                       "Can Undo",
+                       NULL,
+                       FALSE,
+                       G_PARAM_READABLE));
 }
 
 static void
@@ -242,6 +296,9 @@ e_editor_widget_init (EEditorWidget *editor)
        document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (editor));
        webkit_dom_document_exec_command (
                document, "styleWithCSS", FALSE, "false");
+
+       g_signal_connect (editor, "user-changed-contents",
+               G_CALLBACK (editor_widget_user_changed_contents_cb), NULL);
 }
 
 EEditorWidget *


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