[evolution/wip/webkit2] Fix the EHTMLEditorCellDialog



commit 6e9b9c3f094aa4661927a0e9f8a591e059c6b26c
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Jul 22 13:07:14 2016 +0200

    Fix the EHTMLEditorCellDialog

 e-util/e-html-editor-cell-dialog.c                 |   25 +++++++++--
 modules/webkit-editor/e-webkit-editor.c            |    2 +-
 .../web-extension/e-dialogs-dom-functions.c        |   46 +++++++++++++-------
 .../web-extension/e-editor-dom-functions.c         |    2 +-
 .../web-extension/e-editor-web-extension.c         |   14 +++---
 5 files changed, 59 insertions(+), 30 deletions(-)
---
diff --git a/e-util/e-html-editor-cell-dialog.c b/e-util/e-html-editor-cell-dialog.c
index 396b02b..b5379ec 100644
--- a/e-util/e-html-editor-cell-dialog.c
+++ b/e-util/e-html-editor-cell-dialog.c
@@ -146,8 +146,8 @@ html_editor_cell_dialog_set_wrap_text (EHTMLEditorCellDialog *dialog)
 
        e_content_editor_cell_set_wrap (
                cnt_editor,
-               gtk_combo_box_get_active (
-                       GTK_COMBO_BOX (dialog->priv->wrap_text_check)),
+               gtk_toggle_button_get_active (
+                       GTK_TOGGLE_BUTTON (dialog->priv->wrap_text_check)),
                dialog->priv->scope);
 }
 
@@ -194,6 +194,20 @@ html_editor_cell_dialog_set_width (EHTMLEditorCellDialog *dialog)
 }
 
 static void
+html_editor_cell_dialog_width_units_changed (GtkWidget *widget,
+                                             EHTMLEditorCellDialog *dialog)
+{
+       if (gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->width_units)) == 0) {
+               gtk_spin_button_set_range (
+                       GTK_SPIN_BUTTON (dialog->priv->width_edit), 0, G_MAXUINT);
+       } else
+               gtk_spin_button_set_range (
+                       GTK_SPIN_BUTTON (dialog->priv->width_edit), 0, 100);
+
+       html_editor_cell_dialog_set_width (dialog);
+}
+
+static void
 html_editor_cell_dialog_set_column_span (EHTMLEditorCellDialog *dialog)
 {
        EHTMLEditor *editor;
@@ -540,7 +554,8 @@ e_html_editor_cell_dialog_init (EHTMLEditorCellDialog *dialog)
        gtk_grid_attach (grid, widget, 0, 0, 1, 1);
        dialog->priv->width_check = widget;
 
-       widget = gtk_spin_button_new_with_range (0, G_MAXUINT, 1);
+       widget = gtk_spin_button_new_with_range (1, 100, 1);
+       gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), 0);
        gtk_grid_attach (grid, widget, 1, 0, 1, 1);
        dialog->priv->width_edit = widget;
 
@@ -558,9 +573,9 @@ e_html_editor_cell_dialog_init (EHTMLEditorCellDialog *dialog)
        gtk_grid_attach (grid, widget, 2, 0, 1, 1);
        dialog->priv->width_units = widget;
 
-       g_signal_connect_swapped (
+       g_signal_connect (
                widget, "changed",
-               G_CALLBACK (html_editor_cell_dialog_set_width), dialog);
+               G_CALLBACK (html_editor_cell_dialog_width_units_changed), dialog);
        e_binding_bind_property (
                dialog->priv->width_check, "active",
                widget, "sensitive",
diff --git a/modules/webkit-editor/e-webkit-editor.c b/modules/webkit-editor/e-webkit-editor.c
index 8508d70..11cf6f7 100644
--- a/modules/webkit-editor/e-webkit-editor.c
+++ b/modules/webkit-editor/e-webkit-editor.c
@@ -3834,7 +3834,7 @@ webkit_editor_on_cell_dialog_open (EContentEditor *editor)
        g_dbus_proxy_call (
                wk_editor->priv->web_extension,
                "EEditorCellDialogMarkCurrentCellElement",
-               g_variant_new ("(ts)", current_page_id (wk_editor), "-x-evo-table-cell"),
+               g_variant_new ("(ts)", current_page_id (wk_editor), "-x-evo-current-cell"),
                G_DBUS_CALL_FLAGS_NONE,
                -1,
                NULL,
diff --git a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c 
b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
index 5e7c949..71dbc70 100644
--- a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
@@ -34,7 +34,7 @@
 /* ******************** Cell Dialog ***************** */
 
 typedef void (*DOMStrFunc) (WebKitDOMHTMLTableCellElement *cell, const gchar *val, gpointer user_data);
-typedef void (*DOMUlongFunc) (WebKitDOMHTMLTableCellElement *cell, gulong val, gpointer user_data);
+typedef void (*DOMLongFunc) (WebKitDOMHTMLTableCellElement *cell, glong val, gpointer user_data);
 typedef void (*DOMBoolFunc) (WebKitDOMHTMLTableCellElement *cell, gboolean val, gpointer user_data);
 
 static WebKitDOMElement *
@@ -53,8 +53,8 @@ call_cell_dom_func (WebKitDOMHTMLTableCellElement *cell,
                DOMStrFunc f = func;
                f (cell, g_value_get_string (value), user_data);
        } else if (G_VALUE_HOLDS_LONG (value)) {
-               DOMUlongFunc f = func;
-               f (cell, g_value_get_ulong (value), user_data);
+               DOMLongFunc f = func;
+               f (cell, g_value_get_long (value), user_data);
        } else if (G_VALUE_HOLDS_BOOLEAN (value)) {
                DOMBoolFunc f = func;
                f (cell, g_value_get_boolean (value), user_data);
@@ -240,23 +240,38 @@ e_dialogs_dom_cell_mark_current_cell_element (EEditorPage *editor_page,
                                              const gchar *id)
 {
        EEditorUndoRedoManager *manager;
-       WebKitDOMElement *element, *parent = NULL;
+       WebKitDOMElement *cell;
        WebKitDOMDocument *document;
+       WebKitDOMNode *node_under_mouse_click;
 
        g_return_if_fail (E_IS_EDITOR_PAGE (editor_page));
        g_return_if_fail (id != NULL);
 
        document = e_editor_page_get_document (editor_page);
 
-       element = webkit_dom_document_get_element_by_id (document, id);
+       node_under_mouse_click = e_editor_page_get_node_under_mouse_click (editor_page);
 
-       parent = dom_node_find_parent_element (WEBKIT_DOM_NODE (element), "TD");
-       if (!parent)
-               parent = dom_node_find_parent_element (WEBKIT_DOM_NODE (element), "TH");
+       if (node_under_mouse_click && WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (node_under_mouse_click)) {
+               cell = WEBKIT_DOM_ELEMENT (node_under_mouse_click);
+       } else {
+               WebKitDOMElement *selection_start;
 
-       element = webkit_dom_document_get_element_by_id (document, "-x-evo-current-cell");
-       if (element)
-               webkit_dom_element_remove_attribute (element, "id");
+               e_editor_dom_selection_save (editor_page);
+
+               selection_start = webkit_dom_document_get_element_by_id (
+                       document, "-x-evo-selection-start-marker");
+
+               cell = dom_node_find_parent_element (WEBKIT_DOM_NODE (selection_start), "TD");
+               if (!cell)
+                       cell = dom_node_find_parent_element (WEBKIT_DOM_NODE (selection_start), "TH");
+
+               e_editor_dom_selection_restore (editor_page);
+       }
+
+       if (cell)
+               webkit_dom_element_set_id (cell, "-x-evo-current-cell");
+       else
+               return;
 
        manager = e_editor_page_get_undo_redo_manager (editor_page);
        if (!e_editor_undo_redo_manager_is_operation_in_progress (manager)) {
@@ -273,14 +288,13 @@ e_dialogs_dom_cell_mark_current_cell_element (EEditorPage *editor_page,
                        &ev->before.end.y);
 
                table = dom_node_find_parent_element (
-                       WEBKIT_DOM_NODE (parent), "TABLE");
-               ev->data.dom.from = webkit_dom_node_clone_node_with_error (
-                       WEBKIT_DOM_NODE (table), TRUE, NULL);
+                       WEBKIT_DOM_NODE (cell), "TABLE");
+               if (table)
+                       ev->data.dom.from = webkit_dom_node_clone_node_with_error (
+                               WEBKIT_DOM_NODE (table), TRUE, NULL);
 
                e_editor_undo_redo_manager_insert_history_event (manager, ev);
        }
-
-       webkit_dom_element_set_id (parent, "-x-evo-current-cell");
 }
 
 void
diff --git a/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index de628cd..e3e122d 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -133,7 +133,7 @@ e_editor_dom_test_html_equal (WebKitDOMDocument *document,
 static WebKitDOMElement *
 get_table_cell_element (WebKitDOMDocument *document)
 {
-       return webkit_dom_document_get_element_by_id (document, "-x-evo-table-cell");
+       return webkit_dom_document_get_element_by_id (document, "-x-evo-current-cell");
 }
 
 static void
diff --git a/modules/webkit-editor/web-extension/e-editor-web-extension.c 
b/modules/webkit-editor/web-extension/e-editor-web-extension.c
index a38737a..aad9a02 100644
--- a/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -885,7 +885,7 @@ handle_method_call (GDBusConnection *connection,
                const gchar *value;
                EContentEditorScope scope;
 
-               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(t&si)", &page_id, &value, &scope);
 
                editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
                if (!editor_page)
@@ -898,7 +898,7 @@ handle_method_call (GDBusConnection *connection,
                gboolean value;
                EContentEditorScope scope;
 
-               g_variant_get (parameters, "(tbu)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(tbi)", &page_id, &value, &scope);
 
                editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
                if (!editor_page)
@@ -911,7 +911,7 @@ handle_method_call (GDBusConnection *connection,
                gboolean value;
                EContentEditorScope scope;
 
-               g_variant_get (parameters, "(tbu)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(tbi)", &page_id, &value, &scope);
 
                editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
                if (!editor_page)
@@ -924,7 +924,7 @@ handle_method_call (GDBusConnection *connection,
                const gchar *value;
                EContentEditorScope scope;
 
-               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(t&si)", &page_id, &value, &scope);
 
                editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
                if (!editor_page)
@@ -937,7 +937,7 @@ handle_method_call (GDBusConnection *connection,
                glong value;
                EContentEditorScope scope;
 
-               g_variant_get (parameters, "(tiu)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(tii)", &page_id, &value, &scope);
 
                editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
                if (!editor_page)
@@ -950,7 +950,7 @@ handle_method_call (GDBusConnection *connection,
                glong value;
                EContentEditorScope scope;
 
-               g_variant_get (parameters, "(tiu)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(tii)", &page_id, &value, &scope);
 
                editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
                if (!editor_page)
@@ -963,7 +963,7 @@ handle_method_call (GDBusConnection *connection,
                const gchar *value;
                EContentEditorScope scope;
 
-               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(t&si)", &page_id, &value, &scope);
 
                editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
                if (!editor_page)


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