mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
LibGUI: Add a ClipboardClient for GUI::Clipboard
Anyone who inherits from `GUI::Clipboard::ClipboardClient` will receive clipboard notifications via `clipboard_content_did_change()`. Update ClipboardHistoryModel, TextEditor and TerminalWidget to inherit from this class.
This commit is contained in:
parent
95f393ebcd
commit
0c53c2dfa2
Notes:
sideshowbarker
2024-07-18 08:00:21 +09:00
Author: https://github.com/SeekingBlues
Commit: 0c53c2dfa2
Pull-request: https://github.com/SerenityOS/serenity/pull/9028
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/caoimhebyrne ✅
8 changed files with 106 additions and 72 deletions
|
@ -83,6 +83,7 @@ void TextEditor::create_actions()
|
|||
m_cut_action->set_enabled(false);
|
||||
m_copy_action->set_enabled(false);
|
||||
m_paste_action = CommonActions::make_paste_action([&](auto&) { paste(); }, this);
|
||||
m_paste_action->set_enabled(is_editable() && Clipboard::the().mime_type().starts_with("text/") && !Clipboard::the().data().is_empty());
|
||||
m_delete_action = CommonActions::make_delete_action([&](auto&) { do_delete(); }, this);
|
||||
if (is_multi_line()) {
|
||||
m_go_to_line_action = Action::create(
|
||||
|
@ -98,9 +99,6 @@ void TextEditor::create_actions()
|
|||
this);
|
||||
}
|
||||
m_select_all_action = CommonActions::make_select_all_action([this](auto&) { select_all(); }, this);
|
||||
Clipboard::the().on_change = [this](auto const& mime_type) {
|
||||
m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/") && !Clipboard::the().data().is_empty());
|
||||
};
|
||||
}
|
||||
|
||||
void TextEditor::set_text(StringView const& text)
|
||||
|
@ -1801,6 +1799,11 @@ void TextEditor::document_did_set_cursor(TextPosition const& position)
|
|||
set_cursor(position);
|
||||
}
|
||||
|
||||
void TextEditor::clipboard_content_did_change(String const& mime_type)
|
||||
{
|
||||
m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/") && !Clipboard::the().data().is_empty());
|
||||
}
|
||||
|
||||
void TextEditor::set_document(TextDocument& document)
|
||||
{
|
||||
if (m_document.ptr() == &document)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue