Ticket #3560: bug#3560-status-line-enhancement-005.patch

File bug#3560-status-line-enhancement-005.patch, 6.7 KB (added by TigerKid001, 9 years ago)

Added number of items selected

  • src/kits/tracker/CountView.cpp

    From c87d5b9e1723f610016712b0d4adc8c90b314712 Mon Sep 17 00:00:00 2001
    From: "Sidhant Sharma [:TigerKid001]" <tigerkid001@gmail.com>
    Date: Mon, 15 Dec 2014 13:06:35 +0000
    Subject: [PATCH] Status line enhancement v2.0
    
    ---
     src/kits/tracker/CountView.cpp | 126 ++++++++++++++++++++++++++++++++++-------
     src/kits/tracker/CountView.h   |   7 ++-
     src/kits/tracker/PoseView.cpp  |   2 +-
     3 files changed, 114 insertions(+), 21 deletions(-)
    
    diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp
    index a1d3c7c..7931705 100644
    a b All rights reserved.  
    4747#include "Bitmaps.h"
    4848#include "ContainerWindow.h"
    4949#include "DirMenu.h"
     50#include "Entry.h"
     51#include "Model.h"
    5052#include "PoseView.h"
     53#include "StringForSize.h"
    5154#include "Utilities.h"
    5255
    5356
    BCountView::BCountView(BRect bounds, BPoseView* view)  
    6669    BView(bounds, "CountVw", B_FOLLOW_LEFT + B_FOLLOW_BOTTOM,
    6770        B_PULSE_NEEDED | B_WILL_DRAW),
    6871    fLastCount(-1),
     72    fLastSelectionCount(0),
     73    fFileCount(0),
     74    fDirCount(0),
     75    fTotalFilesSize(0),
    6976    fPoseView(view),
     77    fMoreFiles(false),
    7078    fShowingBarberPole(false),
    7179    fBorderHighlighted(false),
    7280    fBarberPoleMap(NULL),
    7381    fLastBarberPoleOffset(5),
    7482    fStartSpinningAfter(0),
     83    fStatusString(""),
    7584    fTypeAheadString(""),
    7685    fFilterString("")
    7786{
    BCountView::TextAndBarberPoleRect() const  
    195204void
    196205BCountView::CheckCount()
    197206{
     207    PoseList* selectionList = fPoseView->SelectionList();
    198208    // invalidate the count text area if necessary
    199     if (fLastCount != fPoseView->CountItems()) {
     209    if (fLastCount != fPoseView->CountItems() ||
     210                    fLastSelectionCount != selectionList->CountItems()){
    200211        fLastCount = fPoseView->CountItems();
     212        fLastSelectionCount = selectionList->CountItems();
     213        _UpdateCountsAndSizes(fLastSelectionCount);
    201214        Invalidate(TextInvalRect());
    202215    }
    203216
    BCountView::CheckCount()  
    207220
    208221
    209222void
     223BCountView::_UpdateCountsAndSizes(int32 selectionCount)
     224{
     225    fFileCount = 0;
     226    fDirCount = 0;
     227    fTotalFilesSize = 0;
     228    fLastCount = fPoseView->CountItems();
     229    fMoreFiles = false;
     230    bool hasSelection = selectionCount==0?false:true;
     231
     232    node_ref ref;
     233    Model* model = fPoseView->TargetModel();
     234    if (model->IsDirectory())
     235        ref = *model->NodeRef();
     236    else {
     237        // we can't check for files and folders if model is not a directory
     238        return;
     239    }
     240
     241    BDirectory dir(&ref);
     242    BEntry entry;
     243    while (dir.GetNextEntry(&entry) == B_OK) {
     244        StatStruct statbuf;
     245        status_t status = entry.GetStat(&statbuf);
     246        if (status != B_OK) {
     247            fMoreFiles = true;
     248            continue;
     249        }
     250
     251        if (S_ISDIR(statbuf.st_mode))
     252            fDirCount++;
     253        else {
     254            fFileCount++;
     255            fTotalFilesSize += statbuf.st_size;
     256        }
     257    }
     258       
     259    BString itemString,selectionString;
     260    BString fileString, folderString, sizeString;
     261    BString empty = "--";
     262    fStatusString = "";
     263    if (IsTypingAhead())
     264        fStatusString << TypeAhead();
     265    else if (IsFiltering()) {
     266        fStatusString << fLastCount << " " << Filter();
     267    } else {
     268        if (fLastCount == 0)
     269            fStatusString << B_TRANSLATE("no items");
     270        else {
     271            if (!hasSelection) {
     272            fStatusString = "";
     273            static BMessageFormat itemFormat(B_TRANSLATE_COMMENT(
     274                "{0, plural, one{# item} other{# items}}",
     275                "Number of selected items: \"1 item\" or \"2 items\""));
     276            itemFormat.Format(itemString, fLastCount);
     277            fStatusString += itemString;
     278
     279            fStatusString += " | ";
     280            static BMessageFormat folderFormat(B_TRANSLATE_COMMENT(
     281                "{0, plural, one{# folder} other{# folders}}",
     282                "Number of selected folders: \"1 folder\" or \"2 folders\""));
     283            folderFormat.Format(folderString, fDirCount);
     284            fStatusString += folderString;
     285
     286            fStatusString += " | ";
     287            static BMessageFormat fileFormat(B_TRANSLATE_COMMENT(
     288                "{0, plural, one{#%more% file} other{#%more% files}} (%size%)",
     289                "Number of selected files: \"1 file\" or \"2 files\""));
     290            fileFormat.Format(fileString, fFileCount);
     291            fileString.ReplaceFirst("%more%", (fMoreFiles?"+":"") );
     292            char sizeBuffer[128];
     293            sizeString = string_for_size((double)fTotalFilesSize,
     294                        sizeBuffer, sizeof(sizeBuffer));
     295            fileString.ReplaceFirst("%size%",
     296                        (sizeString.Length()==0?empty:sizeString));
     297            fStatusString += fileString;
     298            }
     299            else {
     300                fStatusString = "";
     301                static BMessageFormat selectionFormat(B_TRANSLATE_COMMENT(
     302                    "{0, plural, one{# item} other{# items}} selected",
     303                    "Number of selected items: \"1 item selected\""
     304                        "or \"2 items selected\""));
     305                selectionFormat.Format(selectionString, selectionCount);
     306                fStatusString += selectionString;
     307            }
     308        }
     309    }
     310}
     311
     312
     313void
    210314BCountView::Draw(BRect updateRect)
    211315{
    212316    BRect bounds(Bounds());
    BCountView::Draw(BRect updateRect)  
    223327            ViewColor());
    224328    }
    225329
    226     BString itemString;
    227     if (IsTypingAhead())
    228         itemString << TypeAhead();
    229     else if (IsFiltering()) {
    230         itemString << fLastCount << " " << Filter();
    231     } else {
    232         if (fLastCount == 0)
    233             itemString << B_TRANSLATE("no items");
    234         else {
    235             static BMessageFormat format(B_TRANSLATE_COMMENT(
    236                 "{0, plural, one{# item} other{# items}}",
    237                 "Number of selected items: \"1 item\" or \"2 items\""));
    238             format.Format(itemString, fLastCount);
    239         }
    240     }
    241 
    242330    BRect textRect(TextInvalRect());
    243331
    244     TruncateString(&itemString, IsTypingAhead() ? B_TRUNCATE_BEGINNING
     332    TruncateString(&fStatusString, IsTypingAhead() ? B_TRUNCATE_BEGINNING
    245333            : IsFiltering() ? B_TRUNCATE_MIDDLE : B_TRUNCATE_END,
    246334        textRect.Width());
    247335
    BCountView::Draw(BRect updateRect)  
    253341        SetHighColor(0, 0, 0);
    254342
    255343    MovePenTo(textRect.LeftBottom());
    256     DrawString(itemString.String());
     344    DrawString(fStatusString.String());
    257345
    258346    bounds.top++;
    259347
  • src/kits/tracker/CountView.h

    diff --git a/src/kits/tracker/CountView.h b/src/kits/tracker/CountView.h
    index 52ad97e..24009b1 100644
    a b private:  
    7878    BRect TextInvalRect() const;
    7979    BRect TextAndBarberPoleRect() const;
    8080    void TrySpinningBarberPole();
     81    void _UpdateCountsAndSizes(int32);
    8182
    82     int32 fLastCount;
     83    int32 fLastCount, fLastSelectionCount;
     84    int32 fFileCount, fDirCount;
     85    off_t fTotalFilesSize;
    8386    BPoseView* fPoseView;
     87    bool fMoreFiles : 1;
    8488    bool fShowingBarberPole : 1;
    8589    bool fBorderHighlighted : 1;
    8690    BBitmap* fBarberPoleMap;
    8791    float fLastBarberPoleOffset;
    8892    bigtime_t fStartSpinningAfter;
     93    BString fStatusString;
    8994    BString fTypeAheadString;
    9095    BString fFilterString;
    9196};
  • src/kits/tracker/PoseView.cpp

    diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp
    index 486c3c8..9c078e5 100644
    a b using std::max;  
    111111
    112112
    113113const float kDoubleClickTresh = 6;
    114 const float kCountViewWidth = 76;
     114const float kCountViewWidth = 250;
    115115
    116116const uint32 kAddNewPoses = 'Tanp';
    117117const uint32 kAddPosesCompleted = 'Tapc';