mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 23:48:11 +00:00

The QuickLaunchWidget now renders the buttons on its own, in preparation for allowing the user to reorder the widget's entries.
137 lines
4.1 KiB
C++
137 lines
4.1 KiB
C++
/*
|
|
* Copyright (c) 2021, Fabian Blatz <fabianblatz@gmail.com>
|
|
* Copyright (c) 2023, David Ganz <david.g.ganz@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/RefPtr.h>
|
|
#include <LibConfig/Listener.h>
|
|
#include <LibCore/FileWatcher.h>
|
|
#include <LibDesktop/AppFile.h>
|
|
#include <LibGUI/Button.h>
|
|
#include <LibGUI/Frame.h>
|
|
#include <LibGfx/Rect.h>
|
|
|
|
namespace Taskbar {
|
|
|
|
class QuickLaunchEntry {
|
|
public:
|
|
virtual ~QuickLaunchEntry() = default;
|
|
virtual ErrorOr<void> launch() const = 0;
|
|
virtual GUI::Icon icon() const = 0;
|
|
virtual DeprecatedString name() const = 0;
|
|
virtual DeprecatedString file_name_to_watch() const = 0;
|
|
|
|
static OwnPtr<QuickLaunchEntry> create_from_config_value(StringView path);
|
|
static OwnPtr<QuickLaunchEntry> create_from_path(StringView path);
|
|
|
|
bool is_hovered() const { return m_hovered; }
|
|
void set_hovered(bool hovered) { m_hovered = hovered; }
|
|
|
|
void set_pressed(bool pressed) { m_pressed = pressed; }
|
|
bool is_pressed() const { return m_pressed; }
|
|
|
|
private:
|
|
bool m_hovered { false };
|
|
bool m_pressed { false };
|
|
};
|
|
|
|
class QuickLaunchEntryAppFile : public QuickLaunchEntry {
|
|
public:
|
|
explicit QuickLaunchEntryAppFile(NonnullRefPtr<Desktop::AppFile> file)
|
|
: m_app_file(move(file))
|
|
{
|
|
}
|
|
|
|
virtual ErrorOr<void> launch() const override;
|
|
virtual GUI::Icon icon() const override { return m_app_file->icon(); }
|
|
virtual DeprecatedString name() const override { return m_app_file->name(); }
|
|
virtual DeprecatedString file_name_to_watch() const override { return {}; }
|
|
|
|
private:
|
|
NonnullRefPtr<Desktop::AppFile> m_app_file;
|
|
};
|
|
|
|
class QuickLaunchEntryExecutable : public QuickLaunchEntry {
|
|
public:
|
|
explicit QuickLaunchEntryExecutable(DeprecatedString path)
|
|
: m_path(move(path))
|
|
{
|
|
}
|
|
|
|
virtual ErrorOr<void> launch() const override;
|
|
virtual GUI::Icon icon() const override;
|
|
virtual DeprecatedString name() const override;
|
|
virtual DeprecatedString file_name_to_watch() const override { return m_path; }
|
|
|
|
private:
|
|
DeprecatedString m_path;
|
|
};
|
|
class QuickLaunchEntryFile : public QuickLaunchEntry {
|
|
public:
|
|
explicit QuickLaunchEntryFile(DeprecatedString path)
|
|
: m_path(move(path))
|
|
{
|
|
}
|
|
|
|
virtual ErrorOr<void> launch() const override;
|
|
virtual GUI::Icon icon() const override;
|
|
virtual DeprecatedString name() const override;
|
|
virtual DeprecatedString file_name_to_watch() const override { return m_path; }
|
|
|
|
private:
|
|
DeprecatedString m_path;
|
|
};
|
|
|
|
class QuickLaunchWidget : public GUI::Frame
|
|
, public Config::Listener {
|
|
C_OBJECT(QuickLaunchWidget);
|
|
|
|
public:
|
|
static ErrorOr<NonnullRefPtr<QuickLaunchWidget>> create();
|
|
virtual ~QuickLaunchWidget() override = default;
|
|
|
|
virtual void config_key_was_removed(StringView, StringView, StringView) override;
|
|
virtual void config_string_did_change(StringView, StringView, StringView, StringView) override;
|
|
|
|
virtual void drag_enter_event(GUI::DragEvent&) override;
|
|
virtual void drop_event(GUI::DropEvent&) override;
|
|
|
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
|
virtual void mousemove_event(GUI::MouseEvent&) override;
|
|
virtual void mouseup_event(GUI::MouseEvent&) override;
|
|
virtual void context_menu_event(GUI::ContextMenuEvent&) override;
|
|
|
|
virtual void leave_event(Core::Event&) override;
|
|
|
|
virtual void paint_event(GUI::PaintEvent&) override;
|
|
|
|
ErrorOr<bool> add_from_pid(pid_t pid);
|
|
|
|
private:
|
|
explicit QuickLaunchWidget();
|
|
ErrorOr<void> add_or_adjust_button(DeprecatedString const&, NonnullOwnPtr<QuickLaunchEntry>);
|
|
ErrorOr<void> create_context_menu();
|
|
void add_quick_launch_buttons(Vector<NonnullOwnPtr<QuickLaunchEntry>> entries);
|
|
|
|
template<typename Callback>
|
|
void for_each_entry(Callback);
|
|
|
|
void resize();
|
|
|
|
void set_or_insert_entry(NonnullOwnPtr<QuickLaunchEntry>);
|
|
void remove_entry(DeprecatedString const&);
|
|
|
|
RefPtr<GUI::Menu> m_context_menu;
|
|
RefPtr<GUI::Action> m_context_menu_default_action;
|
|
DeprecatedString m_context_menu_app_name;
|
|
RefPtr<Core::FileWatcher> m_watcher;
|
|
|
|
Vector<NonnullOwnPtr<QuickLaunchEntry>> m_entries;
|
|
};
|
|
|
|
}
|