mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
Taskbar: Add a factory function for QuickLaunchWidget
This helps propagate errors that might happen when constructing the quick launch menu. However, the errors are not propagated all the way yet.
This commit is contained in:
parent
fa1416987a
commit
f40cb8d771
3 changed files with 39 additions and 12 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "QuickLaunchWidget.h"
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <Kernel/API/InodeWatcherFlags.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/FileWatcher.h>
|
||||
|
@ -82,7 +83,25 @@ DeprecatedString QuickLaunchEntryFile::name() const
|
|||
return m_path;
|
||||
}
|
||||
|
||||
QuickLaunchWidget::QuickLaunchWidget()
|
||||
ErrorOr<NonnullRefPtr<QuickLaunchWidget>> QuickLaunchWidget::create()
|
||||
{
|
||||
Vector<NonnullOwnPtr<QuickLaunchEntry>> entries;
|
||||
auto keys = Config::list_keys("Taskbar"sv, quick_launch);
|
||||
for (auto& name : keys) {
|
||||
auto value = Config::read_string("Taskbar"sv, quick_launch, name);
|
||||
auto entry = QuickLaunchEntry::create_from_config_value(value);
|
||||
if (!entry)
|
||||
continue;
|
||||
|
||||
entries.append(entry.release_nonnull());
|
||||
}
|
||||
|
||||
auto widget = TRY(AK::adopt_nonnull_ref_or_enomem(new (nothrow) QuickLaunchWidget(move(entries))));
|
||||
TRY(widget->create_context_menu());
|
||||
return widget;
|
||||
}
|
||||
|
||||
QuickLaunchWidget::QuickLaunchWidget(Vector<NonnullOwnPtr<QuickLaunchEntry>> entries)
|
||||
{
|
||||
set_shrink_to_fit(true);
|
||||
set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
@ -90,8 +109,17 @@ QuickLaunchWidget::QuickLaunchWidget()
|
|||
set_frame_thickness(0);
|
||||
set_fixed_height(24);
|
||||
|
||||
for (auto& entry : entries) {
|
||||
auto name = entry->name();
|
||||
add_or_adjust_button(name, move(entry));
|
||||
}
|
||||
}
|
||||
|
||||
ErrorOr<void> QuickLaunchWidget::create_context_menu()
|
||||
{
|
||||
auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png"sv));
|
||||
m_context_menu = GUI::Menu::construct();
|
||||
m_context_menu_default_action = GUI::Action::create("&Remove", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) {
|
||||
m_context_menu_default_action = GUI::Action::create("&Remove", icon, [this](auto&) {
|
||||
Config::remove_key("Taskbar"sv, quick_launch, m_context_menu_app_name);
|
||||
auto button = find_child_of_type_named<GUI::Button>(m_context_menu_app_name);
|
||||
if (button) {
|
||||
|
@ -100,14 +128,7 @@ QuickLaunchWidget::QuickLaunchWidget()
|
|||
});
|
||||
m_context_menu->add_action(*m_context_menu_default_action);
|
||||
|
||||
auto keys = Config::list_keys("Taskbar"sv, quick_launch);
|
||||
for (auto& name : keys) {
|
||||
auto value = Config::read_string("Taskbar"sv, quick_launch, name);
|
||||
auto entry = QuickLaunchEntry::create_from_config_value(value);
|
||||
if (!entry)
|
||||
continue;
|
||||
add_or_adjust_button(name, entry.release_nonnull());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
OwnPtr<QuickLaunchEntry> QuickLaunchEntry::create_from_config_value(StringView value)
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <LibConfig/Listener.h>
|
||||
#include <LibCore/FileWatcher.h>
|
||||
#include <LibDesktop/AppFile.h>
|
||||
|
@ -78,6 +80,7 @@ class QuickLaunchWidget : public GUI::Frame
|
|||
C_OBJECT(QuickLaunchWidget);
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<QuickLaunchWidget>> create();
|
||||
virtual ~QuickLaunchWidget() override = default;
|
||||
|
||||
virtual void config_key_was_removed(DeprecatedString const&, DeprecatedString const&, DeprecatedString const&) override;
|
||||
|
@ -87,8 +90,10 @@ public:
|
|||
virtual void drop_event(GUI::DropEvent&) override;
|
||||
|
||||
private:
|
||||
QuickLaunchWidget();
|
||||
explicit QuickLaunchWidget(Vector<NonnullOwnPtr<QuickLaunchEntry>> entries);
|
||||
void add_or_adjust_button(DeprecatedString const&, NonnullOwnPtr<QuickLaunchEntry>&&);
|
||||
ErrorOr<void> create_context_menu();
|
||||
|
||||
RefPtr<GUI::Menu> m_context_menu;
|
||||
RefPtr<GUI::Action> m_context_menu_default_action;
|
||||
DeprecatedString m_context_menu_app_name;
|
||||
|
|
|
@ -63,7 +63,8 @@ TaskbarWindow::TaskbarWindow()
|
|||
main_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
main_widget.layout()->set_margins({ 2, 3, 0, 3 });
|
||||
|
||||
m_quick_launch = Taskbar::QuickLaunchWidget::construct();
|
||||
// FIXME: Propagate this error up as well
|
||||
m_quick_launch = MUST(Taskbar::QuickLaunchWidget::create());
|
||||
main_widget.add_child(*m_quick_launch);
|
||||
|
||||
m_task_button_container = main_widget.add<GUI::Widget>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue