summaryrefslogtreecommitdiff
path: root/Applications/TextEditor
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-12-19 20:20:20 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-12-20 20:07:10 +0100
commit6425b8714a800836a7cf822c404f02878c10cda1 (patch)
tree24e1080317a0eddb005e76f5d563167675c870ab /Applications/TextEditor
parentcfcb38dff196d3f9b3b66d7a62765092b846aa8a (diff)
downloadserenity-6425b8714a800836a7cf822c404f02878c10cda1.zip
TextEditor: Handle drop events
We now handle drop events with data type "url-list". This makes it possible to drop a file from FileManager on TextEditor to open it.
Diffstat (limited to 'Applications/TextEditor')
-rw-r--r--Applications/TextEditor/TextEditorWidget.cpp19
-rw-r--r--Applications/TextEditor/TextEditorWidget.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp
index 3a5beb9994..96dce569e2 100644
--- a/Applications/TextEditor/TextEditorWidget.cpp
+++ b/Applications/TextEditor/TextEditorWidget.cpp
@@ -1,6 +1,7 @@
#include "TextEditorWidget.h"
#include <AK/Optional.h>
#include <AK/StringBuilder.h>
+#include <AK/URL.h>
#include <LibCore/CFile.h>
#include <LibDraw/PNGLoader.h>
#include <LibGUI/GAboutDialog.h>
@@ -302,3 +303,21 @@ bool TextEditorWidget::request_close()
auto result = GMessageBox::show("The document has been modified. Quit without saving?", "Quit without saving?", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window());
return result == GMessageBox::ExecOK;
}
+
+void TextEditorWidget::drop_event(GDropEvent& event)
+{
+ event.accept();
+ window()->move_to_front();
+
+ if (event.data_type() == "url-list") {
+ auto lines = event.data().split_view('\n');
+ if (lines.is_empty())
+ return;
+ if (lines.size() > 1) {
+ GMessageBox::show("TextEditor can only open one file at a time!", "One at a time please!", GMessageBox::Type::Error, GMessageBox::InputType::OK, window());
+ return;
+ }
+ URL url(lines[0]);
+ open_sesame(url.path());
+ }
+}
diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h
index c3b2a3dc99..ac23c3bcbf 100644
--- a/Applications/TextEditor/TextEditorWidget.h
+++ b/Applications/TextEditor/TextEditorWidget.h
@@ -26,6 +26,8 @@ private:
void set_path(const FileSystemPath& file);
void update_title();
+ virtual void drop_event(GDropEvent&) override;
+
RefPtr<GTextEditor> m_editor;
String m_path;
String m_name;