--- xfrun.c 2005-05-15 23:16:25.000000000 +0530 +++ xfrun-new-tabload.c 2005-05-15 23:18:56.000000000 +0530 @@ -3,7 +3,8 @@ * Copyright (C) 2002 Jasper Huijsmans (huysmans@users.sourceforge.net) * Copyright (C) 2003 Eduard Roccatello (master@spine-group.org) * Copyright (C) 2003,2004 Edscott Wilson Garcia - * + * Copyright (C) 2005, Shuveb Hussain (shuveb@gmail.com) + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -27,6 +28,7 @@ #include #include +#include #include #include #include @@ -68,6 +70,7 @@ gboolean use_xfc_combo=FALSE; gboolean open_with=FALSE; char *argument; +GList *executables = NULL; #if HAVE_LIBDBH #include "xfcombo.i" @@ -82,6 +85,48 @@ gpointer user_data); +void fill_executables_from (const char *dirname) +{ + struct dirent *dent; + DIR *dir; + + dir = opendir(dirname); + + if(dir == NULL) + return; + + while( (dent = readdir(dir)) != NULL) { + char *file = g_strconcat(dirname, "/", dent->d_name, NULL); + + if(access(file, X_OK) == 0) + executables = g_list_prepend(executables, + g_strdup (dent->d_name)); + } + + closedir (dir); +} + +void fill_executables (void) +{ + int i; + const char *path; + char **pathv; + + executables = NULL; + + path = g_getenv("PATH"); + + if(path == NULL || path[0] == '\0') + return; + + pathv = g_strsplit(path, ":", 0); + + for(i = 0; pathv[i] != NULL; i++) + fill_executables_from(pathv[i]); + + g_strfreev(pathv); +} + gboolean run_completion (GtkWidget *widget, GdkEventKey *event, @@ -97,6 +142,12 @@ g_signal_handlers_block_by_func (GTK_OBJECT (widget), run_completion, NULL); + if(executables == NULL){ /* Fill up only when tab is hit for the first time */ + fill_executables(); + /* Add executable names found in $PATH to the completion list */ + g_completion_add_items(complete, executables); + } + text = gtk_entry_get_text(GTK_ENTRY(widget)); len = g_utf8_strlen(text, -1); if (len!=0) { @@ -145,6 +196,7 @@ g_signal_stop_emission_by_name (GTK_OBJECT (widget), "key-press-event"); return TRUE; } + void set_history_checkbox(GtkList *list, GtkWidget *child) { gint ipos = gtk_list_child_position(list, child); @@ -364,6 +416,16 @@ g_free(hitem); } +void g_list_deep_free(GList *list) +{ + GList *li; + for(li = list; li != NULL; li = li->next) { + g_free(li->data); + li->data = NULL; + } + g_list_free(list); +} + gboolean runit(GtkEntry * entry, gpointer user_data) { @@ -521,13 +583,13 @@ g_signal_connect_after(GTK_WIDGET(combo_entry), "key-press-event", G_CALLBACK(tabFocusStop), NULL); } - + gtk_editable_select_region(GTK_EDITABLE(combo_entry), 0, -1); gtk_widget_grab_focus(combo_entry); gtk_widget_show(checkbox); gtk_widget_show(combo); - + while (1) { int response = GTK_RESPONSE_NONE; @@ -552,6 +614,8 @@ g_list_free(history); } + g_list_deep_free(executables); + #if HAVE_LIBDBH if (use_xfc_combo) {