diff options
author | RickySeverino <rickyseverino@protonmail.com> | 2021-04-11 14:53:48 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-12 18:03:55 +0200 |
commit | 21ecd5b804b5ec13931357315e80c63fd89baa02 (patch) | |
tree | aca4b120d3323114f9bcb6073fca9471361e4b5f | |
parent | 2c93123daf6d011cc687eae9e695e8b48709add9 (diff) | |
download | serenity-21ecd5b804b5ec13931357315e80c63fd89baa02.zip |
HackStudio: Allow users to drag and drop files into the editor
-rw-r--r-- | Userland/DevTools/HackStudio/Editor.cpp | 18 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/Editor.h | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/Editor.cpp b/Userland/DevTools/HackStudio/Editor.cpp index 71f703d05d..e4b1c8bf74 100644 --- a/Userland/DevTools/HackStudio/Editor.cpp +++ b/Userland/DevTools/HackStudio/Editor.cpp @@ -40,6 +40,7 @@ #include <LibGUI/GMLSyntaxHighlighter.h> #include <LibGUI/INISyntaxHighlighter.h> #include <LibGUI/Label.h> +#include <LibGUI/MessageBox.h> #include <LibGUI/Painter.h> #include <LibGUI/ScrollBar.h> #include <LibGUI/Window.h> @@ -302,6 +303,23 @@ void Editor::mousedown_event(GUI::MouseEvent& event) GUI::TextEditor::mousedown_event(event); } +void Editor::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(), "HackStudio can only open one file at a time!", "One at a time please!", GUI::MessageBox::Type::Error); + return; + } + open_file(urls.first().path()); + } +} + void Editor::enter_event(Core::Event& event) { m_hovering_editor = true; diff --git a/Userland/DevTools/HackStudio/Editor.h b/Userland/DevTools/HackStudio/Editor.h index 588965bfc9..9343fa5e37 100644 --- a/Userland/DevTools/HackStudio/Editor.h +++ b/Userland/DevTools/HackStudio/Editor.h @@ -80,6 +80,7 @@ private: virtual void paint_event(GUI::PaintEvent&) override; virtual void mousemove_event(GUI::MouseEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override; + virtual void drop_event(GUI::DropEvent&) override; virtual void enter_event(Core::Event&) override; virtual void leave_event(Core::Event&) override; |