--- panel-run-dialog.c.~1.26.~	Thu May 13 06:19:28 2004
+++ panel-run-dialog.c	Fri May 14 14:37:27 2004
@@ -75,7 +75,7 @@
 	
 	GtkListStore     *program_list_store;
 
-	GList            *executables;
+	GList            *executables, *potential_executables;
 	GCompletion      *completion;
 	
 	GSList           *add_icon_paths;
@@ -138,6 +138,11 @@
 	g_list_free (dialog->executables);
 	dialog->executables = NULL;
 
+	for (l = dialog->potential_executables; l; l = l->next)
+		g_free (l->data);
+	g_list_free (dialog->potential_executables);
+	dialog->potential_executables = NULL;
+
 	if (dialog->completion)
 		g_completion_free (dialog->completion);
 	dialog->completion = NULL;
@@ -1072,13 +1077,48 @@
 }
 
 static void
+panel_run_dialog_resolve_prefix (PanelRunDialog *dialog,
+				 const char *prefix)
+{
+	GList *l, *next = NULL, *new_stuff = NULL;
+	size_t prefixlen = strlen (prefix);
+
+	for (l = dialog->potential_executables; l; l = next) {
+		char *filename = l->data;
+		char *basename = g_path_get_basename (filename);
+
+		next = l->next;
+		if (strncmp (basename, prefix, prefixlen) == 0) {
+			struct stat file_stat;
+
+			if (access (filename, X_OK) == 0 &&
+			    stat (filename, &file_stat) == 0 &&
+			    S_ISREG (file_stat.st_mode)) {
+				new_stuff = g_list_prepend (new_stuff, basename);
+				basename = NULL;
+			}
+
+			g_free (filename);
+			dialog->potential_executables =
+				g_list_delete_link (dialog->potential_executables, l);
+		}
+		g_free (basename);
+	}
+
+	if (new_stuff) {
+		g_completion_add_items (dialog->completion, new_stuff);
+		dialog->executables = g_list_concat (dialog->executables, new_stuff);
+	}
+}
+
+
+static void
 panel_run_dialog_fill_executables_from (PanelRunDialog *dialog,
 					const char     *dirname)
 {
 	struct dirent *dent;
 	DIR           *dir;
 	char          *file;
-	struct stat    file_stat;
 
 	dir = opendir (dirname);
 
@@ -1086,14 +1126,15 @@
 		return;
 
 	while ((dent = readdir (dir))) {
+		const char *basename = dent->d_name;
+		if (!strcmp (basename, ".") || !strcmp (basename, ".."))
+			continue;
+
 		file = g_build_filename (dirname, dent->d_name, NULL);
 
-		if (!access (file, X_OK) &&
-		    !stat (file, &file_stat) && !S_ISDIR (file_stat.st_mode))
-			dialog->executables = g_list_prepend (dialog->executables,
-							      g_strdup (dent->d_name));
-		
-		g_free (file);
+		dialog->potential_executables =
+			g_list_prepend (dialog->potential_executables,
+					file);
 	}
 
 	closedir (dir);
@@ -1183,6 +1224,7 @@
 		pos = strlen (prefix);
 		nprefix = NULL;
 
+		panel_run_dialog_resolve_prefix (dialog, prefix);
 		g_completion_complete (dialog->completion, prefix, &nprefix);
 
 		if (nprefix) {
