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

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

Updated patch, fixed more issues.

  • src/kits/tracker/CountView.cpp

    From 4a41c37a6ea41141a3373603a62bea67d6132899 Mon Sep 17 00:00:00 2001
    From: "Sidhant Sharma [:TigerKid001]" <tigerkid001@gmail.com>
    Date: Fri, 24 Oct 2014 19:41:01 +0530
    Subject: [PATCH] Status line enhancement v1.2
    
    ---
     src/kits/tracker/CountView.cpp | 73 +++++++++++++++++++++++++++++++++++++++---
     src/kits/tracker/CountView.h   |  3 ++
     src/kits/tracker/PoseView.cpp  |  2 +-
     3 files changed, 72 insertions(+), 6 deletions(-)
    
    diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp
    index a1d3c7c..4bd8d08 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
    All rights reserved.  
    5659
    5760
    5861const bigtime_t kBarberPoleDelay = 500000;
    59 
     62bool gMoreFiles;
    6063
    6164//  #pragma mark - BCountView
    6265
    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    fFileCount(0),
     73    fDirCount(0),
     74    fTotalFilesSize(0),
    6975    fPoseView(view),
    7076    fShowingBarberPole(false),
    7177    fBorderHighlighted(false),
    BCountView::CheckCount()  
    198204    // invalidate the count text area if necessary
    199205    if (fLastCount != fPoseView->CountItems()) {
    200206        fLastCount = fPoseView->CountItems();
     207        _UpdateCountsAndSizes();
    201208        Invalidate(TextInvalRect());
    202209    }
    203210
    BCountView::CheckCount()  
    207214
    208215
    209216void
     217BCountView::_UpdateCountsAndSizes()
     218{
     219    fFileCount = 0;
     220    fDirCount = 0;
     221    fTotalFilesSize = 0;
     222    fLastCount = fPoseView->CountItems();
     223    gMoreFiles = false;
     224
     225    node_ref ref;
     226    Model* model = fPoseView->TargetModel();
     227    if (model->IsDirectory())
     228        ref = *model->NodeRef();
     229    else {
     230        // we can't check for files and folders if model is not a directory
     231        return;
     232    }
     233   
     234    BDirectory dir(&ref);
     235    BEntry entry;
     236    while (dir.GetNextEntry(&entry) == B_OK) {
     237        StatStruct statbuf;
     238        status_t status = entry.GetStat(&statbuf);
     239        if (status != B_OK) {
     240            gMoreFiles = true;
     241            continue;
     242        }
     243
     244        if (S_ISDIR(statbuf.st_mode))
     245            fDirCount++;
     246        else {
     247            fFileCount++;
     248            fTotalFilesSize += statbuf.st_size;
     249        }
     250    }
     251}
     252
     253
     254void
    210255BCountView::Draw(BRect updateRect)
    211256{
    212257    BRect bounds(Bounds());
    BCountView::Draw(BRect updateRect)  
    222267        be_control_look->DrawMenuBarBackground(this, bounds, updateRect,
    223268            ViewColor());
    224269    }
    225 
    226270    BString itemString;
     271    BString fileString, folderString, sizeString;
    227272    if (IsTypingAhead())
    228273        itemString << TypeAhead();
    229274    else if (IsFiltering()) {
    BCountView::Draw(BRect updateRect)  
    232277        if (fLastCount == 0)
    233278            itemString << B_TRANSLATE("no items");
    234279        else {
    235             static BMessageFormat format(B_TRANSLATE_COMMENT(
     280            static BMessageFormat itemFormat(B_TRANSLATE_COMMENT(
    236281                "{0, plural, one{# item} other{# items}}",
    237282                "Number of selected items: \"1 item\" or \"2 items\""));
    238             format.Format(itemString, fLastCount);
     283            itemFormat.Format(itemString, fLastCount);
     284
     285            itemString += " | ";
     286            static BMessageFormat folderFormat(B_TRANSLATE_COMMENT(
     287                "{0, plural, one{# folder} other{# folders}}",
     288                "Number of selected folders: \"1 folder\" or \"2 folders\""));
     289            folderFormat.Format(folderString, fDirCount);
     290            itemString += folderString;
     291
     292            itemString += " | ";
     293            static BMessageFormat fileFormat(B_TRANSLATE_COMMENT(
     294                "{0, plural, one{#%more% file} other{#%more% files}} (%size%)",
     295                "Number of selected files: \"1 file\" or \"2 files\""));
     296            fileFormat.Format(fileString, fFileCount);
     297            fileString.ReplaceFirst("%more%", (gMoreFiles?"+":"") );
     298            char sizeBuffer[128];
     299            sizeString = string_for_size((double)fTotalFilesSize,
     300                        sizeBuffer, sizeof(sizeBuffer));
     301            fileString.ReplaceFirst("%size%", sizeString);
     302            itemString += fileString;
    239303        }
    240304    }
    241 
    242305    BRect textRect(TextInvalRect());
    243306
    244307    TruncateString(&itemString, IsTypingAhead() ? B_TRUNCATE_BEGINNING
  • src/kits/tracker/CountView.h

    diff --git a/src/kits/tracker/CountView.h b/src/kits/tracker/CountView.h
    index 52ad97e..2ec5007 100644
    a b private:  
    7878    BRect TextInvalRect() const;
    7979    BRect TextAndBarberPoleRect() const;
    8080    void TrySpinningBarberPole();
     81    void _UpdateCountsAndSizes();
    8182
    8283    int32 fLastCount;
     84    int32 fFileCount, fDirCount;
     85    off_t fTotalFilesSize;
    8386    BPoseView* fPoseView;
    8487    bool fShowingBarberPole : 1;
    8588    bool fBorderHighlighted : 1;
  • src/kits/tracker/PoseView.cpp

    diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp
    index ae04731..a13b00c 100644
    a b using std::max;  
    113113
    114114
    115115const float kDoubleClickTresh = 6;
    116 const float kCountViewWidth = 76;
     116const float kCountViewWidth = 250;
    117117
    118118const uint32 kAddNewPoses = 'Tanp';
    119119const uint32 kAddPosesCompleted = 'Tapc';