diff --git a/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h b/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h index 459adbdb972..c62718dcbb2 100644 --- a/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h +++ b/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h @@ -44,7 +44,7 @@ private: virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override; // ^GUI::Clipboard::ClipboardClient - virtual void clipboard_content_did_change(const String&) override { add_item(GUI::Clipboard::the().data_and_type()); } + virtual void clipboard_content_did_change(const String&) override { add_item(GUI::Clipboard::the().fetch_data_and_type()); } Vector m_history_items; size_t m_history_limit; diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 7fbae4a5500..2463a7e21d3 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -136,7 +136,7 @@ Tab::Tab(BrowserWindow& window) }; m_location_box->add_custom_context_menu_action(GUI::Action::create("Paste && Go", [this](auto&) { - 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; auto const& paste_text = data; diff --git a/Userland/Applications/Calculator/main.cpp b/Userland/Applications/Calculator/main.cpp index d69fb3123b5..bf7d34a3582 100644 --- a/Userland/Applications/Calculator/main.cpp +++ b/Userland/Applications/Calculator/main.cpp @@ -58,7 +58,7 @@ int main(int argc, char** argv) GUI::Clipboard::the().set_plain_text(widget.get_entry()); })); edit_menu.add_action(GUI::CommonActions::make_paste_action([&](auto&) { - auto clipboard = GUI::Clipboard::the().data_and_type(); + auto clipboard = GUI::Clipboard::the().fetch_data_and_type(); if (clipboard.mime_type == "text/plain") { if (!clipboard.data.is_empty()) { auto data = atof(StringView(clipboard.data).to_string().characters()); diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 7929d138579..8371415def4 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -151,7 +151,7 @@ void do_copy(Vector const& selected_file_paths, FileOperation file_opera void do_paste(String const& target_directory, GUI::Window* window) { - auto data_and_type = GUI::Clipboard::the().data_and_type(); + auto data_and_type = GUI::Clipboard::the().fetch_data_and_type(); if (data_and_type.mime_type != "text/uri-list") { dbgln("Cannot paste clipboard type {}", data_and_type.mime_type); return; @@ -345,7 +345,7 @@ int run_in_desktop_mode() do_paste(directory_view.path(), directory_view.window()); }, window); - paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "text/uri-list" && access(directory_view.path().characters(), W_OK) == 0); + paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type() == "text/uri-list" && access(directory_view.path().characters(), W_OK) == 0); GUI::Clipboard::the().on_change = [&](String const& data_type) { paste_action->set_enabled(data_type == "text/uri-list" && access(directory_view.path().characters(), W_OK) == 0); @@ -1007,7 +1007,7 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init) mkdir_action->set_enabled(can_write_in_path); touch_action->set_enabled(can_write_in_path); - paste_action->set_enabled(can_write_in_path && GUI::Clipboard::the().mime_type() == "text/uri-list"); + paste_action->set_enabled(can_write_in_path && GUI::Clipboard::the().fetch_mime_type() == "text/uri-list"); go_forward_action->set_enabled(directory_view.path_history_position() < directory_view.path_history_size() - 1); go_back_action->set_enabled(directory_view.path_history_position() > 0); open_parent_directory_action->set_enabled(new_path != "/"); @@ -1089,7 +1089,7 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init) auto& node = directory_view.node(index); if (node.is_directory()) { - auto should_get_enabled = access(node.full_path().characters(), W_OK) == 0 && GUI::Clipboard::the().mime_type() == "text/uri-list"; + auto should_get_enabled = access(node.full_path().characters(), W_OK) == 0 && GUI::Clipboard::the().fetch_mime_type() == "text/uri-list"; folder_specific_paste_action->set_enabled(should_get_enabled); directory_context_menu->popup(event.screen_position(), directory_open_action); } else { @@ -1207,7 +1207,7 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init) directory_view.open(initial_location); directory_view.set_focus(true); - paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "text/uri-list" && access(initial_location.characters(), W_OK) == 0); + paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type() == "text/uri-list" && access(initial_location.characters(), W_OK) == 0); window->set_rect({ left, top, width, height }); if (was_maximized) diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp index 0b0bceb810a..c3aa56b475f 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/FontEditor.cpp @@ -202,7 +202,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& m_glyph_editor_widget->paste_glyph(); m_glyph_map_widget->update_glyph(m_glyph_map_widget->selected_glyph()); }); - m_paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "glyph/x-fonteditor"); + m_paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type() == "glyph/x-fonteditor"); m_delete_action = GUI::CommonActions::make_delete_action([this](auto&) { if (m_glyph_editor_widget->is_glyph_empty() && m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()) == 0) return; diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp index 63f7311db7d..bf385106e14 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp @@ -84,7 +84,7 @@ void GlyphEditorWidget::copy_glyph() void GlyphEditorWidget::paste_glyph() { - auto [data, mime_type, metadata] = GUI::Clipboard::the().data_and_type(); + auto [data, mime_type, metadata] = GUI::Clipboard::the().fetch_data_and_type(); if (!mime_type.starts_with("glyph/")) return; diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 4e3613a457a..80a7bcba4fd 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -214,7 +214,7 @@ void MainWidget::initialize_menubar(GUI::Window& window) auto* editor = current_image_editor(); if (!editor) return; - auto bitmap = GUI::Clipboard::the().data_and_type().as_bitmap(); + auto bitmap = GUI::Clipboard::the().fetch_data_and_type().as_bitmap(); if (!bitmap) return; @@ -226,7 +226,7 @@ void MainWidget::initialize_menubar(GUI::Window& window) GUI::Clipboard::the().on_change = [&](auto& mime_type) { m_paste_action->set_enabled(mime_type == "image/x-serenityos"); }; - m_paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "image/x-serenityos"); + m_paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type() == "image/x-serenityos"); m_undo_action = GUI::CommonActions::make_undo_action([&](auto&) { if (auto* editor = current_image_editor()) diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index 93dd8644943..95272b8fb22 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -170,7 +170,7 @@ SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector&& sheets, bool s auto& sheet = *worksheet_ptr; auto& cells = sheet.selected_cells(); VERIFY(!cells.is_empty()); - const auto& data = GUI::Clipboard::the().data_and_type(); + const auto& data = GUI::Clipboard::the().fetch_data_and_type(); if (auto spreadsheet_data = data.metadata.get("text/x-spreadsheet-data"); spreadsheet_data.has_value()) { Vector source_positions, target_positions; auto lines = spreadsheet_data.value().split_view('\n'); diff --git a/Userland/Libraries/LibGUI/Clipboard.cpp b/Userland/Libraries/LibGUI/Clipboard.cpp index 19b0281cf85..ff1f5e5e0f9 100644 --- a/Userland/Libraries/LibGUI/Clipboard.cpp +++ b/Userland/Libraries/LibGUI/Clipboard.cpp @@ -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()) diff --git a/Userland/Libraries/LibGUI/Clipboard.h b/Userland/Libraries/LibGUI/Clipboard.h index 4034555b758..873bb778b2c 100644 --- a/Userland/Libraries/LibGUI/Clipboard.h +++ b/Userland/Libraries/LibGUI/Clipboard.h @@ -39,9 +39,8 @@ public: static void initialize(Badge); 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 const& metadata = {}); void set_plain_text(String const& text) { set_data(text.bytes()); } diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 32c62ba8958..e1e5c5c427d 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -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; diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index 3b7c7e0e901..4c47b67a8d0 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -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()); } diff --git a/Userland/Utilities/paste.cpp b/Userland/Utilities/paste.cpp index 061d8c8fc70..e21b3858f32 100644 --- a/Userland/Utilities/paste.cpp +++ b/Userland/Utilities/paste.cpp @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) clipboard.on_change = [&](const String&) { // Technically there's a race here... - auto data_and_type = clipboard.data_and_type(); + auto data_and_type = clipboard.fetch_data_and_type(); if (data_and_type.mime_type.is_null()) { spawn_command(watch_command, {}, "clear"); } else { @@ -88,7 +88,7 @@ int main(int argc, char* argv[]) return app->exec(); } - auto data_and_type = clipboard.data_and_type(); + auto data_and_type = clipboard.fetch_data_and_type(); if (data_and_type.mime_type.is_null()) { warnln("Nothing copied");