From b5d682209bd8394c4fcccd6f2dd84ad53143a60c Mon Sep 17 00:00:00 2001 From: Tomas Popela Date: Wed, 25 Jun 2014 14:13:39 +0200 Subject: Bug 731508 - [webkit-composer] no option to paste as text (without formatting) --- e-util/e-html-editor-actions.c | 18 ++++++++++++++++ e-util/e-html-editor-manager.ui | 2 ++ e-util/e-html-editor-selection.c | 16 +++++++++++++++ e-util/e-html-editor-selection.h | 9 +++++--- e-util/e-html-editor-view.c | 44 ++++++++++++++++++++++++++++++++++++++++ e-util/e-html-editor-view.h | 2 ++ 6 files changed, 88 insertions(+), 3 deletions(-) diff --git a/e-util/e-html-editor-actions.c b/e-util/e-html-editor-actions.c index 4d1751e117..6b1276ceed 100644 --- a/e-util/e-html-editor-actions.c +++ b/e-util/e-html-editor-actions.c @@ -704,6 +704,16 @@ action_paste_cb (GtkAction *action, e_html_editor_view_force_spell_check (view); } +static void +action_paste_as_text_cb (GtkAction *action, + EHTMLEditor *editor) +{ + EHTMLEditorView *view = e_html_editor_get_view (editor); + + e_html_editor_view_paste_as_text (view); + e_html_editor_view_force_spell_check (view); +} + static void action_paste_quote_cb (GtkAction *action, EHTMLEditor *editor) @@ -1337,6 +1347,14 @@ static GtkActionEntry html_entries[] = { NULL, NULL, NULL }, + + { "paste-as-text", + NULL, + N_("Paste As _Text"), + NULL, + NULL, + G_CALLBACK (action_paste_as_text_cb) }, + }; static GtkToggleActionEntry html_toggle_entries[] = { diff --git a/e-util/e-html-editor-manager.ui b/e-util/e-html-editor-manager.ui index 75f2c34b20..1bdba8cfc6 100644 --- a/e-util/e-html-editor-manager.ui +++ b/e-util/e-html-editor-manager.ui @@ -12,6 +12,7 @@ + @@ -145,6 +146,7 @@ + diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c index 4db05b4730..bc0d6f4bf6 100644 --- a/e-util/e-html-editor-selection.c +++ b/e-util/e-html-editor-selection.c @@ -3943,6 +3943,22 @@ e_html_editor_selection_insert_html (EHTMLEditorSelection *selection, g_object_unref (view); } +void +e_html_editor_selection_insert_as_text (EHTMLEditorSelection *selection, + const gchar *html_text) +{ + EHTMLEditorView *view; + + g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection)); + g_return_if_fail (html_text != NULL); + + view = e_html_editor_selection_ref_html_editor_view (selection); + g_return_if_fail (view != NULL); + + e_html_editor_view_convert_and_insert_html_to_plain_text (view, html_text); + + g_object_unref (view); +} /************************* image_load_and_insert_async() *************************/ diff --git a/e-util/e-html-editor-selection.h b/e-util/e-html-editor-selection.h index 1501687d49..291440554b 100644 --- a/e-util/e-html-editor-selection.h +++ b/e-util/e-html-editor-selection.h @@ -165,9 +165,15 @@ const gchar * e_html_editor_selection_get_string (EHTMLEditorSelection *selection); void e_html_editor_selection_replace (EHTMLEditorSelection *selection, const gchar *new_string); +void e_html_editor_selection_insert_text + (EHTMLEditorSelection *selection, + const gchar *plain_text); void e_html_editor_selection_insert_html (EHTMLEditorSelection *selection, const gchar *html_text); +void e_html_editor_selection_insert_as_text + (EHTMLEditorSelection *selection, + const gchar *html_text); void e_html_editor_selection_replace_image_src (EHTMLEditorSelection *selection, WebKitDOMElement *element, @@ -175,9 +181,6 @@ void e_html_editor_selection_replace_image_src void e_html_editor_selection_insert_image (EHTMLEditorSelection *selection, const gchar *image_uri); -void e_html_editor_selection_insert_text - (EHTMLEditorSelection *selection, - const gchar *plain_text); void e_html_editor_selection_clear_caret_position_marker (EHTMLEditorSelection *selection); WebKitDOMNode * diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c index 343a0d3676..0afd7a3f78 100644 --- a/e-util/e-html-editor-view.c +++ b/e-util/e-html-editor-view.c @@ -1588,6 +1588,21 @@ html_editor_view_set_links_active (EHTMLEditorView *view, } } +static void +clipboard_text_received_for_paste_as_text (GtkClipboard *clipboard, + const gchar *text, + EHTMLEditorView *view) +{ + EHTMLEditorSelection *selection; + + if (!text || !*text) + return; + + selection = e_html_editor_view_get_selection (view); + + e_html_editor_selection_insert_as_text (selection, text); +} + static void clipboard_text_received (GtkClipboard *clipboard, const gchar *text, @@ -2272,6 +2287,21 @@ html_editor_view_key_release_event (GtkWidget *widget, key_release_event (widget, event); } +static void +html_editor_view_paste_as_text (EHTMLEditorView *view) +{ + GtkClipboard *clipboard; + + clipboard = gtk_clipboard_get_for_display ( + gdk_display_get_default (), + GDK_SELECTION_CLIPBOARD); + + gtk_clipboard_request_text ( + clipboard, + (GtkClipboardTextReceivedFunc) clipboard_text_received_for_paste_as_text, + view); +} + static void html_editor_view_paste_clipboard_quoted (EHTMLEditorView *view) { @@ -6042,6 +6072,20 @@ e_html_editor_view_set_text_plain (EHTMLEditorView *view, WEBKIT_WEB_VIEW (view), text, "text/plain", NULL, "file://"); } +/** + * e_html_editor_view_paste_as_text: + * @view: an #EHTMLEditorView + * + * Pastes current content of clipboard into the editor without formatting + */ +void +e_html_editor_view_paste_as_text (EHTMLEditorView *view) +{ + g_return_if_fail (E_IS_HTML_EDITOR_VIEW (view)); + + html_editor_view_paste_as_text (view); +} + /** * e_html_editor_view_paste_clipboard_quoted: * @view: an #EHTMLEditorView diff --git a/e-util/e-html-editor-view.h b/e-util/e-html-editor-view.h index ea8315884b..2f27fb8934 100644 --- a/e-util/e-html-editor-view.h +++ b/e-util/e-html-editor-view.h @@ -130,6 +130,8 @@ void e_html_editor_view_set_text_html void e_html_editor_view_set_text_plain (EHTMLEditorView *view, const gchar *text); +void e_html_editor_view_paste_as_text + (EHTMLEditorView *view); void e_html_editor_view_paste_clipboard_quoted (EHTMLEditorView *view); void e_html_editor_view_embed_styles (EHTMLEditorView *view); -- cgit v1.2.3