mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +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)
|
||||
{
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue