Userland: Store MIME keys as String in Core::MimeData
This commit is contained in:
parent
4f638d3af2
commit
2f35348104
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/krkk Commit: https://github.com/SerenityOS/serenity/commit/2f35348104 Pull-request: https://github.com/SerenityOS/serenity/pull/21179 Reviewed-by: https://github.com/AtkinsSJ ✅
13 changed files with 22 additions and 22 deletions
|
@ -157,7 +157,7 @@ RefPtr<Core::MimeData> SheetModel::mime_data(const GUI::ModelSelection& selectio
|
|||
auto new_data = DeprecatedString::formatted("{}\n{}",
|
||||
cursor_position.to_url(m_sheet).to_deprecated_string(),
|
||||
StringView(mime_data_buffer));
|
||||
mime_data->set_data("text/x-spreadsheet-data", new_data.to_byte_buffer());
|
||||
mime_data->set_data("text/x-spreadsheet-data"_string, new_data.to_byte_buffer());
|
||||
|
||||
return mime_data;
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@ Vector<DeprecatedString> MimeData::formats() const
|
|||
Vector<DeprecatedString> mime_types;
|
||||
mime_types.ensure_capacity(m_data.size());
|
||||
for (auto& it : m_data)
|
||||
mime_types.unchecked_append(it.key);
|
||||
mime_types.unchecked_append(it.key.to_deprecated_string());
|
||||
return mime_types;
|
||||
}
|
||||
|
||||
Vector<URL> MimeData::urls() const
|
||||
{
|
||||
auto it = m_data.find("text/uri-list");
|
||||
auto it = m_data.find("text/uri-list"sv);
|
||||
if (it == m_data.end())
|
||||
return {};
|
||||
Vector<URL> urls;
|
||||
|
@ -39,19 +39,19 @@ ErrorOr<void> MimeData::set_urls(Vector<URL> const& urls)
|
|||
TRY(builder.try_append(url.to_deprecated_string()));
|
||||
TRY(builder.try_append('\n'));
|
||||
}
|
||||
set_data("text/uri-list", TRY(builder.to_byte_buffer()));
|
||||
set_data("text/uri-list"_string, TRY(builder.to_byte_buffer()));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
DeprecatedString MimeData::text() const
|
||||
{
|
||||
return DeprecatedString::copy(m_data.get("text/plain").value_or({}));
|
||||
return DeprecatedString::copy(m_data.get("text/plain"sv).value_or({}));
|
||||
}
|
||||
|
||||
void MimeData::set_text(DeprecatedString const& text)
|
||||
{
|
||||
set_data("text/plain", text.to_byte_buffer());
|
||||
set_data("text/plain"_string, text.to_byte_buffer());
|
||||
}
|
||||
|
||||
// FIXME: Share this, TextEditor and HackStudio language detection somehow.
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
virtual ~MimeData() = default;
|
||||
|
||||
ByteBuffer data(StringView mime_type) const { return m_data.get(mime_type).value_or({}); }
|
||||
void set_data(DeprecatedString const& mime_type, ByteBuffer&& data) { m_data.set(mime_type, move(data)); }
|
||||
void set_data(String const& mime_type, ByteBuffer&& data) { m_data.set(mime_type, move(data)); }
|
||||
|
||||
bool has_format(StringView mime_type) const { return m_data.contains(mime_type); }
|
||||
Vector<DeprecatedString> formats() const;
|
||||
|
@ -36,16 +36,16 @@ public:
|
|||
Vector<URL> urls() const;
|
||||
ErrorOr<void> set_urls(Vector<URL> const&);
|
||||
|
||||
HashMap<DeprecatedString, ByteBuffer> const& all_data() const { return m_data; }
|
||||
HashMap<String, ByteBuffer> const& all_data() const { return m_data; }
|
||||
|
||||
private:
|
||||
MimeData() = default;
|
||||
explicit MimeData(HashMap<DeprecatedString, ByteBuffer> const& data)
|
||||
explicit MimeData(HashMap<String, ByteBuffer> const& data)
|
||||
: m_data(data.clone().release_value_but_fixme_should_propagate_errors())
|
||||
{
|
||||
}
|
||||
|
||||
HashMap<DeprecatedString, ByteBuffer> m_data;
|
||||
HashMap<String, ByteBuffer> m_data;
|
||||
};
|
||||
|
||||
StringView guess_mime_type_based_on_filename(StringView);
|
||||
|
|
|
@ -349,7 +349,7 @@ void ConnectionToWindowServer::applet_area_rect_changed(Gfx::IntRect const& rect
|
|||
});
|
||||
}
|
||||
|
||||
void ConnectionToWindowServer::drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, DeprecatedString const& text, HashMap<DeprecatedString, ByteBuffer> const& mime_data)
|
||||
void ConnectionToWindowServer::drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, DeprecatedString const& text, HashMap<String, ByteBuffer> const& mime_data)
|
||||
{
|
||||
if (auto* window = Window::from_window_id(window_id)) {
|
||||
auto mime_data_obj = Core::MimeData::construct(mime_data);
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
virtual void menu_visibility_did_change(i32, bool) override;
|
||||
virtual void screen_rects_changed(Vector<Gfx::IntRect> const&, u32, u32, u32) override;
|
||||
virtual void applet_area_rect_changed(Gfx::IntRect const&) override;
|
||||
virtual void drag_dropped(i32, Gfx::IntPoint, DeprecatedString const&, HashMap<DeprecatedString, ByteBuffer> const&) override;
|
||||
virtual void drag_dropped(i32, Gfx::IntPoint, DeprecatedString const&, HashMap<String, ByteBuffer> const&) override;
|
||||
virtual void drag_accepted() override;
|
||||
virtual void drag_cancelled() override;
|
||||
virtual void update_system_theme(Core::AnonymousBuffer const&) override;
|
||||
|
|
|
@ -84,9 +84,9 @@ void DragOperation::set_bitmap(Gfx::Bitmap const* bitmap)
|
|||
if (!m_mime_data)
|
||||
m_mime_data = Core::MimeData::construct();
|
||||
if (bitmap)
|
||||
m_mime_data->set_data("image/x-raw-bitmap", bitmap->serialize_to_byte_buffer().release_value_but_fixme_should_propagate_errors());
|
||||
m_mime_data->set_data("image/x-raw-bitmap"_string, bitmap->serialize_to_byte_buffer().release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
void DragOperation::set_data(DeprecatedString const& data_type, DeprecatedString const& data)
|
||||
void DragOperation::set_data(String const& data_type, DeprecatedString const& data)
|
||||
{
|
||||
if (!m_mime_data)
|
||||
m_mime_data = Core::MimeData::construct();
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
void set_mime_data(RefPtr<Core::MimeData> mime_data) { m_mime_data = move(mime_data); }
|
||||
void set_text(DeprecatedString const& text);
|
||||
void set_bitmap(Gfx::Bitmap const* bitmap);
|
||||
void set_data(DeprecatedString const& data_type, DeprecatedString const& data);
|
||||
void set_data(String const& data_type, DeprecatedString const& data);
|
||||
|
||||
Outcome exec();
|
||||
Outcome outcome() const { return m_outcome; }
|
||||
|
|
|
@ -125,10 +125,10 @@ RefPtr<Core::MimeData> Model::mime_data(ModelSelection const& selection) const
|
|||
}
|
||||
});
|
||||
|
||||
mime_data->set_data(drag_data_type(), data_builder.to_byte_buffer().release_value_but_fixme_should_propagate_errors());
|
||||
mime_data->set_data(MUST(String::from_utf8(drag_data_type())), data_builder.to_byte_buffer().release_value_but_fixme_should_propagate_errors());
|
||||
mime_data->set_text(text_builder.to_deprecated_string());
|
||||
if (bitmap)
|
||||
mime_data->set_data("image/x-raw-bitmap", bitmap->serialize_to_byte_buffer().release_value_but_fixme_should_propagate_errors());
|
||||
mime_data->set_data("image/x-raw-bitmap"_string, bitmap->serialize_to_byte_buffer().release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
return mime_data;
|
||||
}
|
||||
|
|
|
@ -912,7 +912,7 @@ void TerminalWidget::mousemove_event(GUI::MouseEvent& event)
|
|||
|
||||
auto drag_operation = GUI::DragOperation::construct();
|
||||
drag_operation->set_text(m_active_href);
|
||||
drag_operation->set_data("text/uri-list", m_active_href);
|
||||
drag_operation->set_data("text/uri-list"_string, m_active_href);
|
||||
|
||||
m_active_href = {};
|
||||
m_active_href_id = {};
|
||||
|
|
|
@ -872,7 +872,7 @@ void ConnectionFromClient::start_window_resize(i32 window_id, i32 resize_directi
|
|||
WindowManager::the().start_window_resize(window, ScreenInput::the().cursor_location(), MouseButton::Primary, (ResizeDirection)resize_direction);
|
||||
}
|
||||
|
||||
Messages::WindowServer::StartDragResponse ConnectionFromClient::start_drag(DeprecatedString const& text, HashMap<DeprecatedString, ByteBuffer> const& mime_data, Gfx::ShareableBitmap const& drag_bitmap)
|
||||
Messages::WindowServer::StartDragResponse ConnectionFromClient::start_drag(DeprecatedString const& text, HashMap<String, ByteBuffer> const& mime_data, Gfx::ShareableBitmap const& drag_bitmap)
|
||||
{
|
||||
auto& wm = WindowManager::the();
|
||||
if (wm.dnd_client() || !(wm.last_processed_buttons() & MouseButton::Primary))
|
||||
|
|
|
@ -144,7 +144,7 @@ private:
|
|||
virtual void popup_menu(i32, Gfx::IntPoint, Gfx::IntRect const&) override;
|
||||
virtual void dismiss_menu(i32) override;
|
||||
virtual void set_window_icon_bitmap(i32, Gfx::ShareableBitmap const&) override;
|
||||
virtual Messages::WindowServer::StartDragResponse start_drag(DeprecatedString const&, HashMap<DeprecatedString, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
|
||||
virtual Messages::WindowServer::StartDragResponse start_drag(DeprecatedString const&, HashMap<String, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
|
||||
virtual void set_accepts_drag(bool) override;
|
||||
virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(DeprecatedString const&, DeprecatedString const&, bool keep_desktop_background, Optional<DeprecatedString> const& color_scheme_path) override;
|
||||
virtual Messages::WindowServer::GetSystemThemeResponse get_system_theme() override;
|
||||
|
|
|
@ -36,7 +36,7 @@ endpoint WindowClient
|
|||
drag_accepted() =|
|
||||
drag_cancelled() =|
|
||||
|
||||
drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] DeprecatedString text, HashMap<DeprecatedString,ByteBuffer> mime_data) =|
|
||||
drag_dropped(i32 window_id, Gfx::IntPoint mouse_position, [UTF8] DeprecatedString text, HashMap<String,ByteBuffer> mime_data) =|
|
||||
|
||||
update_system_theme(Core::AnonymousBuffer theme_buffer) =|
|
||||
update_system_fonts(DeprecatedString default_font_query, DeprecatedString fixed_width_font_query, DeprecatedString window_title_font_query) =|
|
||||
|
|
|
@ -128,7 +128,7 @@ endpoint WindowServer
|
|||
set_window_cursor(i32 window_id, i32 cursor_type) =|
|
||||
set_window_custom_cursor(i32 window_id, Gfx::ShareableBitmap cursor) =|
|
||||
|
||||
start_drag([UTF8] DeprecatedString text, HashMap<DeprecatedString,ByteBuffer> mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started)
|
||||
start_drag([UTF8] DeprecatedString text, HashMap<String,ByteBuffer> mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started)
|
||||
set_accepts_drag(bool accepts) =|
|
||||
|
||||
set_system_theme(DeprecatedString theme_path, [UTF8] DeprecatedString theme_name, bool keep_desktop_background, Optional<DeprecatedString> color_scheme_path) => (bool success)
|
||||
|
|
Loading…
Add table
Reference in a new issue