Ticket #2368: swap panels should respect sort options.

Initial step: refactoring: create new panel_sort_info_t structure
to store sort options of panel.
Type accuracy.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-12-16 11:44:47 +03:00
parent 728596871e
commit 2ebfd4e293
9 changed files with 109 additions and 101 deletions

View File

@ -576,7 +576,7 @@ display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int
/* --------------------------------------------------------------------------------------------- */
const panel_field_t *
sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive, int *exec_first)
sort_box (panel_sort_info_t *info)
{
int dlg_width = 40, dlg_height = 7;
@ -585,7 +585,7 @@ sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive,
int sort_idx = 0;
const panel_field_t *result = sort_format;
const panel_field_t *result = info->sort_field;
sort_orders_names = panel_get_sortable_fields (&sort_names_num);
dlg_height += sort_names_num;
@ -601,14 +601,13 @@ sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive,
/* 1 */
QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
/* 2 */
QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), &info->reverse),
/* 3 */
QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), &info->case_sensitive),
/* 4 */
QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), &info->exec_first),
/* 5 */
QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
NULL, &sort_idx),
QUICK_RADIO (4, dlg_width, 3, dlg_height, 0, NULL, &sort_idx),
QUICK_END
};
@ -622,7 +621,7 @@ sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive,
quick_widgets[5].u.radio.count = sort_names_num;
for (i = 0; i < sort_names_num; i++)
if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0)
if (strcmp (sort_orders_names[i], _(info->sort_field->title_hotkey)) == 0)
{
sort_idx = i;
break;
@ -670,7 +669,7 @@ sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive,
result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
if (result == NULL)
result = sort_format;
result = info->sort_field;
}
g_strfreev ((gchar **) sort_orders_names);
return result;

View File

@ -19,8 +19,7 @@
/*** declarations of public functions ************************************************************/
int display_box (WPanel * p, char **user, char **mini, int *use_msformat, int num);
const panel_field_t *sort_box (const panel_field_t *, int *reverse,
int *case_sensitive, int *exec_first);
const panel_field_t *sort_box (panel_sort_info_t *info);
void confirm_box (void);
void display_bits_box (void);
void configure_vfs (void);

View File

@ -1522,7 +1522,7 @@ single_dirsize_cmd (void)
recalculate_panel_summary (panel);
if (current_panel->current_sort_field->sort_routine == (sortfn *) sort_size)
if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
panel_re_sort (panel);
panel->dirty = 1;
@ -1560,7 +1560,7 @@ dirsizes_cmd (void)
recalculate_panel_summary (panel);
if (current_panel->current_sort_field->sort_routine == (sortfn *) sort_size)
if (current_panel->sort_info.sort_field->sort_routine == (sortfn *) sort_size)
panel_re_sort (panel);
panel->dirty = 1;

View File

@ -47,7 +47,7 @@
/*** file scope macro definitions ****************************************************************/
#define MY_ISDIR(x) (\
(is_exe (x->st.st_mode) && !(S_ISDIR (x->st.st_mode) || x->f.link_to_dir) && (exec_first == 1)) \
(is_exe (x->st.st_mode) && !(S_ISDIR (x->st.st_mode) || x->f.link_to_dir) && exec_first) \
? 1 \
: ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 2 : 0) )
@ -62,7 +62,7 @@ static int reverse = 1;
static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT;
/* Are the exec_bit files top in list */
static int exec_first = 1;
static gboolean exec_first = TRUE;
static dir_list dir_copy = { 0, 0 };
@ -400,8 +400,8 @@ sort_size (file_entry * a, file_entry * b)
/* --------------------------------------------------------------------------------------------- */
void
do_sort (dir_list * list, sortfn * sort, int top, int reverse_f, int case_sensitive_f,
int exec_first_f)
do_sort (dir_list * list, sortfn * sort, int top, gboolean reverse_f, gboolean case_sensitive_f,
gboolean exec_first_f)
{
int dot_dot_found = 0;
@ -410,11 +410,11 @@ do_sort (dir_list * list, sortfn * sort, int top, int reverse_f, int case_sensit
/* If there is an ".." entry the caller must take care to
ensure that it occupies the first list element. */
if (!strcmp (list->list[0].fname, ".."))
if (strcmp (list->list[0].fname, "..") == 0)
dot_dot_found = 1;
reverse = reverse_f ? -1 : 1;
case_sensitive = case_sensitive_f;
case_sensitive = case_sensitive_f ? 1 : 0;
exec_first = exec_first_f;
qsort (&(list->list)[dot_dot_found], top + 1 - dot_dot_found, sizeof (file_entry), sort);
@ -511,8 +511,8 @@ handle_path (dir_list * list, const char *path,
/* --------------------------------------------------------------------------------------------- */
int
do_load_dir (const char *path, dir_list * list, sortfn * sort, int lc_reverse,
int lc_case_sensitive, int exec_ff, const char *fltr)
do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean lc_reverse,
gboolean lc_case_sensitive, gboolean exec_ff, const char *fltr)
{
DIR *dirp;
struct dirent *dp;
@ -593,7 +593,7 @@ if_link_is_exe (const char *full_name, const file_entry * file)
int
do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count,
int rev, int lc_case_sensitive, int exec_ff, const char *fltr)
gboolean lc_reverse, gboolean lc_case_sensitive, gboolean exec_ff, const char *fltr)
{
DIR *dirp;
struct dirent *dp;
@ -704,7 +704,7 @@ do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count,
g_hash_table_destroy (marked_files);
if (next_free)
{
do_sort (list, sort, next_free - 1, rev, lc_case_sensitive, exec_ff);
do_sort (list, sort, next_free - 1, lc_reverse, lc_case_sensitive, exec_ff);
}
clean_dir (&dir_copy, count);
return next_free;

View File

@ -52,12 +52,12 @@ typedef struct
/*** declarations of public functions ************************************************************/
int do_load_dir (const char *path, dir_list * list, sortfn * sort, int reverse,
int case_sensitive, int exec_ff, const char *fltr);
void do_sort (dir_list * list, sortfn * sort, int top, int reverse,
int case_sensitive, int exec_ff);
int do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean reverse,
gboolean case_sensitive, gboolean exec_ff, const char *fltr);
void do_sort (dir_list * list, sortfn * sort, int top, gboolean reverse,
gboolean case_sensitive, gboolean exec_ff);
int do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count,
int reverse, int case_sensitive, int exec_ff, const char *fltr);
gboolean reverse, gboolean case_sensitive, gboolean exec_ff, const char *fltr);
void clean_dir (dir_list * list, int count);
gboolean set_zero_dir (dir_list * list);
int handle_path (dir_list * list, const char *path, struct stat *buf1,

View File

@ -404,8 +404,7 @@ sort_cmd (void)
return;
p = MENU_PANEL;
sort_order = sort_box (p->current_sort_field, &p->reverse, &p->case_sensitive, &p->exec_first);
sort_order = sort_box (&p->sort_info);
panel_set_sort_order (p, sort_order);
}

View File

@ -1260,17 +1260,16 @@ panel_format_modified (WPanel * panel)
static void
panel_paint_sort_info (WPanel * panel)
{
const char *sort_sign = (panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign;
char *str;
if (*panel->sort_info.sort_field->hotkey != '\0')
{
const char *sort_sign = panel->sort_info.reverse ? panel_sort_down_sign : panel_sort_up_sign;
char *str;
if (*panel->current_sort_field->hotkey == '\0')
return;
str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->current_sort_field->hotkey));
widget_move (&panel->widget, 1, 1);
tty_print_string (str);
g_free (str);
str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->sort_info.sort_field->hotkey));
widget_move (&panel->widget, 1, 1);
tty_print_string (str);
g_free (str);
}
}
/* --------------------------------------------------------------------------------------------- */
@ -1334,9 +1333,10 @@ paint_frame (WPanel * panel)
g_string_set_size (format_txt, 0);
if (panel->list_type == list_long
&& strcmp (format->id, panel->current_sort_field->id) == 0)
&& strcmp (format->id, panel->sort_info.sort_field->id) == 0)
g_string_append (format_txt,
(panel->reverse) ? panel_sort_down_sign : panel_sort_up_sign);
panel->sort_info.reverse
? panel_sort_down_sign : panel_sort_up_sign);
g_string_append (format_txt, format->title);
if (strcmp (format->id, "name") == 0 && panel->filter && *panel->filter)
@ -2131,7 +2131,7 @@ do_search (WPanel * panel, int c_code)
search->is_case_sensitive = FALSE;
break;
default:
search->is_case_sensitive = panel->case_sensitive;
search->is_case_sensitive = panel->sort_info.case_sensitive;
break;
}
sel = panel->selected;
@ -2471,7 +2471,7 @@ panel_toggle_sort_order_prev (WPanel * panel)
const panel_field_t *pfield = NULL;
title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
title = panel_get_title_without_hotkey (panel->sort_info.sort_field->title_hotkey);
lc_index = panel_get_format_field_index_by_name (panel, title);
g_free (title);
@ -2488,10 +2488,12 @@ panel_toggle_sort_order_prev (WPanel * panel)
for (i = panel_get_format_field_count (panel);
i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--);
}
if (pfield == NULL)
return;
panel->current_sort_field = pfield;
panel_set_sort_order (panel, panel->current_sort_field);
if (pfield != NULL)
{
panel->sort_info.sort_field = pfield;
panel_set_sort_order (panel, pfield);
}
}
/* --------------------------------------------------------------------------------------------- */
@ -2501,10 +2503,11 @@ panel_toggle_sort_order_next (WPanel * panel)
{
gsize lc_index, i;
const panel_field_t *pfield = NULL;
gsize format_field_count = panel_get_format_field_count (panel);
gsize format_field_count;
gchar *title;
title = panel_get_title_without_hotkey (panel->current_sort_field->title_hotkey);
format_field_count = panel_get_format_field_count (panel);
title = panel_get_title_without_hotkey (panel->sort_info.sort_field->title_hotkey);
lc_index = panel_get_format_field_index_by_name (panel, title);
g_free (title);
@ -2523,10 +2526,12 @@ panel_toggle_sort_order_next (WPanel * panel)
i != format_field_count
&& (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL; i++);
}
if (pfield == NULL)
return;
panel->current_sort_field = pfield;
panel_set_sort_order (panel, panel->current_sort_field);
if (pfield != NULL)
{
panel->sort_info.sort_field = pfield;
panel_set_sort_order (panel, pfield);
}
}
/* --------------------------------------------------------------------------------------------- */
@ -2535,13 +2540,13 @@ static void
panel_select_sort_order (WPanel * panel)
{
const panel_field_t *sort_order;
sort_order = sort_box (panel->current_sort_field, &panel->reverse,
&panel->case_sensitive, &panel->exec_first);
if (sort_order == NULL)
return;
panel->current_sort_field = sort_order;
panel_set_sort_order (panel, panel->current_sort_field);
sort_order = sort_box (&panel->sort_info);
if (sort_order != NULL)
{
panel->sort_info.sort_field = sort_order;
panel_set_sort_order (panel, sort_order);
}
}
/* --------------------------------------------------------------------------------------------- */
@ -2549,20 +2554,19 @@ panel_select_sort_order (WPanel * panel)
static void
panel_set_sort_type_by_id (WPanel * panel, const char *name)
{
const panel_field_t *sort_order;
if (strcmp (panel->current_sort_field->id, name) != 0)
if (strcmp (panel->sort_info.sort_field->id, name) != 0)
{
const panel_field_t *sort_order;
sort_order = panel_get_field_by_id (name);
if (sort_order == NULL)
return;
panel->current_sort_field = sort_order;
panel->sort_info.sort_field = sort_order;
}
else
{
panel->reverse = !panel->reverse;
}
panel_set_sort_order (panel, panel->current_sort_field);
panel->sort_info.reverse = !panel->sort_info.reverse;
panel_set_sort_order (panel, panel->sort_info.sort_field);
}
/* --------------------------------------------------------------------------------------------- */
@ -2666,8 +2670,9 @@ _do_panel_cd (WPanel * panel, const char *new_dir, enum cd_enum cd_type)
/* Reload current panel */
panel_clean_dir (panel);
panel->count =
do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter);
do_load_dir (panel->cwd, &panel->dir, panel->sort_info.sort_field->sort_routine,
panel->sort_info.reverse, panel->sort_info.case_sensitive,
panel->sort_info.exec_first, panel->filter);
try_to_select (panel, get_parent_dir_name (panel->cwd, olddir));
load_hint (0);
panel->dirty = 1;
@ -2849,8 +2854,8 @@ panel_execute_cmd (WPanel * panel, unsigned long command)
panel_toggle_sort_order_next (panel);
break;
case CK_PanelReverseSort:
panel->reverse = !panel->reverse;
panel_set_sort_order (panel, panel->current_sort_field);
panel->sort_info.reverse = !panel->sort_info.reverse;
panel_set_sort_order (panel, panel->sort_info.sort_field);
break;
case CK_PanelSortOrderByName:
panel_set_sort_type_by_id (panel, "name");
@ -3053,18 +3058,18 @@ mouse_sort_col (Gpm_Event * event, WPanel * panel)
g_free (title);
}
if (!col_sort_format)
if (col_sort_format == NULL)
return;
if (panel->current_sort_field == col_sort_format)
if (panel->sort_info.sort_field == col_sort_format)
{
/* reverse the sort if clicked column is already the sorted column */
panel->reverse = !panel->reverse;
panel->sort_info.reverse = !panel->sort_info.reverse;
}
else
{
/* new sort is forced to be ascending */
panel->reverse = 0;
panel->sort_info.reverse = FALSE;
}
panel_set_sort_order (panel, col_sort_format);
}
@ -3553,7 +3558,6 @@ panel_new_with_dir (const char *panel_name, const char *wpath)
panel->selected = 0;
panel->marked = 0;
panel->total = 0;
panel->reverse = 0;
panel->dirty = 1;
panel->searching = FALSE;
panel->dirs_marked = 0;
@ -3604,8 +3608,9 @@ panel_new_with_dir (const char *panel_name, const char *wpath)
/* Load the default format */
panel->count =
do_load_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
panel->reverse, panel->case_sensitive, panel->exec_first, panel->filter);
do_load_dir (panel->cwd, &panel->dir, panel->sort_info.sort_field->sort_routine,
panel->sort_info.reverse, panel->sort_info.case_sensitive,
panel->sort_info.exec_first, panel->filter);
/* Restore old right path */
if (curdir[0] != '\0')
@ -3646,9 +3651,9 @@ panel_reload (WPanel * panel)
}
panel->count =
do_reload_dir (panel->cwd, &panel->dir, panel->current_sort_field->sort_routine,
panel->count, panel->reverse, panel->case_sensitive,
panel->exec_first, panel->filter);
do_reload_dir (panel->cwd, &panel->dir, panel->sort_info.sort_field->sort_routine,
panel->count, panel->sort_info.reverse, panel->sort_info.case_sensitive,
panel->sort_info.exec_first, panel->filter);
panel->dirty = 1;
if (panel->selected >= panel->count)
@ -3883,8 +3888,9 @@ panel_re_sort (WPanel * panel)
filename = g_strdup (selection (panel)->fname);
unselect_item (panel);
do_sort (&panel->dir, panel->current_sort_field->sort_routine, panel->count - 1, panel->reverse,
panel->case_sensitive, panel->exec_first);
do_sort (&panel->dir, panel->sort_info.sort_field->sort_routine, panel->count - 1,
panel->sort_info.reverse, panel->sort_info.case_sensitive,
panel->sort_info.exec_first);
panel->selected = -1;
for (i = panel->count; i; i--)
{
@ -3905,10 +3911,10 @@ panel_re_sort (WPanel * panel)
void
panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order)
{
if (sort_order == 0)
if (sort_order == NULL)
return;
panel->current_sort_field = sort_order;
panel->sort_info.sort_field = sort_order;
/* The directory is already sorted, we have to load the unsorted stuff */
if (sort_order->sort_routine == (sortfn *) unsorted)

View File

@ -61,7 +61,7 @@ typedef enum
struct format_e;
typedef struct panel_format_struct
typedef struct panel_field_struct
{
const char *id;
int min_size;
@ -75,6 +75,14 @@ typedef struct panel_format_struct
sortfn *sort_routine; /* used by mouse_sort_col() */
} panel_field_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? */
const panel_field_t *sort_field;
} panel_sort_info_t;
typedef struct WPanel
{
Widget widget;
@ -92,14 +100,11 @@ typedef struct WPanel
uintmax_t total; /* Bytes in marked files */
int top_file; /* The file showed on the top of the panel */
int selected; /* Index to the selected file */
int reverse; /* Show listing in reverse? */
int case_sensitive; /* Listing is case sensitive? */
int exec_first; /* Show executable top in list? */
int split; /* Split panel to allow two columns */
int is_panelized; /* Flag: special filelisting, can't reload */
int frame_size; /* half or full frame */
const panel_field_t *current_sort_field;
char *filter; /* File name filter */
panel_sort_info_t sort_info; /* Sort descriptor */
int dirty; /* Should we redisplay the panel? */

View File

@ -1302,17 +1302,17 @@ panel_load_setup (WPanel * panel, const char *section)
size_t i;
char *buffer, buffer2[BUF_TINY];
panel->reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
panel->case_sensitive =
panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
panel->sort_info.case_sensitive =
mc_config_get_int (mc_panels_config, section, "case_sensitive",
OS_SORT_CASE_SENSITIVE_DEFAULT);
panel->exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
/* Load sort order */
buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
panel->current_sort_field = panel_get_field_by_id (buffer);
if (panel->current_sort_field == NULL)
panel->current_sort_field = panel_get_field_by_id ("name");
panel->sort_info.sort_field = panel_get_field_by_id (buffer);
if (panel->sort_info.sort_field == NULL)
panel->sort_info.sort_field = panel_get_field_by_id ("name");
g_free (buffer);
@ -1351,11 +1351,11 @@ panel_save_setup (struct WPanel *panel, const char *section)
char buffer[BUF_TINY];
size_t i;
mc_config_set_int (mc_panels_config, section, "reverse", panel->reverse);
mc_config_set_int (mc_panels_config, section, "case_sensitive", panel->case_sensitive);
mc_config_set_int (mc_panels_config, section, "exec_first", panel->exec_first);
mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
mc_config_set_int (mc_panels_config, section, "case_sensitive", panel->sort_info.case_sensitive);
mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
mc_config_set_string (mc_panels_config, section, "sort_order", panel->current_sort_field->id);
mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
for (i = 0; list_types[i].key != NULL; i++)
if (list_types[i].list_type == panel->list_type)