mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
ClipboardHistory: Add a Clear history action
This clears the history from the table view and clears the clipboard.
This commit is contained in:
parent
944c43a8b4
commit
68fa8525bf
|
@ -136,6 +136,12 @@ void ClipboardHistoryModel::remove_item(int index)
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClipboardHistoryModel::clear()
|
||||||
|
{
|
||||||
|
m_history_items.clear();
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
void ClipboardHistoryModel::config_string_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value_string)
|
void ClipboardHistoryModel::config_string_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value_string)
|
||||||
{
|
{
|
||||||
if (domain != "ClipboardHistory" || group != "ClipboardHistory")
|
if (domain != "ClipboardHistory" || group != "ClipboardHistory")
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
ClipboardItem const& item_at(int index) const { return m_history_items[index]; }
|
ClipboardItem const& item_at(int index) const { return m_history_items[index]; }
|
||||||
void add_item(const GUI::Clipboard::DataAndType& item);
|
void add_item(const GUI::Clipboard::DataAndType& item);
|
||||||
void remove_item(int index);
|
void remove_item(int index);
|
||||||
|
void clear();
|
||||||
bool is_empty() { return m_history_items.is_empty(); }
|
bool is_empty() { return m_history_items.is_empty(); }
|
||||||
|
|
||||||
// ^GUI::Model
|
// ^GUI::Model
|
||||||
|
|
|
@ -67,12 +67,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
auto clear_action = GUI::Action::create("Clear history", TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/trash-can.png"sv)), [&](const GUI::Action&) {
|
||||||
|
model->clear();
|
||||||
|
GUI::Clipboard::the().clear();
|
||||||
|
});
|
||||||
|
|
||||||
auto entry_context_menu = TRY(GUI::Menu::try_create());
|
auto entry_context_menu = TRY(GUI::Menu::try_create());
|
||||||
TRY(entry_context_menu->try_add_action(delete_action));
|
TRY(entry_context_menu->try_add_action(delete_action));
|
||||||
TRY(entry_context_menu->try_add_action(debug_dump_action));
|
TRY(entry_context_menu->try_add_action(debug_dump_action));
|
||||||
|
entry_context_menu->add_separator();
|
||||||
|
TRY(entry_context_menu->try_add_action(clear_action));
|
||||||
table_view->on_context_menu_request = [&](GUI::ModelIndex const&, GUI::ContextMenuEvent const& event) {
|
table_view->on_context_menu_request = [&](GUI::ModelIndex const&, GUI::ContextMenuEvent const& event) {
|
||||||
delete_action->set_enabled(!table_view->selection().is_empty());
|
delete_action->set_enabled(!table_view->selection().is_empty());
|
||||||
debug_dump_action->set_enabled(!table_view->selection().is_empty());
|
debug_dump_action->set_enabled(!table_view->selection().is_empty());
|
||||||
|
clear_action->set_enabled(!model->is_empty());
|
||||||
entry_context_menu->popup(event.screen_position());
|
entry_context_menu->popup(event.screen_position());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue