From 9fb72ec18e1a861a74575c8e1378477e6e51d5c6 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 1 Jun 2015 19:31:05 -0400 Subject: [PATCH] Expander: don't scroll to the end if the user modifies the scrollbar position. Fixes #11027. This preserves the functionality of scroll-to-end while allowing the user to interrupt it (and resume it, in the case of extremely long archives). --- src/apps/expander/ExpanderWindow.cpp | 20 +++++++++++++++----- src/apps/expander/ExpanderWindow.h | 2 ++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/apps/expander/ExpanderWindow.cpp b/src/apps/expander/ExpanderWindow.cpp index 63d2cdaf02..44b122e8c5 100644 --- a/src/apps/expander/ExpanderWindow.cpp +++ b/src/apps/expander/ExpanderWindow.cpp @@ -91,8 +91,8 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref, fListingText->SetWordWrap(false); BFont font = be_fixed_font; fListingText->SetFontAndColor(&font); - BScrollView* scrollView = new BScrollView("", fListingText, - B_INVALIDATE_AFTER_LAYOUT, true, true); + fScrollView = 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 @@ -127,14 +127,14 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref, .End() .End() .End() - .Add(scrollView) + .Add(fScrollView) .SetInsets(spacing, spacing, spacing, spacing) .End() .End(); pathLayout->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); size = GetLayout()->View()->PreferredSize(); - fSizeLimit = size.Height() - scrollView->PreferredSize().height - spacing; + fSizeLimit = size.Height() - fScrollView->PreferredSize().height - spacing; ResizeTo(Bounds().Width(), fSizeLimit); SetSizeLimits(size.Width(), 32767.0f, fSizeLimit, fSizeLimit); @@ -369,6 +369,12 @@ ExpanderWindow::MessageReceived(BMessage* message) case 'outp': if (!fExpandingStarted && fListingStarted) { + // Check if the vertical scroll bar is at the end + float max, pos; + fScrollView->ScrollBar(B_VERTICAL)->GetRange(NULL, &max); + pos = fScrollView->ScrollBar(B_VERTICAL)->Value(); + bool atEnd = (pos == max); + BString string; int32 i = 0; while (message->FindString("output", i++, &string) == B_OK) { @@ -379,7 +385,11 @@ ExpanderWindow::MessageReceived(BMessage* message) fListingText->Insert(string.String()); } - fListingText->ScrollToSelection(); + + if (atEnd && fScrollView->ScrollBar(B_VERTICAL)->Value() == pos) { + fScrollView->ScrollBar(B_VERTICAL)->GetRange(NULL, &max); + fScrollView->ScrollBar(B_VERTICAL)->SetValue(max); + } } else if (fExpandingStarted) { BString string; int32 i = 0; diff --git a/src/apps/expander/ExpanderWindow.h b/src/apps/expander/ExpanderWindow.h index 8d324cd7a7..fbbfac7e19 100644 --- a/src/apps/expander/ExpanderWindow.h +++ b/src/apps/expander/ExpanderWindow.h @@ -20,6 +20,7 @@ class BCheckBox; class BMenu; class BLayout; +class BScrollView; class BStringView; class BTextControl; class BTextView; @@ -80,6 +81,7 @@ private: BTextControl* fDestText; BStringView* fStatusView; BTextView* fListingText; + BScrollView* fScrollView; ExpanderThread* fListingThread; bool fListingStarted;