diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp index efd72c67f3..1b730157c0 100644 --- a/Userland/Libraries/LibGUI/TabWidget.cpp +++ b/Userland/Libraries/LibGUI/TabWidget.cpp @@ -64,6 +64,22 @@ void TabWidget::remove_widget(Widget& widget) on_tab_count_change(m_tabs.size()); } +void TabWidget::remove_all_tabs_except(Widget& widget) +{ + VERIFY(widget.parent() == this); + set_active_widget(&widget); + m_tabs.remove_all_matching([this, &widget](auto& entry) { + bool is_other = &widget != entry.widget; + if (is_other) + remove_child(*entry.widget); + return is_other; + }); + VERIFY(m_tabs.size() == 1); + update_focus_policy(); + if (on_tab_count_change) + on_tab_count_change(1); +} + void TabWidget::update_focus_policy() { FocusPolicy policy; diff --git a/Userland/Libraries/LibGUI/TabWidget.h b/Userland/Libraries/LibGUI/TabWidget.h index 1cfd6ee6fc..82fec65ada 100644 --- a/Userland/Libraries/LibGUI/TabWidget.h +++ b/Userland/Libraries/LibGUI/TabWidget.h @@ -48,6 +48,7 @@ public: } void remove_tab(Widget& tab) { remove_widget(tab); } + void remove_all_tabs_except(Widget& tab); void set_tab_title(Widget& tab, const StringView& title); void set_tab_icon(Widget& tab, const Gfx::Bitmap*);