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 MainWidget::load_from_file(String const& filename, NonnullOwnPtrmove_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); + virtual void drag_enter_event(GUI::DragEvent&) override; + virtual void drop_event(GUI::DropEvent&) override; + void save_to_file(String const& filename, NonnullOwnPtr file); ErrorOr 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();