* src/modest-text-utils.[ch]:
authorJose Dapena Paz <jdapena@igalia.com>
Mon, 4 Feb 2008 09:41:25 +0000 (09:41 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Mon, 4 Feb 2008 09:41:25 +0000 (09:41 +0000)
        * 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
src/modest-text-utils.h
src/modest-ui-actions.c
src/modest-ui-dimming-rules.c

index afaedef..561ca9f 100644 (file)
@@ -1631,3 +1631,23 @@ modest_text_utils_is_forbidden_char (const gchar character,
 
        return FALSE; /* it's valid! */
 }
 
        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 ("");
+       }
+}
index 7944dbe..3b27aa9 100644 (file)
@@ -37,6 +37,7 @@
 #include <glib.h>
 #include <gdk/gdkcolor.h>
 #include <gtk/gtktextbuffer.h>
 #include <glib.h>
 #include <gdk/gdkcolor.h>
 #include <gtk/gtktextbuffer.h>
+#include <gtk/gtklabel.h>
 
 #define _FM(str) dgettext("hildon-fm",str)
 #define _CS(str) dgettext("hildon-common-strings",str)
 
 #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;
 
        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:
 
 /**
  * modest_text_utils_is_forbidden_char:
index f6f7892..a175fb0 100644 (file)
@@ -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)) {
        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)) {
                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)
 {
                   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);
        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
 }
 
 static void
index 56c3baa..50ef80b 100644 (file)
@@ -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)) {
                                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;
                } else {
                        gboolean do_check = TRUE;
                        GtkClipboard *clipboard;