[gnome-flashback/wip/muktupavels/lp1875317: 6/6] desktop: fix RENAMED event handling



commit fae736fc328ea5d26e11d06df2946017ac541499
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Apr 29 22:26:30 2020 +0300

    desktop: fix RENAMED event handling

 gnome-flashback/libdesktop/gf-icon-view.c | 44 ++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 13 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index 57bdb1e..e117f6b 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -776,6 +776,19 @@ remove_icon_from_view (GfIconView *self,
     self->extend_from_icon = NULL;
 }
 
+static void
+remove_icon (GfIconView *self,
+             GfIconInfo *info)
+{
+  remove_icon_from_view (self, info);
+
+  self->icons = g_list_remove (self->icons, info);
+  gf_icon_info_free (info);
+
+  if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+    remove_and_readd_icons (self);
+}
+
 static void
 file_deleted (GfIconView *self,
               GFile      *deleted_file)
@@ -787,13 +800,7 @@ file_deleted (GfIconView *self,
   if (info == NULL)
     return;
 
-  remove_icon_from_view (self, info);
-
-  self->icons = g_list_remove (self->icons, info);
-  gf_icon_info_free (info);
-
-  if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
-    remove_and_readd_icons (self);
+  remove_icon (self, info);
 }
 
 static void
@@ -820,14 +827,25 @@ file_renamed (GfIconView *self,
               GFile      *old_file,
               GFile      *new_file)
 {
-  GfIconInfo *info;
-
-  info = find_icon_info_by_file (self, old_file);
+  GfIconInfo *old_info;
+  GfIconInfo *new_info;
 
-  if (info == NULL)
-    return;
+  old_info = find_icon_info_by_file (self, old_file);
+  new_info = find_icon_info_by_file (self, new_file);
 
-  gf_icon_set_file (GF_ICON (info->icon), new_file);
+  if (old_info != NULL && new_info != NULL)
+    {
+      gf_icon_set_file (GF_ICON (new_info->icon), new_file);
+      remove_icon (self, old_info);
+    }
+  else if (old_info != NULL)
+    {
+      gf_icon_set_file (GF_ICON (old_info->icon), new_file);
+    }
+  else if (new_info != NULL)
+    {
+      gf_icon_set_file (GF_ICON (new_info->icon), new_file);
+    }
 }
 
 static void


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