Ticket #276: mc-show_total_size.patch

File mc-show_total_size.patch, 9.0 KB (added by andrew_b, 15 years ago)
  • ChangeLog

    diff --git a/ChangeLog b/ChangeLog
    index add4360..6662dd7 100644
    a b  
     12009-02-19 Andrew Borodin  <aborodin@vmail.ru> 
     2 
     3        * src/screen.c: reimplemented displaying size of total marked files. 
     4          If mini-status is on, total size is displayed on mini_info_separator. 
     5          If mini-status is off, total marked size or current size is displayed 
     6          at the bottom of panel. 
     7          show_free_space(): more glib usage. Use macro for array size. 
     8          Set attribute here instead of show_dir(). 
     9          display_mini_info(): check the show_mini_info value before call this. 
     10          Move display size of total marked files from here... 
     11          dispaly_total_marked_size(): ...to this new function. 
     12          display_mini_info(): removed unused return. 
     13          mini_info_separator(): check the show_mini_info value before call this. 
     14          Set attribute independently of HAVE_SLANG. Show total size of marked files. 
     15          show_dir(): show size of current selected file or total size of marked 
     16          files if mini-status is off. 
     17          panel_update_contents(): removed. Since total size of marked files 
     18          is displayed on mini-info-separator, paint_panel() is used instead. 
     19          paint_panel(): used in update_dirty_panels() and panel_event() 
     20          instead of panel_update_contents(). Fixed double call of show_dir(). 
    121 
    2222009-02-05 Mikhail Pobolovets  <styx.mp@gmail.com> 
    323 
    4         * nl.po: update by mpol (#271) 
     24        * po/nl.po: update by mpol (#271) 
    525 
    6262009-02-05 Patrick Winnertz <winnie@debian.org> 
    727 
     
    1737        * lib/mc.lib: added patch on #219 by angel_il 
    1838        * edit/editcmd.c, configure.ac: removed obsolete own implementation of memove (#242) 
    1939        * vfs/extfs/u7z: patch from mandriva (#194) 
    20         * added andrew_b's patch for showing free space (#188) 
     40        * added Andrew Borodin's patch for showing free space (#188) 
    2141 
    22422009-02-01 Enrico Weigelt, metux ITS <weigelt@metux.de> 
    2343 
    2444        * src/util.c: fixed name_trunc() on NULL or empty parameters 
    2545        * src/achown.c: fixed unitialized var in init_chown_advanced() 
    26           (patch from andrew_b) 
     46          (patch from Andrew Borodin) 
    2747        * replaced gboolean by bool (from mhl/types.h) 
    2848 
    29492009-01-31 Enrico Weigelt, metux ITS <weigelt@metux.de>, Patrick Winnertz <winnie@debian.org>, Slava Zanko <slavazanko@gmail.com>, Sergei Trofimovich  <slyfox@inbox.ru> 
  • src/screen.c

    diff --git a/src/screen.c b/src/screen.c
    index b069b17..a570943 100644
    a b repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus) 
    659659static void 
    660660display_mini_info (WPanel *panel) 
    661661{ 
    662     if (!show_mini_info) 
    663         return; 
    664  
    665662    widget_move (&panel->widget, llines (panel)+3, 1); 
    666663 
    667664    if (panel->searching){ 
    display_mini_info (WPanel *panel) 
    671668        return; 
    672669    } 
    673670 
    674     /* Status displays total marked size */ 
    675     if (panel->marked){ 
    676         char buffer[BUF_SMALL], b_bytes[BUF_SMALL]; 
    677         const char *p = "  %-*s"; 
    678         int  cols = panel->widget.cols-2; 
    679  
    680         attrset (MARKED_COLOR); 
    681         tty_printf  ("%*s", cols, " "); 
    682         widget_move (&panel->widget, llines (panel)+3, 1); 
    683  
    684         /* 
    685          * This is a trick to use two ngettext() calls in one sentence. 
    686          * First make "N bytes", then insert it into "X in M files". 
    687          */ 
    688         g_snprintf(b_bytes, sizeof (b_bytes), 
    689                    ngettext("%s byte", "%s bytes", 
    690                             (unsigned long)panel->total), 
    691                    size_trunc_sep(panel->total)); 
    692         g_snprintf(buffer, sizeof (buffer), 
    693                    ngettext("%s in %d file", "%s in %d files", panel->marked), 
    694                    b_bytes, panel->marked); 
    695  
    696         if ((int) strlen (buffer) > cols-2){ 
    697             buffer [cols] = 0; 
    698             p += 2; 
    699         } else 
    700             cols -= 2; 
    701         tty_printf (p, cols, buffer); 
    702         return; 
    703     } 
    704  
    705671    /* Status resolves links and show them */ 
    706672    set_colors (panel); 
    707673 
    display_mini_info (WPanel *panel) 
    718684                     name_trunc (link_target, panel->widget.cols - 5)); 
    719685        } else 
    720686            tty_printf ("%-*s", panel->widget.cols - 2, _("<readlink failed>")); 
    721         return; 
    722     } 
    723  
    724     /* Default behavior */ 
    725     repaint_file (panel, panel->selected, 0, STATUS, 1); 
    726     return; 
     687    } else 
     688        /* Default behavior */ 
     689        repaint_file (panel, panel->selected, 0, STATUS, 1); 
    727690} 
    728691 
    729692static void 
    paint_dir (WPanel *panel) 
    748711} 
    749712 
    750713static void 
    751 mini_info_separator (WPanel *panel) 
     714dispaly_total_marked_size (WPanel *panel, int y, int x, gboolean size_only) 
    752715{ 
    753     if (!show_mini_info) 
     716    char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf; 
     717    int cols; 
     718    size_t blen; 
     719 
     720    if (panel->marked <= 0) 
    754721        return; 
    755722 
     723    buf = size_only ? b_bytes : buffer; 
     724    cols = panel->widget.cols - 2; 
     725 
     726    /* 
     727     * This is a trick to use two ngettext() calls in one sentence. 
     728     * First make "N bytes", then insert it into "X in M files". 
     729     */ 
     730    g_snprintf (b_bytes, sizeof (b_bytes), 
     731                ngettext("%s byte", "%s bytes", (unsigned long) panel->total), 
     732                size_trunc_sep (panel->total)); 
     733    if (!size_only) 
     734        g_snprintf (buffer, sizeof (buffer), 
     735                    ngettext("%s in %d file", "%s in %d files", panel->marked), 
     736                    b_bytes, panel->marked); 
     737 
     738    blen = strlen (buf); 
     739 
     740    /* don't forget spaces around buffer content */ 
     741    if ((int) blen > cols - 2) { 
     742        buf[cols - 2] = '\0'; 
     743        blen = (size_t) (cols - 2); 
     744    } 
     745 
     746    if (x < 0) 
     747        /* center in panel */ 
     748        x = (panel->widget.cols - (int) blen) / 2 - 1; 
     749 
     750    /* 
     751     * y == llines (panel) + 2      for mini_info_separator 
     752     * y == panel->widget.lines - 1 for panel bottom frame 
     753     */ 
     754    widget_move (&panel->widget, y, x); 
     755    attrset (MARKED_SELECTED_COLOR); 
     756    tty_printf (" %s ", buf); 
     757} 
     758 
     759static void 
     760mini_info_separator (WPanel *panel) 
     761{ 
     762    const int y = llines (panel) + 2; 
     763 
    756764    standend (); 
    757     widget_move (&panel->widget, llines (panel) + 2, 1); 
    758 #ifdef HAVE_SLANG 
     765    widget_move (&panel->widget, y, 1); 
    759766    attrset (NORMAL_COLOR); 
     767#ifdef HAVE_SLANG 
    760768    hline (ACS_HLINE, panel->widget.cols - 2); 
    761769#else 
    762770    hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR, 
    763771           panel->widget.cols - 2); 
    764772#endif                          /* !HAVE_SLANG */ 
     773 
     774    /* Status displays total marked size. 
     775     * Centered in panel, full format. */ 
     776    dispaly_total_marked_size (panel, y, -1, FALSE); 
    765777} 
    766778 
    767779static void 
    show_free_space (WPanel *panel) 
    790802    } 
    791803 
    792804    if (myfs_stats.avail > 0 || myfs_stats.total > 0) { 
    793         char buffer1 [6], buffer2[6], tmp[256]; 
    794         size_trunc_len (buffer1, 5, myfs_stats.avail, 1); 
    795         size_trunc_len (buffer2, 5, myfs_stats.total, 1); 
    796         snprintf (tmp, sizeof(tmp), " %s/%s (%d%%) ", buffer1, buffer2, 
     805        char buffer1[6], buffer2[6], tmp[BUF_SMALL]; 
     806        size_trunc_len (buffer1, sizeof(buffer1) - 1, myfs_stats.avail, 1); 
     807        size_trunc_len (buffer2, sizeof(buffer2) - 1, myfs_stats.total, 1); 
     808        g_snprintf (tmp, sizeof(tmp), " %s/%s (%d%%) ", buffer1, buffer2, 
    797809                                myfs_stats.total > 0 ? 
    798810                                (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0); 
    799811        widget_move (&panel->widget, panel->widget.lines - 1, 
    800                                      panel->widget.cols - 2 - strlen(tmp)); 
     812                                     panel->widget.cols - 2 - (int) strlen (tmp)); 
     813        attrset (NORMAL_COLOR); 
    801814        addstr (tmp); 
    802815    } 
    803816} 
    show_dir (WPanel *panel) 
    844857    widget_move (&panel->widget, 0, panel->widget.cols - 3); 
    845858    addstr ("v"); 
    846859 
    847     attrset (NORMAL_COLOR); 
     860    if (!show_mini_info) { 
     861        if (panel->marked == 0) { 
     862            /* Show size of curret file in the bottom of panel */ 
     863            if (S_ISREG (panel->dir.list [panel->selected].st.st_mode)) { 
     864                char buffer[BUF_SMALL]; 
     865 
     866                g_snprintf (buffer, sizeof (buffer), " %s ", 
     867                            size_trunc_sep (panel->dir.list [panel->selected].st.st_size)); 
     868                attrset (NORMAL_COLOR); 
     869                widget_move (&panel->widget, panel->widget.lines - 1, 2); 
     870                addstr (buffer); 
     871            } 
     872        } else { 
     873            /* Show total size of marked files 
     874             * In the bottom of panel, display size only. */ 
     875            dispaly_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE); 
     876        } 
     877    } 
    848878 
    849879    show_free_space (panel); 
    850880 
    adjust_top_file (WPanel *panel) 
    864894        panel->top_file = panel->count - llines (panel); 
    865895} 
    866896 
    867 /* 
    868  * Repaint everything that can change on the panel - title, entries and 
    869  * mini status.  The rest of the frame and the mini status separator are 
    870  * not repainted. 
    871  */ 
    872 static void 
    873 panel_update_contents (WPanel *panel) 
    874 { 
    875     show_dir (panel); 
    876     paint_dir (panel); 
    877     display_mini_info (panel); 
    878     panel->dirty = 0; 
    879 } 
    880  
    881897/* Repaint everything, including frame and separator */ 
    882898static void 
    883899paint_panel (WPanel *panel) 
    884900{ 
    885     paint_frame (panel); 
    886     panel_update_contents (panel); 
    887     mini_info_separator (panel); 
     901    paint_frame (panel); /* including show_dir */ 
     902    paint_dir (panel); 
     903 
     904    if (show_mini_info) { 
     905        mini_info_separator (panel); 
     906        display_mini_info (panel); 
     907    } 
     908 
     909    panel->dirty = 0; 
    888910} 
    889911 
    890912/* 
    void 
    897919update_dirty_panels (void) 
    898920{ 
    899921    if (current_panel->dirty) 
    900         panel_update_contents (current_panel); 
     922        paint_panel (current_panel); 
    901923 
    902924    if ((get_other_type () == view_listing) && other_panel->dirty) 
    903         panel_update_contents (other_panel); 
     925        paint_panel (other_panel); 
    904926} 
    905927 
    906928static void 
    panel_event (Gpm_Event *event, void *data) 
    24912513 
    24922514    ret = do_panel_event (event, panel, &redir); 
    24932515    if (!redir) 
    2494         panel_update_contents (panel); 
     2516        paint_panel (panel); 
    24952517 
    24962518    return ret; 
    24972519}