[gnome-builder] project-tree: set default text for rename popover



commit 2a6223a40738205be14564365b1e34c4518a197d
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 10 11:12:13 2016 +0300

    project-tree: set default text for rename popover
    
    This sets the default text to the current filename, but selects the name
    without the dot suffix. This should more closely mimic nautilus.

 plugins/project-tree/gb-rename-file-popover.c |   31 +++++++++++++++++++++----
 1 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/plugins/project-tree/gb-rename-file-popover.c b/plugins/project-tree/gb-rename-file-popover.c
index 4356276..b425e9f 100644
--- a/plugins/project-tree/gb-rename-file-popover.c
+++ b/plugins/project-tree/gb-rename-file-popover.c
@@ -72,16 +72,14 @@ gb_rename_file_popover_set_file (GbRenameFilePopover *self,
     {
       if (file != NULL)
         {
-          gchar *name;
-          gchar *label;
+          g_autofree gchar *name = NULL;
+          g_autofree gchar *label = NULL;
 
           name = g_file_get_basename (file);
           label = g_strdup_printf (_("Rename %s"), name);
 
           gtk_label_set_label (self->label, label);
-
-          g_free (name);
-          g_free (label);
+          gtk_entry_set_text (self->entry, name);
         }
 
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_FILE]);
@@ -198,6 +196,23 @@ gb_rename_file_popover__entry_activate (GbRenameFilePopover *self,
 }
 
 static void
+gb_rename_file_popover__entry_focus_in_event (GbRenameFilePopover *self,
+                                              GdkEvent            *event,
+                                              GtkEntry            *entry)
+{
+  const gchar *name;
+  const gchar *tmp;
+
+  g_assert (GB_IS_RENAME_FILE_POPOVER (self));
+  g_assert (GTK_IS_ENTRY (entry));
+
+  name = gtk_entry_get_text (entry);
+
+  if (NULL != (tmp = strrchr (name, '.')))
+    gtk_editable_select_region (GTK_EDITABLE (entry), 0, tmp - name);
+}
+
+static void
 gb_rename_file_popover__button_clicked (GbRenameFilePopover *self,
                                         GtkButton           *button)
 {
@@ -352,4 +367,10 @@ gb_rename_file_popover_init (GbRenameFilePopover *self)
                            G_CALLBACK (gb_rename_file_popover__button_clicked),
                            self,
                            G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (self->entry,
+                           "focus-in-event",
+                           G_CALLBACK (gb_rename_file_popover__entry_focus_in_event),
+                           self,
+                           G_CONNECT_SWAPPED | G_CONNECT_AFTER);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]