From 1a7dc9ac997d7c103c07990db943d05d9bba4990 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 5 Oct 2022 00:51:48 +0200 Subject: [PATCH] Support drag and drop onto the content list (#1220). --- src/wx/content_panel.cc | 74 ++++++++++++++++++++++++++++++++++++++--- src/wx/content_panel.h | 5 ++- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 83085db5a..6e0864417 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -50,6 +50,7 @@ #include LIBDCP_DISABLE_WARNINGS #include +#include #include #include #include @@ -72,6 +73,51 @@ using namespace boost::placeholders; #endif +class ContentDropTarget : public wxFileDropTarget +{ +public: + ContentDropTarget(ContentPanel* owner) + : _panel(owner) + {} + + bool OnDropFiles(wxCoord, wxCoord, wxArrayString const& filenames) override + { + vector files; + vector dcps; + vector folders; + for (size_t i = 0; i < filenames.GetCount(); ++i) { + auto path = boost::filesystem::path(wx_to_std(filenames[i])); + if (boost::filesystem::is_regular_file(path)) { + files.push_back(path); + } else if (boost::filesystem::is_directory(path)) { + if (contains_assetmap(path)) { + dcps.push_back(path); + } else { + folders.push_back(path); + } + } + } + + if (!filenames.empty()) { + _panel->add_files(files); + } + + for (auto dcp: dcps) { + _panel->add_dcp(dcp); + } + + for (auto dir: folders) { + _panel->add_folder(dir); + } + + return true; + }; + +private: + ContentPanel* _panel; +}; + + ContentPanel::ContentPanel (wxNotebook* n, shared_ptr film, weak_ptr viewer) : _parent (n) , _film (film) @@ -146,6 +192,8 @@ ContentPanel::ContentPanel (wxNotebook* n, shared_ptr film, weak_ptrBind (wxEVT_BUTTON, boost::bind (&ContentPanel::earlier_clicked, this)); _later->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::later_clicked, this)); _timeline->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::timeline_clicked, this)); + + _content->SetDropTarget(new ContentDropTarget(this)); } @@ -479,10 +527,17 @@ ContentPanel::add_folder_clicked () return; } + add_folder(path); +} + + +void +ContentPanel::add_folder(boost::filesystem::path folder) +{ vector> content; try { - content = content_factory (path); + content = content_factory(folder); } catch (exception& e) { error_dialog (_parent, e.what()); return; @@ -497,7 +552,7 @@ ContentPanel::add_folder_clicked () auto ic = dynamic_pointer_cast (i); if (ic) { auto e = new ImageSequenceDialog (_splitter); - r = e->ShowModal (); + int const r = e->ShowModal(); auto const frame_rate = e->frame_rate (); e->Destroy (); @@ -525,8 +580,15 @@ ContentPanel::add_dcp_clicked () return; } + add_dcp(path); +} + + +void +ContentPanel::add_dcp(boost::filesystem::path dcp) +{ try { - _film->examine_and_add_content (make_shared(path)); + _film->examine_and_add_content(make_shared(dcp)); } catch (ProjectFolderError &) { error_dialog ( _parent, @@ -536,7 +598,7 @@ ContentPanel::add_dcp_clicked () ) ); } catch (exception& e) { - error_dialog (_parent, e.what()); + error_dialog(_parent, e.what()); } } @@ -808,6 +870,10 @@ ContentPanel::files_dropped (wxDropFilesEvent& event) void ContentPanel::add_files (vector paths) { + if (!_film) { + return; + } + /* It has been reported that the paths returned from e.g. wxFileDialog are not always sorted; I can't reproduce that, but sort them anyway. Don't use ImageFilenameSorter as a normal alphabetical sort is expected here. diff --git a/src/wx/content_panel.h b/src/wx/content_panel.h index eec062284..896c81880 100644 --- a/src/wx/content_panel.h +++ b/src/wx/content_panel.h @@ -113,6 +113,10 @@ public: return _film_viewer; } + void add_files(std::vector files); + void add_dcp(boost::filesystem::path dcp); + void add_folder(boost::filesystem::path folder); + boost::signals2::signal SelectionChanged; private: @@ -131,7 +135,6 @@ private: void setup_sensitivity (); void set_selected_state(int item, bool state); - void add_files (std::vector); std::list panels () const; LimitedSplitter* _splitter; -- 2.30.2