From d27a0a29347366d5421e7e796eca4655ef0d095a Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Mon, 4 Feb 2008 09:41:25 +0000 Subject: [PATCH 1/1] * src/modest-text-utils.[ch]: * Refactorized method to get the current selection of a label in text utils. This will be now used in ui actions and dimming rules. * src/modest-ui-actions.c: * (modest_ui_actions_on_copy): now copy gets the selection of a focused label, instead of the full label (fixes NB#80195). * (folder_move_to_cb): now we focus the new position of a folder after a move to operation to avoid losing focus (fixes NB#78939). * src/modest-ui-dimming-rules.c: * (..._on_add_to_contacts): now we use the text utils method to retrieve current selection of a GtkLabel. pmo-trunk-r4134 --- src/modest-text-utils.c | 20 ++++++++++++++++++++ src/modest-text-utils.h | 10 ++++++++++ src/modest-ui-actions.c | 15 ++++++++++++++- src/modest-ui-dimming-rules.c | 12 +----------- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index afaedef..561ca9f 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -1631,3 +1631,23 @@ modest_text_utils_is_forbidden_char (const gchar character, return FALSE; /* it's valid! */ } + +gchar * +modest_text_utils_label_get_selection (GtkLabel *label) +{ + gint start, end; + gchar *selection; + + if (gtk_label_get_selection_bounds (GTK_LABEL (label), &start, &end)) { + const gchar *start_offset; + const gchar *end_offset; + start_offset = gtk_label_get_text (GTK_LABEL (label)); + start_offset = g_utf8_offset_to_pointer (start_offset, start); + end_offset = gtk_label_get_text (GTK_LABEL (label)); + end_offset = g_utf8_offset_to_pointer (end_offset, end); + selection = g_strndup (start_offset, end_offset - start_offset); + return selection; + } else { + return g_strdup (""); + } +} diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 7944dbe..3b27aa9 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -37,6 +37,7 @@ #include #include #include +#include #define _FM(str) dgettext("hildon-fm",str) #define _CS(str) dgettext("hildon-common-strings",str) @@ -412,6 +413,15 @@ typedef enum { USER_NAME_FORBIDDEN_NAMES, } ModestTextUtilsForbiddenCharType; +/** + * modest_text_utils_label_get_selection: + * @label: a #GtkLabel + * + * Obtain the current selection of @label + * + * Returns: a string with current selection, or %NULL if no selection in @label + */ +gchar * modest_text_utils_label_get_selection (GtkLabel *label); /** * modest_text_utils_is_forbidden_char: diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index f6f7892..a175fb0 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -3316,7 +3316,10 @@ modest_ui_actions_on_copy (GtkAction *action, focused_widget = gtk_window_get_focus (GTK_WINDOW (window)); if (GTK_IS_LABEL (focused_widget)) { - gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1); + gchar *selection; + selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget)); + gtk_clipboard_set_text (clipboard, selection, -1); + g_free (selection); gtk_clipboard_set_can_store (clipboard, NULL, 0); gtk_clipboard_store (clipboard); } else if (GTK_IS_EDITABLE (focused_widget)) { @@ -4342,7 +4345,17 @@ folder_move_to_cb (ModestMailOperation *mail_op, TnyFolder *new_folder, gpointer user_data) { + GtkWidget *folder_view; + GObject *object; + + object = modest_mail_operation_get_source (mail_op); + folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object), + MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); + g_object_ref (folder_view); + g_object_unref (object); move_to_cb (mail_op, user_data); + modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE); + g_object_unref (folder_view); } static void diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index 56c3baa..50ef80b 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -1809,17 +1809,7 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat selection = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); } } else if (GTK_IS_LABEL (focused)) { - gint start, end; - if (gtk_label_get_selection_bounds (GTK_LABEL (focused), &start, &end)) { - const gchar *start_offset; - const gchar *end_offset; - start_offset = gtk_label_get_text (GTK_LABEL (focused)); - start_offset = g_utf8_offset_to_pointer (start_offset, start); - end_offset = gtk_label_get_text (GTK_LABEL (focused)); - end_offset = g_utf8_offset_to_pointer (end_offset, end); - selection = g_strndup (start_offset, end_offset - start_offset); - g_message (selection); - } + selection = modest_text_utils_label_get_selection (GTK_LABEL (focused)); } else { gboolean do_check = TRUE; GtkClipboard *clipboard; -- 1.7.9.5