From 6deea3c6886ee5333f0c60ce7ae85bf556f63ec7 Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Wed, 25 Mar 2015 17:34:07 +0100 Subject: Rework thunar_file_monitor to properly register moved files --- thunar/thunar-file.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 41fe230..4bd3b2b 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -762,32 +762,54 @@ thunar_file_reload_parent (ThunarFile *file) static void thunar_file_monitor (GFileMonitor *monitor, - GFile *path, + GFile *event_path, GFile *other_path, GFileMonitorEvent event_type, gpointer user_data) { ThunarFile *file = THUNAR_FILE (user_data); + ThunarFile *other_file; _thunar_return_if_fail (G_IS_FILE_MONITOR (monitor)); + _thunar_return_if_fail (G_IS_FILE (event_path)); _thunar_return_if_fail (THUNAR_IS_FILE (file)); - if (G_UNLIKELY (!G_IS_FILE (path) - || !g_file_equal (path, file->gfile))) - return; - - if (event_type == G_FILE_MONITOR_EVENT_MOVED) + if (g_file_equal (event_path, file->gfile)) { - if (G_IS_FILE (other_path)) - thunar_file_monitor_moved (file, other_path); - return; + /* the event occurred for the monitored ThunarFile */ + if (event_type == G_FILE_MONITOR_EVENT_MOVED) + { + thunar_file_monitor_moved (file, other_path); + return; + } + + if (G_LIKELY (event_path)) + thunar_file_monitor_update (event_path, event_type); } + else + { + /* The event did not occur for the monitored ThunarFile, but for + a file that is contained in ThunarFile which is actually a + directory. */ + if (event_type == G_FILE_MONITOR_EVENT_MOVED) + { + /* reload the target file if cached */ + other_file = g_object_ref (thunar_file_cache_lookup (other_path)); + if (other_file) + thunar_file_reload (other_file); + else + other_file = thunar_file_get (other_path, NULL); + + if (!other_file) + return; - if (G_LIKELY (G_IS_FILE (path))) - thunar_file_monitor_update (path, event_type); + /* reload the containing target folder */ + thunar_file_reload_parent (other_file); - if (G_UNLIKELY (G_IS_FILE (other_path))) - thunar_file_monitor_update (other_path, event_type); + g_object_unref (other_file); + } + return; + } } -- 2.3.3