[evolution/wip/webkit-composer: 108/372] Make 'Table Cell Properties' work



commit 28f3d6650bfc5d44fc476739dfbdb2cd5abae7b7
Author: Dan Vrátil <dvratil redhat com>
Date:   Wed Aug 15 12:58:29 2012 +0200

    Make 'Table Cell Properties' work
    
    The dialog is implemented in EEditorCellDialog class.
    This commit also fixes the 'Insert Row', 'Insert Column' etc.
    actions from context menu to be more straightforward and failsafe.

 e-util/Makefile.am            |    3 +-
 e-util/e-editor-actions.c     |  397 ++++++-----------
 e-util/e-editor-builder.ui    |  951 -----------------------------------------
 e-util/e-editor-cell-dialog.c |  876 +++++++++++++++++++++++++++++++++++++
 e-util/e-editor-cell-dialog.h |   72 +++
 e-util/e-editor-private.h     |    3 +
 e-util/e-editor-selection.h   |    2 +-
 e-util/e-editor-widget.c      |    9 +
 e-util/e-editor.c             |    7 +-
 e-util/e-util.h               |    1 +
 10 files changed, 1108 insertions(+), 1213 deletions(-)
---
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index 0fc72c7..d1a57a5 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -40,7 +40,6 @@ errordir = $(privdatadir)/errors
 @EVO_PLUGIN_RULE@
 
 ui_DATA = \
-       e-editor-builder.ui \
        e-editor-manager.ui \
        e-send-options.ui \
        e-table-config.ui \
@@ -178,6 +177,7 @@ evolution_util_include_HEADERS =  \
        e-dialog-utils.h \
        e-dialog-widgets.h \
        e-editor-actions.h \
+       e-editor-cell-dialog.h \
        e-editor-dialog.h \
        e-editor-find-dialog.h \
        e-editor-hrule-dialog.h \
@@ -447,6 +447,7 @@ libevolution_util_la_SOURCES = \
        e-dialog-utils.c \
        e-dialog-widgets.c \
        e-editor-actions.c \
+       e-editor-cell-dialog.c \
        e-editor-dialog.c \
        e-editor-find-dialog.c \
        e-editor-hrule-dialog.c \
diff --git a/e-util/e-editor-actions.c b/e-util/e-editor-actions.c
index fcf2f4b..cee473c 100644
--- a/e-util/e-editor-actions.c
+++ b/e-util/e-editor-actions.c
@@ -29,6 +29,7 @@
 #include "e-editor-actions.h"
 #include "e-editor-private.h"
 #include "e-editor-widgets.h"
+#include "e-editor-utils.h"
 #include "e-emoticon-action.h"
 #include "e-emoticon-chooser.h"
 #include "e-image-chooser-dialog.h"
@@ -111,81 +112,36 @@ insert_text_file_ready_cb (GFile *file,
  * Action Callbacks
  *****************************************************************************/
 
-static WebKitDOMNode *
-find_parent_element_by_type (WebKitDOMNode *node, GType type)
-{
-       while (node) {
-
-               if (g_type_is_a (type, webkit_dom_node_get_type ()))
-                       return node;
-
-               node = webkit_dom_node_get_parent_node (node);
-       }
-
-       return NULL;
-}
-
 static void
 action_context_delete_cell_cb (GtkAction *action,
                                EEditor *editor)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
-       WebKitDOMRange *range;
-       WebKitDOMNode *start, *end, *cell;
-       gboolean single_row;
-
-       document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-       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)
-               return;
+       WebKitDOMNode *sibling;
+       WebKitDOMElement *cell;
 
-       range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+       g_return_if_fail (editor->priv->table_cell != NULL);
 
-       /* Find TD in which the selection starts */
-       start = webkit_dom_range_get_start_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (start)) {
-               start = find_parent_element_by_type (
-                       start, WEBKIT_TYPE_DOM_HTML_TABLE_CELL_ELEMENT);
+       cell = e_editor_dom_node_find_parent_element (editor->priv->table_cell, "TD");
+       if (!cell) {
+               cell = e_editor_dom_node_find_parent_element (
+                                       editor->priv->table_cell, "TH");
        }
+       g_return_if_fail (cell != NULL);
 
-       /* Find TD in which the selection ends */
-       end = webkit_dom_range_get_end_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (end)) {
-               end = find_parent_element_by_type (
-                       end, WEBKIT_TYPE_DOM_HTML_TABLE_CELL_ELEMENT);
+       sibling = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (cell));
+       if (!sibling) {
+               sibling = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (cell));
        }
 
-       single_row = (webkit_dom_node_get_parent_node (start) ==
-                       webkit_dom_node_get_parent_node (end));
-
-       cell = start;
-       while (cell) {
-               WebKitDOMNodeList *nodes;
-               gulong length, i;
-
-               /* Remove all child nodes in the cell */
-               nodes = webkit_dom_node_get_child_nodes (cell);
-               length = webkit_dom_node_list_get_length (nodes);
-               for (i = 0; i < length; i++) {
-                       webkit_dom_node_remove_child (
-                               cell,
-                               webkit_dom_node_list_item (nodes, i),
-                               NULL);
-               }
-
-               if (cell == end)
-                       break;
-
-               cell = webkit_dom_node_get_next_sibling (cell);
-
-               if (!cell && !single_row) {
-                       cell = webkit_dom_node_get_first_child (
-                               webkit_dom_node_get_parent_node (cell));
-               }
+       webkit_dom_node_remove_child (
+               webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (cell)),
+               WEBKIT_DOM_NODE (cell), NULL);
+
+       if (sibling) {
+               webkit_dom_html_table_cell_element_set_col_span (
+                       (WebKitDOMHTMLTableCellElement *) sibling,
+                       webkit_dom_html_table_cell_element_get_col_span (
+                               (WebKitDOMHTMLTableCellElement *) sibling) + 1);
        }
 }
 
@@ -193,57 +149,37 @@ static void
 action_context_delete_column_cb (GtkAction *action,
                                  EEditor *editor)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
-       WebKitDOMRange *range;
-       WebKitDOMNode *start, *end, *first_row;
-       gulong index, count, i;
-
-       document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-       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) {
-               return;
-       }
+       WebKitDOMElement *cell, *table;
+       WebKitDOMHTMLCollection *rows;
+       gulong index, length, ii;
 
-       range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+       g_return_if_fail (editor->priv->table_cell != NULL);
 
        /* Find TD in which the selection starts */
-       start = webkit_dom_range_get_start_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (start)) {
-               start = find_parent_element_by_type (
-                       start, WEBKIT_TYPE_DOM_HTML_TABLE_CELL_ELEMENT);
+       cell = e_editor_dom_node_find_parent_element (editor->priv->table_cell, "TD");
+       if (!cell) {
+               cell = e_editor_dom_node_find_parent_element (
+                                       editor->priv->table_cell, "TH");
        }
+       g_return_if_fail (cell != NULL);
 
-       /* Find TD in which the selection ends */
-       end = webkit_dom_range_get_end_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (end)) {
-               end = find_parent_element_by_type (
-                       end, WEBKIT_TYPE_DOM_HTML_TABLE_CELL_ELEMENT);
-       }
+       table = e_editor_dom_node_find_parent_element (WEBKIT_DOM_NODE (cell), "TABLE");
+       g_return_if_fail (table != NULL);
 
