diff options
author | meiskam <634802+meiskam@users.noreply.github.com> | 2022-11-04 04:48:47 -0400 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-15 00:14:35 -0700 |
commit | b79be56beda4877735a430eba0bc34ee312d864a (patch) | |
tree | 7c9f1f02947b98f67c823e1e48b5ceb7a5903199 | |
parent | 2dd7fa2d445665ae41db2dd0e1fe7b404e525a57 (diff) | |
download | serenity-b79be56beda4877735a430eba0bc34ee312d864a.zip |
LibGUI: Add `modified` bool to TabWidget
This will allow application with multiple tabs to track modifications
per-tab, not just if the entire window has been modified
-rw-r--r-- | Userland/Libraries/LibGUI/TabWidget.cpp | 28 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TabWidget.h | 5 |
2 files changed, 32 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp index 3bb1c336d5..da523b0867 100644 --- a/Userland/Libraries/LibGUI/TabWidget.cpp +++ b/Userland/Libraries/LibGUI/TabWidget.cpp @@ -53,7 +53,7 @@ TabWidget::TabWidget() ErrorOr<void> TabWidget::try_add_widget(Widget& widget) { - m_tabs.append({ widget.title(), nullptr, &widget }); + m_tabs.append({ widget.title(), nullptr, &widget, false }); add_child(widget); update_focus_policy(); if (on_tab_count_change) @@ -603,6 +603,32 @@ void TabWidget::set_tab_icon(Widget& tab, Gfx::Bitmap const* icon) } } +bool TabWidget::is_tab_modified(Widget& tab_input) +{ + auto it = m_tabs.find_if([&](auto t) { return t.widget == &tab_input; }); + if (it.is_end()) + return false; + auto& tab = *it; + return tab.modified; +} + +void TabWidget::set_tab_modified(Widget& tab_input, bool modified) +{ + auto it = m_tabs.find_if([&](auto t) { return t.widget == &tab_input; }); + if (it.is_end()) + return; + auto& tab = *it; + if (tab.modified != modified) { + tab.modified = modified; + update(); + } +} + +bool TabWidget::is_any_tab_modified() +{ + return any_of(m_tabs, [](auto& t) { return t.modified; }); +} + void TabWidget::activate_next_tab() { if (m_tabs.size() <= 1) diff --git a/Userland/Libraries/LibGUI/TabWidget.h b/Userland/Libraries/LibGUI/TabWidget.h index 68505769f2..47a383a0a2 100644 --- a/Userland/Libraries/LibGUI/TabWidget.h +++ b/Userland/Libraries/LibGUI/TabWidget.h @@ -79,6 +79,10 @@ public: void set_tab_title(Widget& tab, StringView title); void set_tab_icon(Widget& tab, Gfx::Bitmap const*); + bool is_tab_modified(Widget& tab); + void set_tab_modified(Widget& tab, bool modified); + bool is_any_tab_modified(); + void activate_next_tab(); void activate_previous_tab(); void activate_last_tab(); @@ -139,6 +143,7 @@ private: DeprecatedString title; RefPtr<Gfx::Bitmap> icon; Widget* widget { nullptr }; + bool modified { false }; }; Vector<TabData> m_tabs; TabPosition m_tab_position { TabPosition::Top }; |