[evolution/wip/webkit-composer: 255/372] Move caret position setting from em-composer-utils to e-composer-private
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit-composer: 255/372] Move caret position setting from em-composer-utils to e-composer-private
- Date: Thu, 6 Feb 2014 11:44:56 +0000 (UTC)
commit c9fc31248db2074786f7f776a2835f6b26b64d2e
Author: Tomas Popela <tpopela redhat com>
Date: Tue Apr 23 11:06:09 2013 +0200
Move caret position setting from em-composer-utils to e-composer-private
Moving caret position setting from mail/em-composer-utils.c to
composer/e-composer-private.c because the caret position set in em-composer-utils.c
was modified by setting a signature to email. Also e_editor_selection_{save|restore}
calls were removed because they are not working properly in this case.
composer/e-composer-private.c | 109 +++++++++++++++++++++++++++++++++++++++--
mail/em-composer-utils.c | 96 ------------------------------------
2 files changed, 105 insertions(+), 100 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 5b0d841..d8018c9 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -746,6 +746,110 @@ use_top_signature (EMsgComposer *composer)
}
static void
+composer_size_allocate_cb (GtkWidget *widget,
+ gpointer user_data)
+{
+ GtkWidget *scrolled_window;
+ GtkAdjustment *adj;
+
+ scrolled_window = gtk_widget_get_parent (GTK_WIDGET (widget));
+ adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window));
+
+ /* Scroll only when there is some size allocated */
+ if (gtk_adjustment_get_upper (adj) != 0.0) {
+ /* Scroll web view down to caret */
+ gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size
(adj));
+ gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window), adj);
+ /* Disconnect because we don't want to scroll down the view on every window size change */
+ g_signal_handlers_disconnect_by_func (
+ widget, G_CALLBACK (composer_size_allocate_cb), NULL);
+ }
+}
+
+static void
+composer_move_caret (EMsgComposer *composer)
+{
+ WebKitDOMHTMLElement *body;
+ WebKitDOMRange *new_range;
+ EEditor *editor;
+ EEditorWidget *editor_widget;
+ WebKitDOMDocument *document;
+ WebKitDOMDOMWindow *window;
+ WebKitDOMElement *br_bottom;
+ WebKitDOMDOMSelection *dom_selection;
+ GSettings *settings;
+ gboolean start_bottom;
+
+ /* When there is an option composer-reply-start-bottom set we have
+ * to move the caret between reply and signature. */
+ settings = g_settings_new ("org.gnome.evolution.mail");
+ start_bottom = g_settings_get_boolean (settings, "composer-reply-start-bottom");
+
+ editor = e_msg_composer_get_editor (composer);
+ editor_widget = e_editor_get_editor_widget (editor);
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (editor_widget));
+ window = webkit_dom_document_get_default_view (document);
+ dom_selection = webkit_dom_dom_window_get_selection (window);
+
+ body = webkit_dom_document_get_body (document);
+ new_range = webkit_dom_document_create_range (document);
+
+ if (start_bottom) {
+ WebKitDOMNodeList *blockquotes;
+
+ blockquotes = webkit_dom_document_get_elements_by_tag_name (document, "blockquote");
+ if (webkit_dom_node_list_get_length (blockquotes) != 0) {
+ /* Move caret between reply and signature. */
+ new_range = webkit_dom_document_create_range (document);
+ webkit_dom_range_select_node_contents (new_range,
+ WEBKIT_DOM_NODE (
+ webkit_dom_node_get_next_sibling (webkit_dom_node_list_item
(blockquotes, 0))
+ ), NULL);
+ webkit_dom_range_collapse (new_range, TRUE, NULL);
+
+ } else {
+ br_bottom = webkit_dom_document_get_element_by_id (document, "-x-evolution-br-reply");
+
+ if (!br_bottom) {
+ WebKitDOMElement *br;
+
+ br = webkit_dom_document_create_element (document, "BR", NULL);
+ webkit_dom_html_element_set_id (WEBKIT_DOM_HTML_ELEMENT (br),
"-x-evolution-br-reply");
+ webkit_dom_node_append_child (WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (br),
NULL);
+ br_bottom = webkit_dom_document_get_element_by_id (document,
"-x-evolution-br-reply");
+ }
+
+ webkit_dom_range_select_node_contents (new_range, WEBKIT_DOM_NODE (br_bottom), NULL);
+ webkit_dom_range_collapse (new_range, FALSE, NULL);
+ }
+
+ g_signal_connect (
+ editor_widget, "size-allocate",
+ G_CALLBACK (composer_size_allocate_cb), NULL);
+ } else {
+ /* Move caret on the beginning of message */
+ if (!webkit_dom_document_get_element_by_id (document, "-x-evolution-br-reply")) {
+ WebKitDOMElement *br;
+
+ br = webkit_dom_document_create_element (document, "BR", NULL);
+ webkit_dom_html_element_set_id (WEBKIT_DOM_HTML_ELEMENT (br),
"-x-evolution-br-reply");
+ webkit_dom_node_insert_before (WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (br),
webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)), NULL);
+ }
+
+ webkit_dom_range_select_node_contents (new_range,
+ WEBKIT_DOM_NODE (
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))
+ ), NULL);
+ webkit_dom_range_collapse (new_range, TRUE, NULL);
+ }
+
+ webkit_dom_dom_selection_remove_all_ranges (dom_selection);
+ webkit_dom_dom_selection_add_range (dom_selection, new_range);
+
+ g_object_unref (settings);
+}
+
+static void
composer_load_signature_cb (EMailSignatureComboBox *combo_box,
GAsyncResult *result,
EMsgComposer *composer)
@@ -855,8 +959,6 @@ insert:
editor_widget = e_editor_get_editor_widget (editor);
selection = e_editor_widget_get_selection (editor_widget);
- e_editor_selection_save (selection);
-
/* This prevents our command before/after callbacks from
* screwing around with the signature as we insert it. */
composer->priv->in_signature_insert = TRUE;
@@ -917,8 +1019,7 @@ insert:
g_string_free (html_buffer, TRUE);
}
- e_editor_selection_restore (selection);
-
+ composer_move_caret (composer);
composer->priv->in_signature_insert = FALSE;
exit:
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 4e3e374..2a43c78 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -2812,88 +2812,6 @@ attribution_format (CamelMimeMessage *message)
}
static void
-composer_size_allocate_cb (GtkWidget *widget,
- gpointer user_data)
-{
- GtkWidget *scrolled_window;
- GtkAdjustment *adj;
-
- scrolled_window = gtk_widget_get_parent (GTK_WIDGET (widget));
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window));
-
- /* Scroll only when there is some size allocated */
- if (gtk_adjustment_get_upper (adj) != 0.0) {
- /* Scroll web view down to caret */
- gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size
(adj));
- gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window), adj);
- /* Disconnect because we don't want to scroll down the view on every window size change */
- g_signal_handlers_disconnect_by_func (
- widget, G_CALLBACK (composer_size_allocate_cb), NULL);
- }
-}
-
-static void
-web_view_load_status_changed_cb (WebKitWebView *webkit_web_view,
- GParamSpec *pspec,
- gpointer user_data)
-{
- WebKitDOMDocument *document;
- WebKitDOMRange *new_range;
- WebKitDOMElement *br;
- WebKitDOMHTMLElement *body;
- WebKitDOMNode *br_node;
- WebKitDOMDOMWindow *window;
- WebKitDOMDOMSelection *window_selection;
- WebKitLoadStatus status;
-
- status = webkit_web_view_get_load_status (webkit_web_view);
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- /* Move caret on the end of body element */
- document = webkit_web_view_get_dom_document (webkit_web_view);
- window = webkit_dom_document_get_default_view (document);
- window_selection = webkit_dom_dom_window_get_selection (window);
- body = webkit_dom_document_get_body (document);
-
- br = webkit_dom_document_create_element (document, "BR", NULL);
- br_node = webkit_dom_node_append_child (WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE(br), NULL);
-
- new_range = webkit_dom_document_create_range (document);
- webkit_dom_range_select_node_contents (new_range, WEBKIT_DOM_NODE (br_node), NULL);
- webkit_dom_range_collapse (new_range, FALSE, NULL);
-
- webkit_dom_dom_selection_remove_all_ranges (window_selection);
- webkit_dom_dom_selection_add_range (window_selection, new_range);
-
- /* Disconnect because we don't want to move caret down on every web view status change */
- g_signal_handlers_disconnect_by_func (
- webkit_web_view, G_CALLBACK (web_view_load_status_changed_cb), NULL);
-}
-
-static void
-composer_set_caret_on_body_end (EMsgComposer *composer)
-{
- EEditor *editor;
- EEditorWidget *widget;
-
- editor = e_msg_composer_get_editor (composer);
- widget = e_editor_get_editor_widget (editor);
-
- /* Scroll web view down to caret - we have to wait until
- * GtkScrolledWindow is resized */
- g_signal_connect (
- widget, "size-allocate",
- G_CALLBACK (composer_size_allocate_cb), NULL);
-
- /* Set caret on the end of body - we have to wait until
- * the page is loaded */
- g_signal_connect (
- WEBKIT_WEB_VIEW(widget), "notify::load-status",
- G_CALLBACK (web_view_load_status_changed_cb), NULL);
-}
-
-static void
composer_set_body (EMsgComposer *composer,
CamelMimeMessage *message,
EMailReplyStyle style,
@@ -2902,16 +2820,10 @@ composer_set_body (EMsgComposer *composer,
gchar *text, *credits, *original;
CamelMimePart *part;
CamelSession *session;
- GSettings *settings;
- gboolean start_bottom;
guint32 validity_found = 0;
session = e_msg_composer_ref_session (composer);
- settings = g_settings_new ("org.gnome.evolution.mail");
-
- start_bottom = g_settings_get_boolean (settings, "composer-reply-start-bottom");
-
switch (style) {
case E_MAIL_REPLY_STYLE_DO_NOT_QUOTE:
/* do nothing */
@@ -2932,9 +2844,6 @@ composer_set_body (EMsgComposer *composer,
g_free (text);
g_free (original);
emu_update_composers_security (composer, validity_found);
-
- if (start_bottom)
- composer_set_caret_on_body_end (composer);
break;
case E_MAIL_REPLY_STYLE_QUOTED:
@@ -2949,14 +2858,9 @@ composer_set_body (EMsgComposer *composer,
e_msg_composer_set_body_text (composer, text, TRUE);
g_free (text);
emu_update_composers_security (composer, validity_found);
-
- if (start_bottom)
- composer_set_caret_on_body_end (composer);
break;
}
- g_object_unref (settings);
-
g_object_unref (session);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]