summaryrefslogtreecommitdiff
path: root/Userland/Applications/ThemeEditor
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2023-01-10 22:30:36 +0100
committerSam Atkins <atkinssj@gmail.com>2023-01-11 20:15:47 +0000
commit93a2b2a02d65fa6ec76c016a463e49c1f09f1c9b (patch)
treed6f76f28207b43443ebae2e4edde56d91800195f /Userland/Applications/ThemeEditor
parent0267d35258994398d1aa4c5e54d92908a0f8b4c9 (diff)
downloadserenity-93a2b2a02d65fa6ec76c016a463e49c1f09f1c9b.zip
ThemeEditor: Take drop events from the whole window
Drops were handled only by the Preview Widget previously. It probably made a little more sense before the program redesign, as it took most of window the space, but now honestly this idea doesn't hold up that well.
Diffstat (limited to 'Userland/Applications/ThemeEditor')
-rw-r--r--Userland/Applications/ThemeEditor/MainWidget.cpp31
-rw-r--r--Userland/Applications/ThemeEditor/MainWidget.h3
-rw-r--r--Userland/Applications/ThemeEditor/PreviewWidget.cpp31
-rw-r--r--Userland/Applications/ThemeEditor/PreviewWidget.h2
4 files changed, 34 insertions, 33 deletions
diff --git a/Userland/Applications/ThemeEditor/MainWidget.cpp b/Userland/Applications/ThemeEditor/MainWidget.cpp
index 25092c7d3a..d88dfd9a1f 100644
--- a/Userland/Applications/ThemeEditor/MainWidget.cpp
+++ b/Userland/Applications/ThemeEditor/MainWidget.cpp
@@ -646,4 +646,35 @@ ErrorOr<void> MainWidget::load_from_file(String const& filename, NonnullOwnPtr<C
return {};
}
+void MainWidget::drag_enter_event(GUI::DragEvent& event)
+{
+ auto const& mime_types = event.mime_types();
+ if (mime_types.contains_slow("text/uri-list"))
+ event.accept();
+}
+
+void MainWidget::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!"sv, "One at a time please!"sv, GUI::MessageBox::Type::Error);
+ return;
+ }
+
+ auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), urls.first().path(), Core::OpenMode::ReadOnly);
+ if (response.is_error())
+ return;
+
+ auto set_theme_from_file_result = m_preview_widget->set_theme_from_file(response.release_value());
+ if (set_theme_from_file_result.is_error())
+ GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Setting theme from file has failed: {}", set_theme_from_file_result.error()));
+ }
+}
+
}
diff --git a/Userland/Applications/ThemeEditor/MainWidget.h b/Userland/Applications/ThemeEditor/MainWidget.h
index 07809ccfcc..d33155de80 100644
--- a/Userland/Applications/ThemeEditor/MainWidget.h
+++ b/Userland/Applications/ThemeEditor/MainWidget.h
@@ -91,6 +91,9 @@ public:
private:
explicit MainWidget(NonnullRefPtr<AlignmentModel>);
+ virtual void drag_enter_event(GUI::DragEvent&) override;
+ virtual void drop_event(GUI::DropEvent&) override;
+
void save_to_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file);
ErrorOr<Core::AnonymousBuffer> encode();
void set_path(DeprecatedString);
diff --git a/Userland/Applications/ThemeEditor/PreviewWidget.cpp b/Userland/Applications/ThemeEditor/PreviewWidget.cpp
index db2f524485..58732192ae 100644
--- a/Userland/Applications/ThemeEditor/PreviewWidget.cpp
+++ b/Userland/Applications/ThemeEditor/PreviewWidget.cpp
@@ -149,35 +149,4 @@ void PreviewWidget::resize_event(GUI::ResizeEvent&)
update_preview_window_locations();
}
-void PreviewWidget::drag_enter_event(GUI::DragEvent& event)
-{
- auto const& mime_types = event.mime_types();
- if (mime_types.contains_slow("text/uri-list"))
- event.accept();
-}
-
-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!"sv, "One at a time please!"sv, GUI::MessageBox::Type::Error);
- return;
- }
-
- auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), urls.first().path(), Core::OpenMode::ReadOnly);
- if (response.is_error())
- return;
-
- auto set_theme_from_file_result = set_theme_from_file(response.release_value());
- if (set_theme_from_file_result.is_error())
- GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Setting theme from file has failed: {}", set_theme_from_file_result.error()));
- }
-}
-
}
diff --git a/Userland/Applications/ThemeEditor/PreviewWidget.h b/Userland/Applications/ThemeEditor/PreviewWidget.h
index 0ba05d4b02..392d01a4c2 100644
--- a/Userland/Applications/ThemeEditor/PreviewWidget.h
+++ b/Userland/Applications/ThemeEditor/PreviewWidget.h
@@ -38,8 +38,6 @@ private:
virtual void paint_preview(GUI::PaintEvent&) override;
virtual void second_paint_event(GUI::PaintEvent&) override;
virtual void resize_event(GUI::ResizeEvent&) override;
- virtual void drag_enter_event(GUI::DragEvent&) override;
- virtual void drop_event(GUI::DropEvent&) override;
virtual void palette_changed() override;
void paint_hightlight_window();