-       first_row = find_parent_element_by_type (
-               start, WEBKIT_TYPE_DOM_HTML_TABLE_ROW_ELEMENT);
-       first_row = webkit_dom_node_get_first_child (
-               webkit_dom_node_get_parent_node (first_row));
+       rows = webkit_dom_html_table_element_get_rows (
+                       (WebKitDOMHTMLTableElement *) table);
+       length = webkit_dom_html_collection_get_length (rows);
 
        index = webkit_dom_html_table_cell_element_get_cell_index (
-                       WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (start));
-       count = webkit_dom_html_table_cell_element_get_cell_index (
-                       WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (end)) - index;
+                       (WebKitDOMHTMLTableCellElement *) cell);
 
-       for (i = 0; i < count; i++) {
-               WebKitDOMNode *row = first_row;
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *row;
 
-               while (row) {
-                       webkit_dom_html_table_row_element_delete_cell (
-                               WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (row),
-                               index, NULL);
+               row = webkit_dom_html_collection_item (rows, ii);
 
-                       row = webkit_dom_node_get_next_sibling (row);
-               }
+               webkit_dom_html_table_row_element_delete_cell (
+                       (WebKitDOMHTMLTableRowElement *) row, index, NULL);
        }
 }
 
@@ -251,117 +187,67 @@ static void
 action_context_delete_row_cb (GtkAction *action,
                               EEditor *editor)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
-       WebKitDOMRange *range;
-       WebKitDOMNode *start, *end, *table;
-       gulong index, row_count, i;
-
-       document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-       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)
-               return;
+       WebKitDOMElement *row;
 
-       range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
-
-       start = webkit_dom_range_get_start_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT (start)) {
-               start = find_parent_element_by_type (
-                       start, WEBKIT_TYPE_DOM_HTML_TABLE_ROW_ELEMENT);
-       }
-
-       end = webkit_dom_range_get_end_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT (end)) {
-               end = find_parent_element_by_type (
-                       end, WEBKIT_TYPE_DOM_HTML_TABLE_ROW_ELEMENT);
-       }
+       g_return_if_fail (editor->priv->table_cell != NULL);
 
-       table = find_parent_element_by_type (
-                       start, WEBKIT_TYPE_DOM_HTML_TABLE_ELEMENT);
+       row = e_editor_dom_node_find_parent_element (editor->priv->table_cell, "TR");
+       g_return_if_fail (row != NULL);
 
-       index = webkit_dom_html_table_row_element_get_row_index (
-                       WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (start));
-       row_count = webkit_dom_html_table_row_element_get_row_index (
-                       WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (end)) - index;
-
-       for (i = 0; i < row_count; i++) {
-               webkit_dom_html_table_element_delete_row (
-                       WEBKIT_DOM_HTML_TABLE_ELEMENT (table), index, NULL);
-       }
+       webkit_dom_node_remove_child (
+               webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (row)),
+               WEBKIT_DOM_NODE (row), NULL);
 }
 
 static void
 action_context_delete_table_cb (GtkAction *action,
-    EEditor *editor)
+                               EEditor *editor)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
-       WebKitDOMRange *range;
-       WebKitDOMNode *table;
-
-       document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-       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)
-               return;
+       WebKitDOMElement *table;
 
-       range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+       g_return_if_fail (editor->priv->table_cell != NULL);
 
-       table = webkit_dom_range_get_start_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_ELEMENT (table)) {
-               table = find_parent_element_by_type (
-                       table, WEBKIT_TYPE_DOM_HTML_TABLE_ELEMENT);
-       }
+       table = e_editor_dom_node_find_parent_element (editor->priv->table_cell, "TABLE");
+       g_return_if_fail (table != NULL);
 
        webkit_dom_node_remove_child (
-               webkit_dom_node_get_parent_node (table), table, NULL);
+               webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (table)),
+               WEBKIT_DOM_NODE (table), NULL);
 }
 
 static void
 action_context_insert_column_after_cb (GtkAction *action,
                                        EEditor *editor)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
-       WebKitDOMRange *range;
-       WebKitDOMNode *cell, *row;
+       WebKitDOMElement *cell, *row;
        gulong index;
 
-       document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-       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)
-               return;
-
-       range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+       g_return_if_fail (editor->priv->table_cell != NULL);
 
-       cell = webkit_dom_range_get_end_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (cell)) {
-               cell = find_parent_element_by_type (
-                       cell, WEBKIT_TYPE_DOM_HTML_TABLE_CELL_ELEMENT);
+       cell = e_editor_dom_node_find_parent_element (editor->priv->table_cell, "TD");
+       if (!cell) {
+               cell = e_editor_dom_node_find_parent_element (
+                                       editor->priv->table_cell, "TH");
        }
+       g_return_if_fail (cell != NULL);
+
+       row = e_editor_dom_node_find_parent_element (WEBKIT_DOM_NODE (cell), "TR");
+       g_return_if_fail (row != NULL);
 
-       row = find_parent_element_by_type (
-               cell, WEBKIT_TYPE_DOM_HTML_TABLE_ROW_ELEMENT);
        /* Get the first row in the table */
-       row = webkit_dom_node_get_first_child (
-               webkit_dom_node_get_parent_node (row));
+       row = (WebKitDOMElement *)
+               webkit_dom_node_get_first_child (
+                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (row)));
 
        index = webkit_dom_html_table_cell_element_get_cell_index (
-                       WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (cell));
+                       (WebKitDOMHTMLTableCellElement *) (cell));
 
        while (row) {
                webkit_dom_html_table_row_element_insert_cell (
-                       WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (row), index + 1, NULL);
+                       (WebKitDOMHTMLTableRowElement *) row, index + 1, NULL);
 
-               row = webkit_dom_node_get_next_sibling (row);
+               row = (WebKitDOMElement *)
+                       webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (row));
        }
 }
 
@@ -369,42 +255,35 @@ static void
 action_context_insert_column_before_cb (GtkAction *action,
                                         EEditor *editor)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
-       WebKitDOMRange *range;
-       WebKitDOMNode *cell, *row;
+       WebKitDOMElement *cell, *row;
        gulong index;
 
-       document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-       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)
-               return;
-
-       range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+       g_return_if_fail (editor->priv->table_cell != NULL);
 
-       cell = webkit_dom_range_get_start_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (cell)) {
-               cell = find_parent_element_by_type (
-                       cell, WEBKIT_TYPE_DOM_HTML_TABLE_CELL_ELEMENT);
+       cell = e_editor_dom_node_find_parent_element (editor->priv->table_cell, "TD");
+       if (!cell) {
+               cell = e_editor_dom_node_find_parent_element (
+                               editor->priv->table_cell, "TH");
        }
+       g_return_if_fail (cell != NULL);
+
+       row = e_editor_dom_node_find_parent_element (WEBKIT_DOM_NODE (cell), "TR");
+       g_return_if_fail (row != NULL);
 
-       row = find_parent_element_by_type (
-               cell, WEBKIT_TYPE_DOM_HTML_TABLE_ROW_ELEMENT);
        /* Get the first row in the table */
-       row = webkit_dom_node_get_first_child (
-               webkit_dom_node_get_parent_node (row));
+       row = (WebKitDOMElement *)
+               webkit_dom_node_get_first_child (
+                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (row)));
 
        index = webkit_dom_html_table_cell_element_get_cell_index (
-                       WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (cell));
+                       (WebKitDOMHTMLTableCellElement *) (cell));
 
        while (row) {
                webkit_dom_html_table_row_element_insert_cell (
-                       WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (row), index - 1, NULL);
+                       (WebKitDOMHTMLTableRowElement *) row, index - 1, NULL);
 
-               row = webkit_dom_node_get_next_sibling (row);
+               row = (WebKitDOMElement *)
+                       webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (row));
        }
 }
 
@@ -412,72 +291,65 @@ static void
 action_context_insert_row_above_cb (GtkAction *action,
                                     EEditor *editor)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
-       WebKitDOMRange *range;
-       WebKitDOMNode *row, *table;
-       gulong index;
+       WebKitDOMElement *row, *table;
+       WebKitDOMHTMLCollection *cells;
+       WebKitDOMHTMLElement *new_row;
+       gulong index, cell_count, ii;
 
-       document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-       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)
-               return;
+       g_return_if_fail (editor->priv->table_cell != NULL);
 
-       range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+       row = e_editor_dom_node_find_parent_element (editor->priv->table_cell, "TR");
+       g_return_if_fail (row != NULL);
 
-       row = webkit_dom_range_get_start_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (row)) {
-               row = find_parent_element_by_type (
-                       row, WEBKIT_TYPE_DOM_HTML_TABLE_ROW_ELEMENT);
-       }
-
-       table = find_parent_element_by_type (
-               row, WEBKIT_TYPE_DOM_HTML_TABLE_ELEMENT);
+       table = e_editor_dom_node_find_parent_element (WEBKIT_DOM_NODE (row), "TABLE");
+       g_return_if_fail (table != NULL);
 
        index = webkit_dom_html_table_row_element_get_row_index (
-                       WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (row));
+                       (WebKitDOMHTMLTableRowElement *) row);
+
+       new_row = webkit_dom_html_table_element_insert_row (
+                       (WebKitDOMHTMLTableElement *) table, index, NULL);
+
+       cells = webkit_dom_html_table_row_element_get_cells (
+                       (WebKitDOMHTMLTableRowElement *) row);
+       cell_count = webkit_dom_html_collection_get_length (cells);
+       for (ii = 0; ii < cell_count; ii++) {
+               webkit_dom_html_table_row_element_insert_cell (
+                       (WebKitDOMHTMLTableRowElement *) new_row, -1, NULL);
+       }
 
-       webkit_dom_html_table_element_insert_row (
-               WEBKIT_DOM_HTML_TABLE_ELEMENT (table), index - 1, NULL);
 }
 
 static void
 action_context_insert_row_below_cb (GtkAction *action,
                                     EEditor *editor)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
-       WebKitDOMRange *range;
-       WebKitDOMNode *row, *table;
-       gulong index;
+       WebKitDOMElement *row, *table;
+       WebKitDOMHTMLCollection *cells;
+       WebKitDOMHTMLElement *new_row;
+       gulong index, cell_count, ii;
 
-       document = webkit_web_view_get_dom_document (
-                       WEBKIT_WEB_VIEW (e_editor_get_editor_widget (editor)));
-       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)
-               return;
+       g_return_if_fail (editor->priv->table_cell != NULL);
 
-       range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
-
-       row = webkit_dom_range_get_end_container (range, NULL);
-       if (!WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (row)) {
-               row = find_parent_element_by_type (
-                       row, WEBKIT_TYPE_DOM_HTML_TABLE_ROW_ELEMENT);
-       }
+       row = e_editor_dom_node_find_parent_element (editor->priv->table_cell, "TR");
+       g_return_if_fail (row != NULL);
 
-       table = find_parent_element_by_type (
-               row, WEBKIT_TYPE_DOM_HTML_TABLE_ELEMENT);
+       table = e_editor_dom_node_find_parent_element (WEBKIT_DOM_NODE (row), "TABLE");
+       g_return_if_fail (table != NULL);
 
        index = webkit_dom_html_table_row_element_get_row_index (
-                       WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (row));
+                       (WebKitDOMHTMLTableRowElement *) row);
+
+       new_row = webkit_dom_html_table_element_insert_row (
+                       (WebKitDOMHTMLTableElement *) table, index + 1, NULL);
 
-       webkit_dom_html_table_element_insert_row (
-               WEBKIT_DOM_HTML_TABLE_ELEMENT (table), index + 1, NULL);
+       cells = webkit_dom_html_table_row_element_get_cells (
+                       (WebKitDOMHTMLTableRowElement *) row);
+       cell_count = webkit_dom_html_collection_get_length (cells);
+       for (ii = 0; ii < cell_count; ii++) {
+               webkit_dom_html_table_row_element_insert_cell (
+                       (WebKitDOMHTMLTableRowElement *) new_row, -1, NULL);
+       }
 }
 
 static void
@@ -899,7 +771,14 @@ static void
 action_properties_cell_cb (GtkAction *action,
                            EEditor *editor)
 {
-       gtk_window_present (GTK_WINDOW (WIDGET (CELL_PROPERTIES_WINDOW)));
+       if (editor->priv->cell_dialog == NULL) {
+               editor->priv->cell_dialog =
+                       e_editor_cell_dialog_new (editor);
+       }
+
+       e_editor_cell_dialog_show (
+               E_EDITOR_CELL_DIALOG (editor->priv->cell_dialog),
+               editor->priv->table_cell);
 }
 
 static void
