mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +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
Notes:
sideshowbarker
2024-07-17 02:39:10 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/944c43a8b4 Pull-request: https://github.com/SerenityOS/serenity/pull/17017 Reviewed-by: https://github.com/gmta
2 changed files with 6 additions and 1 deletions
|
@ -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