mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:37:34 +00:00
Userland: Store MIME keys as String in Core::MimeData
This commit is contained in:
parent
4f638d3af2
commit
2f35348104
13 changed files with 22 additions and 22 deletions
|
@ -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 = {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue