[evolution] EHTMLEditor - Don't insert new HR element when trying to change properties of existing one
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditor - Don't insert new HR element when trying to change properties of existing one
- Date: Fri, 6 Mar 2015 08:40:30 +0000 (UTC)
commit aed859decf046a37b564dce105b93f29b88fa5a7
Author: Tomas Popela <tpopela redhat com>
Date: Fri Mar 6 08:36:01 2015 +0100
EHTMLEditor - Don't insert new HR element when trying to change properties of existing one
e-util/e-html-editor-actions.c | 7 ++-
e-util/e-html-editor-hrule-dialog.c | 91 +++++++++++++++++++----------------
e-util/e-html-editor-hrule-dialog.h | 2 +
e-util/e-html-editor-private.h | 1 +
e-util/e-html-editor.c | 16 ++++--
5 files changed, 68 insertions(+), 49 deletions(-)
---
diff --git a/e-util/e-html-editor-actions.c b/e-util/e-html-editor-actions.c
index c40df25..a7196fc 100644
--- a/e-util/e-html-editor-actions.c
+++ b/e-util/e-html-editor-actions.c
@@ -550,7 +550,8 @@ action_insert_rule_cb (GtkAction *action,
editor->priv->hrule_dialog =
e_html_editor_hrule_dialog_new (editor);
- gtk_window_present (GTK_WINDOW (editor->priv->hrule_dialog));
+ e_html_editor_hrule_dialog_show (
+ E_HTML_EDITOR_HRULE_DIALOG (editor->priv->hrule_dialog), NULL);
}
static void
@@ -811,7 +812,9 @@ action_properties_rule_cb (GtkAction *action,
e_html_editor_hrule_dialog_new (editor);
}
- gtk_window_present (GTK_WINDOW (editor->priv->hrule_dialog));
+ e_html_editor_hrule_dialog_show (
+ E_HTML_EDITOR_HRULE_DIALOG (editor->priv->hrule_dialog),
+ editor->priv->current_node);
}
static void
diff --git a/e-util/e-html-editor-hrule-dialog.c b/e-util/e-html-editor-hrule-dialog.c
index 51660bd..52aafab 100644
--- a/e-util/e-html-editor-hrule-dialog.c
+++ b/e-util/e-html-editor-hrule-dialog.c
@@ -25,6 +25,7 @@
#include "e-html-editor-hrule-dialog.h"
#include "e-html-editor-utils.h"
#include "e-html-editor-view.h"
+#include "e-web-view.h"
#include <glib/gi18n-lib.h>
#include <webkit/webkitdom.h>
@@ -206,68 +207,64 @@ html_editor_hrule_dialog_hide (GtkWidget *widget)
GTK_WIDGET_CLASS (e_html_editor_hrule_dialog_parent_class)->hide (widget);
}
+static WebKitDOMElement *
+get_parent_block_element (WebKitDOMNode *node)
+{
+ WebKitDOMElement *parent = webkit_dom_node_get_parent_element (node);
+
+ if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent))
+ return WEBKIT_DOM_ELEMENT (node);
+
+ while (parent &&
+ !WEBKIT_DOM_IS_HTML_DIV_ELEMENT (parent) &&
+ !WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (parent) &&
+ !WEBKIT_DOM_IS_HTMLU_LIST_ELEMENT (parent) &&
+ !WEBKIT_DOM_IS_HTMLO_LIST_ELEMENT (parent) &&
+ !WEBKIT_DOM_IS_HTML_PRE_ELEMENT (parent) &&
+ !WEBKIT_DOM_IS_HTML_HEADING_ELEMENT (parent) &&
+ !element_has_tag (parent, "address")) {
+ parent = webkit_dom_node_get_parent_element (
+ WEBKIT_DOM_NODE (parent));
+ }
+
+ return parent;
+}
+
static void
html_editor_hrule_dialog_show (GtkWidget *widget)
{
EHTMLEditorHRuleDialog *dialog;
EHTMLEditor *editor;
- EHTMLEditorSelection *editor_selection;
+ EHTMLEditorSelection *selection;
EHTMLEditorView *view;
WebKitDOMDocument *document;
- WebKitDOMDOMWindow *window;
- WebKitDOMDOMSelection *selection;
- WebKitDOMElement *rule;
- WebKitDOMRange *range;
- WebKitDOMNode *node;
dialog = E_HTML_EDITOR_HRULE_DIALOG (widget);
editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
view = e_html_editor_get_view (editor);
- editor_selection = e_html_editor_view_get_selection (view);
-
- document = webkit_web_view_get_dom_document (
- WEBKIT_WEB_VIEW (view));
- window = webkit_dom_document_get_default_view (document);
- selection = webkit_dom_dom_window_get_selection (window);
- if (webkit_dom_dom_selection_get_range_count (selection) < 1) {
- GTK_WIDGET_CLASS (e_html_editor_hrule_dialog_parent_class)->show (widget);
- return;
- }
-
- range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
- node = webkit_dom_range_get_common_ancestor_container (range, NULL);
- if (node && !WEBKIT_DOM_IS_HTMLHR_ELEMENT (node)) {
- rule = e_html_editor_dom_node_find_parent_element (node, "A");
- if (rule && !WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (rule))
- rule = NULL;
- } else
- rule = WEBKIT_DOM_ELEMENT (node);
+ selection = e_html_editor_view_get_selection (view);
- if (!rule) {
- WebKitDOMElement *caret, *parent, *element;
+ if (!dialog->priv->hr_element) {
+ WebKitDOMElement *selection_start, *parent, *rule;
- caret = e_html_editor_selection_save_caret_position (editor_selection);
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
+ e_html_editor_selection_save (selection);
- parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (caret));
- element = caret;
-
- while (!WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
- element = parent;
- parent = webkit_dom_node_get_parent_element (
- WEBKIT_DOM_NODE (parent));
- }
+ selection_start = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ parent = get_parent_block_element (WEBKIT_DOM_NODE (selection_start));
rule = webkit_dom_document_create_element (document, "HR", NULL);
/* Insert horizontal rule into body below the caret */
webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (parent),
+ webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (parent)),
WEBKIT_DOM_NODE (rule),
- webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
+ webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (parent)),
NULL);
- e_html_editor_selection_clear_caret_position_marker (editor_selection);
+ e_html_editor_selection_restore (selection);
dialog->priv->hr_element = WEBKIT_DOM_HTMLHR_ELEMENT (rule);
@@ -290,8 +287,6 @@ html_editor_hrule_dialog_show (GtkWidget *widget)
e_html_editor_view_set_changed (view, TRUE);
} else {
- dialog->priv->hr_element = WEBKIT_DOM_HTMLHR_ELEMENT (rule);
-
html_editor_hrule_dialog_get_alignment (dialog);
html_editor_hrule_dialog_get_size (dialog);
html_editor_hrule_dialog_get_width (dialog);
@@ -429,3 +424,17 @@ e_html_editor_hrule_dialog_new (EHTMLEditor *editor)
"title", _("Rule properties"),
NULL));
}
+
+void
+e_html_editor_hrule_dialog_show (EHTMLEditorHRuleDialog *dialog,
+ WebKitDOMNode *rule)
+{
+ EHTMLEditorHRuleDialogClass *class;
+
+ g_return_if_fail (E_IS_HTML_EDITOR_HRULE_DIALOG (dialog));
+
+ dialog->priv->hr_element = rule ? WEBKIT_DOM_HTMLHR_ELEMENT (rule) : NULL;
+
+ class = E_HTML_EDITOR_HRULE_DIALOG_GET_CLASS (dialog);
+ GTK_WIDGET_CLASS (class)->show (GTK_WIDGET (dialog));
+}
diff --git a/e-util/e-html-editor-hrule-dialog.h b/e-util/e-html-editor-hrule-dialog.h
index 876fc25..b616da9 100644
--- a/e-util/e-html-editor-hrule-dialog.h
+++ b/e-util/e-html-editor-hrule-dialog.h
@@ -64,6 +64,8 @@ struct _EHTMLEditorHRuleDialogClass {
GType e_html_editor_hrule_dialog_get_type
(void) G_GNUC_CONST;
GtkWidget * e_html_editor_hrule_dialog_new (EHTMLEditor *editor);
+void e_html_editor_hrule_dialog_show (EHTMLEditorHRuleDialog *dialog,
+ WebKitDOMNode *rule);
G_END_DECLS
diff --git a/e-util/e-html-editor-private.h b/e-util/e-html-editor-private.h
index 98823e6..60f6706 100644
--- a/e-util/e-html-editor-private.h
+++ b/e-util/e-html-editor-private.h
@@ -93,6 +93,7 @@ struct _EHTMLEditorPrivate {
WebKitDOMNode *image;
WebKitDOMNode *table_cell;
+ WebKitDOMNode *current_node;
gint editor_layout_row;
};
diff --git a/e-util/e-html-editor.c b/e-util/e-html-editor.c
index 15840d5..8935db4 100644
--- a/e-util/e-html-editor.c
+++ b/e-util/e-html-editor.c
@@ -331,8 +331,9 @@ html_editor_update_actions (EHTMLEditor *editor,
web_view = WEBKIT_WEB_VIEW (view);
manager = e_html_editor_get_ui_manager (editor);
- editor->priv->image = NULL;
- editor->priv->table_cell = NULL;
+ g_clear_object (&editor->priv->table_cell);
+ g_clear_object (&editor->priv->image);
+ g_clear_object (&editor->priv->current_node);
/* Update context menu item visibility. */
hit_test = webkit_web_view_get_hit_test_result (web_view, event);
@@ -342,10 +343,11 @@ html_editor_update_actions (EHTMLEditor *editor,
"inner-node", &node, NULL);
g_object_unref (hit_test);
+ editor->priv->current_node = g_object_ref (node);
visible = (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE);
gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_IMAGE), visible);
if (visible)
- editor->priv->image = node;
+ editor->priv->image = g_object_ref (node);
visible = (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK);
gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_LINK), visible);
@@ -385,7 +387,7 @@ html_editor_update_actions (EHTMLEditor *editor,
gtk_action_set_visible (ACTION (CONTEXT_INSERT_TABLE), visible);
gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_CELL), visible);
if (visible)
- editor->priv->table_cell = node;
+ editor->priv->table_cell = g_object_ref (node);
/* Note the |= (cursor must be in a table cell). */
visible |= (WEBKIT_DOM_IS_HTML_TABLE_ELEMENT (node) ||
@@ -758,6 +760,10 @@ html_editor_dispose (GObject *object)
g_clear_object (&priv->style_combo_box);
g_clear_object (&priv->scrolled_window);
+ g_clear_object (&priv->table_cell);
+ g_clear_object (&priv->current_node);
+ g_clear_object (&priv->image);
+
g_clear_object (&priv->html_editor_view);
/* Chain up to parent's dispose() method. */
@@ -1180,5 +1186,3 @@ e_html_editor_save (EHTMLEditor *editor,
return TRUE;
}
-
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]