Ticket #276: mc-show_total_size.patch
File mc-show_total_size.patch, 9.0 KB (added by andrew_b, 16 years ago) |
---|
-
ChangeLog
diff --git a/ChangeLog b/ChangeLog index add4360..6662dd7 100644
a b 1 2009-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(). 1 21 2 22 2009-02-05 Mikhail Pobolovets <styx.mp@gmail.com> 3 23 4 * nl.po: update by mpol (#271)24 * po/nl.po: update by mpol (#271) 5 25 6 26 2009-02-05 Patrick Winnertz <winnie@debian.org> 7 27 … … 17 37 * lib/mc.lib: added patch on #219 by angel_il 18 38 * edit/editcmd.c, configure.ac: removed obsolete own implementation of memove (#242) 19 39 * 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) 21 41 22 42 2009-02-01 Enrico Weigelt, metux ITS <weigelt@metux.de> 23 43 24 44 * src/util.c: fixed name_trunc() on NULL or empty parameters 25 45 * src/achown.c: fixed unitialized var in init_chown_advanced() 26 (patch from andrew_b)46 (patch from Andrew Borodin) 27 47 * replaced gboolean by bool (from mhl/types.h) 28 48 29 49 2009-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) 659 659 static void 660 660 display_mini_info (WPanel *panel) 661 661 { 662 if (!show_mini_info)663 return;664 665 662 widget_move (&panel->widget, llines (panel)+3, 1); 666 663 667 664 if (panel->searching){ … … display_mini_info (WPanel *panel) 671 668 return; 672 669 } 673 670 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 } else700 cols -= 2;701 tty_printf (p, cols, buffer);702 return;703 }704 705 671 /* Status resolves links and show them */ 706 672 set_colors (panel); 707 673 … … display_mini_info (WPanel *panel) 718 684 name_trunc (link_target, panel->widget.cols - 5)); 719 685 } else 720 686 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); 727 690 } 728 691 729 692 static void … … paint_dir (WPanel *panel) 748 711 } 749 712 750 713 static void 751 mini_info_separator (WPanel *panel)714 dispaly_total_marked_size (WPanel *panel, int y, int x, gboolean size_only) 752 715 { 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) 754 721 return; 755 722 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 759 static void 760 mini_info_separator (WPanel *panel) 761 { 762 const int y = llines (panel) + 2; 763 756 764 standend (); 757 widget_move (&panel->widget, llines (panel) + 2, 1); 758 #ifdef HAVE_SLANG 765 widget_move (&panel->widget, y, 1); 759 766 attrset (NORMAL_COLOR); 767 #ifdef HAVE_SLANG 760 768 hline (ACS_HLINE, panel->widget.cols - 2); 761 769 #else 762 770 hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR, 763 771 panel->widget.cols - 2); 764 772 #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); 765 777 } 766 778 767 779 static void … … show_free_space (WPanel *panel) 790 802 } 791 803 792 804 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, 797 809 myfs_stats.total > 0 ? 798 810 (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0); 799 811 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); 801 814 addstr (tmp); 802 815 } 803 816 } … … show_dir (WPanel *panel) 844 857 widget_move (&panel->widget, 0, panel->widget.cols - 3); 845 858 addstr ("v"); 846 859 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 } 848 878 849 879 show_free_space (panel); 850 880 … … adjust_top_file (WPanel *panel) 864 894 panel->top_file = panel->count - llines (panel); 865 895 } 866 896 867 /*868 * Repaint everything that can change on the panel - title, entries and869 * mini status. The rest of the frame and the mini status separator are870 * not repainted.871 */872 static void873 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 881 897 /* Repaint everything, including frame and separator */ 882 898 static void 883 899 paint_panel (WPanel *panel) 884 900 { 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; 888 910 } 889 911 890 912 /* … … void 897 919 update_dirty_panels (void) 898 920 { 899 921 if (current_panel->dirty) 900 pa nel_update_contents(current_panel);922 paint_panel (current_panel); 901 923 902 924 if ((get_other_type () == view_listing) && other_panel->dirty) 903 pa nel_update_contents(other_panel);925 paint_panel (other_panel); 904 926 } 905 927 906 928 static void … … panel_event (Gpm_Event *event, void *data) 2491 2513 2492 2514 ret = do_panel_event (event, panel, &redir); 2493 2515 if (!redir) 2494 pa nel_update_contents(panel);2516 paint_panel (panel); 2495 2517 2496 2518 return ret; 2497 2519 }