[evolution] EHTMLEditor - Various fixes when editting the message as new
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditor - Various fixes when editting the message as new
- Date: Thu, 23 Oct 2014 14:01:01 +0000 (UTC)
commit ba6b345acd7bab15035cdc50827b0ec0d3d34e4a
Author: Tomas Popela <tpopela redhat com>
Date: Thu Oct 23 15:55:12 2014 +0200
EHTMLEditor - Various fixes when editting the message as new
Don't insert the unnecessary new line into the body and always move the
caret to the beginning the of body. Also rename the is_from_draft
variable in composer to is_message_from_draft.
composer/e-composer-private.c | 38 +++++++++++++---------
composer/e-composer-private.h | 1 -
composer/e-msg-composer.c | 30 +++++++++++------
e-util/e-html-editor-view.c | 70 ++++++++++++++++++++++++++++++++---------
e-util/e-html-editor-view.h | 5 +++
5 files changed, 101 insertions(+), 43 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 5f26c0d..229b3aa 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -131,7 +131,6 @@ e_composer_private_constructed (EMsgComposer *composer)
priv->charset = e_composer_get_default_charset ();
- priv->is_from_message = FALSE;
priv->is_from_new_message = FALSE;
priv->set_signature_from_message = FALSE;
priv->disable_signature = FALSE;
@@ -818,7 +817,9 @@ composer_move_caret (EMsgComposer *composer)
EHTMLEditorView *view;
EHTMLEditorSelection *editor_selection;
GSettings *settings;
- gboolean start_bottom, top_signature, is_from_draft;
+ gboolean start_bottom, top_signature;
+ gboolean is_message_from_draft;
+ gboolean is_message_from_edit_as_new;
gboolean has_paragraphs_in_body = TRUE;
WebKitDOMDocument *document;
WebKitDOMDOMWindow *window;
@@ -834,15 +835,17 @@ composer_move_caret (EMsgComposer *composer)
start_bottom = g_settings_get_boolean (settings, "composer-reply-start-bottom");
g_object_unref (settings);
- top_signature =
- use_top_signature (composer) &&
- !composer->priv->is_from_message &&
- !composer->priv->is_from_new_message;
-
editor = e_msg_composer_get_editor (composer);
view = e_html_editor_get_view (editor);
editor_selection = e_html_editor_view_get_selection (view);
- is_from_draft = e_html_editor_view_is_message_from_draft (view);
+ is_message_from_draft = e_html_editor_view_is_message_from_draft (view);
+ is_message_from_edit_as_new =
+ e_html_editor_view_is_message_from_edit_as_new (view);
+
+ top_signature =
+ use_top_signature (composer) &&
+ !is_message_from_edit_as_new &&
+ !composer->priv->is_from_new_message;
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
window = webkit_dom_document_get_default_view (document);
@@ -854,8 +857,8 @@ composer_move_caret (EMsgComposer *composer)
new_range = webkit_dom_document_create_range (document);
/* If editing message as new don't handle with caret */
- if (composer->priv->is_from_message || is_from_draft) {
- if (composer->priv->is_from_message)
+ if (is_message_from_edit_as_new || is_message_from_draft) {
+ if (is_message_from_edit_as_new)
webkit_dom_element_set_attribute (
WEBKIT_DOM_ELEMENT (body),
"data-edit-as-new",
@@ -993,6 +996,7 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
gulong list_length, ii;
GSettings *settings;
gboolean start_bottom;
+ gboolean is_message_from_edit_as_new;
e_mail_signature_combo_box_load_selected_finish (
combo_box, result, &contents, &length, &is_html, &error);
@@ -1004,11 +1008,16 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
goto exit;
}
- /* "Edit as New Message" sets "priv->is_from_message".
+ editor = e_msg_composer_get_editor (composer);
+ view = e_html_editor_get_view (editor);
+ is_message_from_edit_as_new =
+ e_html_editor_view_is_message_from_edit_as_new (view);
+
+ /* "Edit as New Message" sets is_message_from_edit_as_new.
* Always put the signature at the bottom for that case. */
top_signature =
use_top_signature (composer) &&
- !composer->priv->is_from_message &&
+ !is_message_from_edit_as_new &&
!composer->priv->is_from_new_message;
settings = g_settings_new ("org.gnome.evolution.mail");
@@ -1081,9 +1090,6 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
insert:
/* Remove the old signature and insert the new one. */
- editor = e_msg_composer_get_editor (composer);
- view = e_html_editor_get_view (editor);
-
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
signatures = webkit_dom_document_get_elements_by_class_name (
@@ -1100,7 +1106,7 @@ insert:
/* When we are editing a message with signature we need to set active
* signature id in signature combo box otherwise no signature will be
* added but we have to do it just once when the composer opens */
- if (composer->priv->is_from_message && composer->priv->set_signature_from_message) {
+ if (is_message_from_edit_as_new && composer->priv->set_signature_from_message) {
gchar *name = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (signature),
"name");
gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo_box), name);
g_free (name);
diff --git a/composer/e-composer-private.h b/composer/e-composer-private.h
index 46c72b7..2a64f35 100644
--- a/composer/e-composer-private.h
+++ b/composer/e-composer-private.h
@@ -95,7 +95,6 @@ struct _EMsgComposerPrivate {
gboolean busy;
gboolean disable_signature;
gboolean is_from_draft;
- gboolean is_from_message;
gboolean is_from_new_message;
/* The web view is uneditable while the editor is busy.
* This is used to restore the previous editable state. */
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index a62ace0..41a7275 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1586,6 +1586,8 @@ msg_composer_subject_changed_cb (EMsgComposer *composer)
static void
msg_composer_mail_identity_changed_cb (EMsgComposer *composer)
{
+ EHTMLEditor *editor;
+ EHTMLEditorView *view;
EMailSignatureComboBox *combo_box;
ESourceMailComposition *mc;
ESourceOpenPGP *pgp;
@@ -1598,6 +1600,7 @@ msg_composer_mail_identity_changed_cb (EMsgComposer *composer)
gboolean pgp_sign;
gboolean smime_sign;
gboolean smime_encrypt;
+ gboolean is_message_from_edit_as_new;
const gchar *extension_name;
const gchar *uid;
@@ -1630,21 +1633,26 @@ msg_composer_mail_identity_changed_cb (EMsgComposer *composer)
composer->priv->mime_type,
"text/calendar", 13) != 0);
+ editor = e_msg_composer_get_editor (composer);
+ view = e_html_editor_get_view (editor);
+ is_message_from_edit_as_new =
+ e_html_editor_view_is_message_from_edit_as_new (view);
+
action = GTK_TOGGLE_ACTION (ACTION (PGP_SIGN));
active = gtk_toggle_action_get_active (action);
- active &= composer->priv->is_from_message;
+ active &= is_message_from_edit_as_new;
active |= (can_sign && pgp_sign);
gtk_toggle_action_set_active (action, active);
action = GTK_TOGGLE_ACTION (ACTION (SMIME_SIGN));
active = gtk_toggle_action_get_active (action);
- active &= composer->priv->is_from_message;
+ active &= is_message_from_edit_as_new;
active |= (can_sign && smime_sign);
gtk_toggle_action_set_active (action, active);
action = GTK_TOGGLE_ACTION (ACTION (SMIME_ENCRYPT));
active = gtk_toggle_action_get_active (action);
- active &= composer->priv->is_from_message;
+ active &= is_message_from_edit_as_new;
active |= smime_encrypt;
gtk_toggle_action_set_active (action, active);
@@ -3043,19 +3051,19 @@ handle_multipart (EMsgComposer *composer,
} else if (depth == 0 && i == 0) {
EHTMLEditor *editor;
- gboolean is_from_draft, is_html = FALSE;
+ gboolean is_message_from_draft, is_html = FALSE;
gchar *html;
gssize length;
editor = e_msg_composer_get_editor (composer);
- is_from_draft = e_html_editor_view_is_message_from_draft (
+ is_message_from_draft = e_html_editor_view_is_message_from_draft (
e_html_editor_get_view (editor));
/* Since the first part is not multipart/alternative,
* this must be the body. */
/* If we are opening message from Drafts */
- if (is_from_draft) {
+ if (is_message_from_draft) {
/* Extract the body */
CamelDataWrapper *dw;
@@ -3226,7 +3234,7 @@ e_msg_composer_new_with_message (EShell *shell,
struct _camel_header_raw *xev;
gchar *identity_uid;
gint len, i;
- gboolean is_from_draft = FALSE;
+ gboolean is_message_from_draft = FALSE;
g_return_val_if_fail (E_IS_SHELL (shell), NULL);
@@ -3370,8 +3378,8 @@ e_msg_composer_new_with_message (EShell *shell,
CAMEL_MEDIUM (message), "X-Evolution-Composer-Mode");
if (composer_mode && *composer_mode) {
- is_from_draft = TRUE;
- e_html_editor_view_set_is_message_from_draft (view, is_from_draft);
+ is_message_from_draft = TRUE;
+ e_html_editor_view_set_is_message_from_draft (view, TRUE);
}
if (format != NULL) {
@@ -3504,7 +3512,7 @@ e_msg_composer_new_with_message (EShell *shell,
}
/* If we are opening message from Drafts */
- if (is_from_draft) {
+ if (is_message_from_draft) {
/* Extract the body */
CamelDataWrapper *dw;
@@ -3531,7 +3539,7 @@ e_msg_composer_new_with_message (EShell *shell,
e_msg_composer_set_pending_body (composer, html, length, is_html);
}
- priv->is_from_message = TRUE;
+ e_html_editor_view_set_is_message_from_edit_as_new (view, TRUE);
priv->set_signature_from_message = TRUE;
/* We wait until now to set the body text because we need to
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 073a5d1..2504421 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -87,6 +87,7 @@ struct _EHTMLEditorViewPrivate {
gboolean convertor_insert;
gboolean body_input_event_removed;
gboolean is_message_from_draft;
+ gboolean is_message_from_edit_as_new;
gboolean is_message_from_selection;
WebKitWebView *convertor_web_view;
@@ -4261,6 +4262,33 @@ create_text_markers_for_citations_in_element (WebKitDOMElement *element)
return count;
}
+static void
+add_selection_markers_into_element (WebKitDOMDocument *document,
+ WebKitDOMElement *element)
+{
+ WebKitDOMElement *marker;
+
+ marker = webkit_dom_document_create_element (
+ document, "SPAN", NULL);
+ webkit_dom_element_set_id (
+ marker, "-x-evo-selection-end-marker");
+ webkit_dom_node_insert_before (
+ WEBKIT_DOM_NODE (element),
+ WEBKIT_DOM_NODE (marker),
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)),
+ NULL);
+
+ marker = webkit_dom_document_create_element (
+ document, "SPAN", NULL);
+ webkit_dom_element_set_id (
+ marker, "-x-evo-selection-start-marker");
+ webkit_dom_node_insert_before (
+ WEBKIT_DOM_NODE (element),
+ WEBKIT_DOM_NODE (marker),
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)),
+ NULL);
+}
+
static WebKitDOMElement *
prepare_paragraph (EHTMLEditorSelection *selection,
WebKitDOMDocument *document,
@@ -4272,21 +4300,8 @@ prepare_paragraph (EHTMLEditorSelection *selection,
selection, document, -1, 0);
webkit_dom_element_set_id (paragraph, "-x-evo-input-start");
- if (with_selection) {
- element = webkit_dom_document_create_element (
- document, "SPAN", NULL);
- webkit_dom_element_set_id (
- element, "-x-evo-selection-start-marker");
- webkit_dom_node_append_child (
- WEBKIT_DOM_NODE (paragraph), WEBKIT_DOM_NODE (element), NULL);
-
- element = webkit_dom_document_create_element (
- document, "SPAN", NULL);
- webkit_dom_element_set_id (
- element, "-x-evo-selection-end-marker");
- webkit_dom_node_append_child (
- WEBKIT_DOM_NODE (paragraph), WEBKIT_DOM_NODE (element), NULL);
- }
+ if (with_selection)
+ add_selection_markers_into_element (document, paragraph);
element = webkit_dom_document_create_element (document, "BR", NULL);
@@ -4461,6 +4476,14 @@ html_editor_view_process_document_from_convertor (EHTMLEditorView *view,
remove_node (WEBKIT_DOM_NODE (wrapper));
}
+ if (view->priv->is_message_from_edit_as_new) {
+ remove_node (WEBKIT_DOM_NODE (paragraph));
+ add_selection_markers_into_element (
+ document,
+ WEBKIT_DOM_ELEMENT (
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))));
+ }
+
paragraph = webkit_dom_document_query_selector (document, "br.-x-evo-last-br", NULL);
if (paragraph)
webkit_dom_element_remove_attribute (paragraph, "class");
@@ -5017,6 +5040,7 @@ e_html_editor_view_init (EHTMLEditorView *view)
view->priv->body_input_event_removed = TRUE;
view->priv->is_message_from_draft = FALSE;
view->priv->is_message_from_selection = FALSE;
+ view->priv->is_message_from_edit_as_new = FALSE;
view->priv->convertor_insert = FALSE;
view->priv->convertor_web_view =
@@ -8015,3 +8039,19 @@ e_html_editor_view_set_is_message_from_selection (EHTMLEditorView *view,
view->priv->is_message_from_selection = value;
}
+
+gboolean
+e_html_editor_view_is_message_from_edit_as_new (EHTMLEditorView *view)
+{
+ g_return_val_if_fail (E_IS_HTML_EDITOR_VIEW (view), FALSE);
+
+ return view->priv->is_message_from_edit_as_new;
+}
+void
+e_html_editor_view_set_is_message_from_edit_as_new (EHTMLEditorView *view,
+ gboolean value)
+{
+ g_return_if_fail (E_IS_HTML_EDITOR_VIEW (view));
+
+ view->priv->is_message_from_edit_as_new = value;
+}
diff --git a/e-util/e-html-editor-view.h b/e-util/e-html-editor-view.h
index 073e03c..6414d46 100644
--- a/e-util/e-html-editor-view.h
+++ b/e-util/e-html-editor-view.h
@@ -175,6 +175,11 @@ void e_html_editor_view_set_is_message_from_draft
void e_html_editor_view_set_is_message_from_selection
(EHTMLEditorView *view,
gboolean value);
+gboolean e_html_editor_view_is_message_from_edit_as_new
+ (EHTMLEditorView *view);
+void e_html_editor_view_set_is_message_from_edit_as_new
+ (EHTMLEditorView *view,
+ gboolean value);
G_END_DECLS
#endif /* E_HTML_EDITOR_VIEW_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]