From 0de68335546e486df9d6dd1756e02c191a974249 Mon Sep 17 00:00:00 2001
From: ilia <admin@darkstar.example.net>
Date: Sun, 25 Jan 2009 21:19:02 +0000
Subject: [PATCH] Menu sort option to move executables in top of files list in panel, after directory list (ticket#173)
Signed-off-by: ilia <admin@darkstar.example.net>
---
src/boxes.c | 12 ++++++++----
src/boxes.h | 2 +-
src/dir.c | 16 ++++++++++------
src/dir.h | 6 +++---
src/main.c | 7 +++++--
src/panel.h | 1 +
src/screen.c | 8 +++++---
src/setup.c | 5 ++++-
8 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/src/boxes.c b/src/boxes.c
index 0fd2a0b..bd0a94c 100644
a
|
b
|
display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int n |
266 | 266 | return result; |
267 | 267 | } |
268 | 268 | |
269 | | static int SORT_X = 40, SORT_Y = 14; |
| 269 | static int SORT_X = 60, SORT_Y = 14; |
270 | 270 | |
271 | 271 | static const char *sort_orders_names [SORT_TYPES]; |
272 | 272 | |
273 | 273 | sortfn * |
274 | | sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive) |
| 274 | sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive, int *exec_first) |
275 | 275 | { |
276 | 276 | int i, r, l; |
277 | 277 | sortfn *result; |
278 | | WCheck *c, *case_sense; |
| 278 | WCheck *c, *case_sense, *exec_ff; |
279 | 279 | |
280 | 280 | const char *ok_button = _("&OK"); |
281 | 281 | const char *cancel_button = _("&Cancel"); |
282 | 282 | const char *reverse_label = _("&Reverse"); |
283 | 283 | const char *case_label = _("case sensi&tive"); |
284 | 284 | const char *sort_title = _("Sort order"); |
285 | | |
| 285 | const char *exec_label = _("Executable first"); |
| 286 | |
286 | 287 | static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0; |
287 | 288 | |
288 | 289 | if (!i18n_sort_flag) { |
… |
… |
sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive) |
339 | 340 | button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, |
340 | 341 | ok_button, 0)); |
341 | 342 | |
| 343 | exec_ff = check_new (5, check_pos, *exec_first, exec_label); |
| 344 | add_widget (dd, exec_ff); |
342 | 345 | case_sense = check_new (4, check_pos, *case_sensitive, case_label); |
343 | 346 | add_widget (dd, case_sense); |
344 | 347 | c = check_new (3, check_pos, *reverse, reverse_label); |
… |
… |
sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive) |
355 | 358 | result = (sortfn *) sort_orders[my_radio->sel].sort_fn; |
356 | 359 | *reverse = c->state & C_BOOL; |
357 | 360 | *case_sensitive = case_sense->state & C_BOOL; |
| 361 | *exec_first = exec_ff->state & C_BOOL; |
358 | 362 | } else |
359 | 363 | result = sort_fn; |
360 | 364 | destroy_dlg (dd); |
diff --git a/src/boxes.h b/src/boxes.h
index 77c016c..4496c11 100644
a
|
b
|
|
7 | 7 | int display_box (WPanel *p, char **user, char **mini, |
8 | 8 | int *use_msformat, int num); |
9 | 9 | sortfn *sort_box (sortfn *sort_fn, int *reverse, |
10 | | int *case_sensitive); |
| 10 | int *case_sensitive, int *exec_first); |
11 | 11 | void confirm_box (void); |
12 | 12 | void display_bits_box (void); |
13 | 13 | void configure_vfs (void); |
diff --git a/src/dir.c b/src/dir.c
index 6992f40..26df6fb 100644
a
|
b
|
static int reverse = 1; |
46 | 46 | /* Are the files sorted case sensitively? */ |
47 | 47 | static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT; |
48 | 48 | |
49 | | #define MY_ISDIR(x) ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 1 : 0) |
| 49 | /* Are the exec_bit files top in list*/ |
| 50 | static int exec_first = 1; |
| 51 | |
| 52 | #define MY_ISDIR(x) ( (is_exe (x->st.st_mode) && !(S_ISDIR (x->st.st_mode) || x->f.link_to_dir) && (exec_first == 1)) ? 1 : ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 2 : 0) ) |
50 | 53 | |
51 | 54 | sort_orders_t sort_orders [SORT_TYPES_TOTAL] = { |
52 | 55 | { N_("&Unsorted"), unsorted }, |
… |
… |
sort_size (const file_entry *a, const file_entry *b) |
226 | 229 | |
227 | 230 | |
228 | 231 | void |
229 | | do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f) |
| 232 | do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f, int exec_first_f) |
230 | 233 | { |
231 | 234 | int dot_dot_found = 0; |
232 | 235 | |
… |
… |
do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitiv |
240 | 243 | |
241 | 244 | reverse = reverse_f ? -1 : 1; |
242 | 245 | case_sensitive = case_sensitive_f; |
| 246 | exec_first = exec_first_f; |
243 | 247 | qsort (&(list->list) [dot_dot_found], |
244 | 248 | top + 1 - dot_dot_found, sizeof (file_entry), sort); |
245 | 249 | } |
… |
… |
handle_path (dir_list *list, const char *path, |
382 | 386 | |
383 | 387 | int |
384 | 388 | do_load_dir (const char *path, dir_list *list, sortfn *sort, int reverse, |
385 | | int case_sensitive, const char *filter) |
| 389 | int case_sensitive, int exec_ff, const char *filter) |
386 | 390 | { |
387 | 391 | DIR *dirp; |
388 | 392 | struct dirent *dp; |
… |
… |
do_load_dir (const char *path, dir_list *list, sortfn *sort, int reverse, |
428 | 432 | } |
429 | 433 | |
430 | 434 | if (next_free) { |
431 | | do_sort (list, sort, next_free - 1, reverse, case_sensitive); |
| 435 | do_sort (list, sort, next_free - 1, reverse, case_sensitive, exec_ff); |
432 | 436 | } |
433 | 437 | |
434 | 438 | mc_closedir (dirp); |
… |
… |
alloc_dir_copy (int size) |
484 | 488 | /* If filter is null, then it is a match */ |
485 | 489 | int |
486 | 490 | do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count, |
487 | | int rev, int case_sensitive, const char *filter) |
| 491 | int rev, int case_sensitive, int exec_ff, const char *filter) |
488 | 492 | { |
489 | 493 | DIR *dirp; |
490 | 494 | struct dirent *dp; |
… |
… |
do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count, |
581 | 585 | tree_store_end_check (); |
582 | 586 | g_hash_table_destroy (marked_files); |
583 | 587 | if (next_free) { |
584 | | do_sort (list, sort, next_free - 1, rev, case_sensitive); |
| 588 | do_sort (list, sort, next_free - 1, rev, case_sensitive, exec_ff); |
585 | 589 | } |
586 | 590 | clean_dir (&dir_copy, count); |
587 | 591 | return next_free; |
diff --git a/src/dir.h b/src/dir.h
index 5f852af..90af8bb 100644
a
|
b
|
typedef struct { |
31 | 31 | typedef int sortfn (const void *, const void *); |
32 | 32 | |
33 | 33 | int do_load_dir (const char *path, dir_list * list, sortfn * sort, int reverse, |
34 | | int case_sensitive, const char *filter); |
| 34 | int case_sensitive, int exec_ff, const char *filter); |
35 | 35 | void do_sort (dir_list * list, sortfn * sort, int top, int reverse, |
36 | | int case_sensitive); |
| 36 | int case_sensitive, int exec_ff); |
37 | 37 | int do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count, |
38 | | int reverse, int case_sensitive, const char *filter); |
| 38 | int reverse, int case_sensitive, int exec_ff, const char *filter); |
39 | 39 | void clean_dir (dir_list * list, int count); |
40 | 40 | int set_zero_dir (dir_list * list); |
41 | 41 | int handle_path (dir_list *list, const char *path, struct stat *buf1, |
diff --git a/src/main.c b/src/main.c
index 624df71..890f1df 100644
a
|
b
|
_do_panel_cd (WPanel *panel, const char *new_dir, enum cd_enum cd_type) |
609 | 609 | panel_clean_dir (panel); |
610 | 610 | panel->count = |
611 | 611 | do_load_dir (panel->cwd, &panel->dir, panel->sort_type, |
612 | | panel->reverse, panel->case_sensitive, panel->filter); |
| 612 | panel->reverse, panel->case_sensitive, |
| 613 | panel->exec_first, panel->filter); |
613 | 614 | try_to_select (panel, get_parent_dir_name (panel->cwd, olddir)); |
614 | 615 | load_hint (0); |
615 | 616 | panel->dirty = 1; |
… |
… |
sort_cmd (void) |
759 | 760 | return; |
760 | 761 | |
761 | 762 | p = MENU_PANEL; |
762 | | sort_order = sort_box (p->sort_type, &p->reverse, &p->case_sensitive); |
| 763 | sort_order = sort_box (p->sort_type, &p->reverse, |
| 764 | &p->case_sensitive, |
| 765 | &p->exec_first); |
763 | 766 | |
764 | 767 | panel_set_sort_order (p, sort_order); |
765 | 768 | |
diff --git a/src/panel.h b/src/panel.h
index 1cd15af..ebd0bed 100644
a
|
b
|
typedef struct WPanel { |
49 | 49 | int selected; /* Index to the selected file */ |
50 | 50 | int reverse; /* Show listing in reverse? */ |
51 | 51 | int case_sensitive; /* Listing is case sensitive? */ |
| 52 | int exec_first; /* Show executable top in list? */ |
52 | 53 | int split; /* Split panel to allow two columns */ |
53 | 54 | int is_panelized; /* Flag: special filelisting, can't reload */ |
54 | 55 | int frame_size; /* half or full frame */ |
diff --git a/src/screen.c b/src/screen.c
index f35099e..a6c67c1 100644
a
|
b
|
panel_new (const char *panel_name) |
1054 | 1054 | /* Load the default format */ |
1055 | 1055 | panel->count = |
1056 | 1056 | do_load_dir (panel->cwd, &panel->dir, panel->sort_type, |
1057 | | panel->reverse, panel->case_sensitive, panel->filter); |
| 1057 | panel->reverse, panel->case_sensitive, |
| 1058 | panel->exec_first, panel->filter); |
1058 | 1059 | return panel; |
1059 | 1060 | } |
1060 | 1061 | |
… |
… |
panel_reload (WPanel *panel) |
1088 | 1089 | panel->count = |
1089 | 1090 | do_reload_dir (panel->cwd, &panel->dir, panel->sort_type, |
1090 | 1091 | panel->count, panel->reverse, panel->case_sensitive, |
1091 | | panel->filter); |
| 1092 | panel->exec_first, panel->filter); |
1092 | 1093 | |
1093 | 1094 | panel->dirty = 1; |
1094 | 1095 | if (panel->selected >= panel->count) |
… |
… |
panel_re_sort (WPanel *panel) |
2464 | 2465 | |
2465 | 2466 | filename = g_strdup (selection (panel)->fname); |
2466 | 2467 | unselect_item (panel); |
2467 | | do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, panel->case_sensitive); |
| 2468 | do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, |
| 2469 | panel->case_sensitive, panel->exec_first); |
2468 | 2470 | panel->selected = -1; |
2469 | 2471 | for (i = panel->count; i; i--){ |
2470 | 2472 | if (!strcmp (panel->dir.list [i-1].fname, filename)){ |
diff --git a/src/setup.c b/src/setup.c
index f26566a..9fa8784 100644
a
|
b
|
panel_save_setup (struct WPanel *panel, const char *section) |
247 | 247 | save_string (section, "reverse", buffer, profile_name); |
248 | 248 | g_snprintf (buffer, sizeof (buffer), "%d", panel->case_sensitive); |
249 | 249 | save_string (section, "case_sensitive", buffer, profile_name); |
| 250 | g_snprintf (buffer, sizeof (buffer), "%d", panel->exec_first); |
| 251 | save_string (section, "exec_first", buffer, profile_name); |
250 | 252 | for (i = 0; sort_names [i].key; i++) |
251 | 253 | if (sort_names [i].sort_type == (sortfn *) panel->sort_type){ |
252 | 254 | save_string (section, "sort_order", |
… |
… |
panel_load_setup (WPanel *panel, const char *section) |
388 | 390 | |
389 | 391 | panel->reverse = load_int (section, "reverse", 0); |
390 | 392 | panel->case_sensitive = load_int (section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT); |
391 | | |
| 393 | panel->exec_first = load_int (section, "exec_first", 1); |
| 394 | |
392 | 395 | /* Load sort order */ |
393 | 396 | load_string (section, "sort_order", "name", buffer, sizeof (buffer)); |
394 | 397 | panel->sort_type = (sortfn *) sort_name; |