1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +00:00

Taskbar/QuickLaunchWidget: Small cleanup

This commit is contained in:
david072 2023-11-05 12:34:39 +01:00 committed by Andreas Kling
parent e100c1458a
commit 2d29a96dbe
2 changed files with 14 additions and 10 deletions

View file

@ -315,8 +315,7 @@ ErrorOr<void> QuickLaunchWidget::create_context_menu()
m_context_menu = GUI::Menu::construct(); m_context_menu = GUI::Menu::construct();
m_context_menu_default_action = GUI::Action::create("&Remove", icon, [this](auto&) { m_context_menu_default_action = GUI::Action::create("&Remove", icon, [this](auto&) {
remove_entry(m_context_menu_app_name); remove_entry(m_context_menu_app_name);
resize(); repaint();
update();
}); });
m_context_menu->add_action(*m_context_menu_default_action); m_context_menu->add_action(*m_context_menu_default_action);
@ -333,7 +332,6 @@ void QuickLaunchWidget::load_entries(bool save)
Vector<ConfigEntry> config_entries; Vector<ConfigEntry> config_entries;
auto keys = Config::list_keys(CONFIG_DOMAIN, CONFIG_GROUP_ENTRIES); auto keys = Config::list_keys(CONFIG_DOMAIN, CONFIG_GROUP_ENTRIES);
for (auto& name : keys) { for (auto& name : keys) {
dbgln("loading key: {}", name);
auto value = Config::read_string(CONFIG_DOMAIN, CONFIG_GROUP_ENTRIES, name); auto value = Config::read_string(CONFIG_DOMAIN, CONFIG_GROUP_ENTRIES, name);
auto values = value.split(':'); auto values = value.split(':');
@ -353,6 +351,7 @@ void QuickLaunchWidget::load_entries(bool save)
entries.append(entry.release_nonnull()); entries.append(entry.release_nonnull());
} }
m_entries.clear();
add_entries(move(entries), save); add_entries(move(entries), save);
} }
@ -365,8 +364,7 @@ void QuickLaunchWidget::add_entries(Vector<NonnullOwnPtr<QuickLaunchEntry>> entr
Config::write_string(CONFIG_DOMAIN, CONFIG_GROUP_ENTRIES, sanitize_name(m_entries.last()->name()), entry_to_config_string(m_entries.size() - 1, m_entries.last())); Config::write_string(CONFIG_DOMAIN, CONFIG_GROUP_ENTRIES, sanitize_name(m_entries.last()->name()), entry_to_config_string(m_entries.size() - 1, m_entries.last()));
} }
resize(); repaint();
update();
} }
ErrorOr<void> QuickLaunchWidget::update_entry(DeprecatedString const& button_name, NonnullOwnPtr<QuickLaunchEntry> entry, bool save) ErrorOr<void> QuickLaunchWidget::update_entry(DeprecatedString const& button_name, NonnullOwnPtr<QuickLaunchEntry> entry, bool save)
@ -378,16 +376,14 @@ ErrorOr<void> QuickLaunchWidget::update_entry(DeprecatedString const& button_nam
m_watcher->on_change = [button_name, save, this](Core::FileWatcherEvent const&) { m_watcher->on_change = [button_name, save, this](Core::FileWatcherEvent const&) {
dbgln("Removing QuickLaunch entry \"{}\"", button_name); dbgln("Removing QuickLaunch entry \"{}\"", button_name);
remove_entry(button_name, save); remove_entry(button_name, save);
resize(); repaint();
update();
}; };
} }
TRY(m_watcher->add_watch(file_name_to_watch, Core::FileWatcherEvent::Type::Deleted)); TRY(m_watcher->add_watch(file_name_to_watch, Core::FileWatcherEvent::Type::Deleted));
} }
set_or_insert_entry(move(entry), save); set_or_insert_entry(move(entry), save);
resize(); repaint();
update();
return {}; return {};
} }
@ -404,7 +400,13 @@ void QuickLaunchWidget::for_each_entry(Callback callback)
void QuickLaunchWidget::resize() void QuickLaunchWidget::resize()
{ {
set_fixed_width(m_entries.size() * BUTTON_SIZE); set_fixed_width(static_cast<int>(m_entries.size()) * BUTTON_SIZE);
}
void QuickLaunchWidget::repaint()
{
resize();
update();
} }
void QuickLaunchWidget::set_or_insert_entry(NonnullOwnPtr<QuickLaunchEntry> entry, bool save) void QuickLaunchWidget::set_or_insert_entry(NonnullOwnPtr<QuickLaunchEntry> entry, bool save)

View file

@ -138,6 +138,8 @@ private:
void resize(); void resize();
void repaint();
void set_or_insert_entry(NonnullOwnPtr<QuickLaunchEntry>, bool save = true); void set_or_insert_entry(NonnullOwnPtr<QuickLaunchEntry>, bool save = true);
void remove_entry(DeprecatedString const&, bool save = true); void remove_entry(DeprecatedString const&, bool save = true);
void recalculate_order(); void recalculate_order();