[evolution/wip/webkit2] Simplify how the clipboard paste is done
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] Simplify how the clipboard paste is done
- Date: Thu, 9 Jun 2016 13:22:37 +0000 (UTC)
commit 5b13866713054cb602897adb620f849dbd80ee60
Author: Tomas Popela <tpopela redhat com>
Date: Thu Jun 9 15:22:01 2016 +0200
Simplify how the clipboard paste is done
composer/e-composer-private.c | 1 -
composer/e-composer-private.h | 1 -
composer/e-msg-composer.c | 52 ++++-----
e-util/e-content-editor.c | 20 +---
e-util/e-content-editor.h | 11 +--
.../e-webkit-content-editor.c | 121 ++++++--------------
6 files changed, 61 insertions(+), 145 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 93d4ca3..c0b0db9 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -139,7 +139,6 @@ e_composer_private_constructed (EMsgComposer *composer)
priv->dnd_history_saved = FALSE;
priv->check_if_signature_is_changed = FALSE;
priv->ignore_next_signature_change = FALSE;
- priv->ignore_next_paste_clipboard_signals_emission = FALSE;
priv->focused_entry = NULL;
diff --git a/composer/e-composer-private.h b/composer/e-composer-private.h
index fbf4a91..b2c50df 100644
--- a/composer/e-composer-private.h
+++ b/composer/e-composer-private.h
@@ -106,7 +106,6 @@ struct _EMsgComposerPrivate {
gboolean dnd_history_saved;
gboolean check_if_signature_is_changed;
gboolean ignore_next_signature_change;
- gboolean ignore_next_paste_clipboard_signals_emission;
gboolean last_signal_was_paste_primary;
gint focused_entry_selection_start;
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index defb4da..7979f7a 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1741,54 +1741,44 @@ msg_composer_paste_clipboard_targets_cb (GtkClipboard *clipboard,
return;
}
- composer->priv->ignore_next_paste_clipboard_signals_emission = TRUE;
-
- g_signal_emit_by_name (
- cnt_editor,
- composer->priv->last_signal_was_paste_primary ?
- "paste-primary-clipboard" : "paste-clipboard");
+ if (composer->priv->last_signal_was_paste_primary) {
+ e_content_editor_paste_primary (cnt_editor);
+ } else
+ e_content_editor_paste (cnt_editor);
}
-static void
+static gboolean
msg_composer_paste_primary_clipboard_cb (EContentEditor *cnt_editor,
EMsgComposer *composer)
{
- if (composer->priv->ignore_next_paste_clipboard_signals_emission)
- composer->priv->ignore_next_paste_clipboard_signals_emission = FALSE;
- else {
- GtkClipboard *clipboard;
+ GtkClipboard *clipboard;
- clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+ clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
- composer->priv->last_signal_was_paste_primary = TRUE;
+ composer->priv->last_signal_was_paste_primary = TRUE;
- gtk_clipboard_request_targets (
- clipboard, (GtkClipboardTargetsReceivedFunc)
- msg_composer_paste_clipboard_targets_cb, composer);
+ gtk_clipboard_request_targets (
+ clipboard, (GtkClipboardTargetsReceivedFunc)
+ msg_composer_paste_clipboard_targets_cb, composer);
- g_signal_stop_emission_by_name (cnt_editor, "paste-primary-clipboard");
- }
+ return TRUE;
}
-static void
+static gboolean
msg_composer_paste_clipboard_cb (EContentEditor *cnt_editor,
EMsgComposer *composer)
{
- if (composer->priv->ignore_next_paste_clipboard_signals_emission)
- composer->priv->ignore_next_paste_clipboard_signals_emission = FALSE;
- else {
- GtkClipboard *clipboard;
+ GtkClipboard *clipboard;
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
- composer->priv->last_signal_was_paste_primary = FALSE;
+ composer->priv->last_signal_was_paste_primary = FALSE;
- gtk_clipboard_request_targets (
- clipboard, (GtkClipboardTargetsReceivedFunc)
- msg_composer_paste_clipboard_targets_cb, composer);
+ gtk_clipboard_request_targets (
+ clipboard, (GtkClipboardTargetsReceivedFunc)
+ msg_composer_paste_clipboard_targets_cb, composer);
- g_signal_stop_emission_by_name (cnt_editor, "paste-clipboard");
- }
+ return TRUE;
}
#if 0
static gboolean
@@ -2469,8 +2459,6 @@ msg_composer_constructed (GObject *object)
cnt_editor, "paste-primary-clipboard",
G_CALLBACK (msg_composer_paste_primary_clipboard_cb), composer);
- e_content_editor_reconnect_paste_clipboard_signals (cnt_editor);
-
/* Drag-and-Drop Support */
#if 0 /* FIXME WK2 */
EHTMLEditorView *view;
diff --git a/e-util/e-content-editor.c b/e-util/e-content-editor.c
index b126da6..cb3157b 100644
--- a/e-util/e-content-editor.c
+++ b/e-util/e-content-editor.c
@@ -1390,22 +1390,8 @@ e_content_editor_paste (EContentEditor *editor)
iface->paste (editor);
}
-gboolean
-e_content_editor_paste_prefer_text_html (EContentEditor *editor)
-{
- EContentEditorInterface *iface;
-
- g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), FALSE);
-
- iface = E_CONTENT_EDITOR_GET_IFACE (editor);
- g_return_val_if_fail (iface != NULL, FALSE);
- g_return_val_if_fail (iface->paste_prefer_text_html != NULL, FALSE);
-
- return iface->paste_prefer_text_html (editor);
-}
-
void
-e_content_editor_reconnect_paste_clipboard_signals (EContentEditor *editor)
+e_content_editor_paste_primary (EContentEditor *editor)
{
EContentEditorInterface *iface;
@@ -1413,9 +1399,9 @@ e_content_editor_reconnect_paste_clipboard_signals (EContentEditor *editor)
iface = E_CONTENT_EDITOR_GET_IFACE (editor);
g_return_if_fail (iface != NULL);
- g_return_if_fail (iface->reconnect_paste_clipboard_signals != NULL);
+ g_return_if_fail (iface->paste_primary != NULL);
- iface->reconnect_paste_clipboard_signals (editor);
+ iface->paste_primary (editor);
}
void
diff --git a/e-util/e-content-editor.h b/e-util/e-content-editor.h
index dc08780..aa7e787 100644
--- a/e-util/e-content-editor.h
+++ b/e-util/e-content-editor.h
@@ -81,10 +81,7 @@ struct _EContentEditorInterface {
void (*paste) (EContentEditor *editor);
- gboolean (*paste_prefer_text_html) (EContentEditor *editor);
-
- void (*reconnect_paste_clipboard_signals)
- (EContentEditor *editor);
+ void (*paste_primary) (EContentEditor *editor);
void (*undo) (EContentEditor *editor);
@@ -556,11 +553,7 @@ void e_content_editor_copy (EContentEditor *editor);
void e_content_editor_paste (EContentEditor *editor);
-gboolean e_content_editor_paste_prefer_text_html
- (EContentEditor *editor);
-
-void e_content_editor_reconnect_paste_clipboard_signals
- (EContentEditor *editor);
+void e_content_editor_paste_primary (EContentEditor *editor);
void e_content_editor_undo (EContentEditor *editor);
diff --git a/modules/webkit-content-editor/e-webkit-content-editor.c
b/modules/webkit-content-editor/e-webkit-content-editor.c
index 1ef5223..87d7033 100644
--- a/modules/webkit-content-editor/e-webkit-content-editor.c
+++ b/modules/webkit-content-editor/e-webkit-content-editor.c
@@ -1252,9 +1252,7 @@ webkit_content_editor_insert_content (EContentEditor *editor,
wk_editor->priv->reload_in_progress = TRUE;
- /* FIXME TOTO JE ASI BLBE.. */
if ((flags & E_CONTENT_EDITOR_INSERT_CONVERT) &&
- (flags & E_CONTENT_EDITOR_INSERT_TEXT_HTML) &&
!(flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL)) {
// e_html_editor_view_convert_and_insert_plain_text
// e_html_editor_view_convert_and_insert_html_to_plain_text
@@ -1765,34 +1763,6 @@ webkit_content_editor_copy (EContentEditor *editor)
WEBKIT_WEB_VIEW (wk_editor), WEBKIT_EDITING_COMMAND_COPY);
}
-static void
-webkit_content_editor_paste (EContentEditor *editor)
-{
- gboolean handled;
-
- handled = e_content_editor_emit_paste_clipboard (editor);
-
- if (!handled)
- webkit_web_view_execute_editing_command (
- WEBKIT_WEB_VIEW (editor), WEBKIT_EDITING_COMMAND_PASTE);
-
- /* FIXME
- e_html_editor_view_force_spell_check (view) */
-}
-
-static gboolean
-webkit_content_editor_paste_prefer_text_html (EContentEditor *editor)
-{
- EWebKitContentEditor *wk_editor;
-
- wk_editor = E_WEBKIT_CONTENT_EDITOR (editor);
-
- if (wk_editor->priv->pasting_primary_clipboard)
- return wk_editor->priv->copy_paste_primary_in_view;
- else
- return wk_editor->priv->copy_paste_clipboard_in_view;
-}
-
static ESpellChecker *
webkit_content_editor_get_spell_checker (EContentEditor *editor)
{
@@ -5488,6 +5458,15 @@ webkit_content_editor_copy_cut_clipboard_cb (EWebKitContentEditor *wk_editor)
wk_editor->priv->copy_action_triggered = TRUE;
}
+static gboolean
+webkit_content_editor_paste_prefer_text_html (EWebKitContentEditor *wk_editor)
+{
+ if (wk_editor->priv->pasting_primary_clipboard)
+ return wk_editor->priv->copy_paste_primary_in_view;
+ else
+ return wk_editor->priv->copy_paste_clipboard_in_view;
+}
+
static void
webkit_content_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
GdkAtom *targets,
@@ -5506,7 +5485,7 @@ webkit_content_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
/* Prefer plain text over HTML when in the plain text mode, but only
* when pasting content from outside the editor view. */
if (wk_editor->priv->html_mode ||
- webkit_content_editor_paste_prefer_text_html (E_CONTENT_EDITOR (wk_editor))) {
+ webkit_content_editor_paste_prefer_text_html (wk_editor)) {
gchar *content = NULL;
if (e_targets_include_html (targets, n_targets)) {
@@ -5529,7 +5508,8 @@ webkit_content_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
webkit_content_editor_insert_content (
E_CONTENT_EDITOR (wk_editor),
content,
- E_CONTENT_EDITOR_INSERT_TEXT_PLAIN);
+ E_CONTENT_EDITOR_INSERT_TEXT_PLAIN |
+ E_CONTENT_EDITOR_INSERT_CONVERT);
g_free (content);
return;
@@ -5544,7 +5524,8 @@ webkit_content_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
webkit_content_editor_insert_content (
E_CONTENT_EDITOR (wk_editor),
content,
- E_CONTENT_EDITOR_INSERT_TEXT_PLAIN);
+ E_CONTENT_EDITOR_INSERT_TEXT_PLAIN |
+ E_CONTENT_EDITOR_INSERT_CONVERT);
g_free (content);
return;
@@ -5579,51 +5560,40 @@ webkit_content_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
}
static void
-webkit_content_editor_paste_primary_clipboard_cb (EWebKitContentEditor *wk_editor)
+webkit_content_editor_paste_primary (EContentEditor *editor)
{
- GtkClipboard *clipboard;
- clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+ GtkClipboard *clipboard;
+ EWebKitContentEditor *wk_editor;
- gtk_clipboard_request_targets (
- clipboard, (GtkClipboardTargetsReceivedFunc)
- webkit_content_editor_paste_clipboard_targets_cb, wk_editor);
+ wk_editor = E_WEBKIT_CONTENT_EDITOR (editor);
- g_signal_stop_emission_by_name (wk_editor, "paste-primary-clipboard");
-}
+ /* Remember, that we are pasting primary clipboard to return
+ * correct value in e_html_editor_view_is_pasting_content_from_itself. */
+ wk_editor->priv->pasting_primary_clipboard = TRUE;
-static void
-webkit_content_editor_paste_clipboard_cb (EWebKitContentEditor *wk_editor)
-{
- GtkClipboard *clipboard;
+ webkit_content_editor_move_caret_on_current_coordinates (GTK_WIDGET (wk_editor));
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
gtk_clipboard_request_targets (
clipboard, (GtkClipboardTargetsReceivedFunc)
webkit_content_editor_paste_clipboard_targets_cb, wk_editor);
-
- g_signal_stop_emission_by_name (wk_editor, "paste-clipboard");
}
static void
-webkit_content_editor_reconnect_paste_clipboard_signals (EContentEditor *editor)
+webkit_content_editor_paste (EContentEditor *editor)
{
+ GtkClipboard *clipboard;
EWebKitContentEditor *wk_editor;
wk_editor = E_WEBKIT_CONTENT_EDITOR (editor);
- g_signal_handlers_disconnect_by_func (
- wk_editor, webkit_content_editor_paste_clipboard_cb, NULL);
- g_signal_handlers_disconnect_by_func (
- wk_editor, webkit_content_editor_paste_primary_clipboard_cb, NULL);
+ clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
- g_signal_connect (
- wk_editor, "paste-clipboard",
- G_CALLBACK (webkit_content_editor_paste_clipboard_cb), NULL);
- g_signal_connect (
- wk_editor, "paste-primary-clipboard",
- G_CALLBACK (webkit_content_editor_paste_primary_clipboard_cb), NULL);
+ gtk_clipboard_request_targets (
+ clipboard, (GtkClipboardTargetsReceivedFunc)
+ webkit_content_editor_paste_clipboard_targets_cb, wk_editor);
}
static void
@@ -5679,24 +5649,12 @@ static gboolean
webkit_content_editor_button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
- EWebKitContentEditor *wk_editor;
- gboolean event_handled;
-
- wk_editor = E_WEBKIT_CONTENT_EDITOR (widget);
-
if (event->button == 2) {
- /* Middle click paste */
- webkit_content_editor_move_caret_on_current_coordinates (widget);
- /* Remember, that we are pasting primary clipboard to return
- * correct value in e_html_editor_view_is_pasting_content_from_itself. */
- wk_editor->priv->pasting_primary_clipboard = TRUE;
- event_handled = e_content_editor_emit_paste_primary_clipboard (E_CONTENT_EDITOR (widget));
- } else {
- event_handled = FALSE;
- }
+ if (!e_content_editor_emit_paste_primary_clipboard (E_CONTENT_EDITOR (widget)))
+ webkit_content_editor_paste_primary (E_CONTENT_EDITOR( (widget)));
- if (event_handled)
return TRUE;
+ }
/* Chain up to parent's button_press_event() method. */
return GTK_WIDGET_CLASS (e_webkit_content_editor_parent_class)->button_press_event (widget, event);
@@ -5714,7 +5672,9 @@ webkit_content_editor_key_press_event (GtkWidget *widget,
((event)->keyval == GDK_KEY_Insert)) ||
(((event)->state & GDK_CONTROL_MASK) &&
((event)->keyval == GDK_KEY_v))) {
- webkit_content_editor_paste (E_CONTENT_EDITOR (wk_editor));
+ if (!e_content_editor_emit_paste_clipboard (E_CONTENT_EDITOR (widget)))
+ webkit_content_editor_paste (E_CONTENT_EDITOR (widget));
+
return TRUE;
}
@@ -5840,14 +5800,6 @@ e_webkit_content_editor_init (EWebKitContentEditor *wk_editor)
G_CALLBACK (webkit_content_editor_copy_cut_clipboard_cb), NULL);
g_signal_connect (
- wk_editor, "paste-clipboard",
- G_CALLBACK (webkit_content_editor_paste_clipboard_cb), NULL);
-
- g_signal_connect (
- wk_editor, "paste-primary-clipboard",
- G_CALLBACK (webkit_content_editor_paste_primary_clipboard_cb), NULL);
-
- g_signal_connect (
wk_editor, "context-menu",
G_CALLBACK (webkit_content_editor_context_menu_cb), NULL);
@@ -5932,8 +5884,7 @@ e_webkit_content_editor_content_editor_init (EContentEditorInterface *iface)
iface->cut = webkit_content_editor_cut;
iface->copy = webkit_content_editor_copy;
iface->paste = webkit_content_editor_paste;
- iface->paste_prefer_text_html = webkit_content_editor_paste_prefer_text_html;
- iface->reconnect_paste_clipboard_signals = webkit_content_editor_reconnect_paste_clipboard_signals;
+ iface->paste_primary = webkit_content_editor_paste_primary;
iface->undo = webkit_content_editor_undo;
iface->redo = webkit_content_editor_redo;
iface->clear_undo_redo_history = webkit_content_editor_clear_undo_redo_history;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]