mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibGUI: Port the drag&drop code to Core::MimeData
This commit is contained in:
parent
3cba9c3c25
commit
814d59f462
10 changed files with 59 additions and 53 deletions
|
@ -30,7 +30,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Clipboard.h>
|
||||
|
@ -38,6 +38,7 @@
|
|||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/ScrollBar.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -698,21 +699,23 @@ void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event)
|
|||
|
||||
void TerminalWidget::drop_event(GUI::DropEvent& event)
|
||||
{
|
||||
if (event.data_type() == "text") {
|
||||
if (event.mime_data().has_text()) {
|
||||
event.accept();
|
||||
write(m_ptm_fd, event.data().characters(), event.data().length());
|
||||
} else if (event.data_type() == "url-list") {
|
||||
auto text = event.mime_data().text();
|
||||
write(m_ptm_fd, text.characters(), text.length());
|
||||
} else if (event.mime_data().has_urls()) {
|
||||
event.accept();
|
||||
auto lines = event.data().split('\n');
|
||||
auto urls = event.mime_data().urls();
|
||||
bool first = true;
|
||||
for (auto& line : lines) {
|
||||
if (!first)
|
||||
for (auto& url : event.mime_data().urls()) {
|
||||
if (!first) {
|
||||
write(m_ptm_fd, " ", 1);
|
||||
first = false;
|
||||
|
||||
if (line.starts_with("file://"))
|
||||
line = line.substring(7, line.length() - 7);
|
||||
write(m_ptm_fd, line.characters(), line.length());
|
||||
first = false;
|
||||
}
|
||||
if (url.protocol() == "file")
|
||||
write(m_ptm_fd, url.path().characters(), url.path().length());
|
||||
else
|
||||
write(m_ptm_fd, url.to_string().characters(), url.to_string().length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue