[evolution/webkit-composer: 24/30] Port EMailSignatureEditor to EEditorWindow



commit 909dfd9dda61be3299c91d2aae38b08ca327e56c
Author: Dan VrÃtil <dvratil redhat com>
Date:   Mon Aug 27 17:23:07 2012 +0200

    Port EMailSignatureEditor to EEditorWindow

 widgets/misc/e-mail-signature-editor.c  |  135 +++++++++++++++----------------
 widgets/misc/e-mail-signature-editor.h  |    7 +-
 widgets/misc/e-mail-signature-manager.c |    2 +-
 3 files changed, 70 insertions(+), 74 deletions(-)
---
diff --git a/widgets/misc/e-mail-signature-editor.c b/widgets/misc/e-mail-signature-editor.c
index a954855..bd9028d 100644
--- a/widgets/misc/e-mail-signature-editor.c
+++ b/widgets/misc/e-mail-signature-editor.c
@@ -25,7 +25,6 @@
 #include <string.h>
 #include <glib/gi18n.h>
 
-#include <editor/e-editor.h>
 #include <libevolution-utils/e-alert-dialog.h>
 #include <libevolution-utils/e-alert-sink.h>
 #include <misc/e-alert-bar.h>
@@ -44,8 +43,6 @@ struct _EMailSignatureEditorPrivate {
 	ESource *source;
 	gchar *original_name;
 
-	EEditor *editor;
-
 	GtkWidget *entry;		/* not referenced */
 	GtkWidget *alert_bar;		/* not referenced */
 };
@@ -89,7 +86,7 @@ static void	e_mail_signature_editor_alert_sink_init
 G_DEFINE_TYPE_WITH_CODE (
 	EMailSignatureEditor,
 	e_mail_signature_editor,
-	GTK_TYPE_WINDOW,
+	E_TYPE_EDITOR_WINDOW,
 	G_IMPLEMENT_INTERFACE (
 		E_TYPE_ALERT_SINK,
 		e_mail_signature_editor_alert_sink_init))
@@ -113,10 +110,11 @@ mail_signature_editor_loaded_cb (GObject *object,
                                  GAsyncResult *result,
                                  gpointer user_data)
 {
+	EEditor *editor;
 	EEditorWidget *editor_widget;
 	EEditorSelection *editor_selection;
 	ESource *source;
-	EMailSignatureEditor *editor;
+	EMailSignatureEditor *window;
 	ESourceMailSignature *extension;
 	const gchar *extension_name;
 	const gchar *mime_type;
@@ -125,7 +123,7 @@ mail_signature_editor_loaded_cb (GObject *object,
 	GError *error = NULL;
 
 	source = E_SOURCE (object);
-	editor = E_MAIL_SIGNATURE_EDITOR (user_data);
+	window = E_MAIL_SIGNATURE_EDITOR (user_data);
 
 	e_source_mail_signature_load_finish (
 		source, result, &contents, NULL, &error);
@@ -133,17 +131,17 @@ mail_signature_editor_loaded_cb (GObject *object,
 	/* Ignore cancellations. */
 	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 		g_warn_if_fail (contents == NULL);
-		g_object_unref (editor);
+		g_object_unref (window);
 		g_error_free (error);
 		return;
 
 	} else if (error != NULL) {
 		g_warn_if_fail (contents == NULL);
 		e_alert_submit (
-			E_ALERT_SINK (editor),
+			E_ALERT_SINK (window),
 			"widgets:no-load-signature",
 			error->message, NULL);
-		g_object_unref (editor);
+		g_object_unref (window);
 		g_error_free (error);
 		return;
 	}
@@ -156,7 +154,8 @@ 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);
 
-	editor_widget = e_editor_get_editor_widget (editor->priv->editor);
+	editor = e_editor_window_get_editor (E_EDITOR_WINDOW (object));
+	editor_widget = e_editor_get_editor_widget (editor);
 	e_editor_widget_set_mode (editor_widget,
 		(is_html) ? E_EDITOR_WIDGET_MODE_HTML : E_EDITOR_WIDGET_MODE_PLAIN_TEXT);
 
@@ -169,7 +168,7 @@ mail_signature_editor_loaded_cb (GObject *object,
 
 	g_free (contents);
 
-	g_object_unref (editor);
+	g_object_unref (window);
 }
 
 static gboolean
@@ -188,16 +187,18 @@ mail_signature_editor_delete_event_cb (EMailSignatureEditor *editor,
 
 static void
 action_close_cb (GtkAction *action,
-                 EMailSignatureEditor *editor)
+                 EMailSignatureEditor *window)
 {
+	EEditor *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);
+	original_name = window->priv->original_name;
+	signature_name = gtk_entry_get_text (GTK_ENTRY (window->priv->entry));
+	editor = e_editor_window_get_editor (E_EDITOR_WINDOW (window));
+	editor_widget = e_editor_get_editor_widget (editor);
 
 	something_changed |= webkit_web_view_can_undo (WEBKIT_WEB_VIEW (editor_widget));
 	something_changed |= (strcmp (signature_name, original_name) != 0);
@@ -206,12 +207,12 @@ action_close_cb (GtkAction *action,
 		gint response;
 
 		response = e_alert_run_dialog_for_args (
-			GTK_WINDOW (editor),
+			GTK_WINDOW (window),
 			"widgets:ask-signature-changed", NULL);
 		if (response == GTK_RESPONSE_YES) {
 			GtkActionGroup *action_group;
 
-			action_group = editor->priv->action_group;
+			action_group = window->priv->action_group;
 			action = gtk_action_group_get_action (
 				action_group, "save-and-close");
 			gtk_action_activate (action);
@@ -220,7 +221,7 @@ action_close_cb (GtkAction *action,
 			return;
 	}
 
-	gtk_widget_destroy (GTK_WIDGET (editor));
+	gtk_widget_destroy (GTK_WIDGET (window));
 }
 
 static void
@@ -467,9 +468,10 @@ mail_signature_editor_finalize (GObject *object)
 static void
 mail_signature_editor_constructed (GObject *object)
 {
-	EMailSignatureEditor *editor;
+	EMailSignatureEditor *window;
 	GtkActionGroup *action_group;
 	EFocusTracker *focus_tracker;
+	EEditor *editor;
 	EEditorWidget *editor_widget;
 	GtkUIManager *ui_manager;
 	GDBusObject *dbus_object;
@@ -484,11 +486,11 @@ mail_signature_editor_constructed (GObject *object)
 	G_OBJECT_CLASS (e_mail_signature_editor_parent_class)->
 		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);
+	window = E_MAIL_SIGNATURE_EDITOR (object);
+	editor = e_editor_window_get_editor (E_EDITOR_WINDOW (window));
+	editor_widget = e_editor_get_editor_widget (editor);
 
-	ui_manager = e_editor_get_ui_manager (editor->priv->editor);
+	ui_manager = e_editor_get_ui_manager (editor);
 
 	/* Because we are loading from a hard-coded string, there is
 	 * no chance of I/O errors.  Failure here implies a malformed
@@ -502,25 +504,25 @@ mail_signature_editor_constructed (GObject *object)
 		action_group, GETTEXT_PACKAGE);
 	gtk_action_group_add_actions (
 		action_group, entries,
-		G_N_ELEMENTS (entries), editor);
+		G_N_ELEMENTS (entries), window);
 	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
-	editor->priv->action_group = g_object_ref (action_group);
+	window->priv->action_group = g_object_ref (action_group);
 
 	/* Hide page properties because it is not inherited in the mail. */
-	action = e_editor_get_action (editor->priv->editor, "properties-page");
+	action = e_editor_get_action (editor, "properties-page");
 	gtk_action_set_visible (action, FALSE);
 
-	action = e_editor_get_action (editor->priv->editor, "context-properties-page");
+	action = e_editor_get_action (editor, "context-properties-page");
 	gtk_action_set_visible (action, FALSE);
 
 	gtk_ui_manager_ensure_update (ui_manager);
 
-	gtk_window_set_title (GTK_WINDOW (editor), _("Edit Signature"));
+	gtk_window_set_title (GTK_WINDOW (window), _("Edit Signature"));
 
 	/* Construct the signature name entry. */
 
 	container = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
-	gtk_container_add (GTK_CONTAINER (editor), container);
+	e_editor_window_pack_above (E_EDITOR_WINDOW (window), container);
 	gtk_widget_show (container);
 
 	/* Construct the alert bar for errors. */
@@ -528,76 +530,64 @@ mail_signature_editor_constructed (GObject *object)
 	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 */
+	window->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_hbox_new (FALSE, 6);
 	gtk_container_set_border_width (GTK_CONTAINER (widget), 6);
-	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
-	/* Position 2 should be between the main and style toolbars. */
-	gtk_box_reorder_child (GTK_BOX (container), widget, 2);
+	e_editor_window_pack_above (E_EDITOR_WINDOW (window), widget);
 	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);
-	editor->priv->entry = widget;  /* not referenced */
+	window->priv->entry = widget;  /* not referenced */
 	gtk_widget_show (widget);
 
 	widget = gtk_label_new_with_mnemonic (_("_Signature Name:"));
-	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), editor->priv->entry);
+	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), window->priv->entry);
 	gtk_box_pack_end (GTK_BOX (container), widget, FALSE, FALSE, 0);
 	gtk_widget_show (widget);
 
 	g_signal_connect (
-		editor, "delete-event",
+		window, "delete-event",
 		G_CALLBACK (mail_signature_editor_delete_event_cb), NULL);
 
 
-	/* Configure an EFocusTracker to manage selection actions.
-	 *
-	 * XXX GtkhtmlEditor does not manage its own selection actions,
-	 *     which is technically a bug but works in our favor here
-	 *     because it won't cause any conflicts with EFocusTracker. */
-
-	focus_tracker = e_focus_tracker_new (GTK_WINDOW (editor));
+	/* Configure an EFocusTracker to manage selection actions. */
+	focus_tracker = e_focus_tracker_new (GTK_WINDOW (window));
 
-	action = e_editor_get_action (editor->priv->editor, "cut");
+	action = e_editor_get_action (editor, "cut");
 	e_focus_tracker_set_cut_clipboard_action (focus_tracker, action);
 
-	action = e_editor_get_action (editor->priv->editor, "copy");
+	action = e_editor_get_action (editor, "copy");
 	e_focus_tracker_set_copy_clipboard_action (focus_tracker, action);
 
-	action = e_editor_get_action (editor->priv->editor, "paste");
+	action = e_editor_get_action (editor, "paste");
 	e_focus_tracker_set_paste_clipboard_action (focus_tracker, action);
 
-	action = e_editor_get_action (editor->priv->editor, "select-all");
+	action = e_editor_get_action (editor, "select-all");
 	e_focus_tracker_set_select_all_action (focus_tracker, action);
 
-	editor->priv->focus_tracker = focus_tracker;
+	window->priv->focus_tracker = focus_tracker;
 
-	source = e_mail_signature_editor_get_source (editor);
+	source = e_mail_signature_editor_get_source (window);
 
 	display_name = e_source_get_display_name (source);
 	if (display_name == NULL || *display_name == '\0')
 		display_name = _("Unnamed");
 
 	/* Set the entry text before we grab focus. */
-	g_free (editor->priv->original_name);
-	editor->priv->original_name = g_strdup (display_name);
-	gtk_entry_set_text (GTK_ENTRY (editor->priv->entry), display_name);
+	g_free (window->priv->original_name);
+	window->priv->original_name = g_strdup (display_name);
+	gtk_entry_set_text (GTK_ENTRY (window->priv->entry), display_name);
 
 	/* Set the focus appropriately.  If this is a new signature, draw
 	 * the user's attention to the signature name entry.  Otherwise go
 	 * straight to the editing area. */
 	if (source == NULL) {
-		gtk_widget_grab_focus (editor->priv->entry);
+		gtk_widget_grab_focus (window->priv->entry);
 	} else {
 		gtk_widget_grab_focus (GTK_WIDGET (editor_widget));
 	}
@@ -615,10 +605,10 @@ mail_signature_editor_constructed (GObject *object)
 			G_PRIORITY_DEFAULT,
 			cancellable,
 			mail_signature_editor_loaded_cb,
-			g_object_ref (editor));
+			g_object_ref (window));
 
-		g_warn_if_fail (editor->priv->cancellable == NULL);
-		editor->priv->cancellable = cancellable;
+		g_warn_if_fail (window->priv->cancellable == NULL);
+		window->priv->cancellable = cancellable;
 
 		g_object_unref (dbus_object);
 	}
@@ -811,7 +801,7 @@ mail_signature_editor_commit_cb (GObject *object,
 }
 
 void
-e_mail_signature_editor_commit (EMailSignatureEditor *editor,
+e_mail_signature_editor_commit (EMailSignatureEditor *window,
                                 GCancellable *cancellable,
                                 GAsyncReadyCallback callback,
                                 gpointer user_data)
@@ -824,14 +814,16 @@ e_mail_signature_editor_commit (EMailSignatureEditor *editor,
 	const gchar *extension_name;
 	const gchar *mime_type;
 	gchar *contents;
+	EEditor  *editor;
 	EEditorWidget *editor_widget;
 	EEditorWidgetMode mode;
 
-	g_return_if_fail (E_IS_MAIL_SIGNATURE_EDITOR (editor));
+	g_return_if_fail (E_IS_MAIL_SIGNATURE_EDITOR (window));
 
-	registry = e_mail_signature_editor_get_registry (editor);
-	source = e_mail_signature_editor_get_source (editor);
-	editor_widget = e_editor_get_editor_widget (editor->priv->editor);
+	registry = e_mail_signature_editor_get_registry (window);
+	source = e_mail_signature_editor_get_source (window);
+	editor = e_editor_window_get_editor (E_EDITOR_WINDOW (window));
+	editor_widget = e_editor_get_editor_widget (editor);
 	mode = e_editor_widget_get_mode (editor_widget);
 
 	if (mode == E_EDITOR_WIDGET_MODE_HTML) {
@@ -855,7 +847,7 @@ e_mail_signature_editor_commit (EMailSignatureEditor *editor,
 		async_context->cancellable = g_object_ref (cancellable);
 
 	simple = g_simple_async_result_new (
-		G_OBJECT (editor), callback, user_data,
+		G_OBJECT (window), callback, user_data,
 		e_mail_signature_editor_commit);
 
 	g_simple_async_result_set_op_res_gpointer (
@@ -887,9 +879,12 @@ e_mail_signature_editor_commit_finish (EMailSignatureEditor *editor,
 }
 
 EEditorWidget *
-e_mail_signature_editor_get_editor_widget (EMailSignatureEditor *editor)
+e_mail_signature_editor_get_editor_widget (EMailSignatureEditor *window)
 {
-	g_return_val_if_fail (E_IS_MAIL_SIGNATURE_EDITOR (editor), NULL);
+	EEditor *editor;
+
+	g_return_val_if_fail (E_IS_MAIL_SIGNATURE_EDITOR (window), NULL);
 
-	return e_editor_get_editor_widget (editor->priv->editor);
+	editor = e_editor_window_get_editor (E_EDITOR_WINDOW (window));
+	return e_editor_get_editor_widget (editor);
 }
diff --git a/widgets/misc/e-mail-signature-editor.h b/widgets/misc/e-mail-signature-editor.h
index dfed2a4..56cfad1 100644
--- a/widgets/misc/e-mail-signature-editor.h
+++ b/widgets/misc/e-mail-signature-editor.h
@@ -19,9 +19,10 @@
 #ifndef E_MAIL_SIGNATURE_EDITOR_H
 #define E_MAIL_SIGNATURE_EDITOR_H
 
+#include <editor/e-editor-window.h>
+#include <editor/e-editor-widget.h>
 #include <misc/e-focus-tracker.h>
 #include <libedataserver/libedataserver.h>
-#include <editor/e-editor-widget.h>
 
 /* Standard GObject macros */
 #define E_TYPE_MAIL_SIGNATURE_EDITOR \
@@ -49,12 +50,12 @@ typedef struct _EMailSignatureEditorClass EMailSignatureEditorClass;
 typedef struct _EMailSignatureEditorPrivate EMailSignatureEditorPrivate;
 
 struct _EMailSignatureEditor {
-	GtkWindow parent;
+	EEditorWindow parent;
 	EMailSignatureEditorPrivate *priv;
 };
 
 struct _EMailSignatureEditorClass {
-	GtkWindowClass parent_class;
+	EEditorWindowClass parent_class;
 };
 
 GType		e_mail_signature_editor_get_type
diff --git a/widgets/misc/e-mail-signature-manager.c b/widgets/misc/e-mail-signature-manager.c
index 68e4e6c..4c13caa 100644
--- a/widgets/misc/e-mail-signature-manager.c
+++ b/widgets/misc/e-mail-signature-manager.c
@@ -443,8 +443,8 @@ 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);
+	gtk_widget_show (GTK_WIDGET (editor));
 }
 
 static void



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