Hi,

I rewrote the patch, so that the option will appear in the "Sort order" dialogs.
I added a variable dot_files_last to the panel struct. (One thing that I noticed
is that the variable reverse in the panel struct, seems to be initialized twice,
once in the body of panel_new and once in panel_load_setup, which is called from
panel_new?)

Valter Pohjola

--- ../../org/mc/src/boxes.c	2007-06-14 17:10:35.000000000 +0300
+++ boxes.c	2007-06-14 20:35:20.000000000 +0300
@@ -270,16 +270,17 @@
 static const char *sort_orders_names [SORT_TYPES];
 
 sortfn *
-sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
+sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive, int *dot_files_last)
 {
-    int i, r, l;
+    int i, r, l, d;
     sortfn *result;
-    WCheck *c, *case_sense;
+    WCheck *c, *case_sense, *df_last;
 
     const char *ok_button = _("&OK");
     const char *cancel_button = _("&Cancel");
     const char *reverse_label = _("&Reverse");
     const char *case_label = _("case sensi&tive");
+    const char *dot_files_last_label = _("hidden files &last");
     const char *sort_title = _("Sort order");
 
     static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
@@ -304,6 +305,10 @@
 	i = strlen (cancel_button) + 4;
 	if (i > l)
 	    l = i;
+        
+        d = strlen(dot_files_last_label) + 4;
+        if(d > l)
+            l = d;
 
 	i = check_pos + max (r, l) + 2;
 
@@ -338,6 +343,8 @@
 		button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON,
 			    ok_button, 0));
 
+    df_last = check_new (5, check_pos, *dot_files_last, dot_files_last_label);
+    add_widget (dd, df_last);
     case_sense = check_new (4, check_pos, *case_sensitive, case_label);
     add_widget (dd, case_sense);
     c = check_new (3, check_pos, *reverse, reverse_label);
@@ -354,6 +361,7 @@
 	result = (sortfn *) sort_orders[my_radio->sel].sort_fn;
 	*reverse = c->state & C_BOOL;
 	*case_sensitive = case_sense->state & C_BOOL;
+	*dot_files_last = df_last->state & C_BOOL;
     } else
 	result = sort_fn;
     destroy_dlg (dd);
--- ../../org/mc/src/boxes.h	2007-06-14 17:10:35.000000000 +0300
+++ boxes.h	2007-06-14 19:48:45.000000000 +0300
@@ -7,7 +7,7 @@
 int     display_box      (WPanel *p, char **user, char **mini,
 			  int *use_msformat, int num);
 sortfn *sort_box         (sortfn *sort_fn, int *reverse,
-			  int *case_sensitive);
+			  int *case_sensitive, int *dot_files_last);
 void    confirm_box      (void);
 void    display_bits_box (void);
 void    configure_vfs    (void);
--- ../../org/mc/src/dir.c	2007-06-14 17:10:35.000000000 +0300
+++ dir.c	2007-06-14 19:33:25.000000000 +0300
@@ -45,6 +45,9 @@
 /* Are the files sorted case sensitively? */
 static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT;
 
+/* If true show all dotfiles at bottom of dir listing */
+static int dot_files_last = 0;
+
 #define MY_ISDIR(x) ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 1 : 0)
 
 sort_orders_t sort_orders [SORT_TYPES_TOTAL] = {
@@ -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;
@@ -225,7 +270,7 @@
 
 
 void
-do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f)
+do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f, int dot_files_last_f)
 {
     int dot_dot_found = 0;
 
@@ -239,6 +284,7 @@
 
     reverse = reverse_f ? -1 : 1;
     case_sensitive = case_sensitive_f;
+    dot_files_last = dot_files_last_f;
     qsort (&(list->list) [dot_dot_found],
 	   top + 1 - dot_dot_found, sizeof (file_entry), sort);
 }
@@ -381,7 +427,7 @@
 
 int
 do_load_dir (const char *path, dir_list *list, sortfn *sort, int reverse,
-	     int case_sensitive, const char *filter)
+	     int case_sensitive, int dot_files_last, const char *filter)
 {
     DIR *dirp;
     struct dirent *dp;
@@ -427,7 +473,7 @@
     }
 
     if (next_free) {
-	do_sort (list, sort, next_free - 1, reverse, case_sensitive);
+	do_sort (list, sort, next_free - 1, reverse, case_sensitive, dot_files_last);
     }
 
     mc_closedir (dirp);
@@ -483,7 +529,7 @@
 /* If filter is null, then it is a match */
 int
 do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
-	       int rev, int case_sensitive, const char *filter)
+	       int rev, int case_sensitive, int dot_files_last, const char *filter)
 {
     DIR *dirp;
     struct dirent *dp;
@@ -580,7 +626,7 @@
     tree_store_end_check ();
     g_hash_table_destroy (marked_files);
     if (next_free) {
-	do_sort (list, sort, next_free - 1, rev, case_sensitive);
+	do_sort (list, sort, next_free - 1, rev, case_sensitive, dot_files_last);
     }
     clean_dir (&dir_copy, count);
     return next_free;
--- ../../org/mc/src/dir.h	2007-06-14 17:10:35.000000000 +0300
+++ dir.h	2007-06-14 19:21:55.000000000 +0300
@@ -31,11 +31,11 @@
 typedef int sortfn (const void *, const void *);
 
 int do_load_dir (const char *path, dir_list * list, sortfn * sort, int reverse,
-		 int case_sensitive, const char *filter);
+		 int case_sensitive, int dot_files_last, const char *filter);
 void do_sort (dir_list * list, sortfn * sort, int top, int reverse,
-	      int case_sensitive);
+	      int case_sensitive, int dot_files_last_f);
 int do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count,
-		   int reverse, int case_sensitive, const char *filter);
+		   int reverse, int case_sensitive, int dot_files_last, const char *filter);
 void clean_dir (dir_list * list, int count);
 int set_zero_dir (dir_list * list);
 int handle_path (dir_list *list, const char *path, struct stat *buf1,
--- ../../org/mc/src/main.c	2007-06-14 17:10:35.000000000 +0300
+++ main.c	2007-06-14 19:50:34.000000000 +0300
@@ -608,7 +608,7 @@
     panel_clean_dir (panel);
     panel->count =
 	do_load_dir (panel->cwd, &panel->dir, panel->sort_type,
-		     panel->reverse, panel->case_sensitive, panel->filter);
+		     panel->reverse, panel->case_sensitive, panel->dot_files_last, panel->filter);
     try_to_select (panel, get_parent_dir_name (panel->cwd, olddir));
     load_hint (0);
     panel->dirty = 1;
@@ -758,7 +758,7 @@
 	return;
 
     p = MENU_PANEL;
-    sort_order = sort_box (p->sort_type, &p->reverse, &p->case_sensitive);
+    sort_order = sort_box (p->sort_type, &p->reverse, &p->case_sensitive, &p->dot_files_last);
 
     panel_set_sort_order (p, sort_order);
 
--- ../../org/mc/src/panel.h	2007-06-14 17:10:35.000000000 +0300
+++ panel.h	2007-06-14 19:11:38.000000000 +0300
@@ -49,6 +49,7 @@
     int      selected;		/* Index to the selected file */
     int      reverse;		/* Show listing in reverse? */
     int      case_sensitive;    /* Listing is case sensitive? */
+    int      dot_files_last;    /* Put hidden files at bottom of listing */
     int      split;		/* Split panel to allow two columns */
     int      is_panelized;	/* Flag: special filelisting, can't reload */
     int      frame_size;	/* half or full frame */
--- ../../org/mc/src/screen.c	2007-06-14 17:10:35.000000000 +0300
+++ screen.c	2007-06-14 19:37:10.000000000 +0300
@@ -1050,7 +1050,7 @@
     /* Load the default format */
     panel->count =
 	do_load_dir (panel->cwd, &panel->dir, panel->sort_type,
-		     panel->reverse, panel->case_sensitive, panel->filter);
+		     panel->reverse, panel->case_sensitive, panel->dot_files_last, panel->filter);
     return panel;
 }
 
@@ -1084,7 +1084,7 @@
     panel->count =
 	do_reload_dir (panel->cwd, &panel->dir, panel->sort_type,
 		       panel->count, panel->reverse, panel->case_sensitive,
-		       panel->filter);
+		       panel->dot_files_last, panel->filter);
 
     panel->dirty = 1;
     if (panel->selected >= panel->count)
@@ -2460,7 +2460,7 @@
 
     filename = g_strdup (selection (panel)->fname);
     unselect_item (panel);
-    do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, panel->case_sensitive);
+    do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, panel->case_sensitive, panel->dot_files_last);
     panel->selected = -1;
     for (i = panel->count; i; i--){
 	if (!strcmp (panel->dir.list [i-1].fname, filename)){
--- ../../org/mc/src/setup.c	2007-06-14 17:10:35.000000000 +0300
+++ setup.c	2007-06-14 20:26:37.000000000 +0300
@@ -244,6 +244,9 @@
     save_string (section, "reverse", buffer, profile_name);
     g_snprintf (buffer, sizeof (buffer), "%d", panel->case_sensitive);
     save_string (section, "case_sensitive", buffer, profile_name);
+    g_snprintf (buffer, sizeof (buffer), "%d", panel->dot_files_last);
+    save_string (section, "dot_files_last", buffer, profile_name);
+
     for (i = 0; sort_names [i].key; i++)
 	if (sort_names [i].sort_type == (sortfn *) panel->sort_type){
 	    save_string (section, "sort_order",
@@ -385,6 +388,7 @@
 
     panel->reverse = load_int (section, "reverse", 0);
     panel->case_sensitive = load_int (section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
+    panel->dot_files_last = load_int (section, "dot_files_last", 0);
 
     /* Load sort order */
     load_string (section, "sort_order", "name", buffer, sizeof (buffer));
_______________________________________________
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel

Reply via email to