--- mc/ChangeLog  Mon Aug 18 15:25:48 2003 
+++ mc/ChangeLog  Wed Aug 27 16:11:33 2003 
@@ -0,0 +1,6 @@
+2007-01-23  Martin Petricek  <tux@centrum.cz>  
+
+	* doc/mc.1.in: Added help about config file option to enable
+	indicator to show current sort mode and option to allow
+	switching to reversed sort mode with keyboard shortcut.
+
--- mc/src/ChangeLog   Mon Aug 18 15:25:51 2003 
+++ mc/src/ChangeLog   Wed Aug 27 16:01:37 2003 
@@ -0,0 +1,12 @@
+2007-01-23  Martin Petricek  <tux@centrum.cz> 
+
+	* main.c: added option to enable sort mode indicator letter in
+	upper left corner of file panel showing active sort mode and
+	also to change sort mode with simple keyboard shortcuts. Now
+	these shortcuts are from CTRL+F3 to CTRL+F9 (sort by name, ext,
+	mtime, size, unsorted, ctime, atime). Also added option to allow
+	changing normal and reversed mode with these keyboard shortcuts.
+	* setup.c: Adjust for the above
+	* dir.c: Adjust for the above
+	* dir.h: Adjust for the above
+
--- mc/doc/mc.1.in	Sun Jun 29 07:44:28 2003
+++ mc/doc/mc.1.in	Mon Jun 30 05:20:07 2003
@@ -3109,6 +3109,11 @@
 .PP
 These variables may be set in your ~/.mc/ini file:
 .TP
+.I allow_reversed_sort_modes
+When switching sort modes with keyboard shortcuts, if enabled,
+activating already selected mode will toggle the reversed flag. If
+disabled, nothing will happen when activating already selected mode.
+.TP
 .I clear_before_exec
 By default the Midnight Commander clears the screen before executing a
 command.  If you would prefer to see the output of the command at the
@@ -3119,6 +3124,24 @@
 If you press F3 on a directory, normally MC enters that directory.  If
 this flag is set to 1, then MC will ask for confirmation before changing
 the directory if you have files tagged.
+.TP
+.I enable_sort_indicator
+If enabled, small letter representing currently selected sort mode will
+appear in top left corner of file panels. Uppercase letter means reversed
+sort is enabled, lowercase means disabled.
+
+The meaning of letters is:
+
+.nf
+U      unsorted
+N      sorted by name
+E      sorted by extension
+M      sorted by modify time
+A      sorted by access time
+C      sorted by creation time
+S      sorted by size
+I      sorted by inode
+.fi
 .TP
 .I ftpfs_retry_seconds
 This value is the number of seconds the Midnight Commander will wait
--- mc/src/dir.c	Fri Jun  6 14:50:38 2003
+++ mc/src/dir.c	Mon Jun 30 05:06:32 2003
@@ -47,6 +47,7 @@
 
 #define MY_ISDIR(x) ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 1 : 0)
 
+/** when changing this, you should also update sort_order_indexes in dir.h */
 sort_orders_t sort_orders [SORT_TYPES_TOTAL] = {
     { N_("&Unsorted"),    unsorted },
     { N_("&Name"),        sort_name },
@@ -56,6 +57,18 @@
     { N_("C&Hange time"), sort_ctime },
     { N_("&Size"),        sort_size },
     { N_("&Inode"),       sort_inode },
+};
+
+/** mini indicators of current sort mode */
+char sort_orders_indicator [SORT_TYPES_TOTAL] = {
+    'U',
+    'N',
+    'E',
+    'M',
+    'A',
+    'C',
+    'S',
+    'I',
 };
 
 #ifdef HAVE_STRCOLL
--- mc/src/main.c	Mon Jun 23 14:38:56 2003
+++ mc/src/main.c	Mon Jun 30 05:08:47 2003
@@ -764,6 +764,63 @@
 
 }
 
+/* whether by pressing the sort mode key again when already using
+ the sort mode will toggle reversed flag*/
+int allow_reversed_sort_modes = 1;
+
+/** change sort mode to given value */
+static void
+sort_change (int desired_sort_order)
+{
+    WPanel *p;
+    sortfn *sort_order;
+
+    p = current_panel;
+
+    if (!(get_display_type ((p==right_panel) ? 1 : 0) == view_listing)) return;
+
+    sort_order = (sortfn *) sort_orders [desired_sort_order].sort_fn;
+
+    if (sort_order==p->sort_type) {
+        if (allow_reversed_sort_modes) {
+            p->reverse=!p->reverse;
+            panel_set_sort_order (p, sort_order);
+        }
+        /* else: do not sort when mode not changed */
+    } else {
+        p->reverse=0;
+        panel_set_sort_order (p, sort_order);
+    } 
+}
+
+static void change_sort_name(void) {
+    sort_change(SORT_NAME);
+}
+
+static void change_sort_ext(void) {
+    sort_change(SORT_EXTENSION);
+}
+
+static void change_sort_mtime(void) {
+    sort_change(SORT_MTIME);
+}
+
+static void change_sort_size(void) {
+    sort_change(SORT_SIZE);
+}
+
+static void change_sort_unsorted(void) {
+    sort_change(SORT_UNSORTED);
+}
+
+static void change_sort_ctime(void) {
+    sort_change(SORT_CTIME);
+}
+
+static void change_sort_atime(void) {
+    sort_change(SORT_ATIME);
+}
+
 static void
 treebox_cmd (void)
 {
@@ -1302,6 +1357,17 @@
     {ESC_CHAR, nothing},
     {XCTRL ('c'), nothing},
     {XCTRL ('g'), nothing},
+
+    /* change sort mode */
+
+    {KEY_M_CTRL | (KEY_F(3)), change_sort_name},
+    {KEY_M_CTRL | (KEY_F(4)), change_sort_ext},
+    {KEY_M_CTRL | (KEY_F(5)), change_sort_mtime},
+    {KEY_M_CTRL | (KEY_F(6)), change_sort_size},
+    {KEY_M_CTRL | (KEY_F(7)), change_sort_unsorted},
+    {KEY_M_CTRL | (KEY_F(8)), change_sort_ctime},
+    {KEY_M_CTRL | (KEY_F(9)), change_sort_atime},
+
     {0, 0},
 };
 
--- mc/src/setup.c	Fri Jun 27 21:54:04 2003
+++ mc/src/setup.c	Mon Jun 30 04:55:42 2003
@@ -64,6 +64,10 @@
 
 extern int num_history_items_recorded;
 
+extern int allow_reversed_sort_modes;
+
+extern int enable_sort_indicator;
+
 char *profile_name;		/* .mc/ini */
 char *global_profile_name;	/* mc.lib */
 
@@ -134,6 +138,8 @@
     { "show_mini_info", &show_mini_info },
     { "permission_mode", &permission_mode },
     { "filetype_mode", &filetype_mode },
+    { "enable_sort_indicator", &enable_sort_indicator },
+    { "allow_reversed_sort_modes", &allow_reversed_sort_modes },
     { 0, 0 }
 };
 
--- mc/src/dir.h	Fri Jun  6 14:50:38 2003
+++ mc/src/dir.h	Mon Jun 30 03:48:32 2003
@@ -51,6 +51,18 @@
 int sort_size  (const file_entry *a, const file_entry *b);
 int sort_inode (const file_entry *a, const file_entry *b);
 
+/** indexes to sort_orders in dir.c */
+typedef enum {
+    SORT_UNSORTED,
+    SORT_NAME,
+    SORT_EXTENSION,
+    SORT_MTIME,
+    SORT_ATIME,
+    SORT_CTIME,
+    SORT_SIZE,
+    SORT_INODE,
+} sort_order_indexes;
+
 /* SORT_TYPES is used to build the nice dialog box entries */
 #define SORT_TYPES 8
 
--- mc/src/screen.c	Mon Aug 18 15:25:51 2003
+++ mc/src/screen.c	Sun Aug 31 20:42:57 2003
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h> /* For tolower() */
 
 #include <unistd.h>
 
@@ -818,17 +819,45 @@
 	panel->top_file = panel->count - llines (panel);
 }
 
+/** whether to draw a letter representing current sort mode in window corner*/
+int enable_sort_indicator=0;
+
+extern char sort_orders_indicator[SORT_TYPES_TOTAL];
+
+/* repaint sort mode indicator letter on current panel*/
+void
+paint_sort_indicator(WPanel *panel)
+{
+    char c='?';
+    int i;
+    /* iterate thru all functions to find the correct one */
+    for (i=0;i<SORT_TYPES_TOTAL;i++) {
+        if ((void *)panel->sort_type==(void *)sort_orders[i].sort_fn) {
+            c=sort_orders_indicator[i]; //use corresponding indicator letter
+            break;
+        }
+    }
+    //paint in upper left corner of panel
+    widget_move (&panel->widget, 1, 1);
+    //if the mode is reversed, print in upper case, otherwise lower case
+    if (!panel->reverse) c=tolower(c);
+    // the indicator have the same color as marked file (yellow)
+    attrset (MARKED_COLOR);
+    printw ("%c", c);
+}
+
 /*
  * Repaint everything that can change on the panel - title, entries and
  * mini status.  The rest of the frame and the mini status separator are
  * not repainted.
  */
 static void
 panel_update_contents (WPanel *panel)
 {
     show_dir (panel);
     paint_dir (panel);
     display_mini_info (panel);
+    if (enable_sort_indicator) paint_sort_indicator(panel);
     panel->dirty = 0;
 }
 
