From 52474b49a3282f5119c61c2657b8d85d0b070639 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 19 Nov 2010 01:06:02 +0000 Subject: [PATCH] Added MoveTab() method. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39489 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/SmartTabView.cpp | 23 +++++++++++++++++++++++ src/apps/terminal/SmartTabView.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/apps/terminal/SmartTabView.cpp b/src/apps/terminal/SmartTabView.cpp index f13dc52adf..23cc198b7c 100644 --- a/src/apps/terminal/SmartTabView.cpp +++ b/src/apps/terminal/SmartTabView.cpp @@ -206,6 +206,29 @@ SmartTabView::RemoveTab(int32 index) } +void +SmartTabView::MoveTab(int32 index, int32 newIndex) +{ + // check the indexes + int32 count = CountTabs(); + if (index == newIndex || index < 0 || newIndex < 0 || index >= count + || newIndex >= count) { + return; + } + + // Remove the tab from its position and add it to the end. Then cycle the + // tabs starting after the new position (save the tab already moved) to the + // end. + BTab* tab = BTabView::RemoveTab(index); + BTabView::AddTab(tab->View(), tab); + + for (int32 i = newIndex; i < count - 1; i++) { + tab = BTabView::RemoveTab(newIndex); + BTabView::AddTab(tab->View(), tab); + } +} + + BRect SmartTabView::DrawTabs() { diff --git a/src/apps/terminal/SmartTabView.h b/src/apps/terminal/SmartTabView.h index 64df4aa518..cc6e49c7e0 100644 --- a/src/apps/terminal/SmartTabView.h +++ b/src/apps/terminal/SmartTabView.h @@ -48,6 +48,7 @@ public: virtual void AddTab(BView* target, BTab* tab = NULL); virtual BTab* RemoveTab(int32 index); + void MoveTab(int32 index, int32 newIndex); virtual BRect DrawTabs();