diff options
author | Florian Förster <foerster.florianjr@gmail.com> | 2020-11-24 21:37:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-24 21:37:04 +0100 |
commit | 438829a1d5c0244aaa1b432d553885ae2542e668 (patch) | |
tree | eb1eb2557ec7710c193cdea5e55758cd9a2f0b4d | |
parent | b1fd06eb4cf27d0439e240551a632f31a6dfe6f9 (diff) | |
download | serenity-438829a1d5c0244aaa1b432d553885ae2542e668.zip |
MenuApplets: Added ability to remove entry from ClipboardHistory (#4143)
-rw-r--r-- | MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp | 5 | ||||
-rw-r--r-- | MenuApplets/ClipboardHistory/ClipboardHistoryModel.h | 1 | ||||
-rw-r--r-- | MenuApplets/ClipboardHistory/main.cpp | 12 |
3 files changed, 18 insertions, 0 deletions
diff --git a/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp b/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp index 2d66870bfc..7d6d18eea1 100644 --- a/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp +++ b/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp @@ -99,3 +99,8 @@ void ClipboardHistoryModel::add_item(const GUI::Clipboard::DataAndType& item) m_history_items.prepend(item); update(); } + +void ClipboardHistoryModel::remove_item(int index) +{ + m_history_items.remove(index); +} diff --git a/MenuApplets/ClipboardHistory/ClipboardHistoryModel.h b/MenuApplets/ClipboardHistory/ClipboardHistoryModel.h index e10ee6ac4e..6398f9c4de 100644 --- a/MenuApplets/ClipboardHistory/ClipboardHistoryModel.h +++ b/MenuApplets/ClipboardHistory/ClipboardHistoryModel.h @@ -45,6 +45,7 @@ public: const GUI::Clipboard::DataAndType& item_at(int index) const { return m_history_items[index]; } void add_item(const GUI::Clipboard::DataAndType& item); + void remove_item(int index); private: virtual int row_count(const GUI::ModelIndex&) const override { return m_history_items.size(); } diff --git a/MenuApplets/ClipboardHistory/main.cpp b/MenuApplets/ClipboardHistory/main.cpp index 016be66c0b..0cb83647d1 100644 --- a/MenuApplets/ClipboardHistory/main.cpp +++ b/MenuApplets/ClipboardHistory/main.cpp @@ -25,8 +25,10 @@ */ #include "ClipboardHistoryModel.h" +#include <LibGUI/Action.h> #include <LibGUI/Application.h> #include <LibGUI/ImageWidget.h> +#include <LibGUI/Menu.h> #include <LibGUI/TableView.h> #include <LibGUI/Window.h> #include <stdio.h> @@ -73,6 +75,16 @@ int main(int argc, char* argv[]) GUI::Clipboard::the().set_data(data_and_type.data, data_and_type.mime_type, data_and_type.metadata); }; + auto delete_action = GUI::CommonActions::make_delete_action([&](const GUI::Action&) { + model->remove_item(table_view.selection().first().row()); + }); + + auto entry_context_menu = GUI::Menu::construct(); + entry_context_menu->add_action(delete_action); + table_view.on_context_menu_request = [&](const GUI::ModelIndex&, const GUI::ContextMenuEvent& event) { + entry_context_menu->popup(event.screen_position()); + }; + auto applet_window = GUI::Window::construct(); applet_window->set_title("ClipboardHistory"); applet_window->set_window_type(GUI::WindowType::MenuApplet); |