diff --git a/e-util/e-editor-cell-dialog.c b/e-util/e-editor-cell-dialog.c
new file mode 100644
index 0000000..1b4700a
--- /dev/null
+++ b/e-util/e-editor-cell-dialog.c
@@ -0,0 +1,876 @@
+/*
+ * e-editor-cell-dialog.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+ 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "e-editor-cell-dialog.h"
+
+#include <glib/gi18n-lib.h>
+#include <stdlib.h>
+
+#include "e-color-combo.h"
+#include "e-editor-utils.h"
+#include "e-image-chooser-dialog.h"
+#include "e-misc-utils.h"
+
+G_DEFINE_TYPE (
+       EEditorCellDialog,
+       e_editor_cell_dialog,
+       E_TYPE_EDITOR_DIALOG);
+
+enum {
+       SCOPE_CELL,
+       SCOPE_ROW,
+       SCOPE_COLUMN,
+       SCOPE_TABLE
+} DialogScope;
+
+struct _EEditorCellDialogPrivate {
+       GtkWidget *scope_cell_button;
+       GtkWidget *scope_table_button;
+       GtkWidget *scope_row_button;
+       GtkWidget *scope_column_button;
+
+       GtkWidget *halign_combo;
+       GtkWidget *valign_combo;
+
+       GtkWidget *wrap_text_check;
+       GtkWidget *header_style_check;
+
+       GtkWidget *width_check;
+       GtkWidget *width_edit;
+       GtkWidget *width_units;
+
+       GtkWidget *row_span_edit;
+       GtkWidget *col_span_edit;
+
+       GtkWidget *background_color_picker;
+       GtkWidget *background_image_chooser;
+
+       GtkWidget *close_button;
+
+       WebKitDOMElement *cell;
+       guint scope;
+};
+
+static GdkRGBA white = { 1, 1, 1, 1 };
+
+typedef void (*DOMStrFunc) (WebKitDOMHTMLTableCellElement *cell, const gchar *val, gpointer user_data);
+typedef void (*DOMUlongFunc) (WebKitDOMHTMLTableCellElement *cell, gulong val, gpointer user_data);
+typedef void (*DOMBoolFunc) (WebKitDOMHTMLTableCellElement *cell, gboolean val, gpointer user_data);
+
+static void
+call_cell_dom_func (WebKitDOMHTMLTableCellElement *cell,
+                   gpointer func,
+                   GValue *value,
+                   gpointer user_data)
+{
+       if (G_VALUE_HOLDS_STRING (value)) {
+               DOMStrFunc f = func;
+               f (cell, g_value_get_string (value), user_data);
+       } else if (G_VALUE_HOLDS_ULONG (value)) {
+               DOMUlongFunc f = func;
+               f (cell, g_value_get_ulong (value), user_data);
+       } else if (G_VALUE_HOLDS_BOOLEAN (value)) {
+               DOMBoolFunc f = func;
+               f (cell, g_value_get_boolean (value), user_data);
+       }
+}
+
+static void
+for_each_cell_do (WebKitDOMElement *row,
+                 gpointer func,
+                 GValue *value,
+                 gpointer user_data)
+{
+       WebKitDOMHTMLCollection *cells;
+       gulong ii, length;
+       cells = webkit_dom_html_table_row_element_get_cells (
+                       (WebKitDOMHTMLTableRowElement *) row);
+       length = webkit_dom_html_collection_get_length (cells);
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *cell;
+               cell = webkit_dom_html_collection_item (cells, ii);
+               if (!cell) {
+                       continue;
+               }
+
+               call_cell_dom_func (
+                       (WebKitDOMHTMLTableCellElement *) cell, func, value, user_data);
+       }
+}
+
+static void
+editor_cell_dialog_set_attribute (EEditorCellDialog *dialog,
+                                 gpointer func,
+                                 GValue *value,
+                                 gpointer user_data)
+{
+       if (dialog->priv->scope == SCOPE_CELL) {
+
+               call_cell_dom_func (
+                       (WebKitDOMHTMLTableCellElement *) dialog->priv->cell,
+                       func, value, user_data);
+
+       } else if (dialog->priv->scope == SCOPE_COLUMN) {
+               gulong index, ii, length;
+               WebKitDOMElement *table;
+               WebKitDOMHTMLCollection *rows;
+
+               index = webkit_dom_html_table_cell_element_get_cell_index (
+                               (WebKitDOMHTMLTableCellElement *) dialog->priv->cell);
+               table = e_editor_dom_node_find_parent_element (
+                               (WebKitDOMNode *) dialog->priv->cell, "TABLE");
+               if (!table) {
+                       return;
+               }
+
+               rows = webkit_dom_html_table_element_get_rows (
+                               (WebKitDOMHTMLTableElement *) table);
+               length = webkit_dom_html_collection_get_length (rows);
+               for (ii = 0; ii < length; ii++) {
+                       WebKitDOMNode *row, *cell;
+                       WebKitDOMHTMLCollection *cells;
+
+                       row = webkit_dom_html_collection_item (rows, ii);
+                       cells = webkit_dom_html_table_row_element_get_cells (
+                                       (WebKitDOMHTMLTableRowElement *) row);
+                       cell = webkit_dom_html_collection_item (cells, index);
+                       if (!cell) {
+                               continue;
+                       }
+
+                       call_cell_dom_func (
+                               (WebKitDOMHTMLTableCellElement *) cell,
+                               func, value, user_data);
+               }
+
+       } else if (dialog->priv->scope == SCOPE_ROW) {
+               WebKitDOMElement *row;
+
+               row = e_editor_dom_node_find_parent_element (
+                               (WebKitDOMNode *) dialog->priv->cell, "TR");
+               if (!row) {
+                       return;
+               }
+
+               for_each_cell_do (row, func, value, user_data);
+
+       } else if (dialog->priv->scope == SCOPE_TABLE) {
+               gulong ii, length;
+               WebKitDOMElement *table;
+               WebKitDOMHTMLCollection *rows;
+
+               table = e_editor_dom_node_find_parent_element (
+                               (WebKitDOMNode *) dialog->priv->cell, "TABLE");
+               if (!table) {
+                       return;
+               }
+
+               rows = webkit_dom_html_table_element_get_rows (
+                               (WebKitDOMHTMLTableElement *) table);
+               length = webkit_dom_html_collection_get_length (rows);
+               for (ii = 0; ii < length; ii++) {
+                       WebKitDOMNode *row;
+
+                       row = webkit_dom_html_collection_item (rows, ii);
+                       if (!row) {
+                               continue;
+                       }
+
+                       for_each_cell_do (
+                               (WebKitDOMElement *) row, func, value, user_data);
+               }
+       }
+}
+
+
+static void
+editor_cell_dialog_set_scope (EEditorCellDialog *dialog)
+{
+       if (gtk_toggle_button_get_active (
+               GTK_TOGGLE_BUTTON (dialog->priv->scope_cell_button))) {
+
+               dialog->priv->scope = SCOPE_CELL;
+
+       } else if (gtk_toggle_button_get_active (
+               GTK_TOGGLE_BUTTON (dialog->priv->scope_row_button))) {
+
+               dialog->priv->scope = SCOPE_ROW;
+
+       } else if (gtk_toggle_button_get_active (
+               GTK_TOGGLE_BUTTON (dialog->priv->scope_column_button))) {
+
+               dialog->priv->scope = SCOPE_COLUMN;
+
+       } else if (gtk_toggle_button_get_active (
+               GTK_TOGGLE_BUTTON (dialog->priv->scope_table_button))) {
+
+               dialog->priv->scope = SCOPE_TABLE;
+
+       }
+}
+
+static  void
+editor_cell_dialog_set_valign (EEditorCellDialog *dialog)
+{
+       GValue val = { 0 };
+
+       g_value_init (&val, G_TYPE_STRING);
+       g_value_set_string (
+               &val,
+               gtk_combo_box_get_active_id (
+                       GTK_COMBO_BOX (dialog->priv->valign_combo)));
+
+       editor_cell_dialog_set_attribute (
+               dialog, webkit_dom_html_table_cell_element_set_v_align, &val, NULL);
+}
+
+static void
+editor_cell_dialog_set_halign (EEditorCellDialog *dialog)
+{
+       GValue val = { 0 };
+
+       g_value_init (&val, G_TYPE_STRING);
+       g_value_set_string (
+               &val,
+               gtk_combo_box_get_active_id (
+                       GTK_COMBO_BOX (dialog->priv->halign_combo)));
+
+       editor_cell_dialog_set_attribute (
+               dialog, webkit_dom_html_table_cell_element_set_align, &val, NULL);
+}
+
+static void
+editor_cell_dialog_set_wrap_text (EEditorCellDialog *dialog)
+{
+       GValue val = { 0 };
+
+       g_value_init (&val, G_TYPE_BOOLEAN);
+       g_value_set_boolean (&val,
+               !gtk_toggle_button_get_active (
+                       GTK_TOGGLE_BUTTON (dialog->priv->wrap_text_check)));
+
+
+       editor_cell_dialog_set_attribute (
+               dialog, webkit_dom_html_table_cell_element_set_no_wrap, &val, NULL);
+}
+
+static void
+cell_set_header_style (WebKitDOMHTMLTableCellElement *cell,
+                      gboolean header_style,
+                      gpointer user_data)
+{
+       EEditorCellDialog *dialog = user_data;
+       WebKitDOMDocument *document;
+       WebKitDOMNodeList *nodes;
+       WebKitDOMElement *new_cell;
+       gulong length, ii;
+       gchar *tagname;
+
+       document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (cell));
+       tagname = webkit_dom_element_get_tag_name (WEBKIT_DOM_ELEMENT (cell));
+
+       if (header_style && (g_ascii_strncasecmp (tagname, "TD", 2) == 0)) {
+
+               new_cell = webkit_dom_document_create_element (document, "TH", NULL);
+
+       } else if (!header_style && (g_ascii_strncasecmp (tagname, "TH", 2) == 0)) {
+
+               new_cell = webkit_dom_document_create_element (document, "TD", NULL);
+
+       } else {
+               return;
+       }
+
+       /* Move all child nodes from cell to new_cell */
+       nodes = webkit_dom_node_get_child_nodes (WEBKIT_DOM_NODE (cell));
+       length = webkit_dom_node_list_get_length (nodes);
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node;
+
+               node = webkit_dom_node_list_item (nodes, ii);
+               webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (new_cell), node, NULL);
+       }
+
+       /* Insert new_cell before cell and remove cell */
+       webkit_dom_node_insert_before (
+               webkit_dom_node_get_parent_node (
+                       WEBKIT_DOM_NODE (cell)),
+               WEBKIT_DOM_NODE (new_cell),
+               WEBKIT_DOM_NODE (cell), NULL);
+
+       webkit_dom_node_remove_child (
+               webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (cell)),
+               WEBKIT_DOM_NODE (cell), NULL);
+
+       dialog->priv->cell = new_cell;
+}
+
+static void
+editor_cell_dialog_set_header_style (EEditorCellDialog *dialog)
+{
+       GValue val = { 0 };
+
+       g_value_init (&val, G_TYPE_BOOLEAN);
+       g_value_set_boolean (&val,
+               gtk_toggle_button_get_active (
+                       GTK_TOGGLE_BUTTON (dialog->priv->header_style_check)));
+
+
+       editor_cell_dialog_set_attribute (
+               dialog, cell_set_header_style, &val, dialog);
+}
+
+static void
+editor_cell_dialog_set_width (EEditorCellDialog *dialog)
+{
+       GValue val = { 0 };
+       gchar *width;
+
+       if (!gtk_toggle_button_get_active (
+               GTK_TOGGLE_BUTTON (dialog->priv->width_check))) {
+
+               width = g_strdup ("auto");
+       } else {
+
+               width = g_strdup_printf ("%d%s",
+                       gtk_spin_button_get_value_as_int (
+                               GTK_SPIN_BUTTON (dialog->priv->width_edit)),
+                       ((gtk_combo_box_get_active (
+                               GTK_COMBO_BOX (dialog->priv->width_units)) == 0) ?
+                                       "px" : "%"));
+       }
+
+       g_value_init (&val, G_TYPE_STRING);
+       g_value_take_string (&val, width);
+       editor_cell_dialog_set_attribute (
+               dialog, webkit_dom_html_table_cell_element_set_width, &val, NULL);
+
+       g_free (width);
+}
+
+static void
+editor_cell_dialog_set_column_span (EEditorCellDialog *dialog)
+{
+       GValue val = { 0 };
+
+       g_value_init (&val, G_TYPE_ULONG);
+       g_value_set_ulong (&val,
+               gtk_spin_button_get_value_as_int (
+                       GTK_SPIN_BUTTON (dialog->priv->col_span_edit)));
+
+       editor_cell_dialog_set_attribute (
+               dialog, webkit_dom_html_table_cell_element_set_col_span, &val, NULL);
+}
+
+static void
+editor_cell_dialog_set_row_span (EEditorCellDialog *dialog)
+{
+       GValue val = { 0 };
+
+       g_value_init (&val, G_TYPE_ULONG);
+       g_value_set_ulong (&val,
+               gtk_spin_button_get_value_as_int (
+                       GTK_SPIN_BUTTON (dialog->priv->row_span_edit)));
+
+       editor_cell_dialog_set_attribute (
+               dialog, webkit_dom_html_table_cell_element_set_row_span, &val, NULL);
+}
+
+static void
+editor_cell_dialog_set_background_color (EEditorCellDialog *dialog)
+{
+       gchar *color;
+       GdkRGBA rgba;
+       GValue val = { 0 };
+
+       e_color_combo_get_current_color (
+               E_COLOR_COMBO (dialog->priv->background_color_picker), &rgba);
+       color = g_strdup_printf ("#%06x", e_rgba_to_value (&rgba));
+
+       g_value_init (&val, G_TYPE_STRING);
+       g_value_take_string (&val, color);
+
+       editor_cell_dialog_set_attribute (
+               dialog, webkit_dom_html_table_cell_element_set_bg_color, &val, NULL);
+
+       g_free (color);
+}
+
+static void
+cell_set_background_image (WebKitDOMHTMLTableCellElement *cell,
+                          const gchar *uri,
+                          gpointer user_data)
+{
+       if (!uri || !*uri) {
+               webkit_dom_element_remove_attribute (
+                       (WebKitDOMElement *) cell, "background");
+       } else {
+               webkit_dom_element_set_attribute (
+                       (WebKitDOMElement *) cell, "background", uri, NULL);
+       }
+}
+
+static void
+editor_cell_dialog_set_background_image (EEditorCellDialog *dialog)
+{
+       const gchar *uri;
+       GValue val = { 0 };
+
+       uri = gtk_file_chooser_get_uri (
+               GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
+
+       g_value_init (&val, G_TYPE_STRING);
+       g_value_take_string (&val, (gchar *) uri);
+
+       editor_cell_dialog_set_attribute (
+               dialog, cell_set_background_image, &val, NULL);
+}
+
+static void
+editor_cell_dialog_show (GtkWidget *gtk_widget)
+{
+       EEditorCellDialog *dialog;
+       gchar *tmp;
+       GdkRGBA color;
+
+       dialog = E_EDITOR_CELL_DIALOG (gtk_widget);
+
+       gtk_toggle_button_set_active (
+               GTK_TOGGLE_BUTTON (dialog->priv->scope_cell_button), TRUE);
+
+       tmp = webkit_dom_html_table_cell_element_get_align (
+                       (WebKitDOMHTMLTableCellElement *) dialog->priv->cell);
+       gtk_combo_box_set_active_id (
+               GTK_COMBO_BOX (dialog->priv->halign_combo),
+               (tmp && *tmp) ? tmp : "left");
+       g_free (tmp);
+
+       tmp = webkit_dom_html_table_cell_element_get_v_align (
+                       (WebKitDOMHTMLTableCellElement *) dialog->priv->cell);
+       gtk_combo_box_set_active_id (
+               GTK_COMBO_BOX (dialog->priv->valign_combo),
+               (tmp && *tmp) ? tmp : "middle");
+       g_free (tmp);
+
+       gtk_toggle_button_set_active (
+               GTK_TOGGLE_BUTTON (dialog->priv->wrap_text_check),
+               !webkit_dom_html_table_cell_element_get_no_wrap (
+                       (WebKitDOMHTMLTableCellElement *) dialog->priv->cell));
+
+       tmp = webkit_dom_element_get_tag_name (
+               (WebKitDOMElement *) dialog->priv->cell);
+       gtk_toggle_button_set_active (
+               GTK_TOGGLE_BUTTON (dialog->priv->header_style_check),
+               (g_ascii_strncasecmp (tmp, "TH", 2) == 0));
+       g_free (tmp);
+
+       tmp = webkit_dom_html_table_cell_element_get_width (
+               (WebKitDOMHTMLTableCellElement *) dialog->priv->cell);
+       if (tmp && *tmp) {
+               gint val = atoi (tmp);
+               gtk_spin_button_set_value (
+                       GTK_SPIN_BUTTON (dialog->priv->width_edit), val);
+               gtk_toggle_button_set_active (
+                       GTK_TOGGLE_BUTTON (dialog->priv->width_check), TRUE);
+       } else {
+               gtk_spin_button_set_value (
+                       GTK_SPIN_BUTTON (dialog->priv->width_edit), 0);
+               gtk_toggle_button_set_active (
+                       GTK_TOGGLE_BUTTON (dialog->priv->width_check), FALSE);
+       }
+       gtk_combo_box_set_active_id (
+               GTK_COMBO_BOX (dialog->priv->width_units), "units-px");
+       g_free (tmp);
+
+       gtk_spin_button_set_value (
+               GTK_SPIN_BUTTON (dialog->priv->row_span_edit),
+               webkit_dom_html_table_cell_element_get_row_span (
+                       (WebKitDOMHTMLTableCellElement *) dialog->priv->cell));
+       gtk_spin_button_set_value (
+               GTK_SPIN_BUTTON (dialog->priv->col_span_edit),
+               webkit_dom_html_table_cell_element_get_col_span (
+                       (WebKitDOMHTMLTableCellElement *) dialog->priv->cell));
+
+       if (webkit_dom_element_has_attribute (
+               (WebKitDOMElement *) dialog->priv->cell, "background")) {
+               tmp = webkit_dom_element_get_attribute (
+                       (WebKitDOMElement *) dialog->priv->cell, "background");
+
+               gtk_file_chooser_set_uri (
+                       GTK_FILE_CHOOSER (dialog->priv->background_image_chooser),
+                       tmp);
+
+               g_free (tmp);
+       } else {
+               gtk_file_chooser_unselect_all (
+                       GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
+       }
+
+       tmp = webkit_dom_html_table_cell_element_get_bg_color (
+               (WebKitDOMHTMLTableCellElement *) dialog->priv->cell);
+       if (!tmp || *tmp) {
+               color = white;
+       }
+       if (gdk_rgba_parse (&color, tmp)) {
+               e_color_combo_set_current_color (
+                       E_COLOR_COMBO (dialog->priv->background_color_picker),
+                       &color);
+       } else {
+               e_color_combo_set_current_color (
+                       E_COLOR_COMBO (dialog->priv->background_color_picker),
+                       &white);
+       }
+       g_free (tmp);
+
+
+       GTK_WIDGET_CLASS (e_editor_cell_dialog_parent_class)->show (gtk_widget);
+}
+
+static void
+e_editor_cell_dialog_class_init (EEditorCellDialogClass *klass)
+{
+       GtkWidgetClass *widget_class;
+
+       e_editor_cell_dialog_parent_class = g_type_class_peek_parent (klass);
+       g_type_class_add_private (klass, sizeof (EEditorCellDialogPrivate));
+
+       widget_class = GTK_WIDGET_CLASS (klass);
+       widget_class->show = editor_cell_dialog_show;
+}
+
+
+static void
+e_editor_cell_dialog_init (EEditorCellDialog *dialog)
+{
+       GtkBox *main_layout;
+       GtkGrid *grid;
+       GtkWidget *widget;
+       GtkFileFilter *file_filter;
+
+       dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (
+               dialog, E_TYPE_EDITOR_CELL_DIALOG, EEditorCellDialogPrivate);
+
+       main_layout = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 5));
+       gtk_container_add (GTK_CONTAINER (dialog), GTK_WIDGET (main_layout));
+       gtk_container_set_border_width (GTK_CONTAINER (dialog), 10);
+
+       /* == Scope == */
+       widget = gtk_label_new ("");
+       gtk_label_set_markup (GTK_LABEL (widget), _("<b>Scope</b>"));
+       gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
+       gtk_box_pack_start (main_layout, widget, TRUE, TRUE, 5);
+
+       grid = GTK_GRID (gtk_grid_new ());
+       gtk_grid_set_row_spacing (grid, 5);
+       gtk_grid_set_column_spacing (grid, 5);
+       gtk_box_pack_start (main_layout, GTK_WIDGET (grid), TRUE, TRUE, 0);
+       gtk_widget_set_margin_left (GTK_WIDGET (grid), 10);
+
+       /* Scope: cell */
+       widget = gtk_image_new_from_icon_name ("stock_select-cell", GTK_ICON_SIZE_BUTTON);
+       gtk_grid_attach (grid, widget, 0, 0, 1, 1);
+
+       widget = gtk_radio_button_new_with_mnemonic(NULL, _("Cell"));
+       gtk_grid_attach (grid, widget, 1, 0, 1, 1);
+       dialog->priv->scope_cell_button = widget;
+
+       g_signal_connect_swapped (
+               widget, "toggled",
+               G_CALLBACK (editor_cell_dialog_set_scope), dialog);     
+
+       /* Scope: row */
+       widget = gtk_image_new_from_icon_name ("stock_select-row", GTK_ICON_SIZE_BUTTON);
+       gtk_grid_attach (grid, widget, 2, 0, 1, 1);
+
+       widget = gtk_radio_button_new_with_mnemonic_from_widget (
+               GTK_RADIO_BUTTON (dialog->priv->scope_cell_button), _("Row"));
+       gtk_grid_attach (grid, widget, 3, 0, 1, 1);
+       dialog->priv->scope_row_button = widget;
+
+       g_signal_connect_swapped (
+               widget, "toggled",
+               G_CALLBACK (editor_cell_dialog_set_scope), dialog);     
+
+       /* Scope: table */
+       widget = gtk_image_new_from_icon_name ("stock_select-table", GTK_ICON_SIZE_BUTTON);
+       gtk_grid_attach (grid, widget, 0, 1, 1, 1);
+
+       widget = gtk_radio_button_new_with_mnemonic_from_widget (
+               GTK_RADIO_BUTTON (dialog->priv->scope_cell_button), _("Table"));
+       gtk_grid_attach (grid, widget, 1, 1, 1, 1);
+       dialog->priv->scope_table_button = widget;
+
+       g_signal_connect_swapped (
+               widget, "toggled",
+               G_CALLBACK (editor_cell_dialog_set_scope), dialog);     
+
+       /* Scope: column */
+       widget = gtk_image_new_from_icon_name ("stock_select-column", GTK_ICON_SIZE_BUTTON);
+       gtk_grid_attach (grid, widget, 2, 1, 1, 1);
+
+       widget = gtk_radio_button_new_with_mnemonic_from_widget (
+               GTK_RADIO_BUTTON (dialog->priv->scope_cell_button), _("Column"));
+       gtk_grid_attach (grid, widget, 3, 1, 1, 1);
+       dialog->priv->scope_column_button = widget;
+
+       g_signal_connect_swapped (
+               widget, "toggled",
+               G_CALLBACK (editor_cell_dialog_set_scope), dialog);
+
+       /* == Alignment & Behavior == */
+       widget = gtk_label_new ("");
+       gtk_label_set_markup (GTK_LABEL (widget), _("<b>Alignment &amp; Behavior</b>"));
+       gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
+       gtk_box_pack_start (main_layout, widget, TRUE, TRUE, 5);
+
+       grid = GTK_GRID (gtk_grid_new ());
+       gtk_grid_set_row_spacing (grid, 5);
+       gtk_grid_set_column_spacing (grid, 5);
+       gtk_box_pack_start (main_layout, GTK_WIDGET (grid), TRUE, TRUE, 0);
+       gtk_widget_set_margin_left (GTK_WIDGET (grid), 10);
+
+       /* Horizontal */
+       widget = gtk_combo_box_text_new ();
+       gtk_widget_set_hexpand (widget, TRUE);
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "left", _("Left"));
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "center", _("Center"));
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "right", _("Right"));
+       gtk_grid_attach (grid, widget, 1, 0, 1, 1);
+       dialog->priv->halign_combo = widget;
+
+       g_signal_connect_swapped (
+               widget, "changed",
+               G_CALLBACK (editor_cell_dialog_set_halign), dialog);
+
+       widget = gtk_label_new_with_mnemonic (_("Horizontal:"));
+       gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->halign_combo);
+       gtk_grid_attach (grid, widget, 0, 0, 1, 1);
+
+       /* Vertical */
+       widget = gtk_combo_box_text_new ();
+       gtk_widget_set_hexpand (widget, TRUE);
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "top", _("Top"));
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "middle", _("Middle"));
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "bottom", _("Bottom"));
+       gtk_grid_attach (grid, widget, 3, 0, 1, 1);
+       dialog->priv->valign_combo = widget;
+
+       g_signal_connect_swapped (
+               widget, "changed",
+               G_CALLBACK (editor_cell_dialog_set_valign), dialog);
+
+       widget = gtk_label_new_with_mnemonic (_("Vertical:"));
+       gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->valign_combo);
+       gtk_grid_attach (grid, widget, 2, 0, 1, 1);
+
+       /* Wrap Text */
+       widget = gtk_check_button_new_with_mnemonic (_("Wrap Text"));
+       dialog->priv->wrap_text_check = widget;
+
+       g_signal_connect_swapped (
+               widget, "toggled",
+               G_CALLBACK (editor_cell_dialog_set_wrap_text), dialog);
+
+       /* Header Style */
+       widget = gtk_check_button_new_with_mnemonic (_("Header Style"));
+       dialog->priv->header_style_check = widget;
+
+       g_signal_connect_swapped (
+               widget, "toggled",
+               G_CALLBACK (editor_cell_dialog_set_header_style), dialog);
+
+       widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
+       gtk_box_pack_start (GTK_BOX (widget), dialog->priv->wrap_text_check, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (widget), dialog->priv->header_style_check, FALSE, FALSE, 0);
+       gtk_grid_attach (grid, widget, 0, 1, 4, 1);
+
+       /* == Layout == */
+       widget = gtk_label_new ("");
+       gtk_label_set_markup (GTK_LABEL (widget), _("<b>Layout</b>"));
+       gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
+       gtk_box_pack_start (main_layout, widget, TRUE, TRUE, 5);
+
+       grid = GTK_GRID (gtk_grid_new ());
+       gtk_grid_set_row_spacing (grid, 5);
+       gtk_grid_set_column_spacing (grid, 5);
+       gtk_box_pack_start (main_layout, GTK_WIDGET (grid), TRUE, TRUE, 0);
+       gtk_widget_set_margin_left (GTK_WIDGET (grid), 10);
+
+       /* Width */
+       widget = gtk_check_button_new_with_mnemonic (_("Width"));
+       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);
+       gtk_grid_attach (grid, widget, 1, 0, 1, 1);
+       dialog->priv->width_edit = widget;
+
+       g_signal_connect_swapped (
+               widget, "value-changed",
+               G_CALLBACK (editor_cell_dialog_set_width), dialog);
+       g_object_bind_property (
+               dialog->priv->width_check, "active",
+               widget, "sensitive",
+               G_BINDING_SYNC_CREATE);
+
+       widget = gtk_combo_box_text_new ();
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "unit-px", "px");
+       gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "unit-percent", "%");
+       gtk_grid_attach (grid, widget, 2, 0, 1, 1);
+       dialog->priv->width_units = widget;
+
+       g_signal_connect_swapped (
+               widget, "changed",
+               G_CALLBACK (editor_cell_dialog_set_width), dialog);
+       g_object_bind_property (
+               dialog->priv->width_check, "active",
+               widget, "sensitive",
+               G_BINDING_SYNC_CREATE);
+
+       /* Row Span */
+       widget = gtk_spin_button_new_with_range (0, G_MAXUINT, 1);
+       gtk_grid_attach (grid, widget, 4, 0, 1, 1);
+       dialog->priv->row_span_edit = widget;
+
+       g_signal_connect_swapped (
+               widget, "value-changed",
+               G_CALLBACK (editor_cell_dialog_set_row_span), dialog);
+
+       widget = gtk_label_new_with_mnemonic (_("Row Span:"));
+       gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->row_span_edit);
+       gtk_grid_attach (grid, widget, 3, 0, 1, 1);
+
+       /* Column Span */
+       widget = gtk_spin_button_new_with_range (0, G_MAXUINT, 1);
+       gtk_grid_attach (grid, widget, 4, 1, 1, 1);
+       dialog->priv->col_span_edit = widget;
+
+       g_signal_connect_swapped (
+               widget, "value-changed",
+               G_CALLBACK (editor_cell_dialog_set_column_span), dialog);
+
+       widget = gtk_label_new_with_mnemonic (_("Column Span:"));
+       gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->col_span_edit);
+       gtk_grid_attach (grid, widget, 3, 1, 1, 1);
+
+       /* == Background == */
+       widget = gtk_label_new ("");
+       gtk_label_set_markup (GTK_LABEL (widget), _("<b>Background</b>"));
+       gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
+       gtk_box_pack_start (main_layout, widget, TRUE, TRUE, 5);
+
+       grid = GTK_GRID (gtk_grid_new ());
+       gtk_grid_set_row_spacing (grid, 5);
+       gtk_grid_set_column_spacing (grid, 5);
+       gtk_box_pack_start (main_layout, GTK_WIDGET (grid), TRUE, TRUE, 0);
+       gtk_widget_set_margin_left (GTK_WIDGET (grid), 10);
+
+       /* Color */
+       widget = e_color_combo_new ();
+       e_color_combo_set_default_color (E_COLOR_COMBO (widget), &white);
+       gtk_widget_set_hexpand (widget, TRUE);
+       gtk_grid_attach (grid, widget, 1, 0, 1, 1);
+       g_signal_connect_swapped (
+               widget, "notify::current-color",
+               G_CALLBACK (editor_cell_dialog_set_background_color), dialog);
+       dialog->priv->background_color_picker = widget;
+
+       widget = gtk_label_new_with_mnemonic (_("_Color:"));
+       gtk_label_set_mnemonic_widget (
+               GTK_LABEL (widget), dialog->priv->background_color_picker);
+       gtk_grid_attach (grid, widget, 0, 0, 1, 1);
+
+       /* Image */
+       widget = e_image_chooser_dialog_new (
+                       _("Choose Background Image"),
+                       GTK_WINDOW (dialog));
+       dialog->priv->background_image_chooser = widget;
+
+       file_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (file_filter, _("Images"));
+       gtk_file_filter_add_mime_type (file_filter, "image/*");
+
+       widget = gtk_file_chooser_button_new_with_dialog (
+                       dialog->priv->background_image_chooser);
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (widget), file_filter);
+       gtk_widget_set_hexpand (widget, TRUE);
+       gtk_grid_attach (grid, widget, 1, 1, 1, 1);
+       g_signal_connect_swapped (
+               widget, "file-set",
+               G_CALLBACK (editor_cell_dialog_set_background_image), dialog);
+       dialog->priv->background_image_chooser = widget;
+
+
+       widget =gtk_label_new_with_mnemonic (_("Image:"));
+       gtk_label_set_mnemonic_widget (
+               GTK_LABEL (widget), dialog->priv->background_image_chooser);
+       gtk_grid_attach (grid, widget, 0, 1, 1, 1);
+
+       /* == Button box == */
+       widget = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
+       g_signal_connect_swapped (
+               widget, "clicked",
+               G_CALLBACK (gtk_widget_hide), dialog);
+       dialog->priv->close_button = widget;
+
+       widget = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+       gtk_button_box_set_layout (GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_END);
+       gtk_box_pack_start (main_layout, GTK_WIDGET (widget), TRUE, TRUE, 0);
+       gtk_box_pack_start (
+               GTK_BOX (widget), dialog->priv->close_button, FALSE, FALSE, 0);
+
+       gtk_widget_show_all (GTK_WIDGET (main_layout));
+}
+
+
+GtkWidget *
+e_editor_cell_dialog_new (EEditor *editor)
+{
+       return GTK_WIDGET (
+               g_object_new (
+                       E_TYPE_EDITOR_CELL_DIALOG,
+                       "editor", editor,
+                       "title", N_("Cell Properties"),
+                       NULL));
+}
+
+void
+e_editor_cell_dialog_show (EEditorCellDialog *dialog,
+                          WebKitDOMNode *cell)
+{
+       EEditorCellDialogClass *klass;
+
+       g_return_if_fail (E_IS_EDITOR_CELL_DIALOG (dialog));
+       g_return_if_fail (cell != NULL);
+
+       dialog->priv->cell = e_editor_dom_node_find_parent_element (cell, "TD");
+       if (dialog->priv->cell == NULL) {
+               dialog->priv->cell =
+                       e_editor_dom_node_find_parent_element (cell, "TH");
+       }
+
+       klass = E_EDITOR_CELL_DIALOG_GET_CLASS (dialog);
+       GTK_WIDGET_CLASS (klass)->show (GTK_WIDGET (dialog));
+}
+
+
diff --git a/e-util/e-editor-cell-dialog.h b/e-util/e-editor-cell-dialog.h
new file mode 100644
index 0000000..2ea9514
--- /dev/null
+++ b/e-util/e-editor-cell-dialog.h
@@ -0,0 +1,72 @@
+/*
+ * e-editor-cell-dialog.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
+#error "Only <e-util/e-util.h> should be included directly."
+#endif
+
+#ifndef E_EDITOR_CELL_DIALOG_H
+#define E_EDITOR_CELL_DIALOG_H
+
+#include <e-util/e-editor-dialog.h>
+
+/* Standard GObject macros */
+#define E_TYPE_EDITOR_CELL_DIALOG \
+       (e_editor_cell_dialog_get_type ())
+#define E_EDITOR_CELL_DIALOG(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), E_TYPE_EDITOR_CELL_DIALOG, EEditorCellDialog))
+#define E_EDITOR_CELL_DIALOG_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), E_TYPE_EDITOR_CELL_DIALOG, EEditorCellDialogClass))
+#define E_IS_EDITOR_CELL_DIALOG(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), E_TYPE_EDITOR_CELL_DIALOG))
+#define E_IS_EDITOR_CELL_DIALOG_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), E_TYPE_EDITOR_CELL_DIALOG))
+#define E_EDITOR_CELL_DIALOG_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), E_TYPE_EDITOR_CELL_DIALOG, EEditorCellDialogClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EEditorCellDialog EEditorCellDialog;
+typedef struct _EEditorCellDialogClass EEditorCellDialogClass;
+typedef struct _EEditorCellDialogPrivate EEditorCellDialogPrivate;
+
+struct _EEditorCellDialog {
+       EEditorDialog parent;
+
+       EEditorCellDialogPrivate *priv;
+};
+
+struct _EEditorCellDialogClass {
+       EEditorDialogClass parent_class;
+};
+
+GType          e_editor_cell_dialog_get_type   (void);
+
+GtkWidget*     e_editor_cell_dialog_new        (EEditor *editor);
+
+void           e_editor_cell_dialog_show       (EEditorCellDialog *dialog,
+                                                WebKitDOMNode *cell);
+
+G_END_DECLS
+
+#endif /* E_EDITOR_CELL_DIALOG_H */
diff --git a/e-util/e-editor-private.h b/e-util/e-editor-private.h
index c06d8e5..6a47fdb 100644
--- a/e-util/e-editor-private.h
+++ b/e-util/e-editor-private.h
@@ -33,6 +33,7 @@
 #include <e-editor-image-dialog.h>
 #include <e-editor-text-dialog.h>
 #include <e-editor-paragraph-dialog.h>
