[evolution/wip/webkit2] EHTMLEditorTableDialog - When creating new table move caret to its first cell



commit f1f8f17c7e22b77532fdc3b28ee0849c12bc3bf3
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Mar 27 13:56:37 2015 +0100

    EHTMLEditorTableDialog - When creating new table move caret to its first cell

 .../e-html-editor-table-dialog-dom-functions.c     |   31 +++++++++++++++----
 .../e-html-editor-table-dialog-dom-functions.h     |    6 ++-
 web-extensions/e-html-editor-web-extension.c       |    4 +-
 3 files changed, 30 insertions(+), 11 deletions(-)
---
diff --git a/web-extensions/e-html-editor-table-dialog-dom-functions.c 
b/web-extensions/e-html-editor-table-dialog-dom-functions.c
index d0d3bd1..a2b0bac 100644
--- a/web-extensions/e-html-editor-table-dialog-dom-functions.c
+++ b/web-extensions/e-html-editor-table-dialog-dom-functions.c
@@ -150,7 +150,8 @@ e_html_editor_table_dialog_get_column_count (WebKitDOMDocument *document)
 }
 
 static void
-create_table (WebKitDOMDocument *document)
+create_table (WebKitDOMDocument *document,
+              EHTMLEditorWebExtension *extension)
 {
        WebKitDOMElement *table, *br, *caret, *parent, *element;
        gint i;
@@ -172,7 +173,9 @@ create_table (WebKitDOMDocument *document)
 
        webkit_dom_element_set_id (table, "-x-evo-current-table");
 
-       caret = dom_save_caret_position (document);
+       dom_selection_save (document);
+       caret = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-end-marker");
 
        parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (caret));
        element = caret;
@@ -197,14 +200,28 @@ create_table (WebKitDOMDocument *document)
                webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
                NULL);
 
-       dom_clear_caret_position_marker (document);
+       /* Move caret to the first cell */
+       element = webkit_dom_element_query_selector (table, "td", NULL);
+       webkit_dom_node_append_child (
+               WEBKIT_DOM_NODE (element),
+               WEBKIT_DOM_NODE (caret),
+               NULL);
+       caret = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+       webkit_dom_node_insert_before (
+               WEBKIT_DOM_NODE (element),
+               WEBKIT_DOM_NODE (caret),
+               webkit_dom_node_get_last_child (WEBKIT_DOM_NODE (element)),
+               NULL);
+
+       dom_selection_restore (document);
 
-       /* FIXME WK2
-       e_html_editor_view_set_changed (view, TRUE);*/
+       e_html_editor_web_extension_set_content_changed (extension);
 }
 
 gboolean
-e_html_editor_table_dialog_show (WebKitDOMDocument *document)
+e_html_editor_table_dialog_show (WebKitDOMDocument *document,
+                                 EHTMLEditorWebExtension *extension)
 {
        WebKitDOMDOMWindow *window;
        WebKitDOMDOMSelection *selection;
@@ -223,7 +240,7 @@ e_html_editor_table_dialog_show (WebKitDOMDocument *document)
                        webkit_dom_element_set_id (table, "-x-evo-current-table");
                        return FALSE;
                } else {
-                       create_table (document);
+                       create_table (document, extension);
                        return TRUE;
                }
        }
diff --git a/web-extensions/e-html-editor-table-dialog-dom-functions.h 
b/web-extensions/e-html-editor-table-dialog-dom-functions.h
index 01a7f8f..fcdf392 100644
--- a/web-extensions/e-html-editor-table-dialog-dom-functions.h
+++ b/web-extensions/e-html-editor-table-dialog-dom-functions.h
@@ -21,6 +21,8 @@
 
 #include <webkitdom/webkitdom.h>
 
+#include "e-html-editor-web-extension.h"
+
 G_BEGIN_DECLS
 
 void           e_html_editor_table_dialog_set_row_count
@@ -37,8 +39,8 @@ void          e_html_editor_table_dialog_set_column_count
 gulong         e_html_editor_table_dialog_get_column_count
                                                (WebKitDOMDocument *document);
 
-gboolean       e_html_editor_table_dialog_show (WebKitDOMDocument *document);
-
+gboolean       e_html_editor_table_dialog_show (WebKitDOMDocument *document,
+                                                EHTMLEditorWebExtension *extension);
 G_END_DECLS
 
 #endif /* E_HTML_EDITOR_TABLE_DIALOG_DOM_FUNCTIONS_H */
diff --git a/web-extensions/e-html-editor-web-extension.c b/web-extensions/e-html-editor-web-extension.c
index 5510cab..af4359a 100644
--- a/web-extensions/e-html-editor-web-extension.c
+++ b/web-extensions/e-html-editor-web-extension.c
@@ -244,7 +244,7 @@ static const char introspection_xml[] =
 "<!-- ********************************************************* -->"
 "    <method name='EHTMLEditorHRuleDialogFindHRule'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='b' name='created' direction='out'/>"
+"      <arg type='b' name='created_new_hr' direction='out'/>"
 "    </method>"
 "    <method name='HRElementSetNoShade'>"
 "      <arg type='t' name='page_id' direction='in'/>"
@@ -1265,7 +1265,7 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               created_new_table = e_html_editor_table_dialog_show (document);
+               created_new_table = e_html_editor_table_dialog_show (document, extension);
 
                g_dbus_method_invocation_return_value (
                        invocation, g_variant_new_boolean (created_new_table));


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