[evolution/wip/webkit-composer: 155/372] Rename e_editor_selection_get_FORMAT to e_editor_selection_is_FORMAT



commit 35aa834855a47cb94850ab933ee08a46d0cef055
Author: Dan Vrátil <dvratil redhat com>
Date:   Sun Dec 2 11:43:29 2012 +0100

    Rename e_editor_selection_get_FORMAT to e_editor_selection_is_FORMAT
    
    selection_is_bold() makes more sense then selection_get_bold().
    Also adds e_editor_selection_is_citation() which checks whether
    current selection is within <blockquote type=cite>.
    e_editor_selection_is_indented() deliberately ignores citations.

 e-util/e-editor-selection.c   |  120 +++++++++++++++++++++++------------------
 e-util/e-editor-selection.h   |   24 ++++----
 e-util/e-editor-text-dialog.c |    8 ++--
 3 files changed, 84 insertions(+), 68 deletions(-)
---
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index d7c083c..2cd5079 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -127,21 +127,26 @@ get_has_style (EEditorSelection *selection,
        result = FALSE;
        while (!result && element) {
                gchar *element_tag;
+               gboolean accept_citation = FALSE;
 
                element_tag = webkit_dom_element_get_tag_name (element);
 
-               result = ((tag_len == strlen (element_tag)) &&
+               if (g_ascii_strncasecmp (style_tag, "citation", 8) == 0) {
+                       result = ((tag_len == 10 /* strlen ("blockquote") */) &&
+                               (g_ascii_strncasecmp (element_tag, "blockquote", 10) == 0));
+               } else {
+                       result = ((tag_len == strlen (element_tag)) &&
                                (g_ascii_strncasecmp (element_tag, style_tag, tag_len) == 0));
+               }
 
                /* Special case: <blockquote type=cite> marks quotation, while
                 * just <blockquote> is used for indentation. If the <blockquote>
-                * has type=cite, then ignore it */
+                * has type=cite, then ignore it unless style_tag is "citation" */
                if (result && g_ascii_strncasecmp (element_tag, "blockquote", 10) == 0) {
                        if (webkit_dom_element_has_attribute (element, "type")) {
                                gchar *type;
-                               type = webkit_dom_element_get_attribute (
-                                               element, "type");
-                               if (g_ascii_strncasecmp (type, "cite", 4) == 0) {
+                               type = webkit_dom_element_get_attribute (element, "type");
+                               if (!accept_citation && (g_ascii_strncasecmp (type, "cite", 4) == 0)) {
                                        result = FALSE;
                                }
                                g_free (type);
@@ -240,7 +245,7 @@ e_editor_selection_get_property (GObject *object,
 
                case PROP_BOLD:
                        g_value_set_boolean (value,
-                               e_editor_selection_get_bold (selection));
+                               e_editor_selection_is_bold (selection));
                        return;
 
                case PROP_FONT_NAME:
@@ -265,32 +270,32 @@ e_editor_selection_get_property (GObject *object,
 
                case PROP_INDENTED:
                        g_value_set_boolean (value,
-                               e_editor_selection_get_indented (selection));
+                               e_editor_selection_is_indented (selection));
                        return;
 
                case PROP_ITALIC:
                        g_value_set_boolean (value,
-                               e_editor_selection_get_italic (selection));
+                               e_editor_selection_is_italic (selection));
                        return;
 
                case PROP_MONOSPACED:
                        g_value_set_boolean (value,
-                               e_editor_selection_get_monospaced (selection));
+                               e_editor_selection_is_monospaced (selection));
                        return;
 
                case PROP_STRIKE_THROUGH:
                        g_value_set_boolean (value,
-                               e_editor_selection_get_strike_through (selection));
+                               e_editor_selection_is_strike_through (selection));
                        return;
 
                case PROP_SUBSCRIPT:
                        g_value_set_boolean (value,
-                               e_editor_selection_get_subscript (selection));
+                               e_editor_selection_is_subscript (selection));
                        return;
 
                case PROP_SUPERSCRIPT:
                        g_value_set_boolean (value,
-                               e_editor_selection_get_superscript (selection));
+                               e_editor_selection_is_superscript (selection));
                        return;
 
                case PROP_TEXT:
@@ -300,7 +305,7 @@ e_editor_selection_get_property (GObject *object,
 
                case PROP_UNDERLINE:
                        g_value_set_boolean (value,
-                               e_editor_selection_get_underline (selection));
+                               e_editor_selection_is_underline (selection));
                        return;
        }
 
@@ -1012,32 +1017,6 @@ e_editor_selection_set_block_format (EEditorSelection *selection,
        g_object_notify (G_OBJECT (selection), "block-format");
 }
 
-gboolean
-e_editor_selection_get_bold (EEditorSelection *selection)
-{
-       g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
-
-       return get_has_style (selection, "b");
-}
-
-void
-e_editor_selection_set_bold (EEditorSelection *selection,
-                            gboolean bold)
-{
-       WebKitDOMDocument *document;
-
-       g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
-
-       if ((e_editor_selection_get_bold (selection) ? TRUE : FALSE)
-                               == (bold ? TRUE : FALSE)) {
-               return;
-       }
-
-       document = webkit_web_view_get_dom_document (selection->priv->webview);
-       webkit_dom_document_exec_command (document, "bold", FALSE, "");
-
-       g_object_notify (G_OBJECT (selection), "bold");
-}
 
 void
 e_editor_selection_get_font_color (EEditorSelection *selection,
@@ -1155,8 +1134,18 @@ e_editor_selection_set_font_size (EEditorSelection *selection,
        g_object_notify (G_OBJECT (selection), "font-size");
 }
 
+/* Not a property! */
 gboolean
-e_editor_selection_get_indented (EEditorSelection *selection)
+e_editor_selection_is_citation (EEditorSelection* selection)
+{
+       g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
+
+       /* citation == <blockquote type='cite'> - special case handled in get_has_style() */
+       return get_has_style (selection, "citation");
+}
+
+gboolean
+e_editor_selection_is_indented (EEditorSelection *selection)
 {
        g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
 
@@ -1190,7 +1179,34 @@ e_editor_selection_unindent (EEditorSelection *selection)
 }
 
 gboolean
-e_editor_selection_get_italic (EEditorSelection *selection)
+e_editor_selection_is_bold (EEditorSelection *selection)
+{
+       g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
+
+       return get_has_style (selection, "b");
+}
+
+void
+e_editor_selection_set_bold (EEditorSelection *selection,
+                            gboolean bold)
+{
+       WebKitDOMDocument *document;
+
+       g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
+
+       if ((e_editor_selection_is_bold (selection) ? TRUE : FALSE)
+                               == (bold ? TRUE : FALSE)) {
+               return;
+       }
+
+       document = webkit_web_view_get_dom_document (selection->priv->webview);
+       webkit_dom_document_exec_command (document, "bold", FALSE, "");
+
+       g_object_notify (G_OBJECT (selection), "bold");
+}
+
+gboolean
+e_editor_selection_is_italic (EEditorSelection *selection)
 {
        g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
 
@@ -1205,7 +1221,7 @@ e_editor_selection_set_italic (EEditorSelection *selection,
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
-       if ((e_editor_selection_get_italic (selection) ? TRUE : FALSE)
+       if ((e_editor_selection_is_italic (selection) ? TRUE : FALSE)
                                == (italic ? TRUE : FALSE)) {
                return;
        }
@@ -1217,7 +1233,7 @@ e_editor_selection_set_italic (EEditorSelection *selection,
 }
 
 gboolean
-e_editor_selection_get_monospaced (EEditorSelection *selection)
+e_editor_selection_is_monospaced (EEditorSelection *selection)
 {
        g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
 
@@ -1234,7 +1250,7 @@ e_editor_selection_set_monospaced (EEditorSelection *selection,
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
-       is_monospaced = e_editor_selection_get_monospaced (selection) ? TRUE : FALSE;
+       is_monospaced = e_editor_selection_is_monospaced (selection) ? TRUE : FALSE;
        if ((is_monospaced ? TRUE : FALSE) == (monospaced ? TRUE : FALSE)) {
                return;
        }
@@ -1271,7 +1287,7 @@ e_editor_selection_set_monospaced (EEditorSelection *selection,
 }
 
 gboolean
-e_editor_selection_get_strike_through (EEditorSelection *selection)
+e_editor_selection_is_strike_through (EEditorSelection *selection)
 {
        g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
 
@@ -1286,7 +1302,7 @@ e_editor_selection_set_strike_through (EEditorSelection *selection,
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
-       if ((e_editor_selection_get_strike_through (selection) ? TRUE : FALSE)
+       if ((e_editor_selection_is_strike_through (selection) ? TRUE : FALSE)
                                == (strike_through? TRUE : FALSE)) {
                return;
        }
@@ -1298,7 +1314,7 @@ e_editor_selection_set_strike_through (EEditorSelection *selection,
 }
 
 gboolean
-e_editor_selection_get_subscript (EEditorSelection *selection)
+e_editor_selection_is_subscript (EEditorSelection *selection)
 {
        WebKitDOMNode *node;
        WebKitDOMRange *range;
@@ -1333,7 +1349,7 @@ e_editor_selection_set_subscript (EEditorSelection *selection,
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
-       if ((e_editor_selection_get_subscript (selection) ? TRUE : FALSE)
+       if ((e_editor_selection_is_subscript (selection) ? TRUE : FALSE)
                                == (subscript? TRUE : FALSE)) {
                return;
        }
@@ -1345,7 +1361,7 @@ e_editor_selection_set_subscript (EEditorSelection *selection,
 }
 
 gboolean
-e_editor_selection_get_superscript (EEditorSelection *selection)
+e_editor_selection_is_superscript (EEditorSelection *selection)
 {
        WebKitDOMNode *node;
        WebKitDOMRange *range;
@@ -1380,7 +1396,7 @@ e_editor_selection_set_superscript (EEditorSelection *selection,
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
-       if ((e_editor_selection_get_superscript (selection) ? TRUE : FALSE)
+       if ((e_editor_selection_is_superscript (selection) ? TRUE : FALSE)
                                == (superscript? TRUE : FALSE)) {
                return;
        }
@@ -1392,7 +1408,7 @@ e_editor_selection_set_superscript (EEditorSelection *selection,
 }
 
 gboolean
-e_editor_selection_get_underline (EEditorSelection *selection)
+e_editor_selection_is_underline (EEditorSelection *selection)
 {
        g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), FALSE);
 
@@ -1407,7 +1423,7 @@ e_editor_selection_set_underline (EEditorSelection *selection,
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
-       if ((e_editor_selection_get_underline (selection) ? TRUE : FALSE)
+       if ((e_editor_selection_is_underline (selection) ? TRUE : FALSE)
                                == (underline? TRUE : FALSE)) {
                return;
        }
diff --git a/e-util/e-editor-selection.h b/e-util/e-editor-selection.h
index 93c41e4..b5e5cfa 100644
--- a/e-util/e-editor-selection.h
+++ b/e-util/e-editor-selection.h
@@ -106,7 +106,6 @@ gchar *                     e_editor_selection_get_caret_word
 void                   e_editor_selection_replace_caret_word
                                                        (EEditorSelection *selection,
                                                         const gchar *replacement);
-
 void                   e_editor_selection_set_alignment
                                                        (EEditorSelection *selection,
                                                         EEditorSelectionAlignment alignment);
@@ -120,10 +119,6 @@ void                       e_editor_selection_set_background_color
 const gchar*           e_editor_selection_get_background_color
                                                        (EEditorSelection *selection);
 
-void                   e_editor_selection_set_bold     (EEditorSelection *selection,
-                                                        gboolean bold);
-gboolean               e_editor_selection_get_bold     (EEditorSelection *selection);
-
 void                   e_editor_selection_set_font_name
                                                        (EEditorSelection *selection,
                                                         const gchar *font_name);
@@ -150,42 +145,47 @@ EEditorSelectionBlockFormat
                        e_editor_selection_get_block_format
                                                        (EEditorSelection *selection);
 
-gboolean               e_editor_selection_get_indented (EEditorSelection *selection);
+gboolean               e_editor_selection_is_citation  (EEditorSelection *selection);
+gboolean               e_editor_selection_is_indented  (EEditorSelection *selection);
 void                   e_editor_selection_indent       (EEditorSelection *selection);
 void                   e_editor_selection_unindent     (EEditorSelection *selection);
 
+void                   e_editor_selection_set_bold     (EEditorSelection *selection,
+                                                        gboolean bold);
+gboolean               e_editor_selection_is_bold      (EEditorSelection *selection);
+
 void                   e_editor_selection_set_italic   (EEditorSelection *selection,
                                                         gboolean italic);
-gboolean               e_editor_selection_get_italic   (EEditorSelection *selection);
+gboolean               e_editor_selection_is_italic    (EEditorSelection *selection);
 
 void                   e_editor_selection_set_monospaced
                                                        (EEditorSelection *selection,
                                                         gboolean monospaced);
-gboolean               e_editor_selection_get_monospaced
+gboolean               e_editor_selection_is_monospaced
                                                        (EEditorSelection *selection);
 
 void                   e_editor_selection_set_strike_through
                                                        (EEditorSelection *selection,
                                                         gboolean strike_through);
-gboolean               e_editor_selection_get_strike_through
+gboolean               e_editor_selection_is_strike_through
                                                        (EEditorSelection *selection);
 
 void                   e_editor_selection_set_superscript
                                                        (EEditorSelection *selection,
                                                         gboolean superscript);
-gboolean               e_editor_selection_get_superscript
+gboolean               e_editor_selection_is_superscript
                                                        (EEditorSelection *selection);
 
 void                   e_editor_selection_set_subscript
                                                        (EEditorSelection *selection,
                                                         gboolean subscript);
-gboolean               e_editor_selection_get_subscript
+gboolean               e_editor_selection_is_subscript
                                                        (EEditorSelection *selection);
 
 void                   e_editor_selection_set_underline
                                                        (EEditorSelection *selection,
                                                         gboolean underline);
-gboolean               e_editor_selection_get_underline
+gboolean               e_editor_selection_is_underline
                                                        (EEditorSelection *selection);
 
 void                   e_editor_selection_unlink       (EEditorSelection *selection);
diff --git a/e-util/e-editor-text-dialog.c b/e-util/e-editor-text-dialog.c
index dd1756b..efaca51 100644
--- a/e-util/e-editor-text-dialog.c
+++ b/e-util/e-editor-text-dialog.c
@@ -159,16 +159,16 @@ editor_text_dialog_show (GtkWidget *gtk_widget)
 
        gtk_toggle_button_set_active (
                GTK_TOGGLE_BUTTON (dialog->priv->bold_check),
-               e_editor_selection_get_bold (selection));
+               e_editor_selection_is_bold (selection));
        gtk_toggle_button_set_active (
                GTK_TOGGLE_BUTTON (dialog->priv->italic_check),
-               e_editor_selection_get_italic (selection));
+               e_editor_selection_is_italic (selection));
        gtk_toggle_button_set_active (
                GTK_TOGGLE_BUTTON (dialog->priv->underline_check),
-               e_editor_selection_get_underline (selection));
+               e_editor_selection_is_underline (selection));
        gtk_toggle_button_set_active (
                GTK_TOGGLE_BUTTON (dialog->priv->strikethrough_check),
-               e_editor_selection_get_strike_through (selection));
+               e_editor_selection_is_strike_through (selection));
 
        gtk_combo_box_set_active (
                GTK_COMBO_BOX (dialog->priv->size_check),


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