1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:47:35 +00:00

ThemeEditor: Accept drop events

This commit is contained in:
Karol Kosek 2021-08-25 22:38:06 +02:00 committed by Andreas Kling
parent 4e1a794abe
commit a9ec98028b
2 changed files with 26 additions and 0 deletions

View file

@ -6,9 +6,12 @@
#include "PreviewWidget.h"
#include <AK/StringView.h>
#include <LibCore/MimeData.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
#include <LibGUI/RadioButton.h>
#include <LibGUI/Statusbar.h>
@ -166,4 +169,26 @@ void PreviewWidget::resize_event(GUI::ResizeEvent&)
m_gallery->set_relative_rect(Gfx::IntRect(0, 0, 320, 240).centered_within(rect()));
}
void PreviewWidget::drop_event(GUI::DropEvent& event)
{
event.accept();
window()->move_to_front();
if (event.mime_data().has_urls()) {
auto urls = event.mime_data().urls();
if (urls.is_empty())
return;
if (urls.size() > 1) {
GUI::MessageBox::show(window(), "ThemeEditor can only open one file at a time!", "One at a time please!", GUI::MessageBox::Type::Error);
return;
}
auto result = FileSystemAccessClient::Client::the().request_file(window()->window_id(), urls.first().path(), Core::OpenMode::ReadOnly);
if (result.error != 0)
return;
set_theme_from_file(urls.first().path(), *result.fd);
}
}
}

View file

@ -30,6 +30,7 @@ private:
virtual void paint_event(GUI::PaintEvent&) override;
virtual void resize_event(GUI::ResizeEvent&) override;
virtual void drop_event(GUI::DropEvent&) override;
Gfx::Palette m_preview_palette;