[evolution/webkit-composer] Disable composer UI when editor is not editable



commit 58a96ef9f96274641168fb101f2e0523540f53bf
Author: Dan VrÃtil <dvratil redhat com>
Date:   Tue Sep 11 11:06:05 2012 +0200

    Disable composer UI when editor is not editable

 composer/e-composer-actions.c     |    1 -
 composer/e-composer-private.c     |   11 ++++++++---
 widgets/editor/e-editor-actions.c |   18 ++++++++++++++++++
 widgets/editor/e-editor-test.c    |   21 +++++++++++++++++++++
 widgets/editor/e-editor.c         |    4 ++++
 5 files changed, 51 insertions(+), 4 deletions(-)
---
diff --git a/composer/e-composer-actions.c b/composer/e-composer-actions.c
index 3d25601..c736e63 100644
--- a/composer/e-composer-actions.c
+++ b/composer/e-composer-actions.c
@@ -530,7 +530,6 @@ e_composer_actions_init (EMsgComposer *composer)
 		ACTION (PICTURE_GALLERY), "sensitive",
 		G_BINDING_SYNC_CREATE);
 
-	/* FIXME WEBKIT Make sure this works */
 	g_object_bind_property (
 		editor_widget, "editable",
 		e_editor_get_action (editor, "edit-menu"), "sensitive",
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 259bdf4..c888ad1 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -261,8 +261,8 @@ e_composer_private_constructed (EMsgComposer *composer)
 
 	priv->focus_tracker = focus_tracker;
 
-	container = gtk_hbox_new (FALSE, 0);
-	gtk_widget_set_hexpand (container, TRUE);
+	container = gtk_vbox_new (FALSE, 0);
+	gtk_widget_set_vexpand (container, FALSE);
 	gtk_widget_show (container);
 	e_editor_window_pack_above (E_EDITOR_WINDOW (composer), container);
 
@@ -283,6 +283,11 @@ e_composer_private_constructed (EMsgComposer *composer)
 	gtk_container_set_border_width (GTK_CONTAINER (widget), 6);
 	gtk_widget_set_hexpand (widget, TRUE);
 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
+	g_object_bind_property (
+		editor_widget, "editable",
+		widget, "sensitive",
+		G_BINDING_SYNC_CREATE);
+
 	/* FIXME WEBKIT
 	if (small_screen_mode)
 		gtk_box_reorder_child (GTK_BOX (container), widget, 1);
@@ -318,7 +323,7 @@ e_composer_private_constructed (EMsgComposer *composer)
 
 	g_object_bind_property (
 		editor_widget, "editable",
-		widget, "editable",
+		widget, "sensitive",
 		G_BINDING_SYNC_CREATE);
 
 	/* FIXME WEBKIT Port this if small_screen_mode works */
diff --git a/widgets/editor/e-editor-actions.c b/widgets/editor/e-editor-actions.c
index 72b01d5..f556165 100644
--- a/widgets/editor/e-editor-actions.c
+++ b/widgets/editor/e-editor-actions.c
@@ -1986,4 +1986,22 @@ editor_actions_init (EEditor *editor)
 		editor->priv->selection, "underline",
 		ACTION (UNDERLINE), "active",
 		G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+
+	/* Disable all actions and toolbars when editor is not editable */
+	g_object_bind_property (
+		editor_widget, "editable",
+		editor->priv->core_actions, "sensitive",
+		G_BINDING_SYNC_CREATE);
+	g_object_bind_property (
+		editor_widget, "editable",
+		editor->priv->html_actions, "sensitive",
+		G_BINDING_SYNC_CREATE);
+	g_object_bind_property (
+		editor_widget, "editable",
+		editor->priv->spell_check_actions, "sensitive",
+		G_BINDING_SYNC_CREATE);
+	g_object_bind_property (
+		editor_widget, "editable",
+		editor->priv->suggestion_actions, "sensitive",
+		G_BINDING_SYNC_CREATE);
 }
diff --git a/widgets/editor/e-editor-test.c b/widgets/editor/e-editor-test.c
index 559340d..a34b4f4 100644
--- a/widgets/editor/e-editor-test.c
+++ b/widgets/editor/e-editor-test.c
@@ -36,6 +36,8 @@ static const gchar *file_ui =
 "     <menuitem action='print-preview'/>\n"
 "     <menuitem action='print'/>\n"
 "     <separator/>\n"
+"     <menuitem action='disable-editor'/>\n"
+"     <separator/>\n"
 "     <menuitem action='quit'/>\n"
 "    </menu>\n"
 "  </menubar>\n"
@@ -253,6 +255,18 @@ action_save_as_cb (GtkAction *action,
 }
 
 static void
+action_toggle_editor (GtkAction *action,
+		      EEditor *editor)
+{
+	EEditorWidget *widget;
+
+	widget = e_editor_get_editor_widget (editor);
+	webkit_web_view_set_editable (
+		WEBKIT_WEB_VIEW (widget),
+		! webkit_web_view_get_editable (WEBKIT_WEB_VIEW (widget)));
+}
+
+static void
 action_view_html_output (GtkAction *action,
                          EEditor *editor)
 {
@@ -323,6 +337,13 @@ static GtkActionEntry file_entries[] = {
 	  NULL,
 	  G_CALLBACK (action_save_as_cb) },
 
+	{ "disable-editor",
+	  NULL,
+	  N_("Disable/Enable Editor"),
+	  NULL,
+	  NULL,
+	  G_CALLBACK (action_toggle_editor) },
+
 	{ "file-menu",
 	  NULL,
 	  N_("_File"),
diff --git a/widgets/editor/e-editor.c b/widgets/editor/e-editor.c
index 0c4d667..3e25ec9 100644
--- a/widgets/editor/e-editor.c
+++ b/widgets/editor/e-editor.c
@@ -646,6 +646,10 @@ editor_constructed (GObject *object)
 		priv->color_combo_box, "current-color",
 		priv->selection, "font-color",
 		G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+	g_object_bind_property (
+		priv->editor_widget, "editable",
+		priv->color_combo_box, "sensitive",
+		G_BINDING_SYNC_CREATE);
 
 	tool_item = gtk_tool_item_new ();
 	widget = e_action_combo_box_new_with_action (



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