Restore AWOL timing panel.
[dcpomatic.git] / src / wx / content_panel.cc
1 /*
2     Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "content_panel.h"
22 #include "wx_util.h"
23 #include "video_panel.h"
24 #include "audio_panel.h"
25 #include "text_panel.h"
26 #include "timing_panel.h"
27 #include "timeline_dialog.h"
28 #include "image_sequence_dialog.h"
29 #include "film_viewer.h"
30 #include "lib/audio_content.h"
31 #include "lib/text_content.h"
32 #include "lib/video_content.h"
33 #include "lib/ffmpeg_content.h"
34 #include "lib/content_factory.h"
35 #include "lib/image_content.h"
36 #include "lib/dcp_content.h"
37 #include "lib/case_insensitive_sorter.h"
38 #include "lib/playlist.h"
39 #include "lib/config.h"
40 #include "lib/log.h"
41 #include "lib/compose.hpp"
42 #include "lib/string_text_file_content.h"
43 #include "lib/string_text_file.h"
44 #include <wx/wx.h>
45 #include <wx/notebook.h>
46 #include <wx/listctrl.h>
47 #include <boost/filesystem.hpp>
48 #include <boost/foreach.hpp>
49 #include <iostream>
50
51 using std::list;
52 using std::string;
53 using std::cout;
54 using std::vector;
55 using std::max;
56 using std::exception;
57 using boost::shared_ptr;
58 using boost::weak_ptr;
59 using boost::dynamic_pointer_cast;
60 using boost::optional;
61
62 #define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
63
64 ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr<Film> film, FilmViewer* viewer)
65         : _timeline_dialog (0)
66         , _parent (n)
67         , _last_selected_tab (0)
68         , _film (film)
69         , _film_viewer (viewer)
70         , _generally_sensitive (true)
71 {
72         _panel = new wxPanel (n);
73         _sizer = new wxBoxSizer (wxVERTICAL);
74         _panel->SetSizer (_sizer);
75
76         _menu = new ContentMenu (_panel);
77
78         {
79                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
80
81                 _content = new wxListCtrl (_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER);
82                 _content->DragAcceptFiles (true);
83                 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
84
85                 _content->InsertColumn (0, wxT(""));
86                 _content->SetColumnWidth (0, 512);
87
88                 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
89
90                 _add_file = new wxButton (_panel, wxID_ANY, _("Add file(s)..."));
91                 _add_file->SetToolTip (_("Add video, image, sound or subtitle files to the film."));
92                 b->Add (_add_file, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
93
94                 _add_folder = new wxButton (_panel, wxID_ANY, _("Add folder..."));
95                 _add_folder->SetToolTip (_("Add a folder of image files (which will be used as a moving image sequence) or a folder of sound files."));
96                 b->Add (_add_folder, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
97
98                 _add_dcp = new wxButton (_panel, wxID_ANY, _("Add DCP..."));
99                 _add_dcp->SetToolTip (_("Add a DCP."));
100                 b->Add (_add_dcp, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
101
102                 _remove = new wxButton (_panel, wxID_ANY, _("Remove"));
103                 _remove->SetToolTip (_("Remove the selected piece of content from the film."));
104                 b->Add (_remove, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
105
106                 _earlier = new wxButton (_panel, wxID_ANY, _("Earlier"));
107                 _earlier->SetToolTip (_("Move the selected piece of content earlier in the film."));
108                 b->Add (_earlier, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
109
110                 _later = new wxButton (_panel, wxID_ANY, _("Later"));
111                 _later->SetToolTip (_("Move the selected piece of content later in the film."));
112                 b->Add (_later, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
113
114                 _timeline = new wxButton (_panel, wxID_ANY, _("Timeline..."));
115                 _timeline->SetToolTip (_("Open the timeline for the film."));
116                 b->Add (_timeline, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
117
118                 s->Add (b, 0, wxALL, 4);
119
120                 _sizer->Add (s, 0, wxEXPAND | wxALL, 6);
121         }
122
123         _notebook = new wxNotebook (_panel, wxID_ANY);
124         _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
125
126         _video_panel = new VideoPanel (this);
127         _panels.push_back (_video_panel);
128         _audio_panel = new AudioPanel (this);
129         _panels.push_back (_audio_panel);
130         for (int i = 0; i < TEXT_COUNT; ++i) {
131                 _text_panel[i] = new TextPanel (this, static_cast<TextType>(i));
132                 _panels.push_back (_text_panel[i]);
133         }
134         _timing_panel = new TimingPanel (this, _film_viewer);
135         _panels.push_back (_timing_panel);
136         _notebook->AddPage (_timing_panel, _("Timing"), false);
137
138         _content->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&ContentPanel::selection_changed, this));
139         _content->Bind (wxEVT_LIST_ITEM_DESELECTED, boost::bind (&ContentPanel::selection_changed, this));
140         _content->Bind (wxEVT_LIST_ITEM_RIGHT_CLICK, boost::bind (&ContentPanel::right_click, this, _1));
141         _content->Bind (wxEVT_DROP_FILES, boost::bind (&ContentPanel::files_dropped, this, _1));
142         _add_file->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::add_file_clicked, this));
143         _add_folder->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::add_folder_clicked, this));
144         _add_dcp->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::add_dcp_clicked, this));
145         _remove->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::remove_clicked, this, false));
146         _earlier->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::earlier_clicked, this));
147         _later->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::later_clicked, this));
148         _timeline->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::timeline_clicked, this));
149 }
150
151 ContentList
152 ContentPanel::selected ()
153 {
154         ContentList sel;
155         long int s = -1;
156         while (true) {
157                 s = _content->GetNextItem (s, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
158                 if (s == -1) {
159                         break;
160                 }
161
162                 if (s < int (_film->content().size ())) {
163                         sel.push_back (_film->content()[s]);
164                 }
165         }
166
167         return sel;
168 }
169
170 ContentList
171 ContentPanel::selected_video ()
172 {
173         ContentList vc;
174
175         BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
176                 if (i->video) {
177                         vc.push_back (i);
178                 }
179         }
180
181         return vc;
182 }
183
184 ContentList
185 ContentPanel::selected_audio ()
186 {
187         ContentList ac;
188
189         BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
190                 if (i->audio) {
191                         ac.push_back (i);
192                 }
193         }
194
195         return ac;
196 }
197
198 ContentList
199 ContentPanel::selected_text ()
200 {
201         ContentList sc;
202
203         BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
204                 if (!i->text.empty()) {
205                         sc.push_back (i);
206                 }
207         }
208
209         return sc;
210 }
211
212 FFmpegContentList
213 ContentPanel::selected_ffmpeg ()
214 {
215         FFmpegContentList sc;
216
217         BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
218                 shared_ptr<FFmpegContent> t = dynamic_pointer_cast<FFmpegContent> (i);
219                 if (t) {
220                         sc.push_back (t);
221                 }
222         }
223
224         return sc;
225 }
226
227 void
228 ContentPanel::film_changed (Film::Property p)
229 {
230         switch (p) {
231         case Film::CONTENT:
232         case Film::CONTENT_ORDER:
233                 setup ();
234                 break;
235         default:
236                 break;
237         }
238
239         BOOST_FOREACH (ContentSubPanel* i, _panels) {
240                 i->film_changed (p);
241         }
242 }
243
244 void
245 ContentPanel::selection_changed ()
246 {
247         if (_last_selected == selected()) {
248                 /* This was triggered by a re-build of the view but the selection
249                    did not really change.
250                 */
251                 return;
252         }
253
254         _last_selected = selected ();
255
256         setup_sensitivity ();
257
258         BOOST_FOREACH (ContentSubPanel* i, _panels) {
259                 i->content_selection_changed ();
260         }
261
262         optional<DCPTime> go_to;
263         BOOST_FOREACH (shared_ptr<Content> i, selected()) {
264                 DCPTime p;
265                 p = i->position();
266                 if (dynamic_pointer_cast<StringTextFileContent>(i) && i->paths_valid()) {
267                         /* Rather special case; if we select a text subtitle file jump to its
268                            first subtitle.
269                         */
270                         StringTextFile ts (dynamic_pointer_cast<StringTextFileContent>(i));
271                         if (ts.first()) {
272                                 p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position()));
273                         }
274                 }
275                 if (!go_to || p < go_to.get()) {
276                         go_to = p;
277                 }
278         }
279
280         if (go_to && Config::instance()->jump_to_selected ()) {
281                 _film_viewer->set_position (go_to.get().ceil(_film->video_frame_rate()));
282         }
283
284         if (_timeline_dialog) {
285                 _timeline_dialog->set_selection (selected());
286         }
287
288         /* Make required tabs visible */
289
290         if (_notebook->GetPageCount() > 1) {
291                 /* There's more than one tab in the notebook so the current selection could be meaningful
292                    to the user; store it so that we can try to restore it later.
293                 */
294                 _last_selected_tab = 0;
295                 if (_notebook->GetSelection() != wxNOT_FOUND) {
296                         _last_selected_tab = _notebook->GetPage(_notebook->GetSelection());
297                 }
298         }
299
300         bool have_video = false;
301         bool have_audio = false;
302         bool have_text[TEXT_COUNT] = { false, false };
303         BOOST_FOREACH (shared_ptr<Content> i, selected()) {
304                 if (i->video) {
305                         have_video = true;
306                 }
307                 if (i->audio) {
308                         have_audio = true;
309                 }
310                 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
311                         have_text[j->original_type()] = true;
312                 }
313         }
314
315         bool video_panel = false;
316         bool audio_panel = false;
317         bool text_panel[TEXT_COUNT] = { false, false };
318         for (size_t i = 0; i < _notebook->GetPageCount(); ++i) {
319                 if (_notebook->GetPage(i) == _video_panel) {
320                         video_panel = true;
321                 } else if (_notebook->GetPage(i) == _audio_panel) {
322                         audio_panel = true;
323                 }
324                 for (int j = 0; j < TEXT_COUNT; ++j) {
325                         if (_notebook->GetPage(i) == _text_panel[j]) {
326                                 text_panel[j] = true;
327                         }
328                 }
329         }
330
331         int off = 0;
332
333         if (have_video != video_panel) {
334                 if (video_panel) {
335                         _notebook->RemovePage (off);
336                 }
337                 if (have_video) {
338                         _notebook->InsertPage (off, _video_panel, _video_panel->name());
339                 }
340         }
341
342         if (have_video) {
343                 ++off;
344         }
345
346         if (have_audio != audio_panel) {
347                 if (audio_panel) {
348                         _notebook->RemovePage (off);
349                 }
350                 if (have_audio) {
351                         _notebook->InsertPage (off, _audio_panel, _audio_panel->name());
352                 }
353         }
354
355         if (have_audio) {
356                 ++off;
357         }
358
359         for (int i = 0; i < TEXT_COUNT; ++i) {
360                 if (have_text[i] != text_panel[i]) {
361                         if (text_panel[i]) {
362                                 _notebook->RemovePage (off);
363                         }
364                         if (have_text[i]) {
365                                 _notebook->InsertPage (off, _text_panel[i], _text_panel[i]->name());
366                         }
367                 }
368                 if (have_text[i]) {
369                         ++off;
370                 }
371         }
372
373         /* Set up the tab selection */
374
375         bool done = false;
376         for (size_t i = 0; i < _notebook->GetPageCount(); ++i) {
377                 if (_notebook->GetPage(i) == _last_selected_tab) {
378                         _notebook->SetSelection (i);
379                         done = true;
380                 }
381         }
382
383         if (!done && _notebook->GetPageCount() > 0) {
384                 _notebook->SetSelection (0);
385         }
386
387         SelectionChanged ();
388 }
389
390 void
391 ContentPanel::add_file_clicked ()
392 {
393         /* This method is also called when Ctrl-A is pressed, so check that our notebook page
394            is visible.
395         */
396         if (_parent->GetCurrentPage() != _panel || !_film) {
397                 return;
398         }
399
400         /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
401            non-Latin filenames or paths.
402         */
403         wxFileDialog* d = new wxFileDialog (
404                 _panel,
405                 _("Choose a file or files"),
406                 wxT (""),
407                 wxT (""),
408                 wxT ("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"),
409                 wxFD_MULTIPLE | wxFD_CHANGE_DIR
410                 );
411
412         int const r = d->ShowModal ();
413
414         if (r != wxID_OK) {
415                 d->Destroy ();
416                 return;
417         }
418
419         wxArrayString paths;
420         d->GetPaths (paths);
421         list<boost::filesystem::path> path_list;
422         for (unsigned int i = 0; i < paths.GetCount(); ++i) {
423                 path_list.push_back (wx_to_std (paths[i]));
424         }
425         add_files (path_list);
426
427         d->Destroy ();
428 }
429
430 void
431 ContentPanel::add_folder_clicked ()
432 {
433         wxDirDialog* d = new wxDirDialog (_panel, _("Choose a folder"), wxT (""), wxDD_DIR_MUST_EXIST);
434         int r = d->ShowModal ();
435         boost::filesystem::path const path (wx_to_std (d->GetPath ()));
436         d->Destroy ();
437
438         if (r != wxID_OK) {
439                 return;
440         }
441
442         list<shared_ptr<Content> > content;
443
444         try {
445                 content = content_factory (_film, path);
446         } catch (exception& e) {
447                 error_dialog (_parent, e.what());
448                 return;
449         }
450
451         if (content.empty ()) {
452                 error_dialog (_parent, _("No content found in this folder."));
453                 return;
454         }
455
456         BOOST_FOREACH (shared_ptr<Content> i, content) {
457                 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (i);
458                 if (ic) {
459                         ImageSequenceDialog* e = new ImageSequenceDialog (_panel);
460                         r = e->ShowModal ();
461                         float const frame_rate = e->frame_rate ();
462                         e->Destroy ();
463
464                         if (r != wxID_OK) {
465                                 return;
466                         }
467
468                         ic->set_video_frame_rate (frame_rate);
469                 }
470
471                 _film->examine_and_add_content (i);
472         }
473 }
474
475 void
476 ContentPanel::add_dcp_clicked ()
477 {
478         wxDirDialog* d = new wxDirDialog (_panel, _("Choose a DCP folder"), wxT (""), wxDD_DIR_MUST_EXIST);
479         int r = d->ShowModal ();
480         boost::filesystem::path const path (wx_to_std (d->GetPath ()));
481         d->Destroy ();
482
483         if (r != wxID_OK) {
484                 return;
485         }
486
487         try {
488                 _film->examine_and_add_content (shared_ptr<Content> (new DCPContent (_film, path)));
489         } catch (exception& e) {
490                 error_dialog (_parent, e.what());
491         }
492 }
493
494 /** @return true if this remove "click" should be ignored */
495 bool
496 ContentPanel::remove_clicked (bool hotkey)
497 {
498         /* If the method was called because Delete was pressed check that our notebook page
499            is visible and that the content list is focussed.
500         */
501         if (hotkey && (_parent->GetCurrentPage() != _panel || !_content->HasFocus())) {
502                 return true;
503         }
504
505         BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
506                 _film->remove_content (i);
507         }
508
509         selection_changed ();
510         return false;
511 }
512
513 void
514 ContentPanel::timeline_clicked ()
515 {
516         if (!_film) {
517                 return;
518         }
519
520         if (_timeline_dialog) {
521                 _timeline_dialog->Destroy ();
522                 _timeline_dialog = 0;
523         }
524
525         _timeline_dialog = new TimelineDialog (this, _film);
526         _timeline_dialog->Show ();
527 }
528
529 void
530 ContentPanel::right_click (wxListEvent& ev)
531 {
532         _menu->popup (_film, selected (), TimelineContentViewList (), ev.GetPoint ());
533 }
534
535 /** Set up broad sensitivity based on the type of content that is selected */
536 void
537 ContentPanel::setup_sensitivity ()
538 {
539         _add_file->Enable (_generally_sensitive);
540         _add_folder->Enable (_generally_sensitive);
541         _add_dcp->Enable (_generally_sensitive);
542
543         ContentList selection = selected ();
544         ContentList video_selection = selected_video ();
545         ContentList audio_selection = selected_audio ();
546
547         _remove->Enable   (_generally_sensitive && !selection.empty());
548         _earlier->Enable  (_generally_sensitive && selection.size() == 1);
549         _later->Enable    (_generally_sensitive && selection.size() == 1);
550         _timeline->Enable (_generally_sensitive && _film && !_film->content().empty());
551
552         _video_panel->Enable    (_generally_sensitive && video_selection.size() > 0);
553         _audio_panel->Enable    (_generally_sensitive && audio_selection.size() > 0);
554         for (int i = 0; i < TEXT_COUNT; ++i) {
555                 _text_panel[i]->Enable  (_generally_sensitive && selection.size() == 1 && !selection.front()->text.empty());
556         }
557         _timing_panel->Enable   (_generally_sensitive);
558 }
559
560 void
561 ContentPanel::set_film (shared_ptr<Film> film)
562 {
563         _audio_panel->set_film (film);
564
565         _film = film;
566
567         film_changed (Film::CONTENT);
568         film_changed (Film::AUDIO_CHANNELS);
569         selection_changed ();
570         setup_sensitivity ();
571 }
572
573 void
574 ContentPanel::set_general_sensitivity (bool s)
575 {
576         _generally_sensitive = s;
577         setup_sensitivity ();
578 }
579
580 void
581 ContentPanel::earlier_clicked ()
582 {
583         ContentList sel = selected ();
584         if (sel.size() == 1) {
585                 _film->move_content_earlier (sel.front ());
586                 selection_changed ();
587         }
588 }
589
590 void
591 ContentPanel::later_clicked ()
592 {
593         ContentList sel = selected ();
594         if (sel.size() == 1) {
595                 _film->move_content_later (sel.front ());
596                 selection_changed ();
597         }
598 }
599
600 void
601 ContentPanel::set_selection (weak_ptr<Content> wc)
602 {
603         ContentList content = _film->content ();
604         for (size_t i = 0; i < content.size(); ++i) {
605                 if (content[i] == wc.lock ()) {
606                         _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
607                 } else {
608                         _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
609                 }
610         }
611 }
612
613 void
614 ContentPanel::set_selection (ContentList cl)
615 {
616         ContentList content = _film->content ();
617         for (size_t i = 0; i < content.size(); ++i) {
618                 if (find(cl.begin(), cl.end(), content[i]) != cl.end()) {
619                         _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
620                 } else {
621                         _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
622                 }
623         }
624 }
625
626 void
627 ContentPanel::film_content_changed (int property)
628 {
629         if (
630                 property == ContentProperty::PATH ||
631                 property == DCPContentProperty::NEEDS_ASSETS ||
632                 property == DCPContentProperty::NEEDS_KDM ||
633                 property == DCPContentProperty::NAME
634                 ) {
635
636                 setup ();
637         }
638
639         BOOST_FOREACH (ContentSubPanel* i, _panels) {
640                 i->film_content_changed (property);
641         }
642 }
643
644 void
645 ContentPanel::setup ()
646 {
647         ContentList content = _film->content ();
648
649         Content* selected_content = 0;
650         int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
651         if (s != -1) {
652                 wxListItem item;
653                 item.SetId (s);
654                 item.SetMask (wxLIST_MASK_DATA);
655                 _content->GetItem (item);
656                 selected_content = reinterpret_cast<Content*> (item.GetData ());
657         }
658
659         _content->DeleteAllItems ();
660
661         BOOST_FOREACH (shared_ptr<Content> i, content) {
662                 int const t = _content->GetItemCount ();
663                 bool const valid = i->paths_valid ();
664
665                 /* Temporary debugging for Igor */
666                 BOOST_FOREACH (boost::filesystem::path j, i->paths()) {
667                         LOG_GENERAL ("Check %1 %2 answer %3", j.string(), boost::filesystem::exists(j) ? "yes" : "no", valid ? "yes" : "no");
668                 }
669
670                 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (i);
671                 bool const needs_kdm = dcp && dcp->needs_kdm ();
672                 bool const needs_assets = dcp && dcp->needs_assets ();
673
674                 wxString s = std_to_wx (i->summary ());
675
676                 if (!valid) {
677                         s = _("MISSING: ") + s;
678                 }
679
680                 if (needs_kdm) {
681                         s = _("NEEDS KDM: ") + s;
682                 }
683
684                 if (needs_assets) {
685                         s = _("NEEDS OV: ") + s;
686                 }
687
688                 wxListItem item;
689                 item.SetId (t);
690                 item.SetText (s);
691                 item.SetData (i.get ());
692                 _content->InsertItem (item);
693
694                 if (i.get() == selected_content) {
695                         _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
696                 }
697
698                 if (!valid || needs_kdm || needs_assets) {
699                         _content->SetItemTextColour (t, *wxRED);
700                 }
701         }
702
703         if (!selected_content && !content.empty ()) {
704                 /* Select the item of content if none was selected before */
705                 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
706         }
707
708         setup_sensitivity ();
709 }
710
711 void
712 ContentPanel::files_dropped (wxDropFilesEvent& event)
713 {
714         if (!_film) {
715                 return;
716         }
717
718         wxString* paths = event.GetFiles ();
719         list<boost::filesystem::path> path_list;
720         for (int i = 0; i < event.GetNumberOfFiles(); i++) {
721                 path_list.push_back (wx_to_std (paths[i]));
722         }
723
724         add_files (path_list);
725 }
726
727 void
728 ContentPanel::add_files (list<boost::filesystem::path> paths)
729 {
730         /* It has been reported that the paths returned from e.g. wxFileDialog are not always sorted;
731            I can't reproduce that, but sort them anyway.  Don't use ImageFilenameSorter as a normal
732            alphabetical sort is expected here.
733         */
734
735         paths.sort (CaseInsensitiveSorter ());
736
737         /* XXX: check for lots of files here and do something */
738
739         try {
740                 BOOST_FOREACH (boost::filesystem::path i, paths) {
741                         BOOST_FOREACH (shared_ptr<Content> j, content_factory (_film, i)) {
742                                 _film->examine_and_add_content (j);
743                         }
744                 }
745         } catch (exception& e) {
746                 error_dialog (_parent, e.what());
747         }
748 }