ClipboardHistory: Ensure model is populated on startup

This ensures that, if the applet restarts, it will remain in sync with
the clipboard.
This commit is contained in:
Tim Ledbetter 2023-01-14 15:08:41 +00:00 committed by Jelle Raaijmakers
parent 174135f909
commit 944c43a8b4
Notes: sideshowbarker 2024-07-17 02:39:10 +09:00
2 changed files with 6 additions and 1 deletions

View file

@ -36,6 +36,7 @@ public:
virtual ~ClipboardHistoryModel() override = default;
ClipboardItem const& item_at(int index) const { return m_history_items[index]; }
void add_item(const GUI::Clipboard::DataAndType& item);
void remove_item(int index);
bool is_empty() { return m_history_items.is_empty(); }
@ -47,7 +48,6 @@ public:
private:
ClipboardHistoryModel();
void add_item(const GUI::Clipboard::DataAndType& item);
// ^GUI::Model
virtual int row_count(const GUI::ModelIndex&) const override { return m_history_items.size(); }

View file

@ -35,6 +35,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto table_view = TRY(main_window->set_main_widget<GUI::TableView>());
auto model = ClipboardHistoryModel::create();
auto data_and_type = GUI::Clipboard::the().fetch_data_and_type();
if (!(data_and_type.data.is_empty() && data_and_type.mime_type.is_empty() && data_and_type.metadata.is_empty()))
model->add_item(data_and_type);
table_view->set_model(model);
table_view->on_activation = [&](GUI::ModelIndex const& index) {