Ticket #2672: mc-4.8.0-listbox_vk111116.patch

File mc-4.8.0-listbox_vk111116.patch, 4.1 KB (added by vakorol, 12 years ago)

numbered listbox patch

  • lib/widget/listbox.c

    diff -ruB mc-4.8.0/lib/widget/listbox.c mc-4.8.0-listbox_vk111116/lib/widget/listbox.c
    old new  
    156156        else 
    157157        { 
    158158            WLEntry *e = (WLEntry *) le->data; 
    159             text = e->text; 
     159            if (l->num_type == LISTBOX_NUMBERED)                    
     160            {                   /* for the numbered list: display entry numbers in 3 characters */ 
     161                text = g_strdup_printf ("%-3i%s", pos, e->text); 
     162            }  
     163            else if (l->num_type == LISTBOX_NUMBERED_HOTKEYS) 
     164            {                   /* display the numbers 0..9 */ 
     165                if (pos <= 9) 
     166                    text = g_strdup_printf ("%-2i%s", pos, e->text); 
     167                else 
     168                    text = g_strdup_printf ("  %s", e->text); 
     169            } 
     170            else 
     171                text = e->text; 
    160172            le = g_list_next (le); 
    161173            pos++; 
    162174        } 
  • lib/widget/listbox.h

    diff -ruB mc-4.8.0/lib/widget/listbox.h mc-4.8.0-listbox_vk111116/lib/widget/listbox.h
    old new  
    3939    void *data;                 /* Client information */ 
    4040} WLEntry; 
    4141 
     42typedef enum 
     43{ 
     44    LISTBOX_UNNUMBERED = 0,     /* unnumbered (default) listbox */ 
     45    LISTBOX_NUMBERED,           /* all items in the listbox are numbered */ 
     46    LISTBOX_NUMBERED_HOTKEYS    /* only the first ten items are numbered 0-9 (to show the hotkeys) */ 
     47} listbox_numbered_t; 
     48 
    4249typedef struct WListbox 
    4350{ 
    4451    Widget widget; 
     
    5158    gboolean deletable;         /* Can list entries be deleted? */ 
    5259    lcback_fn callback;         /* The callback function */ 
    5360    int cursor_x, cursor_y;     /* Cache the values */ 
     61    listbox_numbered_t num_type; /* Numbered or unnumbered list */ 
    5462} WListbox; 
    5563 
    5664/*** global variables defined in .c file *********************************************************/ 
  • src/filemanager/hotlist.c

    diff -ruB mc-4.8.0/src/filemanager/hotlist.c mc-4.8.0-listbox_vk111116/src/filemanager/hotlist.c
    old new  
    326326            break; 
    327327        case HL_TYPE_DOTDOT: 
    328328        case HL_TYPE_ENTRY: 
    329             if (hotlist_state.moving) 
    330                 listbox_add_item (l_movelist, LISTBOX_APPEND_AT_END, 0, current->label, current); 
    331             else 
    332                 listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, current->label, current); 
    333             break; 
     329            { 
     330                char *lbl = g_strdup_printf (" %s", current->label);      /* add a leading space to separate 
     331                                                                           ordinary entries from groups */ 
     332                if (hotlist_state.moving) 
     333                    listbox_add_item (l_movelist, LISTBOX_APPEND_AT_END, 0, lbl, current); 
     334                else 
     335                    listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, lbl, current); 
     336                g_free (lbl); 
     337                break; 
     338            } 
    334339        default: 
    335340            break; 
    336341        } 
     
    812817    } 
    813818    /* get new listbox */ 
    814819    l_hotlist = listbox_new (UY + 1, UX + 1, LINES - 14, COLS - 2 * UX - 8, FALSE, l_call); 
     820    /* display hotkey numbers 0..9 in the listbox */ 
     821    l_hotlist->num_type = LISTBOX_NUMBERED_HOTKEYS; 
    815822 
    816823    /* Fill the hotlist with the active VFS or the hotlist */ 
    817824#ifdef ENABLE_VFS 
     
    976983            g_free (lbl); 
    977984        } 
    978985        else 
    979             listbox_add_item (l_hotlist, pos, 0, new->label, new); 
     986        { 
     987            /* add a leading space to separate ordinary entries from groups */ 
     988            char *lbl = g_strdup_printf(" %s", new->label); 
     989            listbox_add_item (l_hotlist, pos, 0, lbl, new); 
     990        } 
    980991        listbox_select_entry (l_hotlist, l_hotlist->pos); 
    981992    } 
    982993    return new;