diff --git a/src/apps/terminal/SmartTabView.cpp b/src/apps/terminal/SmartTabView.cpp index d40d4cc96c..5f14147c65 100644 --- a/src/apps/terminal/SmartTabView.cpp +++ b/src/apps/terminal/SmartTabView.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -33,7 +34,8 @@ SmartTabView::SmartTabView(BRect frame, const char* name, button_width width, uint32 resizingMode, uint32 flags) : BTabView(frame, name, width, resizingMode, flags), - fInsets(0, 0, 0, 0) + fInsets(0, 0, 0, 0), + fScrollView(NULL) { // Resize the container view to fill the complete tab view for single-tab // mode. Later, when more than one tab is added, we shrink the container @@ -183,13 +185,22 @@ SmartTabView::AddTab(BView* target, BTab* tab) Window()->ResizeBy(0, TabHeight()); } + + // Adapt scroll bar if there is one + if (fScrollView != NULL) { + BScrollBar* bar = fScrollView->ScrollBar(B_VERTICAL); + if (bar != NULL) { + bar->ResizeBy(0, -1); + bar->MoveBy(0, 1); + } + } } Invalidate(TabFrame(CountTabs() - 1).InsetByCopy(-2, -2)); } -BTab * +BTab* SmartTabView::RemoveTab(int32 index) { if (CountTabs() == 2) { @@ -207,6 +218,15 @@ SmartTabView::RemoveTab(int32 index) Window()->ResizeBy(0, -TabHeight()); } + // Adapt scroll bar if there is one + if (fScrollView != NULL) { + BScrollBar* bar = fScrollView->ScrollBar(B_VERTICAL); + if (bar != NULL) { + bar->ResizeBy(0, 1); + bar->MoveBy(0, -1); + } + } + ContainerView()->MoveBy(0, -TabHeight()); ContainerView()->ResizeBy(0, TabHeight()); } @@ -225,6 +245,16 @@ SmartTabView::DrawTabs() } +/*! If you have a vertical scroll view that overlaps with the menu bar, it will + be resized automatically when the tabs are hidden/shown. +*/ +void +SmartTabView::SetScrollView(BScrollView* scrollView) +{ + fScrollView = scrollView; +} + + int32 SmartTabView::_ClickedTabIndex(const BPoint& point) { diff --git a/src/apps/terminal/SmartTabView.h b/src/apps/terminal/SmartTabView.h index 64497ec5a8..a4356fe1e3 100644 --- a/src/apps/terminal/SmartTabView.h +++ b/src/apps/terminal/SmartTabView.h @@ -13,6 +13,7 @@ class BPopUpMenu; +class BScrollView; class SmartTabView : public BTabView { @@ -44,11 +45,14 @@ public: virtual BRect DrawTabs(); + void SetScrollView(BScrollView* scrollView); + private: int32 _ClickedTabIndex(const BPoint& point); private: BRect fInsets; + BScrollView* fScrollView; }; #endif // SMART_TAB_VIEW_H diff --git a/src/apps/terminal/TermScrollView.cpp b/src/apps/terminal/TermScrollView.cpp index f836b4bbf9..9e4150d0a7 100644 --- a/src/apps/terminal/TermScrollView.cpp +++ b/src/apps/terminal/TermScrollView.cpp @@ -12,6 +12,8 @@ #include "TermScrollView.h" +#include + class TermScrollBar : public BScrollBar { public: @@ -31,7 +33,7 @@ public: TermScrollView::TermScrollView(const char* name, BView* child, BView* target, - uint32 resizingMode) + bool overlapTop, uint32 resizingMode) : BScrollView(name, child, resizingMode, 0, false, true, B_NO_BORDER) { @@ -40,8 +42,11 @@ TermScrollView::TermScrollView(const char* name, BView* child, BView* target, BRect frame(fVerticalScrollBar->Frame()); RemoveChild(fVerticalScrollBar); - // Overlap one pixel at the bottom of the scroll bar with - // the resize knob for aesthetical reasons. + // Overlap one pixel at the top (if required) and the bottom of the + // scroll bar with the menu respectively resize knob for aesthetical + // reasons. + if (overlapTop) + frame.top--; frame.bottom -= B_H_SCROLL_BAR_HEIGHT - 1; TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0, diff --git a/src/apps/terminal/TermScrollView.h b/src/apps/terminal/TermScrollView.h index 0ac2a4e324..3bf2a11096 100644 --- a/src/apps/terminal/TermScrollView.h +++ b/src/apps/terminal/TermScrollView.h @@ -11,9 +11,9 @@ class TermScrollView : public BScrollView { public: TermScrollView(const char* name, BView* child, - BView* target, + BView* target, bool overlapTop, uint32 resizingMode = B_FOLLOW_ALL); - ~TermScrollView(); + virtual ~TermScrollView(); }; diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index c2411e7c3b..611578ec8a 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -425,10 +425,11 @@ TermWindow::MessageReceived(BMessage *message) _ActiveTermView()->GetSelection(fFindString); if (fFindString.Length() == 0) { - const char *errorMsg = (!fFindSelection) ? "No search string was entered." : "Nothing is selected."; - BAlert *alert = new BAlert("Find failed", errorMsg, "Ok", NULL, + const char* errorMsg = !fFindSelection + ? "No search string was entered." : "Nothing is selected."; + BAlert* alert = new BAlert("Find failed", errorMsg, "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); - + alert->Go(); fFindPreviousMenuItem->SetEnabled(false); fFindNextMenuItem->SetEnabled(false); @@ -752,21 +753,25 @@ TermWindow::_AddTab(Arguments *args) TermViewContainerView *containerView = new TermViewContainerView(view); BScrollView *scrollView = new TermScrollView("scrollView", - containerView, view); + containerView, view, fSessions.IsEmpty()); + + if (fSessions.IsEmpty()) + fTabView->SetScrollView(scrollView); Session* session = new Session(_NewSessionID(), containerView); session->windowTitle = fInitialTitle; fSessions.AddItem(session); BTab *tab = new BTab; - // TODO: Use a better name. For example, do like MacOsX's Terminal - // and update the title using the last executed command ? - // Or like Gnome's Terminal and use the current path ? fTabView->AddTab(scrollView, tab); tab->SetLabel(session->name.String()); + // TODO: Use a better name. For example, do like MacOS X's Terminal + // and update the title using the last executed command ? + // Or like Gnome's Terminal and use the current path ? view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL)); - view->SetEncoding(EncodingID(PrefHandler::Default()->getString(PREF_TEXT_ENCODING))); + view->SetEncoding(EncodingID( + PrefHandler::Default()->getString(PREF_TEXT_ENCODING))); BFont font; _GetPreferredFont(font); @@ -811,6 +816,11 @@ TermWindow::_RemoveTab(int32 index) { if (fSessions.CountItems() > 1) { if (Session* session = (Session*)fSessions.RemoveItem(index)) { + if (fSessions.CountItems() == 1) { + fTabView->SetScrollView(dynamic_cast( + ((Session*)fSessions.ItemAt(0))->containerView->Parent())); + } + delete session; delete fTabView->RemoveTab(index); if (fFullScreen)