* dir.c (do_load_dir): Add new argument "path" to avoid the need

to request the current directory.
(do_reload_dir): Likewise.  Adjust all callers.
This commit is contained in:
Pavel Roskin 2003-06-06 00:52:35 +00:00
parent ab84c14503
commit 61ac4d5ca1
5 changed files with 56 additions and 50 deletions

View File

@ -1,5 +1,9 @@
2003-06-05 Pavel Roskin <proski@gnu.org> 2003-06-05 Pavel Roskin <proski@gnu.org>
* dir.c (do_load_dir): Add new argument "path" to avoid the need
to request the current directory.
(do_reload_dir): Likewise. Adjust all callers.
* screen.c (panel_destroy): Rewind history to the beginning * screen.c (panel_destroy): Rewind history to the beginning
before freeing it. before freeing it.
* widget.c (input_destroy): Likewise. * widget.c (input_destroy): Likewise.

View File

@ -462,8 +462,8 @@ handle_path (dir_list *list, char *path,
} }
int int
do_load_dir (dir_list *list, sortfn *sort, int reverse, int case_sensitive, do_load_dir (char *path, dir_list *list, sortfn *sort, int reverse,
char *filter) int case_sensitive, char *filter)
{ {
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
@ -504,7 +504,7 @@ do_load_dir (dir_list *list, sortfn *sort, int reverse, int case_sensitive,
if (next_free) { if (next_free) {
/* Add ".." except the root directory */ /* Add ".." except the root directory */
if (strcmp (vfs_canon ("."), "/") != 0) if (strcmp (path, "/") != 0)
add_dotdot_to_list (list, next_free++); add_dotdot_to_list (list, next_free++);
do_sort (list, sort, next_free - 1, reverse, case_sensitive); do_sort (list, sort, next_free - 1, reverse, case_sensitive);
} else { } else {
@ -567,8 +567,8 @@ alloc_dir_copy (int size)
/* If filter is null, then it is a match */ /* If filter is null, then it is a match */
int int
do_reload_dir (dir_list * list, sortfn * sort, int count, int rev, do_reload_dir (char *path, dir_list *list, sortfn *sort, int count,
int case_sensitive, char *filter) int rev, int case_sensitive, char *filter)
{ {
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
@ -656,7 +656,7 @@ do_reload_dir (dir_list * list, sortfn * sort, int count, int rev,
g_hash_table_destroy (marked_files); g_hash_table_destroy (marked_files);
if (next_free) { if (next_free) {
/* Add ".." except the root directory */ /* Add ".." except the root directory */
if (strcmp (vfs_canon ("."), "/") != 0) if (strcmp (path, "/") != 0)
add_dotdot_to_list (list, next_free++); add_dotdot_to_list (list, next_free++);
do_sort (list, sort, next_free - 1, rev, case_sensitive); do_sort (list, sort, next_free - 1, rev, case_sensitive);
} else } else

View File

@ -29,15 +29,15 @@ typedef struct {
typedef int sortfn (const void *, const void *); typedef int sortfn (const void *, const void *);
int do_load_dir (dir_list *list, sortfn *sort, int do_load_dir (char *path, dir_list * list, sortfn * sort, int reverse,
int reverse, int case_sensitive, char *filter); int case_sensitive, char *filter);
void do_sort (dir_list *list, sortfn *sort, int top, void do_sort (dir_list * list, sortfn * sort, int top, int reverse,
int reverse, int case_sensitive); int case_sensitive);
dir_list *do_collect_stat (dir_list *dir, int top); dir_list *do_collect_stat (dir_list * dir, int top);
int do_reload_dir (dir_list *list, sortfn *sort, int count, int do_reload_dir (char *path, dir_list * list, sortfn * sort, int count,
int reverse, int case_sensitive, char *filter); int reverse, int case_sensitive, char *filter);
void clean_dir (dir_list *list, int count); void clean_dir (dir_list * list, int count);
int set_zero_dir (dir_list *list); int set_zero_dir (dir_list * list);
#ifdef DIR_H_INCLUDE_HANDLE_DIRENT #ifdef DIR_H_INCLUDE_HANDLE_DIRENT
int handle_dirent (dir_list *list, char *filter, struct dirent *dp, int handle_dirent (dir_list *list, char *filter, struct dirent *dp,

View File

@ -772,8 +772,8 @@ _do_panel_cd (WPanel *panel, char *new_dir, enum cd_enum cd_type)
/* Reload current panel */ /* Reload current panel */
panel_clean_dir (panel); panel_clean_dir (panel);
panel->count = panel->count =
do_load_dir (&panel->dir, panel->sort_type, panel->reverse, do_load_dir (panel->cwd, &panel->dir, panel->sort_type,
panel->case_sensitive, panel->filter); panel->reverse, panel->case_sensitive, panel->filter);
try_to_select (panel, get_parent_dir_name (panel->cwd, olddir)); try_to_select (panel, get_parent_dir_name (panel->cwd, olddir));
load_hint (0); load_hint (0);
panel_update_contents (panel); panel_update_contents (panel);

View File

@ -942,41 +942,41 @@ panel_new (const char *panel_name)
/* We do not want the cursor */ /* We do not want the cursor */
widget_want_cursor (panel->widget, 0); widget_want_cursor (panel->widget, 0);
mc_get_current_wd (panel->cwd, sizeof (panel->cwd)-2); mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
strcpy (panel->lwd, "."); strcpy (panel->lwd, ".");
panel->hist_name = g_strconcat ("Dir Hist ", panel_name, NULL); panel->hist_name = g_strconcat ("Dir Hist ", panel_name, NULL);
panel->dir_history = history_get (panel->hist_name); panel->dir_history = history_get (panel->hist_name);
directory_history_add (panel, panel->cwd); directory_history_add (panel, panel->cwd);
panel->dir.list = g_new (file_entry, MIN_FILES); panel->dir.list = g_new (file_entry, MIN_FILES);
panel->dir.size = MIN_FILES; panel->dir.size = MIN_FILES;
panel->active = 0; panel->active = 0;
panel->filter = 0; panel->filter = 0;
panel->split = 0; panel->split = 0;
panel->top_file = 0; panel->top_file = 0;
panel->selected = 0; panel->selected = 0;
panel->marked = 0; panel->marked = 0;
panel->total = 0; panel->total = 0;
panel->reverse = 0; panel->reverse = 0;
panel->dirty = 1; panel->dirty = 1;
panel->searching = 0; panel->searching = 0;
panel->dirs_marked = 0; panel->dirs_marked = 0;
panel->is_panelized = 0; panel->is_panelized = 0;
panel->format = 0; panel->format = 0;
panel->status_format = 0; panel->status_format = 0;
panel->format_modified = 1; panel->format_modified = 1;
panel->panel_name = g_strdup (panel_name); panel->panel_name = g_strdup (panel_name);
panel->user_format = g_strdup (DEFAULT_USER_FORMAT); panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
for(i = 0; i < LIST_TYPES; i++) for (i = 0; i < LIST_TYPES; i++)
panel->user_status_format [i] = g_strdup (DEFAULT_USER_FORMAT); panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
panel->search_buffer [0] = 0; panel->search_buffer[0] = 0;
panel->frame_size = frame_half; panel->frame_size = frame_half;
section = g_strconcat ("Temporal:", panel->panel_name, NULL); section = g_strconcat ("Temporal:", panel->panel_name, NULL);
if (!profile_has_section (section, profile_name)){ if (!profile_has_section (section, profile_name)) {
g_free (section); g_free (section);
section = g_strdup (panel->panel_name); section = g_strdup (panel->panel_name);
} }
@ -985,13 +985,14 @@ panel_new (const char *panel_name)
/* Load format strings */ /* Load format strings */
err = set_panel_formats (panel); err = set_panel_formats (panel);
if (err){ if (err) {
set_panel_formats (panel); set_panel_formats (panel);
} }
/* Load the default format */ /* Load the default format */
panel->count = do_load_dir (&panel->dir, panel->sort_type, panel->count =
panel->reverse, panel->case_sensitive, panel->filter); do_load_dir (panel->cwd, &panel->dir, panel->sort_type,
panel->reverse, panel->case_sensitive, panel->filter);
return panel; return panel;
} }
@ -1000,16 +1001,15 @@ panel_reload (WPanel *panel)
{ {
struct stat current_stat; struct stat current_stat;
if (fast_reload if (fast_reload && !stat (panel->cwd, &current_stat)
&& !stat (panel->cwd, &current_stat)
&& current_stat.st_ctime == panel->dir_stat.st_ctime && current_stat.st_ctime == panel->dir_stat.st_ctime
&& current_stat.st_mtime == panel->dir_stat.st_mtime) && current_stat.st_mtime == panel->dir_stat.st_mtime)
return; return;
while (mc_chdir (panel->cwd) == -1){ while (mc_chdir (panel->cwd) == -1) {
char *last_slash; char *last_slash;
if (panel->cwd [0] == PATH_SEP && panel->cwd [1] == 0){ if (panel->cwd[0] == PATH_SEP && panel->cwd[1] == 0) {
panel_clean_dir (panel); panel_clean_dir (panel);
panel->count = set_zero_dir (&panel->dir); panel->count = set_zero_dir (&panel->dir);
return; return;
@ -1019,16 +1019,18 @@ panel_reload (WPanel *panel)
strcpy (panel->cwd, PATH_SEP_STR); strcpy (panel->cwd, PATH_SEP_STR);
else else
*last_slash = 0; *last_slash = 0;
memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat)); memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
show_dir (panel); show_dir (panel);
} }
panel->count = do_reload_dir (&panel->dir, panel->sort_type, panel->count, panel->count =
panel->reverse, panel->case_sensitive, panel->filter); do_reload_dir (panel->cwd, &panel->dir, panel->sort_type,
panel->count, panel->reverse, panel->case_sensitive,
panel->filter);
panel->dirty = 1; panel->dirty = 1;
if (panel->selected >= panel->count) if (panel->selected >= panel->count)
do_select (panel, panel->count-1); do_select (panel, panel->count - 1);
recalculate_panel_summary (panel); recalculate_panel_summary (panel);
} }