mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
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
This commit is contained in:
parent
2dd7fa2d44
commit
b79be56bed
2 changed files with 32 additions and 1 deletions
|
@ -53,7 +53,7 @@ TabWidget::TabWidget()
|
||||||
|
|
||||||
ErrorOr<void> TabWidget::try_add_widget(Widget& widget)
|
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);
|
add_child(widget);
|
||||||
update_focus_policy();
|
update_focus_policy();
|
||||||
if (on_tab_count_change)
|
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()
|
void TabWidget::activate_next_tab()
|
||||||
{
|
{
|
||||||
if (m_tabs.size() <= 1)
|
if (m_tabs.size() <= 1)
|
||||||
|
|
|
@ -79,6 +79,10 @@ public:
|
||||||
void set_tab_title(Widget& tab, StringView title);
|
void set_tab_title(Widget& tab, StringView title);
|
||||||
void set_tab_icon(Widget& tab, Gfx::Bitmap const*);
|
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_next_tab();
|
||||||
void activate_previous_tab();
|
void activate_previous_tab();
|
||||||
void activate_last_tab();
|
void activate_last_tab();
|
||||||
|
@ -139,6 +143,7 @@ private:
|
||||||
DeprecatedString title;
|
DeprecatedString title;
|
||||||
RefPtr<Gfx::Bitmap> icon;
|
RefPtr<Gfx::Bitmap> icon;
|
||||||
Widget* widget { nullptr };
|
Widget* widget { nullptr };
|
||||||
|
bool modified { false };
|
||||||
};
|
};
|
||||||
Vector<TabData> m_tabs;
|
Vector<TabData> m_tabs;
|
||||||
TabPosition m_tab_position { TabPosition::Top };
|
TabPosition m_tab_position { TabPosition::Top };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue