Ticket #5289: 0001-Expander-fix-status-view.patch

File 0001-Expander-fix-status-view.patch, 6.0 KB (added by KapiX, 8 years ago)

This patch removes the workaround and fixes the issue.

  • src/apps/expander/ExpanderWindow.cpp

    From 3e8c60c4e81345a9623264a8857a87c159608b87 Mon Sep 17 00:00:00 2001
    From: Kacper Kasper <kacperkasper@gmail.com>
    Date: Fri, 19 Aug 2016 23:31:02 +0000
    Subject: [PATCH] Expander: fix status view.
    
    * Truncate() would cut Unicode characters in the middle.
    * This commit removes arbitrary message length limit as well as workaround
      it was needed for and fixes #5289.
    * Status view now expands to maximum possible width and cuts the status
      message if necessary using TruncateString().
    ---
     src/apps/expander/ExpanderWindow.cpp | 74 ++++++++++++++++++++++--------------
     src/apps/expander/ExpanderWindow.h   |  4 +-
     2 files changed, 47 insertions(+), 31 deletions(-)
    
    diff --git a/src/apps/expander/ExpanderWindow.cpp b/src/apps/expander/ExpanderWindow.cpp
    index 59b657d..11e7a41 100644
    a b const uint32 MSG_SOURCETEXT = 'mSTX';  
    4545const uint32 MSG_DESTTEXT       = 'mDTX';
    4646const uint32 MSG_SHOWCONTENTS   = 'mSCT';
    4747
    48 const int32 MAX_STATUS_LENGTH   = 35;
     48
     49class StatusView : public BStringView {
     50public:
     51    StatusView()
     52        :
     53        BStringView(NULL, "")
     54    {
     55    }
     56    virtual ~StatusView()
     57    {
     58    }
     59
     60    void SetStatus(const BString &text)
     61    {
     62        fStatus = text;
     63        Invalidate();
     64    }
     65
     66    void Draw(BRect updateRect)
     67    {
     68        BString truncated = fStatus;
     69        if(fStatus.IsEmpty() == false) {
     70            be_plain_font->TruncateString(&truncated, B_TRUNCATE_END,
     71                Bounds().Width());
     72        }
     73
     74        SetText(truncated);
     75        BStringView::Draw(updateRect);
     76    }
     77
     78private:
     79    BString fStatus;
     80};
    4981
    5082
    5183#undef B_TRANSLATION_CONTEXT
    ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,  
    94126    fScrollView = new BScrollView("", fListingText, B_INVALIDATE_AFTER_LAYOUT,
    95127        true, true);
    96128
    97     // workaround to let the layout manager estimate
    98     // the width of status view and fix the #5289
    99     // we assume that spaces are twice narrower than normal chars
    100     BString statusPlaceholderString;
    101     statusPlaceholderString.SetTo(' ', MAX_STATUS_LENGTH * 2);
    102 
    103129    const float spacing = be_control_look->DefaultItemSpacing();
    104130    BGroupLayout* pathLayout;
    105131    BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
    ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,  
    122148                    .Add(fShowContents = new BCheckBox(
    123149                        B_TRANSLATE("Show contents"),
    124150                        new BMessage(MSG_SHOWCONTENTS)))
    125                     .Add(fStatusView = new BStringView(NULL,
    126                         statusPlaceholderString))
     151                    .Add(fStatusView = new StatusView())
    127152                    .End()
    128153                .End()
    129154            .Add(fScrollView)
    ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,  
    134159    size = GetLayout()->View()->PreferredSize();
    135160    fSizeLimit = size.Height() - fScrollView->PreferredSize().height - spacing;
    136161
     162    fStatusView->SetExplicitMinSize(BSize(50.0f, B_SIZE_UNSET));
     163    fStatusView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
     164
    137165    ResizeTo(Bounds().Width(), fSizeLimit);
    138166    SetSizeLimits(size.Width(), 32767.0f, fSizeLimit, fSizeLimit);
    139167    SetZoomLimits(Bounds().Width(), fSizeLimit);
    ExpanderWindow::MessageReceived(BMessage* message)  
    443471            // (finished, quit, killed, we don't know)
    444472            // reset window state
    445473            if (fExpandingStarted) {
    446                 SetStatus(B_TRANSLATE("File expanded"));
     474                fStatusView->SetStatus(B_TRANSLATE("File expanded"));
    447475                StopExpanding();
    448476                OpenDestFolder();
    449477                CloseWindowOrKeepOpen();
    ExpanderWindow::MessageReceived(BMessage* message)  
    452480                StopListing();
    453481                _ExpandListingText();
    454482            } else
    455                 SetStatus("");
     483                fStatusView->SetStatus("");
    456484            break;
    457485
    458486        case 'exrr':
    459487            // thread has finished
    460488            // reset window state
    461489
    462             SetStatus(B_TRANSLATE("Error when expanding archive"));
     490            fStatusView->SetStatus(B_TRANSLATE("Error when expanding archive"));
    463491            CloseWindowOrKeepOpen();
    464492            break;
    465493
    ExpanderWindow::StartExpanding()  
    649677
    650678    BEntry entry(&fSourceRef);
    651679    BPath path(&entry);
    652     BString text(B_TRANSLATE("Expanding '%s'"));
     680    BString text(B_TRANSLATE("Expanding '%s'" B_UTF8_ELLIPSIS));
    653681    text.ReplaceFirst("%s", path.Leaf());
    654     SetStatus(text.String());
     682    fStatusView->SetStatus(text.String());
    655683
    656684    fExpandingThread = new ExpanderThread(&message, new BMessenger(this));
    657685    fExpandingThread->Start();
    ExpanderWindow::_UpdateWindowSize(bool showContents)  
    751779
    752780
    753781void
    754 ExpanderWindow::SetStatus(BString text)
    755 {
    756     if (text.Length() >= MAX_STATUS_LENGTH) {
    757         text.Truncate(MAX_STATUS_LENGTH - 1);
    758         text << B_UTF8_ELLIPSIS;
    759     }
    760 
    761     fStatusView->SetText(text);
    762 }
    763 
    764 
    765 void
    766782ExpanderWindow::StartListing()
    767783{
    768784    _UpdateWindowSize(true);
    ExpanderWindow::StartListing()  
    797813
    798814    BEntry entry(&fSourceRef);
    799815    BPath path(&entry);
    800     BString text(B_TRANSLATE("Creating listing for '%s'"));
     816    BString text(B_TRANSLATE("Creating listing for '%s'" B_UTF8_ELLIPSIS));
    801817    text.ReplaceFirst("%s", path.Leaf());
    802     SetStatus(text.String());
     818    fStatusView->SetStatus(text.String());
    803819    fListingText->SetText("");
    804820
    805821    fListingThread = new ExpanderThread(&message, new BMessenger(this));
    ExpanderWindow::StopListing(void)  
    830846    fSourceButton->SetEnabled(true);
    831847    fDestButton->SetEnabled(true);
    832848    fExpandButton->SetEnabled(true);
    833     SetStatus("");
     849    fStatusView->SetStatus("");
    834850}
    835851
    836852
  • src/apps/expander/ExpanderWindow.h

    diff --git a/src/apps/expander/ExpanderWindow.h b/src/apps/expander/ExpanderWindow.h
    index fbbfac7..3cf18c6 100644
    a b class BTextView;  
    2727
    2828class ExpanderThread;
    2929class ExpanderPreferences;
     30class StatusView;
    3031
    3132
    3233class ExpanderWindow : public BWindow {
    private:  
    5556            void                _ExpandListingText();
    5657            void                StartListing();
    5758            void                StopListing();
    58             void                SetStatus(BString text);
    5959            bool                ValidateDest();
    6060
    6161private:
    private:  
    7979            BCheckBox*          fShowContents;
    8080            BTextControl*       fSourceText;
    8181            BTextControl*       fDestText;
    82             BStringView*        fStatusView;
     82            StatusView*     fStatusView;
    8383            BTextView*          fListingText;
    8484            BScrollView*        fScrollView;
    8585