Rename panel_sort_info_t to dir_sort_options_t

...and use it in routines of load and sort directory.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2013-08-15 10:34:19 +04:00
parent 72ad268a9c
commit e6bb69a0d9
8 changed files with 39 additions and 42 deletions

View File

@ -703,7 +703,7 @@ panel_listing_box (WPanel * panel, char **userp, char **minip, int *use_msformat
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
const panel_field_t * const panel_field_t *
sort_box (panel_sort_info_t * info, const panel_field_t * sort_field) sort_box (dir_sort_options_t * op, const panel_field_t * sort_field)
{ {
const char **sort_orders_names; const char **sort_orders_names;
gsize sort_names_num, i; gsize sort_names_num, i;
@ -725,9 +725,9 @@ sort_box (panel_sort_info_t * info, const panel_field_t * sort_field)
QUICK_START_COLUMNS, QUICK_START_COLUMNS,
QUICK_RADIO (sort_names_num, sort_orders_names, &sort_idx, NULL), QUICK_RADIO (sort_names_num, sort_orders_names, &sort_idx, NULL),
QUICK_NEXT_COLUMN, QUICK_NEXT_COLUMN,
QUICK_CHECKBOX (N_("Executable &first"), &info->exec_first, NULL), QUICK_CHECKBOX (N_("Executable &first"), &op->exec_first, NULL),
QUICK_CHECKBOX (N_("Cas&e sensitive"), &info->case_sensitive, NULL), QUICK_CHECKBOX (N_("Cas&e sensitive"), &op->case_sensitive, NULL),
QUICK_CHECKBOX (N_("&Reverse"), &info->reverse, NULL), QUICK_CHECKBOX (N_("&Reverse"), &op->reverse, NULL),
QUICK_STOP_COLUMNS, QUICK_STOP_COLUMNS,
QUICK_BUTTONS_OK_CANCEL, QUICK_BUTTONS_OK_CANCEL,
QUICK_END QUICK_END

View File

@ -21,7 +21,7 @@
void configure_box (void); void configure_box (void);
void panel_options_box (void); void panel_options_box (void);
int panel_listing_box (WPanel * p, char **user, char **mini, int *use_msformat, int num); int panel_listing_box (WPanel * p, char **user, char **mini, int *use_msformat, int num);
const panel_field_t *sort_box (panel_sort_info_t * info, const panel_field_t * sort_field); const panel_field_t *sort_box (dir_sort_options_t * op, const panel_field_t * sort_field);
void confirm_box (void); void confirm_box (void);
void display_bits_box (void); void display_bits_box (void);
void configure_vfs (void); void configure_vfs (void);

View File

@ -438,8 +438,7 @@ sort_size (file_entry * a, file_entry * b)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void void
do_sort (dir_list * list, GCompareFunc sort, int top, gboolean reverse_f, gboolean case_sensitive_f, do_sort (dir_list * list, GCompareFunc sort, int top, const dir_sort_options_t * sort_op)
gboolean exec_first_f)
{ {
int dot_dot_found = 0; int dot_dot_found = 0;
@ -451,9 +450,9 @@ do_sort (dir_list * list, GCompareFunc sort, int top, gboolean reverse_f, gboole
if (DIR_IS_DOTDOT (list->list[0].fname)) if (DIR_IS_DOTDOT (list->list[0].fname))
dot_dot_found = 1; dot_dot_found = 1;
reverse = reverse_f ? -1 : 1; reverse = sort_op->reverse ? -1 : 1;
case_sensitive = case_sensitive_f ? 1 : 0; case_sensitive = sort_op->case_sensitive ? 1 : 0;
exec_first = exec_first_f; exec_first = sort_op->exec_first;
qsort (&(list->list)[dot_dot_found], top + 1 - dot_dot_found, sizeof (file_entry), sort); qsort (&(list->list)[dot_dot_found], top + 1 - dot_dot_found, sizeof (file_entry), sort);
clean_sort_keys (list, dot_dot_found, top + 1 - dot_dot_found); clean_sort_keys (list, dot_dot_found, top + 1 - dot_dot_found);
@ -546,8 +545,8 @@ handle_path (dir_list * list, const char *path,
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
int int
do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, gboolean lc_reverse, do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
gboolean lc_case_sensitive, gboolean exec_ff, const char *fltr) const dir_sort_options_t * sort_op, const char *fltr)
{ {
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
@ -605,7 +604,7 @@ do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, gbool
} }
if (next_free != 0) if (next_free != 0)
do_sort (list, sort, next_free - 1, lc_reverse, lc_case_sensitive, exec_ff); do_sort (list, sort, next_free - 1, sort_op);
ret: ret:
mc_closedir (dirp); mc_closedir (dirp);
@ -632,7 +631,7 @@ if_link_is_exe (const vfs_path_t * full_name_vpath, const file_entry * file)
int int
do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, int count, do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, int count,
gboolean lc_reverse, gboolean lc_case_sensitive, gboolean exec_ff, const char *fltr) const dir_sort_options_t * sort_op, const char *fltr)
{ {
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
@ -746,10 +745,10 @@ do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, int
mc_closedir (dirp); mc_closedir (dirp);
tree_store_end_check (); tree_store_end_check ();
g_hash_table_destroy (marked_files); g_hash_table_destroy (marked_files);
if (next_free)
{ if (next_free != 0)
do_sort (list, sort, next_free - 1, lc_reverse, lc_case_sensitive, exec_ff); do_sort (list, sort, next_free - 1, sort_op);
}
clean_dir (&dir_copy, count); clean_dir (&dir_copy, count);
rotate_dash (FALSE); rotate_dash (FALSE);

View File

@ -26,16 +26,25 @@ typedef struct
int size; int size;
} dir_list; } dir_list;
/**
* A structure to represent sort options for directory content
*/
typedef struct dir_sort_options_struct
{
gboolean reverse; /**< sort is reverse */
gboolean case_sensitive; /**< sort is case sensitive */
gboolean exec_first; /**< executables are at top of list */
} dir_sort_options_t;
/*** global variables defined in .c file *********************************************************/ /*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
int do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, gboolean reverse, int do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
gboolean case_sensitive, gboolean exec_ff, const char *fltr); const dir_sort_options_t * sort_op, const char *fltr);
void do_sort (dir_list * list, GCompareFunc sort, int top, gboolean reverse, void do_sort (dir_list * list, GCompareFunc sort, int top, const dir_sort_options_t * sort_op);
gboolean case_sensitive, gboolean exec_ff);
int do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, int count, int do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, int count,
gboolean reverse, gboolean case_sensitive, gboolean exec_ff, const char *fltr); const dir_sort_options_t * sort_op, const char *fltr);
void clean_dir (dir_list * list, int count); void clean_dir (dir_list * list, int count);
gboolean set_zero_dir (dir_list * list); gboolean set_zero_dir (dir_list * list);
int handle_path (dir_list * list, const char *path, struct stat *buf1, int handle_path (dir_list * list, const char *path, struct stat *buf1,

View File

@ -1132,7 +1132,7 @@ swap_panels (void)
current_panel = panel1; current_panel = panel1;
/* if sort options are different -> resort panels */ /* if sort options are different -> resort panels */
if (memcmp (&panel1->sort_info, &panel2->sort_info, sizeof (panel_sort_info_t)) != 0) if (memcmp (&panel1->sort_info, &panel2->sort_info, sizeof (dir_sort_options_t)) != 0)
{ {
panel_re_sort (other_panel); panel_re_sort (other_panel);
panel_re_sort (current_panel); panel_re_sort (current_panel);

View File

@ -3065,8 +3065,7 @@ _do_panel_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_
panel->count = panel->count =
do_load_dir (panel->cwd_vpath, &panel->dir, panel->sort_field->sort_routine, do_load_dir (panel->cwd_vpath, &panel->dir, panel->sort_field->sort_routine,
panel->sort_info.reverse, panel->sort_info.case_sensitive, &panel->sort_info, panel->filter);
panel->sort_info.exec_first, panel->filter);
try_to_select (panel, get_parent_dir_name (panel->cwd_vpath, olddir_vpath)); try_to_select (panel, get_parent_dir_name (panel->cwd_vpath, olddir_vpath));
load_hint (0); load_hint (0);
@ -4144,8 +4143,7 @@ panel_new_with_dir (const char *panel_name, const vfs_path_t * vpath)
/* Load the default format */ /* Load the default format */
panel->count = panel->count =
do_load_dir (panel->cwd_vpath, &panel->dir, panel->sort_field->sort_routine, do_load_dir (panel->cwd_vpath, &panel->dir, panel->sort_field->sort_routine,
panel->sort_info.reverse, panel->sort_info.case_sensitive, &panel->sort_info, panel->filter);
panel->sort_info.exec_first, panel->filter);
/* Restore old right path */ /* Restore old right path */
if (curdir != NULL) if (curdir != NULL)
@ -4191,8 +4189,7 @@ panel_reload (WPanel * panel)
panel->count = panel->count =
do_reload_dir (panel->cwd_vpath, &panel->dir, panel->sort_field->sort_routine, do_reload_dir (panel->cwd_vpath, &panel->dir, panel->sort_field->sort_routine,
panel->count, panel->sort_info.reverse, panel->sort_info.case_sensitive, panel->count, &panel->sort_info, panel->filter);
panel->sort_info.exec_first, panel->filter);
panel->dirty = 1; panel->dirty = 1;
if (panel->selected >= panel->count) if (panel->selected >= panel->count)
@ -4447,9 +4444,7 @@ panel_re_sort (WPanel * panel)
filename = g_strdup (selection (panel)->fname); filename = g_strdup (selection (panel)->fname);
unselect_item (panel); unselect_item (panel);
do_sort (&panel->dir, panel->sort_field->sort_routine, panel->count - 1, do_sort (&panel->dir, panel->sort_field->sort_routine, panel->count - 1, &panel->sort_info);
panel->sort_info.reverse, panel->sort_info.case_sensitive,
panel->sort_info.exec_first);
panel->selected = -1; panel->selected = -1;
for (i = panel->count; i; i--) for (i = panel->count; i; i--)
{ {

View File

@ -80,13 +80,6 @@ typedef struct
vfs_path_t *root_vpath; vfs_path_t *root_vpath;
} panelized_panel_t; } panelized_panel_t;
typedef struct panel_sort_info_struct
{
gboolean reverse; /* Show listing in reverse? */
gboolean case_sensitive; /* Listing is case sensitive? */
gboolean exec_first; /* Show executable top in list? */
} panel_sort_info_t;
typedef struct WPanel typedef struct WPanel
{ {
Widget widget; Widget widget;
@ -111,7 +104,7 @@ typedef struct WPanel
char *filter; /* File name filter */ char *filter; /* File name filter */
/* sort */ /* sort */
panel_sort_info_t sort_info; dir_sort_options_t sort_info;
const panel_field_t *sort_field; const panel_field_t *sort_field;
int dirty; /* Should we redisplay the panel? */ int dirty; /* Should we redisplay the panel? */

View File

@ -299,6 +299,7 @@ mcview_load_next_prev_init (mcview_t * view)
const char *fname; const char *fname;
size_t fname_len; size_t fname_len;
int i; int i;
dir_sort_options_t sort_op = { FALSE, TRUE, FALSE };
/* load directory where requested file is */ /* load directory where requested file is */
view->dir = g_new0 (dir_list, 1); view->dir = g_new0 (dir_list, 1);
@ -306,7 +307,7 @@ mcview_load_next_prev_init (mcview_t * view)
view->dir_idx = g_new (int, 1); view->dir_idx = g_new (int, 1);
*view->dir_count = do_load_dir (view->workdir_vpath, view->dir, (GCompareFunc) sort_name, *view->dir_count = do_load_dir (view->workdir_vpath, view->dir, (GCompareFunc) sort_name,
FALSE, TRUE, FALSE, NULL); &sort_op, NULL);
fname = x_basename (vfs_path_as_str (view->filename_vpath)); fname = x_basename (vfs_path_as_str (view->filename_vpath));
fname_len = strlen (fname); fname_len = strlen (fname);