diff --git a/src/browser.c b/src/browser.c index 3fd6bb8254732ffed9447949400a57fd0d733ac5..1413b54fab04594d897b80b10d190bd8fce96388 100644 --- a/src/browser.c +++ b/src/browser.c @@ -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; diff --git a/src/dirlist.c b/src/dirlist.c index 0ffde2d88b8729404f7321a22ba6088112c87b85..a61b8168b84e3808e5900ba46774dfbe52464a3b 100644 --- a/src/dirlist.c +++ b/src/dirlist.c @@ -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) diff --git a/src/dirlist.h b/src/dirlist.h index fb4709b9178f8cd5ac00be51b13018f4f7be958e..c69e117835941f7ec0a492064cee62f10e96b4dc 100644 --- a/src/dirlist.h +++ b/src/dirlist.h @@ -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 *); diff --git a/src/help.c b/src/help.c index 1ba38903f3f271c5c1bfdcbdc81fa2be640f1354..ddb77020cbe97ce3d48b3e160f5f0bd3964ab781 100644 --- a/src/help.c +++ b/src/help.c @@ -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",