diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-06-27 22:05:02 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-06-27 22:05:02 +0800 |
commit | dfa4c7069189ead061488b3057fd56f86f6d89a2 (patch) | |
tree | 43b4dc91486eeebdee2ab3729ecec67a315a62d2 /libempathy-gtk | |
parent | a4f0fc24f06f82f4792836e8e37c5d9d97e92f07 (diff) | |
download | gsoc2013-empathy-dfa4c7069189ead061488b3057fd56f86f6d89a2.tar gsoc2013-empathy-dfa4c7069189ead061488b3057fd56f86f6d89a2.tar.gz gsoc2013-empathy-dfa4c7069189ead061488b3057fd56f86f6d89a2.tar.bz2 gsoc2013-empathy-dfa4c7069189ead061488b3057fd56f86f6d89a2.tar.lz gsoc2013-empathy-dfa4c7069189ead061488b3057fd56f86f6d89a2.tar.xz gsoc2013-empathy-dfa4c7069189ead061488b3057fd56f86f6d89a2.tar.zst gsoc2013-empathy-dfa4c7069189ead061488b3057fd56f86f6d89a2.zip |
factor out empathy_chat_copy()
Much easier to understand its logic that way.
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 95 |
1 files changed, 58 insertions, 37 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index e9ec8467b..fc2100ba7 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -4216,51 +4216,72 @@ empathy_chat_cut (EmpathyChat *chat) } } -void -empathy_chat_copy (EmpathyChat *chat) +static gboolean +copy_from_chat_view (EmpathyChat *chat) +{ + if (!empathy_chat_view_get_has_selection (chat->view)) + return FALSE; + + empathy_chat_view_copy_clipboard (chat->view); + return TRUE; +} + +static gboolean +copy_from_input (EmpathyChat *chat) { GtkTextBuffer *buffer; + GtkClipboard *clipboard; + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view)); + if (!gtk_text_buffer_get_has_selection (buffer)) + return FALSE; + + clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_text_buffer_copy_clipboard (buffer, clipboard); + return TRUE; +} + +static gboolean +copy_from_topic (EmpathyChat *chat) +{ + EmpathyChatPriv *priv = GET_PRIV (chat); + gint start_offset; + gint end_offset; + gchar *start; + gchar *end; + gchar *selection; + const gchar *topic; + GtkClipboard *clipboard; + + if (!gtk_label_get_selection_bounds (GTK_LABEL (priv->label_topic), + &start_offset, + &end_offset)) + return FALSE; + + topic = gtk_label_get_text (GTK_LABEL (priv->label_topic)); + start = g_utf8_offset_to_pointer (topic, start_offset); + end = g_utf8_offset_to_pointer (topic, end_offset); + selection = g_strndup (start, end - start); + + clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, selection, -1); + g_free (selection); + return TRUE; +} + +void +empathy_chat_copy (EmpathyChat *chat) +{ g_return_if_fail (EMPATHY_IS_CHAT (chat)); - if (empathy_chat_view_get_has_selection (chat->view)) { - empathy_chat_view_copy_clipboard (chat->view); + if (copy_from_chat_view (chat)) return; - } - buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view)); - if (gtk_text_buffer_get_has_selection (buffer)) { - GtkClipboard *clipboard; - - clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + if (copy_from_input (chat)) + return; - gtk_text_buffer_copy_clipboard (buffer, clipboard); - } - else { - gint start_offset; - gint end_offset; - EmpathyChatPriv *priv = GET_PRIV (chat); - - if (gtk_label_get_selection_bounds (GTK_LABEL (priv->label_topic), - &start_offset, - &end_offset)) { - gchar *start; - gchar *end; - gchar *selection; - const gchar *topic; - GtkClipboard *clipboard; - - topic = gtk_label_get_text (GTK_LABEL (priv->label_topic)); - start = g_utf8_offset_to_pointer (topic, start_offset); - end = g_utf8_offset_to_pointer (topic, end_offset); - selection = g_strndup (start, end - start); - - clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); - gtk_clipboard_set_text (clipboard, selection, -1); - - g_free (selection); - } - } + copy_from_topic (chat); } void |