Ticket #173: 0001-Menu-sort-option-to-move-executables-in-top-of-files-rev2.patch

File 0001-Menu-sort-option-to-move-executables-in-top-of-files-rev2.patch, 9.9 KB (added by slyfox, 16 years ago)

cleaned up trailing spaces (for clean git am)

  • src/boxes.c

    From 0de68335546e486df9d6dd1756e02c191a974249 Mon Sep 17 00:00:00 2001
    From: ilia <admin@darkstar.example.net>
    Date: Sun, 25 Jan 2009 21:19:02 +0000
    Subject: [PATCH] Menu sort option to move executables in top of files list in panel, after directory list (ticket#173)
    
    Signed-off-by: ilia <admin@darkstar.example.net>
    ---
     src/boxes.c  |   12 ++++++++----
     src/boxes.h  |    2 +-
     src/dir.c    |   16 ++++++++++------
     src/dir.h    |    6 +++---
     src/main.c   |    7 +++++--
     src/panel.h  |    1 +
     src/screen.c |    8 +++++---
     src/setup.c  |    5 ++++-
     8 files changed, 37 insertions(+), 20 deletions(-)
    
    diff --git a/src/boxes.c b/src/boxes.c
    index 0fd2a0b..bd0a94c 100644
    a b display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int n 
    266266    return result; 
    267267} 
    268268 
    269 static int SORT_X = 40, SORT_Y = 14; 
     269static int SORT_X = 60, SORT_Y = 14; 
    270270 
    271271static const char *sort_orders_names [SORT_TYPES]; 
    272272 
    273273sortfn * 
    274 sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive) 
     274sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive, int *exec_first) 
    275275{ 
    276276    int i, r, l; 
    277277    sortfn *result; 
    278     WCheck *c, *case_sense; 
     278    WCheck *c, *case_sense, *exec_ff; 
    279279 
    280280    const char *ok_button = _("&OK"); 
    281281    const char *cancel_button = _("&Cancel"); 
    282282    const char *reverse_label = _("&Reverse"); 
    283283    const char *case_label = _("case sensi&tive"); 
    284284    const char *sort_title = _("Sort order"); 
    285  
     285    const char *exec_label = _("Executable first"); 
     286 
    286287    static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0; 
    287288 
    288289    if (!i18n_sort_flag) { 
    sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive) 
    339340                button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, 
    340341                            ok_button, 0)); 
    341342 
     343    exec_ff = check_new (5, check_pos, *exec_first, exec_label); 
     344    add_widget (dd, exec_ff); 
    342345    case_sense = check_new (4, check_pos, *case_sensitive, case_label); 
    343346    add_widget (dd, case_sense); 
    344347    c = check_new (3, check_pos, *reverse, reverse_label); 
    sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive) 
    355358        result = (sortfn *) sort_orders[my_radio->sel].sort_fn; 
    356359        *reverse = c->state & C_BOOL; 
    357360        *case_sensitive = case_sense->state & C_BOOL; 
     361        *exec_first = exec_ff->state & C_BOOL; 
    358362    } else 
    359363        result = sort_fn; 
    360364    destroy_dlg (dd); 
  • src/boxes.h

    diff --git a/src/boxes.h b/src/boxes.h
    index 77c016c..4496c11 100644
    a b  
    77int     display_box      (WPanel *p, char **user, char **mini, 
    88                          int *use_msformat, int num); 
    99sortfn *sort_box         (sortfn *sort_fn, int *reverse, 
    10                           int *case_sensitive); 
     10                          int *case_sensitive, int *exec_first); 
    1111void    confirm_box      (void); 
    1212void    display_bits_box (void); 
    1313void    configure_vfs    (void); 
  • src/dir.c

    diff --git a/src/dir.c b/src/dir.c
    index 6992f40..26df6fb 100644
    a b static int reverse = 1; 
    4646/* Are the files sorted case sensitively? */ 
    4747static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT; 
    4848 
    49 #define MY_ISDIR(x) ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 1 : 0) 
     49/* Are the exec_bit files top in list*/ 
     50static int exec_first = 1; 
     51 
     52#define MY_ISDIR(x) ( (is_exe (x->st.st_mode) && !(S_ISDIR (x->st.st_mode) || x->f.link_to_dir) && (exec_first == 1)) ? 1 : ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 2 : 0) ) 
    5053 
    5154sort_orders_t sort_orders [SORT_TYPES_TOTAL] = { 
    5255    { N_("&Unsorted"),    unsorted }, 
    sort_size (const file_entry *a, const file_entry *b) 
    226229 
    227230 
    228231void 
    229 do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f) 
     232do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f, int exec_first_f) 
    230233{ 
    231234    int dot_dot_found = 0; 
    232235 
    do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitiv 
    240243 
    241244    reverse = reverse_f ? -1 : 1; 
    242245    case_sensitive = case_sensitive_f; 
     246    exec_first = exec_first_f; 
    243247    qsort (&(list->list) [dot_dot_found], 
    244248           top + 1 - dot_dot_found, sizeof (file_entry), sort); 
    245249} 
    handle_path (dir_list *list, const char *path, 
    382386 
    383387int 
    384388do_load_dir (const char *path, dir_list *list, sortfn *sort, int reverse, 
    385              int case_sensitive, const char *filter) 
     389             int case_sensitive, int exec_ff, const char *filter) 
    386390{ 
    387391    DIR *dirp; 
    388392    struct dirent *dp; 
    do_load_dir (const char *path, dir_list *list, sortfn *sort, int reverse, 
    428432    } 
    429433 
    430434    if (next_free) { 
    431         do_sort (list, sort, next_free - 1, reverse, case_sensitive); 
     435        do_sort (list, sort, next_free - 1, reverse, case_sensitive, exec_ff); 
    432436    } 
    433437 
    434438    mc_closedir (dirp); 
    alloc_dir_copy (int size) 
    484488/* If filter is null, then it is a match */ 
    485489int 
    486490do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count, 
    487                int rev, int case_sensitive, const char *filter) 
     491               int rev, int case_sensitive, int exec_ff, const char *filter) 
    488492{ 
    489493    DIR *dirp; 
    490494    struct dirent *dp; 
    do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count, 
    581585    tree_store_end_check (); 
    582586    g_hash_table_destroy (marked_files); 
    583587    if (next_free) { 
    584         do_sort (list, sort, next_free - 1, rev, case_sensitive); 
     588        do_sort (list, sort, next_free - 1, rev, case_sensitive, exec_ff); 
    585589    } 
    586590    clean_dir (&dir_copy, count); 
    587591    return next_free; 
  • src/dir.h

    diff --git a/src/dir.h b/src/dir.h
    index 5f852af..90af8bb 100644
    a b typedef struct { 
    3131typedef int sortfn (const void *, const void *); 
    3232 
    3333int do_load_dir (const char *path, dir_list * list, sortfn * sort, int reverse, 
    34                  int case_sensitive, const char *filter); 
     34                 int case_sensitive, int exec_ff, const char *filter); 
    3535void do_sort (dir_list * list, sortfn * sort, int top, int reverse, 
    36               int case_sensitive); 
     36              int case_sensitive, int exec_ff); 
    3737int do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count, 
    38                    int reverse, int case_sensitive, const char *filter); 
     38                   int reverse, int case_sensitive, int exec_ff, const char *filter); 
    3939void clean_dir (dir_list * list, int count); 
    4040int set_zero_dir (dir_list * list); 
    4141int handle_path (dir_list *list, const char *path, struct stat *buf1, 
  • src/main.c

    diff --git a/src/main.c b/src/main.c
    index 624df71..890f1df 100644
    a b _do_panel_cd (WPanel *panel, const char *new_dir, enum cd_enum cd_type) 
    609609    panel_clean_dir (panel); 
    610610    panel->count = 
    611611        do_load_dir (panel->cwd, &panel->dir, panel->sort_type, 
    612                      panel->reverse, panel->case_sensitive, panel->filter); 
     612                     panel->reverse, panel->case_sensitive, 
     613                     panel->exec_first, panel->filter); 
    613614    try_to_select (panel, get_parent_dir_name (panel->cwd, olddir)); 
    614615    load_hint (0); 
    615616    panel->dirty = 1; 
    sort_cmd (void) 
    759760        return; 
    760761 
    761762    p = MENU_PANEL; 
    762     sort_order = sort_box (p->sort_type, &p->reverse, &p->case_sensitive); 
     763    sort_order = sort_box (p->sort_type, &p->reverse, 
     764                           &p->case_sensitive, 
     765                           &p->exec_first); 
    763766 
    764767    panel_set_sort_order (p, sort_order); 
    765768 
  • src/panel.h

    diff --git a/src/panel.h b/src/panel.h
    index 1cd15af..ebd0bed 100644
    a b typedef struct WPanel { 
    4949    int      selected;          /* Index to the selected file */ 
    5050    int      reverse;           /* Show listing in reverse? */ 
    5151    int      case_sensitive;    /* Listing is case sensitive? */ 
     52    int      exec_first;        /* Show executable top in list? */ 
    5253    int      split;             /* Split panel to allow two columns */ 
    5354    int      is_panelized;      /* Flag: special filelisting, can't reload */ 
    5455    int      frame_size;        /* half or full frame */ 
  • src/screen.c

    diff --git a/src/screen.c b/src/screen.c
    index f35099e..a6c67c1 100644
    a b panel_new (const char *panel_name) 
    10541054    /* Load the default format */ 
    10551055    panel->count = 
    10561056        do_load_dir (panel->cwd, &panel->dir, panel->sort_type, 
    1057                      panel->reverse, panel->case_sensitive, panel->filter); 
     1057                     panel->reverse, panel->case_sensitive, 
     1058                     panel->exec_first, panel->filter); 
    10581059    return panel; 
    10591060} 
    10601061 
    panel_reload (WPanel *panel) 
    10881089    panel->count = 
    10891090        do_reload_dir (panel->cwd, &panel->dir, panel->sort_type, 
    10901091                       panel->count, panel->reverse, panel->case_sensitive, 
    1091                        panel->filter); 
     1092                       panel->exec_first, panel->filter); 
    10921093 
    10931094    panel->dirty = 1; 
    10941095    if (panel->selected >= panel->count) 
    panel_re_sort (WPanel *panel) 
    24642465 
    24652466    filename = g_strdup (selection (panel)->fname); 
    24662467    unselect_item (panel); 
    2467     do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, panel->case_sensitive); 
     2468    do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, 
     2469             panel->case_sensitive, panel->exec_first); 
    24682470    panel->selected = -1; 
    24692471    for (i = panel->count; i; i--){ 
    24702472        if (!strcmp (panel->dir.list [i-1].fname, filename)){ 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index f26566a..9fa8784 100644
    a b panel_save_setup (struct WPanel *panel, const char *section) 
    247247    save_string (section, "reverse", buffer, profile_name); 
    248248    g_snprintf (buffer, sizeof (buffer), "%d", panel->case_sensitive); 
    249249    save_string (section, "case_sensitive", buffer, profile_name); 
     250    g_snprintf (buffer, sizeof (buffer), "%d", panel->exec_first); 
     251    save_string (section, "exec_first", buffer, profile_name); 
    250252    for (i = 0; sort_names [i].key; i++) 
    251253        if (sort_names [i].sort_type == (sortfn *) panel->sort_type){ 
    252254            save_string (section, "sort_order", 
    panel_load_setup (WPanel *panel, const char *section) 
    388390 
    389391    panel->reverse = load_int (section, "reverse", 0); 
    390392    panel->case_sensitive = load_int (section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT); 
    391  
     393    panel->exec_first = load_int (section, "exec_first", 1); 
     394 
    392395    /* Load sort order */ 
    393396    load_string (section, "sort_order", "name", buffer, sizeof (buffer)); 
    394397    panel->sort_type = (sortfn *) sort_name;