mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 21:37:58 +03: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
Notes:
sideshowbarker
2024-07-17 03:59:29 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/68fa8525bf Pull-request: https://github.com/SerenityOS/serenity/pull/17017 Reviewed-by: https://github.com/gmta
@ -136,6 +136,12 @@ void ClipboardHistoryModel::remove_item(int index)
|
||||
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)
|
||||
{
|
||||
if (domain != "ClipboardHistory" || group != "ClipboardHistory")
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
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);
|
||||
void clear();
|
||||
bool is_empty() { return m_history_items.is_empty(); }
|
||||
|
||||
// ^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());
|
||||
TRY(entry_context_menu->try_add_action(delete_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) {
|
||||
delete_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());
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user