summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris West (Faux) <git@goeswhere.com>2013-01-13 12:13:31 +0000
committerChris West (Faux) <git@goeswhere.com>2013-01-13 12:42:28 +0000
commitfdd86924e5f22669603dc9524e33583d5173f01f (patch)
treee2e24a9ae624d1bc5e2c9acc80290771dbd9c48b
parentcfcac262d11988fb12137db93af74b3985437d59 (diff)
'C' sorts by items
-rw-r--r--src/browser.c4
-rw-r--r--src/dirlist.c21
-rw-r--r--src/dirlist.h1
-rw-r--r--src/help.c3
4 files changed, 22 insertions, 7 deletions
diff --git a/src/browser.c b/src/browser.c
index 3fd6bb8..1413b54 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 0ffde2d..a61b816 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 fb4709b..c69e117 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 1ba3890..ddb7702 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",