Patch to change sort order of hidden files



Hi,

I wrote yesterday a small patch which adds an option that forces hidden files to
be shown last (regardless of sort order).

I think that this a better order, since a user is not that often looking for a
hidden file. It makes the users home directory look much nicer.

The thing that I find annoying with toggling the 'show hidden files' option, is
that you usually forget it on and then everything looks like a mess the next
time you use mc, until you make the effort to push a few buttons and turn it off.

I made the patch from snapshot code (don't know if that was a good idea).

Valter Pohjola 

--- main.c	2006-09-25 17:47:34.000000000 +0300
+++ /home/valter/prog/mc-2007-06-04-22/src/main.c	2007-06-13 12:00:45.000000000 +0300
@@ -1020,6 +1020,13 @@
     update_panels (UP_RELOAD, UP_KEEPSEL);
 }
 
+void
+toggle_dot_files_last(void)
+{
+    dot_files_last = !dot_files_last;
+    update_panels (UP_RELOAD, UP_KEEPSEL);
+}
+
 /*
  * Just a hack for allowing url-like pathnames to be accepted from the
  * command line.
--- main.h	2006-02-06 18:55:43.000000000 +0200
+++ /home/valter/prog/mc-2007-06-04-22/src/main.h	2007-06-13 12:02:06.000000000 +0300
@@ -10,6 +10,8 @@
 void toggle_mix_all_files (void);
 void toggle_show_backup (void);
 void toggle_show_hidden (void);
+void toggle_dot_files_last (void);
+
 
 #define UP_OPTIMIZE 0
 #define UP_RELOAD   1
--- dir.c	2007-01-15 00:55:18.000000000 +0200
+++ /home/valter/prog/mc-2007-06-04-22/src/dir.c	2007-06-13 11:50:42.000000000 +0300
@@ -33,6 +33,9 @@
 /* If true show files starting with a dot */
 int show_dot_files = 1;
 
+/* If true show all dotfiles at bottom of dir listing */
+int dot_files_last = 0;
+
 /* If true show files ending in ~ */
 int show_backups = 1;
 
@@ -100,6 +103,20 @@
 #define string_sortcomp(a,b) (case_sensitive ? strcmp (a,b) : g_strcasecmp (a,b))
 #endif
 
+inline static int
+dot_file_order (const file_entry *a, const file_entry *b)
+{
+    if(dot_files_last)
+    {
+        if(a->fname[0] == '.' && b->fname[0] != '.')
+            return 1;
+
+        if( b->fname[0] == '.' && a->fname[0] != '.')
+            return -1;
+    }
+    return 0;
+}
+
 int
 unsorted (const file_entry *a, const file_entry *b)
 {
@@ -113,6 +130,10 @@
 {
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
+    int df_order;
+
+    if(df_order = dot_file_order(a,b))
+        return df_order;
 
     if (ad == bd || mix_all_files)
 	return string_sortcomp (a->fname, b->fname) * reverse;
@@ -126,6 +147,10 @@
     int r;
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
+    int df_order;
+
+    if(df_order = dot_file_order(a,b))
+        return df_order;
 
     if (ad == bd || mix_all_files){
 	exta = extension (a->fname);
@@ -144,6 +169,10 @@
 {
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
+    int df_order;
+
+    if(df_order = dot_file_order(a,b))
+        return df_order;
 
     if (ad == bd || mix_all_files) {
 	int result = a->st.st_mtime < b->st.st_mtime ? -1 :
@@ -162,6 +191,10 @@
 {
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
+    int df_order;
+
+    if(df_order = dot_file_order(a,b))
+        return df_order;
 
     if (ad == bd || mix_all_files) {
 	int result = a->st.st_ctime < b->st.st_ctime ? -1 :
@@ -180,6 +213,10 @@
 {
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
+    int df_order;
+
+    if(df_order = dot_file_order(a,b))
+        return df_order;
 
     if (ad == bd || mix_all_files) {
 	int result = a->st.st_atime < b->st.st_atime ? -1 :
@@ -198,6 +235,10 @@
 {
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
+    int df_order;
+
+    if(df_order = dot_file_order(a,b))
+        return df_order;
 
     if (ad == bd || mix_all_files)
 	return (a->st.st_ino - b->st.st_ino) * reverse;
@@ -211,6 +252,10 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
     int result = 0;
+    int df_order;
+
+    if(df_order = dot_file_order(a,b))
+        return df_order;
 
     if (ad != bd && !mix_all_files)
 	return bd - ad;
--- dir.h	2007-01-15 00:55:18.000000000 +0200
+++ /home/valter/prog/mc-2007-06-04-22/src/dir.h	2007-06-13 11:18:17.000000000 +0300
@@ -72,6 +72,7 @@
 
 extern int show_backups;
 extern int show_dot_files;
+extern int dot_files_last;
 extern int mix_all_files;
 
 #endif
--- option.c	2006-02-28 19:44:28.000000000 +0200
+++ /home/valter/prog/mc-2007-06-04-22/src/option.c	2007-06-13 11:59:16.000000000 +0300
@@ -65,6 +65,7 @@
    {N_("Compute &Totals"),    &file_op_compute_totals, TOGGLE_VARIABLE,  0 },
    {N_("&Verbose operation"), &verbose,           TOGGLE_VARIABLE,       0 },
    /* panel options */
+   {N_("hidde&N files last"), &dot_files_last,    toggle_dot_files_last, 0 },
    {N_("&Fast dir reload"),   &fast_reload,       toggle_fast_reload,    0 },
    {N_("mi&X all files"),     &mix_all_files,     toggle_mix_all_files,  0 },
    {N_("&Drop down menus"),   &drop_menus,        TOGGLE_VARIABLE,       0 },
@@ -76,7 +77,7 @@
 
 /* Make sure this corresponds to the check_options structure */
 #define OTHER_OPTIONS 12
-#define PANEL_OPTIONS 6
+#define PANEL_OPTIONS 7
 
 static WRadio *pause_radio;
 
--- setup.c	2006-02-23 17:45:06.000000000 +0200
+++ /home/valter/prog/mc-2007-06-04-22/src/setup.c	2007-06-13 12:06:36.000000000 +0300
@@ -143,6 +143,7 @@
 } int_options [] = {
     { "show_backups", &show_backups },
     { "show_dot_files", &show_dot_files },
+    { "dot_files_last", &dot_files_last },
     { "verbose", &verbose },
     { "mark_moves_down", &mark_moves_down },
     { "pause_after_run", &pause_after_run },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]