Ticket #2672: 2672_numbered_listbox.diff

File 2672_numbered_listbox.diff, 4.0 KB (added by angel_il, 13 years ago)

2672_numbered_listbox.diff

  • lib/widget/listbox.c

    diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c
    index a7bfb25..61fe28a 100644
    a b listbox_draw (WListbox * l, gboolean focused) 
    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 --git a/lib/widget/listbox.h b/lib/widget/listbox.h
    index 8842484..90f5dce 100644
    a b typedef struct WLEntry 
    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; 
    typedef struct WListbox 
    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 --git a/src/filemanager/hotlist.c b/src/filemanager/hotlist.c
    index 2c5e8e7..0653174 100644
    a b fill_listbox (void) 
    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        } 
    init_hotlist (int list_type) 
    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 
    add2hotlist (char *label, char *directory, enum HotListType type, listbox_append 
    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;