diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-10-05 00:51:48 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-10-05 00:51:48 +0200 |
| commit | 1a7dc9ac997d7c103c07990db943d05d9bba4990 (patch) | |
| tree | 55f3a5bba54138c9183bc980c99ab05a28efe61c | |
| parent | afa092638250c72a92136b0b440bb6bb7c070702 (diff) | |
Support drag and drop onto the content list (#1220).v2.16.29
| -rw-r--r-- | src/wx/content_panel.cc | 74 | ||||
| -rw-r--r-- | 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 <dcp/warnings.h> LIBDCP_DISABLE_WARNINGS #include <wx/display.h> +#include <wx/dnd.h> #include <wx/listctrl.h> #include <wx/notebook.h> #include <wx/wx.h> @@ -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<boost::filesystem::path> files; + vector<boost::filesystem::path> dcps; + vector<boost::filesystem::path> 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> film, weak_ptr<FilmViewer> viewer) : _parent (n) , _film (film) @@ -146,6 +192,8 @@ ContentPanel::ContentPanel (wxNotebook* n, shared_ptr<Film> film, weak_ptr<FilmV _earlier->Bind (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<shared_ptr<Content>> 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<ImageContent> (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<DCPContent>(path)); + _film->examine_and_add_content(make_shared<DCPContent>(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<boost::filesystem::path> 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<boost::filesystem::path> files); + void add_dcp(boost::filesystem::path dcp); + void add_folder(boost::filesystem::path folder); + boost::signals2::signal<void (void)> SelectionChanged; private: @@ -131,7 +135,6 @@ private: void setup_sensitivity (); void set_selected_state(int item, bool state); - void add_files (std::vector<boost::filesystem::path>); std::list<ContentSubPanel *> panels () const; LimitedSplitter* _splitter; |
