1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +00:00

LibGUI+Everywhere: Make sync requests to Clipboard server more obvious

This commit is contained in:
Ben Wiederhake 2021-11-20 15:22:01 +01:00 committed by Linus Groh
parent 06f140a025
commit f22c0ffe0c
13 changed files with 22 additions and 23 deletions

View file

@ -50,7 +50,7 @@ Clipboard& Clipboard::the()
return *s_the;
}
Clipboard::DataAndType Clipboard::data_and_type() const
Clipboard::DataAndType Clipboard::fetch_data_and_type() const
{
auto response = connection().get_clipboard_data();
if (!response.data().is_valid())

View file

@ -39,9 +39,8 @@ public:
static void initialize(Badge<Application>);
static Clipboard& the();
DataAndType data_and_type() const;
ByteBuffer data() const { return data_and_type().data; }
String mime_type() const { return data_and_type().mime_type; }
DataAndType fetch_data_and_type() const;
String fetch_mime_type() const { return fetch_data_and_type().mime_type; }
void set_data(ReadonlyBytes data, String const& mime_type = "text/plain", HashMap<String, String> const& metadata = {});
void set_plain_text(String const& text) { set_data(text.bytes()); }

View file

@ -83,7 +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/"));
m_paste_action->set_enabled(is_editable() && Clipboard::the().fetch_mime_type().starts_with("text/"));
if (is_multi_line()) {
m_go_to_line_action = Action::create(
"Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
@ -1453,7 +1453,7 @@ void TextEditor::paste()
if (!is_editable())
return;
auto [data, mime_type, _] = GUI::Clipboard::the().data_and_type();
auto [data, mime_type, _] = GUI::Clipboard::the().fetch_data_and_type();
if (!mime_type.starts_with("text/"))
return;

View file

@ -752,7 +752,7 @@ void TerminalWidget::paste()
if (m_ptm_fd == -1)
return;
auto [data, mime_type, _] = GUI::Clipboard::the().data_and_type();
auto [data, mime_type, _] = GUI::Clipboard::the().fetch_data_and_type();
if (!mime_type.starts_with("text/"))
return;
if (data.is_empty())
@ -1166,7 +1166,7 @@ void TerminalWidget::update_copy_action()
void TerminalWidget::update_paste_action()
{
auto [data, mime_type, _] = GUI::Clipboard::the().data_and_type();
auto [data, mime_type, _] = GUI::Clipboard::the().fetch_data_and_type();
m_paste_action->set_enabled(mime_type.starts_with("text/") && !data.is_empty());
}