mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
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:
parent
174135f909
commit
944c43a8b4
|
@ -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(); }
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue