From 8b3864c70aafc7247a74ad629ac8ca792c0e0f22 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 13 Feb 2020 21:46:52 +0100 Subject: LibGUI: Have FileSystemModel accept url-list drags onto directories --- Libraries/LibGUI/FileSystemModel.cpp | 12 +++++++++++- Libraries/LibGUI/FileSystemModel.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/FileSystemModel.cpp b/Libraries/LibGUI/FileSystemModel.cpp index c14e51e498..ea7a12ffd9 100644 --- a/Libraries/LibGUI/FileSystemModel.cpp +++ b/Libraries/LibGUI/FileSystemModel.cpp @@ -27,9 +27,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -557,4 +557,14 @@ Model::ColumnMetadata FileSystemModel::column_metadata(int column) const ASSERT_NOT_REACHED(); } +bool FileSystemModel::accepts_drag(const ModelIndex& index, const StringView& data_type) +{ + if (!index.is_valid()) + return false; + if (data_type != "url-list") + return false; + auto& node = this->node(index); + return node.is_directory(); +} + } diff --git a/Libraries/LibGUI/FileSystemModel.h b/Libraries/LibGUI/FileSystemModel.h index 02bc652075..83c9d39aed 100644 --- a/Libraries/LibGUI/FileSystemModel.h +++ b/Libraries/LibGUI/FileSystemModel.h @@ -124,6 +124,7 @@ public: virtual ModelIndex parent_index(const ModelIndex&) const override; virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override; virtual StringView drag_data_type() const override { return "url-list"; } + virtual bool accepts_drag(const ModelIndex&, const StringView& data_type) override; static String timestamp_string(time_t timestamp) { -- cgit v1.2.3