--- file-manager/fm-directory-view.c.ORG	Thu Oct 16 01:18:38 2003
+++ file-manager/fm-directory-view.c	Fri Oct 17 08:12:41 2003
@@ -191,6 +191,13 @@ static gboolean use_new_window_auto_valu
 static char *scripts_directory_uri;
 static int scripts_directory_uri_length;
 
+typedef struct FMDirectoryViewDir
+{
+        FMDirectoryView *view;
+        NautilusDirectory *current;
+        guint              timout_id;
+} FMDirectoryViewDir;
+
 struct FMDirectoryViewDetails
 {
 	NautilusView *nautilus_view;
@@ -201,6 +208,7 @@ struct FMDirectoryViewDetails
 	BonoboUIComponent *ui;
 
 	GList *scripts_directory_list;
+	GList *update_dir_timer_list;
 
 	guint display_selection_idle_id;
 	guint update_menus_timeout_id;
@@ -328,6 +336,7 @@ static void     zoomable_zoom_to_fit_cal
 static void     schedule_update_menus                          (FMDirectoryView      *view);
 static void     schedule_update_menus_callback                 (gpointer              callback_data);
 static void     remove_update_menus_timeout_callback           (FMDirectoryView      *view);
+static void     remove_update_dirs_timeout_callback           (FMDirectoryView      *view);
 static void     schedule_idle_display_of_pending_files         (FMDirectoryView      *view);
 static void     unschedule_idle_display_of_pending_files       (FMDirectoryView      *view);
 static void     unschedule_display_of_pending_files            (FMDirectoryView      *view);
@@ -1438,6 +1447,7 @@ fm_directory_view_finalize (GObject *obj
 	}
 
 	remove_update_menus_timeout_callback (view);
+        remove_update_dirs_timeout_callback (view);
 
 	fm_directory_view_ignore_hidden_file_preferences (view);
 
@@ -2268,6 +2278,22 @@ display_selection_info_idle_callback (gp
 }
 
 static void
+remove_update_dirs_timeout_callback (FMDirectoryView *view)
+{
+        GList *list = view->details->update_dir_timer_list;
+        FMDirectoryViewDir *viewDir;
+        GList *node;
+
+        for (node = list; node != NULL; node = node->next) {
+            viewDir = (FMDirectoryViewDir *)node->data;
+            if (viewDir->timout_id != 0)
+              g_source_remove (viewDir->timout_id);
+            g_free(viewDir);
+        }
+        g_list_free(view->details->update_dir_timer_list);
+}
+
+static void
 remove_update_menus_timeout_callback (FMDirectoryView *view) 
 {
 	if (view->details->update_menus_timeout_id != 0) {
@@ -2284,6 +2310,8 @@ update_menus_if_pending (FMDirectoryView
 	}
 
 	remove_update_menus_timeout_callback (view);
+        if (view->details->scripts_invalid)
+          remove_update_dirs_timeout_callback (view);
 	fm_directory_view_update_menus (view);
 }
 
@@ -4149,7 +4177,7 @@ directory_belongs_in_scripts_menu (const
 }
 
 static gboolean
-update_directory_in_scripts_menu (FMDirectoryView *view, NautilusDirectory *directory)
+update_directory_in_scripts_menu2 (FMDirectoryView *view, NautilusDirectory *directory)
 {
 	char *menu_path, *popup_path, *popup_bg_path;
 	GList *file_list, *filtered, *node;
@@ -4205,10 +4233,49 @@ update_directory_in_scripts_menu (FMDire
 	g_free (popup_path);
 	g_free (popup_bg_path);
 	g_free (menu_path);
+        nautilus_directory_unref (directory);
 
 	return any_scripts;
 }
 
+static gboolean
+update_directory_in_scripts_menu_cbk (gpointer data)
+{
+        FMDirectoryViewDir *viewDir;
+        FMDirectoryView *view;
+
+        viewDir = (FMDirectoryViewDir *)data;
+        view = viewDir->view;
+                                                                                
+        if (view && view->details) 
+        {
+          g_object_ref (view);
+          update_directory_in_scripts_menu2(view, viewDir->current);
+          view->details->update_dir_timer_list =
+                         g_list_remove(view->details->update_dir_timer_list,
+                                       viewDir);
+          g_object_unref (view);
+        }
+        else
+          nautilus_directory_unref(viewDir->current);
+
+        g_free(viewDir);
+        return FALSE;
+}
+
+static gboolean
+update_directory_in_scripts_menu (FMDirectoryView *view, NautilusDirectory *directory, int dlay)
+{
+        FMDirectoryViewDir *viewDir;
+
+        viewDir = g_new(FMDirectoryViewDir, 1);
+        viewDir->view = view;
+        nautilus_directory_ref(directory);
+        viewDir->current = directory;
+        viewDir->timout_id = g_timeout_add (dlay, update_directory_in_scripts_menu_cbk, viewDir);
+        view->details->update_dir_timer_list = g_list_append(view->details->update_dir_timer_list, viewDir);
+}
+
 static void
 update_scripts_menu (FMDirectoryView *view)
 {
@@ -4216,6 +4283,7 @@ update_scripts_menu (FMDirectoryView *vi
 	GList *sorted_copy, *node;
 	NautilusDirectory *directory;
 	char *uri;
+        int  dlay=50;
 
 	/* There is a race condition here.  If we don't mark the scripts menu as
 	   valid before we begin our task then we can lose script menu updates that
@@ -4239,8 +4307,9 @@ update_scripts_menu (FMDirectoryView *vi
 		uri = nautilus_directory_get_uri (directory);
 		if (!directory_belongs_in_scripts_menu (uri)) {
 			remove_directory_from_scripts_directory_list (view, directory);
-		} else if (update_directory_in_scripts_menu (view, directory)) {
+		} else if (update_directory_in_scripts_menu (view, directory, dlay)) {
 			any_scripts = TRUE;
+ 			dlay += 1000;
 		}
 		g_free (uri);
 	}
@@ -4983,7 +5052,7 @@ schedule_update_menus (FMDirectoryView *
 	if (view->details->menus_merged
 	    && view->details->update_menus_timeout_id == 0) {
 		view->details->update_menus_timeout_id
-			= g_timeout_add (300, update_menus_timeout_callback, view);
+			= g_timeout_add (10000, update_menus_timeout_callback, view);
 	}
 }
 