+#include <e-editor-cell-dialog.h>
 
 #ifdef HAVE_XFREE
 #include <X11/XF86keysym.h>
@@ -70,6 +71,7 @@ struct _EEditorPrivate {
        GtkWidget *image_dialog;
        GtkWidget *text_dialog;
        GtkWidget *paragraph_dialog;
+       GtkWidget *cell_dialog;
 
        GtkWidget *color_combo_box;
        GtkWidget *mode_combo_box;
@@ -83,6 +85,7 @@ struct _EEditorPrivate {
        gchar *filename;
 
        WebKitDOMNode *image;
+       WebKitDOMNode *table_cell;
 };
 
 void           editor_actions_init             (EEditor *editor);
diff --git a/e-util/e-editor-selection.h b/e-util/e-editor-selection.h
index 9ee9ad5..3798d30 100644
--- a/e-util/e-editor-selection.h
+++ b/e-util/e-editor-selection.h
@@ -82,7 +82,7 @@ typedef enum {
 typedef enum {
        E_EDITOR_SELECTION_ALIGNMENT_LEFT,
        E_EDITOR_SELECTION_ALIGNMENT_CENTER,
-       E_EDITOR_SELECTION_ALIGNMENT_RIGHT,
+       E_EDITOR_SELECTION_ALIGNMENT_RIGHT
 } EEditorSelectionAlignment;
 
 struct _EEditorSelection {
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index eb6d78d..313f56a 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -161,6 +161,13 @@ editor_widget_selection_changed_cb (EEditorWidget *widget,
 }
 
 static gboolean
+editor_widget_should_show_delete_interface_for_element (EEditorWidget *widget,
+                                                       WebKitDOMHTMLElement *element)
+{
+       return FALSE;
+}
+
+static gboolean
 editor_widget_button_press_event (GtkWidget *gtk_widget,
                                  GdkEventButton *event)
 {
@@ -663,6 +670,8 @@ e_editor_widget_init (EEditorWidget *editor)
                G_CALLBACK (editor_widget_user_changed_contents_cb), NULL);
        g_signal_connect (editor, "selection-changed",
                G_CALLBACK (editor_widget_selection_changed_cb), NULL);
+       g_signal_connect (editor, "should-show-delete-interface-for-element",
+               G_CALLBACK (editor_widget_should_show_delete_interface_for_element), NULL);
 
        editor->priv->selection = e_editor_selection_new (
                                        WEBKIT_WEB_VIEW (editor));
diff --git a/e-util/e-editor.c b/e-util/e-editor.c
index 23ee597..c755f8c 100644
--- a/e-util/e-editor.c
+++ b/e-util/e-editor.c
@@ -62,6 +62,7 @@ editor_update_actions (EEditor *editor,
        manager = e_editor_get_ui_manager (editor);
 
        editor->priv->image = NULL;
+       editor->priv->table_cell = NULL;
 
        /* Update context menu item visibility. */
        hit_test = webkit_web_view_get_hit_test_result (webview, event);
@@ -102,7 +103,8 @@ editor_update_actions (EEditor *editor,
 
 
        visible = (WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (node) ||
-                  (e_editor_dom_node_find_parent_element (node, "TD") != NULL));
+                  (e_editor_dom_node_find_parent_element (node, "TD") != NULL) ||
+                  (e_editor_dom_node_find_parent_element (node, "TH") != NULL));
        gtk_action_set_visible (ACTION (CONTEXT_DELETE_CELL), visible);
        gtk_action_set_visible (ACTION (CONTEXT_DELETE_COLUMN), visible);
        gtk_action_set_visible (ACTION (CONTEXT_DELETE_ROW), visible);
@@ -113,6 +115,9 @@ editor_update_actions (EEditor *editor,
        gtk_action_set_visible (ACTION (CONTEXT_INSERT_ROW_BELOW), visible);
        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;
+       }
 
        /* Note the |= (cursor must be in a table cell). */
        visible |= (WEBKIT_DOM_IS_HTML_TABLE_ELEMENT (node) ||
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 1a114e1..8718461 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -92,6 +92,7 @@
 #include <e-util/e-dialog-utils.h>
 #include <e-util/e-dialog-widgets.h>
 #include <e-util/e-editor-actions.h>
+#include <e-util/e-editor-cell-dialog.h>
 #include <e-util/e-editor-dialog.h>
 #include <e-util/e-editor-find-dialog.h>
 #include <e-util/e-editor-hrule-dialog.h>


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