summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorKarol Kosek <krkk@krkk.ct8.pl>2021-08-25 22:38:06 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-12 11:49:52 +0200
commita9ec98028b7c50a7fd0308ff78cd86480e224d32 (patch)
tree37d403e9ef3b51a328378063f1ba9454c2950295 /Userland
parent4e1a794abef07c63bcf55d3af57927fe36823284 (diff)
downloadserenity-a9ec98028b7c50a7fd0308ff78cd86480e224d32.zip
ThemeEditor: Accept drop events
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/ThemeEditor/PreviewWidget.cpp25
-rw-r--r--Userland/Applications/ThemeEditor/PreviewWidget.h1
2 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Applications/ThemeEditor/PreviewWidget.cpp b/Userland/Applications/ThemeEditor/PreviewWidget.cpp
index bc6bca6434..ff4443d30d 100644
--- a/Userland/Applications/ThemeEditor/PreviewWidget.cpp
+++ b/Userland/Applications/ThemeEditor/PreviewWidget.cpp
@@ -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);
+ }
+}
+
}
diff --git a/Userland/Applications/ThemeEditor/PreviewWidget.h b/Userland/Applications/ThemeEditor/PreviewWidget.h
index c3000e83a3..7d8dbabd13 100644
--- a/Userland/Applications/ThemeEditor/PreviewWidget.h
+++ b/Userland/Applications/ThemeEditor/PreviewWidget.h
@@ -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;