Skip to content

Commit

Permalink
Hint to layout manager for window width estimation
Browse files Browse the repository at this point in the history
Fixes #5289

Signed-off-by: Siarzhuk Zharski <zharik@gmx.li>
  • Loading branch information
posobin authored and siarzhuk committed Dec 12, 2012
1 parent be56273 commit a51eefd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/apps/expander/ExpanderWindow.cpp
Expand Up @@ -43,6 +43,8 @@ const uint32 MSG_SOURCETEXT = 'mSTX';
const uint32 MSG_DESTTEXT = 'mDTX';
const uint32 MSG_SHOWCONTENTS = 'mSCT';

const int32 MAX_STATUS_LENGTH = 35;


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ExpanderWindow"
Expand Down Expand Up @@ -92,6 +94,12 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,
BScrollView* scrollView = new BScrollView("", fListingText,
B_INVALIDATE_AFTER_LAYOUT, true, true);

// workaround to let the layout manager estimate
// the width of status view and fix the #5289
// we assume that spaces are twice narrower than normal chars
BString statusPlaceholderString;
statusPlaceholderString.SetTo(' ', MAX_STATUS_LENGTH * 2);

BView* topView = layout->View();
const float spacing = be_control_look->DefaultItemSpacing();
topView->AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing)
Expand All @@ -110,7 +118,8 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,
.Add(fShowContents = new BCheckBox(
B_TRANSLATE("Show contents"),
new BMessage(MSG_SHOWCONTENTS)))
.Add(fStatusView = new BStringView(NULL, NULL))
.Add(fStatusView = new BStringView(NULL,
statusPlaceholderString))
.End()
.End()
.End()
Expand Down Expand Up @@ -412,7 +421,7 @@ ExpanderWindow::MessageReceived(BMessage* msg)
// thread has finished (finished, quit, killed, we don't know)
// reset window state
if (fExpandingStarted) {
fStatusView->SetText(B_TRANSLATE("File expanded"));
SetStatus(B_TRANSLATE("File expanded"));
StopExpanding();
OpenDestFolder();
CloseWindowOrKeepOpen();
Expand All @@ -421,13 +430,13 @@ ExpanderWindow::MessageReceived(BMessage* msg)
StopListing();
_ExpandListingText();
} else
fStatusView->SetText("");
SetStatus("");
break;

case 'exrr': // thread has finished
// reset window state

fStatusView->SetText(B_TRANSLATE("Error when expanding archive"));
SetStatus(B_TRANSLATE("Error when expanding archive"));
CloseWindowOrKeepOpen();
break;

Expand Down Expand Up @@ -614,7 +623,7 @@ ExpanderWindow::StartExpanding()
BPath path(&entry);
BString text(B_TRANSLATE("Expanding '%s'"));
text.ReplaceFirst("%s", path.Leaf());
fStatusView->SetText(text.String());
SetStatus(text.String());

fExpandingThread = new ExpanderThread(&message, new BMessenger(this));
fExpandingThread->Start();
Expand Down Expand Up @@ -713,6 +722,18 @@ ExpanderWindow::_UpdateWindowSize(bool showContents)
}


void
ExpanderWindow::SetStatus(BString text)
{
if (text.Length() >= MAX_STATUS_LENGTH) {
text.Truncate(MAX_STATUS_LENGTH - 1);
text << B_UTF8_ELLIPSIS;
}

fStatusView->SetText(text);
}


void
ExpanderWindow::StartListing()
{
Expand Down Expand Up @@ -750,7 +771,7 @@ ExpanderWindow::StartListing()
BPath path(&entry);
BString text(B_TRANSLATE("Creating listing for '%s'"));
text.ReplaceFirst("%s", path.Leaf());
fStatusView->SetText(text.String());
SetStatus(text.String());
fListingText->SetText("");

fListingThread = new ExpanderThread(&message, new BMessenger(this));
Expand Down Expand Up @@ -781,7 +802,7 @@ ExpanderWindow::StopListing(void)
fSourceButton->SetEnabled(true);
fDestButton->SetEnabled(true);
fExpandButton->SetEnabled(true);
fStatusView->SetText("");
SetStatus("");
}


Expand Down
1 change: 1 addition & 0 deletions src/apps/expander/ExpanderWindow.h
Expand Up @@ -54,6 +54,7 @@ class ExpanderWindow : public BWindow {
void _ExpandListingText();
void StartListing();
void StopListing();
void SetStatus(BString text);
bool ValidateDest();

private:
Expand Down

0 comments on commit a51eefd

Please sign in to comment.