Skip to content
Snippets Groups Projects
Commit fdd86924 authored by Chris West (Faux)'s avatar Chris West (Faux)
Browse files

'C' sorts by items

parent cfcac262
No related branches found
No related tags found
No related merge requests found
......@@ -341,6 +341,10 @@ int browse_key(int ch) {
dirlist_set_sort(i, dirlist_sort_col == i ? !dirlist_sort_desc : 1, DL_NOCHANGE);
info_show = 0;
break;
case 'C':
dirlist_set_sort(DL_COL_ITEMS, dirlist_sort_col == DL_COL_ITEMS ? !dirlist_sort_desc : 1, DL_NOCHANGE);
info_show = 0;
break;
case 'e':
dirlist_set_hidden(!dirlist_hidden);
info_show = 0;
......
......@@ -62,25 +62,34 @@ static int dirlist_cmp(struct dir *x, struct dir *y) {
}
/* sort columns:
* 1 -> 2 -> 3
* NAME: name -> size -> asize
* SIZE: size -> asize -> name
* ASIZE: asize -> size -> name
* 1 -> 2 -> 3 -> 4
* NAME: name -> size -> asize -> items
* SIZE: size -> asize -> name -> items
* ASIZE: asize -> size -> name -> items
* ITEMS: items -> size -> asize -> name
*
* Note that the method used below is supposed to be fast, not readable :-)
*/
#define CMP_NAME strcmp(x->name, y->name)
#define CMP_SIZE (x->size > y->size ? 1 : (x->size == y->size ? 0 : -1))
#define CMP_ASIZE (x->asize > y->asize ? 1 : (x->asize == y->asize ? 0 : -1))
#define CMP_ITEMS (x->items > y->items ? 1 : (x->items == y->items ? 0 : -1))
/* try 1 */
r = dirlist_sort_col == DL_COL_NAME ? CMP_NAME : dirlist_sort_col == DL_COL_SIZE ? CMP_SIZE : CMP_ASIZE;
r = dirlist_sort_col == DL_COL_NAME ? CMP_NAME :
dirlist_sort_col == DL_COL_SIZE ? CMP_SIZE :
dirlist_sort_col == DL_COL_ASIZE ? CMP_ASIZE :
CMP_ITEMS;
/* try 2 */
if(!r)
r = dirlist_sort_col == DL_COL_SIZE ? CMP_ASIZE : CMP_SIZE;
/* try 3 */
if(!r)
r = dirlist_sort_col == DL_COL_NAME ? CMP_ASIZE : CMP_NAME;
r = (dirlist_sort_col == DL_COL_NAME || dirlist_sort_col == DL_COL_ITEMS) ?
CMP_ASIZE : CMP_NAME;
/* try 4 */
if(!r)
r = dirlist_sort_col == DL_COL_ITEMS ? CMP_NAME : CMP_ITEMS;
/* reverse when sorting in descending order */
if(dirlist_sort_desc && r != 0)
......
......@@ -36,6 +36,7 @@
#define DL_COL_NAME 0
#define DL_COL_SIZE 1
#define DL_COL_ASIZE 2
#define DL_COL_ITEMS 3
void dirlist_open(struct dir *);
......
......@@ -32,7 +32,7 @@
int page, start;
#define KEYS 15
#define KEYS 16
char *keys[KEYS*2] = {
/*|----key----| |----------------description----------------|*/
"up, k", "Move cursor up",
......@@ -41,6 +41,7 @@ char *keys[KEYS*2] = {
"left, <, h", "Open parent directory",
"n", "Sort by name (ascending/descending)",
"s", "Sort by size (ascending/descending)",
"C", "Sort by items (ascending/descending)",
"d", "Delete selected file or directory",
"t", "Toggle dirs before files when sorting",
"g", "Show percentage and/or graph",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment