From 6f23f3ff80fbd73cdaf183ce8bbdeeea0007ad6b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 5 Oct 2022 00:26:39 +0200 Subject: [PATCH] Support drag-and-drop of DCPs onto the player (#1220). --- src/tools/dcpomatic_player.cc | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index fb5821a9f..d97bdd168 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -71,6 +71,7 @@ LIBDCP_DISABLE_WARNINGS #include #include +#include #include #include #include @@ -148,9 +149,48 @@ enum { ID_go_to_end }; + class DOMFrame : public wxFrame { public: + + class DCPDropTarget : public wxFileDropTarget + { + public: + DCPDropTarget(DOMFrame* owner) + : _frame(owner) + {} + + bool OnDropFiles(wxCoord, wxCoord, wxArrayString const& filenames) override + { + if (filenames.GetCount() == 1) { + /* Try to load a directory */ + auto path = boost::filesystem::path(wx_to_std(filenames[0])); + if (boost::filesystem::is_directory(path)) { + _frame->load_dcp(wx_to_std(filenames[0])); + return true; + } + } + + if (filenames.GetCount() >= 1) { + /* Try to load the parent if we drop some files, one if which is an asset map */ + for (size_t i = 0; i < filenames.GetCount(); ++i) { + auto path = boost::filesystem::path(wx_to_std(filenames[i])); + if (path.filename() == "ASSETMAP" || path.filename() == "ASSETMAP.xml") { + _frame->load_dcp(path.parent_path()); + return true; + } + } + } + + return false; + } + + private: + DOMFrame* _frame; + }; + + DOMFrame () : wxFrame (nullptr, -1, _("DCP-o-matic Player")) , _mode (Config::instance()->player_mode()) @@ -260,6 +300,8 @@ public: setup_screen (); _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1)); + + SetDropTarget(new DCPDropTarget(this)); } ~DOMFrame () -- 2.30.2