Fix alignment of labels on macOS (#2043).
[dcpomatic.git] / src / wx / content_panel.cc
1 /*
2     Copyright (C) 2012-2021 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
22 #include "audio_panel.h"
23 #include "content_panel.h"
24 #include "dcpomatic_button.h"
25 #include "film_viewer.h"
26 #include "image_sequence_dialog.h"
27 #include "text_panel.h"
28 #include "timeline_dialog.h"
29 #include "timing_panel.h"
30 #include "video_panel.h"
31 #include "wx_util.h"
32 #include "lib/audio_content.h"
33 #include "lib/case_insensitive_sorter.h"
34 #include "lib/compose.hpp"
35 #include "lib/config.h"
36 #include "lib/content_factory.h"
37 #include "lib/dcp_content.h"
38 #include "lib/dcpomatic_log.h"
39 #include "lib/ffmpeg_content.h"
40 #include "lib/image_content.h"
41 #include "lib/log.h"
42 #include "lib/playlist.h"
43 #include "lib/string_text_file.h"
44 #include "lib/string_text_file_content.h"
45 #include "lib/text_content.h"
46 #include "lib/video_content.h"
47 #include <wx/wx.h>
48 #include <wx/notebook.h>
49 #include <wx/listctrl.h>
50 #include <wx/display.h>
51 #include <boost/filesystem.hpp>
52 #include <iostream>
53
54
55 using std::cout;
56 using std::dynamic_pointer_cast;
57 using std::exception;
58 using std::list;
59 using std::make_shared;
60 using std::max;
61 using std::shared_ptr;
62 using std::string;
63 using std::vector;
64 using std::weak_ptr;
65 using boost::optional;
66 using namespace dcpomatic;
67 #if BOOST_VERSION >= 106100
68 using namespace boost::placeholders;
69 #endif
70
71
72 ContentPanel::ContentPanel (wxNotebook* n, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer)
73         : _parent (n)
74         , _film (film)
75         , _film_viewer (viewer)
76         , _generally_sensitive (true)
77         , _ignore_deselect (false)
78         , _no_check_selection (false)
79 {
80         for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
81                 _text_panel[i] = 0;
82         }
83
84         _splitter = new LimitedSplitter (n);
85         _top_panel = new wxPanel (_splitter);
86
87         _menu = new ContentMenu (_splitter);
88
89         {
90                 auto s = new wxBoxSizer (wxHORIZONTAL);
91
92                 _content = new wxListCtrl (_top_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER);
93                 _content->DragAcceptFiles (true);
94                 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
95
96                 _content->InsertColumn (0, wxT(""));
97                 _content->SetColumnWidth (0, 512);
98
99                 auto b = new wxBoxSizer (wxVERTICAL);
100
101                 _add_file = new Button (_top_panel, _("Add file(s)..."));
102                 _add_file->SetToolTip (_("Add video, image, sound or subtitle files to the film."));
103                 b->Add (_add_file, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
104
105                 _add_folder = new Button (_top_panel, _("Add folder..."));
106                 _add_folder->SetToolTip (_("Add a folder of image files (which will be used as a moving image sequence) or a folder of sound files."));
107                 b->Add (_add_folder, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
108
109                 _add_dcp = new Button (_top_panel, _("Add DCP..."));
110                 _add_dcp->SetToolTip (_("Add a DCP."));
111                 b->Add (_add_dcp, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
112
113                 _remove = new Button (_top_panel, _("Remove"));
114                 _remove->SetToolTip (_("Remove the selected piece of content from the film."));
115                 b->Add (_remove, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
116
117                 _earlier = new Button (_top_panel, _("Earlier"));
118                 _earlier->SetToolTip (_("Move the selected piece of content earlier in the film."));
119                 b->Add (_earlier, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
120
121                 _later = new Button (_top_panel, _("Later"));
122                 _later->SetToolTip (_("Move the selected piece of content later in the film."));
123                 b->Add (_later, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
124
125                 _timeline = new Button (_top_panel, _("Timeline..."));
126                 _timeline->SetToolTip (_("Open the timeline for the film."));
127                 b->Add (_timeline, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
128
129                 s->Add (b, 0, wxALL, 4);
130                 _top_panel->SetSizer (s);
131         }
132
133         _notebook = new wxNotebook (_splitter, wxID_ANY);
134
135         _timing_panel = new TimingPanel (this, _film_viewer);
136         _notebook->AddPage (_timing_panel, _("Timing"), false);
137
138         _content->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&ContentPanel::item_selected, this));
139         _content->Bind (wxEVT_LIST_ITEM_DESELECTED, boost::bind (&ContentPanel::item_deselected, 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
152 void
153 ContentPanel::first_shown ()
154 {
155         _splitter->first_shown (_top_panel, _notebook);
156 }
157
158
159 ContentList
160 ContentPanel::selected ()
161 {
162         ContentList sel;
163         long int s = -1;
164         while (true) {
165                 s = _content->GetNextItem (s, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
166                 if (s == -1) {
167                         break;
168                 }
169
170                 auto cl = _film->content();
171                 if (s < int (cl.size())) {
172                         sel.push_back (cl[s]);
173                 }
174         }
175
176         return sel;
177 }
178
179
180 ContentList
181 ContentPanel::selected_video ()
182 {
183         ContentList vc;
184
185         for (auto i: selected()) {
186                 if (i->video) {
187                         vc.push_back (i);
188                 }
189         }
190
191         return vc;
192 }
193
194
195 ContentList
196 ContentPanel::selected_audio ()
197 {
198         ContentList ac;
199
200         for (auto i: selected()) {
201                 if (i->audio) {
202                         ac.push_back (i);
203                 }
204         }
205
206         return ac;
207 }
208
209
210 ContentList
211 ContentPanel::selected_text ()
212 {
213         ContentList sc;
214
215         for (auto i: selected()) {
216                 if (!i->text.empty()) {
217                         sc.push_back (i);
218                 }
219         }
220
221         return sc;
222 }
223
224
225 FFmpegContentList
226 ContentPanel::selected_ffmpeg ()
227 {
228         FFmpegContentList sc;
229
230         for (auto i: selected()) {
231                 auto t = dynamic_pointer_cast<FFmpegContent> (i);
232                 if (t) {
233                         sc.push_back (t);
234                 }
235         }
236
237         return sc;
238 }
239
240
241 void
242 ContentPanel::film_changed (Film::Property p)
243 {
244         switch (p) {
245         case Film::Property::CONTENT:
246         case Film::Property::CONTENT_ORDER:
247                 setup ();
248                 break;
249         default:
250                 break;
251         }
252
253         for (auto i: panels()) {
254                 i->film_changed (p);
255         }
256 }
257
258
259 void
260 ContentPanel::item_deselected ()
261 {
262         /* Maybe this is just a re-click on the same item; if not, _ignore_deselect will stay
263            false and item_deselected_foo will handle the deselection.
264         */
265         _ignore_deselect = false;
266         signal_manager->when_idle (boost::bind (&ContentPanel::item_deselected_idle, this));
267 }
268
269
270 void
271 ContentPanel::item_deselected_idle ()
272 {
273         if (!_ignore_deselect) {
274                 check_selection ();
275         }
276 }
277
278
279 void
280 ContentPanel::item_selected ()
281 {
282         _ignore_deselect = true;
283         check_selection ();
284 }
285
286
287 void
288 ContentPanel::check_selection ()
289 {
290         if (_no_check_selection) {
291                 return;
292         }
293
294         setup_sensitivity ();
295
296         for (auto i: panels()) {
297                 i->content_selection_changed ();
298         }
299
300         optional<DCPTime> go_to;
301         for (auto i: selected()) {
302                 DCPTime p;
303                 p = i->position();
304                 if (dynamic_pointer_cast<StringTextFileContent>(i) && i->paths_valid()) {
305                         /* Rather special case; if we select a text subtitle file jump to its
306                            first subtitle.
307                         */
308                         StringTextFile ts (dynamic_pointer_cast<StringTextFileContent>(i));
309                         if (ts.first()) {
310                                 p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position()));
311                         }
312                 }
313                 if (!go_to || p < go_to.get()) {
314                         go_to = p;
315                 }
316         }
317
318         if (go_to && Config::instance()->jump_to_selected() && signal_manager) {
319                 auto fv = _film_viewer.lock ();
320                 DCPOMATIC_ASSERT (fv);
321                 signal_manager->when_idle(boost::bind(&FilmViewer::seek, fv.get(), go_to.get().ceil(_film->video_frame_rate()), true));
322         }
323
324         if (_timeline_dialog) {
325                 _timeline_dialog->set_selection (selected());
326         }
327
328         /* Make required tabs visible */
329
330         if (_notebook->GetPageCount() > 1) {
331                 /* There's more than one tab in the notebook so the current selection could be meaningful
332                    to the user; store it so that we can try to restore it later.
333                 */
334                 _last_selected_tab = 0;
335                 if (_notebook->GetSelection() != wxNOT_FOUND) {
336                         _last_selected_tab = _notebook->GetPage(_notebook->GetSelection());
337                 }
338         }
339
340         bool have_video = false;
341         bool have_audio = false;
342         bool have_text[static_cast<int>(TextType::COUNT)] = { false, false };
343         for (auto i: selected()) {
344                 if (i->video) {
345                         have_video = true;
346                 }
347                 if (i->audio) {
348                         have_audio = true;
349                 }
350                 for (auto j: i->text) {
351                         have_text[static_cast<int>(j->original_type())] = true;
352                 }
353         }
354
355         int off = 0;
356
357         if (have_video && !_video_panel) {
358                 _video_panel = new VideoPanel (this);
359                 _notebook->InsertPage (off, _video_panel, _video_panel->name());
360         } else if (!have_video && _video_panel) {
361                 _notebook->DeletePage (off);
362                 _video_panel = 0;
363         }
364
365         if (have_video) {
366                 ++off;
367         }
368
369         if (have_audio && !_audio_panel) {
370                 _audio_panel = new AudioPanel (this);
371                 _notebook->InsertPage (off, _audio_panel, _audio_panel->name());
372         } else if (!have_audio && _audio_panel) {
373                 _notebook->DeletePage (off);
374                 _audio_panel = 0;
375         }
376
377         if (have_audio) {
378                 ++off;
379         }
380
381         for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
382                 if (have_text[i] && !_text_panel[i]) {
383                         _text_panel[i] = new TextPanel (this, static_cast<TextType>(i));
384                         _notebook->InsertPage (off, _text_panel[i], _text_panel[i]->name());
385                 } else if (!have_text[i] && _text_panel[i]) {
386                         _notebook->DeletePage (off);
387                         _text_panel[i] = 0;
388                 }
389                 if (have_text[i]) {
390                         ++off;
391                 }
392         }
393
394         /* Set up the tab selection */
395
396         auto done = false;
397         for (size_t i = 0; i < _notebook->GetPageCount(); ++i) {
398                 if (_notebook->GetPage(i) == _last_selected_tab) {
399                         _notebook->SetSelection (i);
400                         done = true;
401                 }
402         }
403
404         if (!done && _notebook->GetPageCount() > 0) {
405                 _notebook->SetSelection (0);
406         }
407
408         setup_sensitivity ();
409         SelectionChanged ();
410 }
411
412
413 void
414 ContentPanel::add_file_clicked ()
415 {
416         /* This method is also called when Ctrl-A is pressed, so check that our notebook page
417            is visible.
418         */
419         if (_parent->GetCurrentPage() != _splitter || !_film) {
420                 return;
421         }
422
423         /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
424            non-Latin filenames or paths.
425         */
426         auto d = new wxFileDialog (
427                 _splitter,
428                 _("Choose a file or files"),
429                 wxT (""),
430                 wxT (""),
431                 wxT ("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"),
432                 wxFD_MULTIPLE | wxFD_CHANGE_DIR
433                 );
434
435         int const r = d->ShowModal ();
436
437         if (r != wxID_OK) {
438                 d->Destroy ();
439                 return;
440         }
441
442         wxArrayString paths;
443         d->GetPaths (paths);
444         list<boost::filesystem::path> path_list;
445         for (unsigned int i = 0; i < paths.GetCount(); ++i) {
446                 path_list.push_back (wx_to_std (paths[i]));
447         }
448         add_files (path_list);
449
450         d->Destroy ();
451 }
452
453
454 void
455 ContentPanel::add_folder_clicked ()
456 {
457         auto d = new wxDirDialog (_splitter, _("Choose a folder"), wxT(""), wxDD_DIR_MUST_EXIST);
458         int r = d->ShowModal ();
459         boost::filesystem::path const path (wx_to_std (d->GetPath ()));
460         d->Destroy ();
461
462         if (r != wxID_OK) {
463                 return;
464         }
465
466         list<shared_ptr<Content> > content;
467
468         try {
469                 content = content_factory (path);
470         } catch (exception& e) {
471                 error_dialog (_parent, e.what());
472                 return;
473         }
474
475         if (content.empty ()) {
476                 error_dialog (_parent, _("No content found in this folder."));
477                 return;
478         }
479
480         for (auto i: content) {
481                 auto ic = dynamic_pointer_cast<ImageContent> (i);
482                 if (ic) {
483                         auto e = new ImageSequenceDialog (_splitter);
484                         r = e->ShowModal ();
485                         auto const frame_rate = e->frame_rate ();
486                         e->Destroy ();
487
488                         if (r != wxID_OK) {
489                                 return;
490                         }
491
492                         ic->set_video_frame_rate (frame_rate);
493                 }
494
495                 _film->examine_and_add_content (i);
496         }
497 }
498
499
500 void
501 ContentPanel::add_dcp_clicked ()
502 {
503         auto d = new wxDirDialog (_splitter, _("Choose a DCP folder"), wxT(""), wxDD_DIR_MUST_EXIST);
504         int r = d->ShowModal ();
505         boost::filesystem::path const path (wx_to_std (d->GetPath ()));
506         d->Destroy ();
507
508         if (r != wxID_OK) {
509                 return;
510         }
511
512         try {
513                 _film->examine_and_add_content (make_shared<DCPContent>(path));
514         } catch (ProjectFolderError &) {
515                 error_dialog (
516                         _parent,
517                         _(
518                                 "This looks like a DCP-o-matic project folder, which cannot be added to a different project.  "
519                                 "Choose the DCP directory inside the DCP-o-matic project folder if that's what you want to import."
520                          )
521                         );
522         } catch (exception& e) {
523                 error_dialog (_parent, e.what());
524         }
525 }
526
527
528 /** @return true if this remove "click" should be ignored */
529 bool
530 ContentPanel::remove_clicked (bool hotkey)
531 {
532         /* If the method was called because Delete was pressed check that our notebook page
533            is visible and that the content list is focussed.
534         */
535         if (hotkey && (_parent->GetCurrentPage() != _splitter || !_content->HasFocus())) {
536                 return true;
537         }
538
539         for (auto i: selected ()) {
540                 _film->remove_content (i);
541         }
542
543         check_selection ();
544         return false;
545 }
546
547
548 void
549 ContentPanel::timeline_clicked ()
550 {
551         if (!_film) {
552                 return;
553         }
554
555         if (_timeline_dialog) {
556                 _timeline_dialog->Destroy ();
557                 _timeline_dialog = nullptr;
558         }
559
560         _timeline_dialog = new TimelineDialog (this, _film, _film_viewer);
561         _timeline_dialog->set_selection (selected());
562         _timeline_dialog->Show ();
563 }
564
565
566 void
567 ContentPanel::right_click (wxListEvent& ev)
568 {
569         _menu->popup (_film, selected (), TimelineContentViewList (), ev.GetPoint ());
570 }
571
572
573 /** Set up broad sensitivity based on the type of content that is selected */
574 void
575 ContentPanel::setup_sensitivity ()
576 {
577         _add_file->Enable (_generally_sensitive);
578         _add_folder->Enable (_generally_sensitive);
579         _add_dcp->Enable (_generally_sensitive);
580
581         auto selection = selected ();
582         auto video_selection = selected_video ();
583         auto audio_selection = selected_audio ();
584
585         _remove->Enable   (_generally_sensitive && !selection.empty());
586         _earlier->Enable  (_generally_sensitive && selection.size() == 1);
587         _later->Enable    (_generally_sensitive && selection.size() == 1);
588         _timeline->Enable (_generally_sensitive && _film && !_film->content().empty());
589
590         if (_video_panel) {
591                 _video_panel->Enable (_generally_sensitive && video_selection.size() > 0);
592         }
593         if (_audio_panel) {
594                 _audio_panel->Enable (_generally_sensitive && audio_selection.size() > 0);
595         }
596         for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
597                 if (_text_panel[i]) {
598                         _text_panel[i]->Enable (_generally_sensitive && selection.size() == 1 && !selection.front()->text.empty());
599                 }
600         }
601         _timing_panel->Enable (_generally_sensitive);
602 }
603
604
605 void
606 ContentPanel::set_film (shared_ptr<Film> film)
607 {
608         if (_audio_panel) {
609                 _audio_panel->set_film (film);
610         }
611
612         _film = film;
613
614         film_changed (Film::Property::CONTENT);
615         film_changed (Film::Property::AUDIO_CHANNELS);
616
617         if (_film) {
618                 check_selection ();
619         }
620
621         setup_sensitivity ();
622 }
623
624
625 void
626 ContentPanel::set_general_sensitivity (bool s)
627 {
628         _generally_sensitive = s;
629         setup_sensitivity ();
630 }
631
632
633 void
634 ContentPanel::earlier_clicked ()
635 {
636         auto sel = selected ();
637         if (sel.size() == 1) {
638                 _film->move_content_earlier (sel.front ());
639                 check_selection ();
640         }
641 }
642
643
644 void
645 ContentPanel::later_clicked ()
646 {
647         auto sel = selected ();
648         if (sel.size() == 1) {
649                 _film->move_content_later (sel.front ());
650                 check_selection ();
651         }
652 }
653
654
655 void
656 ContentPanel::set_selection (weak_ptr<Content> wc)
657 {
658         auto content = _film->content ();
659         for (size_t i = 0; i < content.size(); ++i) {
660                 if (content[i] == wc.lock ()) {
661                         _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
662                 } else {
663                         _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
664                 }
665         }
666 }
667
668
669 void
670 ContentPanel::set_selection (ContentList cl)
671 {
672         _no_check_selection = true;
673
674         auto content = _film->content ();
675         for (size_t i = 0; i < content.size(); ++i) {
676                 if (find(cl.begin(), cl.end(), content[i]) != cl.end()) {
677                         _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
678                 } else {
679                         _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
680                 }
681         }
682
683         _no_check_selection = false;
684         check_selection ();
685 }
686
687
688 void
689 ContentPanel::select_all ()
690 {
691         set_selection (_film->content());
692 }
693
694
695 void
696 ContentPanel::film_content_changed (int property)
697 {
698         if (
699                 property == ContentProperty::PATH ||
700                 property == DCPContentProperty::NEEDS_ASSETS ||
701                 property == DCPContentProperty::NEEDS_KDM ||
702                 property == DCPContentProperty::NAME
703                 ) {
704
705                 setup ();
706         }
707
708         for (auto i: panels()) {
709                 i->film_content_changed (property);
710         }
711 }
712
713
714 void
715 ContentPanel::setup ()
716 {
717         if (!_film) {
718                 _content->DeleteAllItems ();
719                 setup_sensitivity ();
720                 return;
721         }
722
723         auto content = _film->content ();
724
725         Content* selected_content = nullptr;
726         auto const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
727         if (s != -1) {
728                 wxListItem item;
729                 item.SetId (s);
730                 item.SetMask (wxLIST_MASK_DATA);
731                 _content->GetItem (item);
732                 selected_content = reinterpret_cast<Content*> (item.GetData ());
733         }
734
735         _content->DeleteAllItems ();
736
737         for (auto i: content) {
738                 int const t = _content->GetItemCount ();
739                 bool const valid = i->paths_valid ();
740
741                 auto dcp = dynamic_pointer_cast<DCPContent> (i);
742                 bool const needs_kdm = dcp && dcp->needs_kdm ();
743                 bool const needs_assets = dcp && dcp->needs_assets ();
744
745                 auto s = std_to_wx (i->summary ());
746
747                 if (!valid) {
748                         s = _("MISSING: ") + s;
749                 }
750
751                 if (needs_kdm) {
752                         s = _("NEEDS KDM: ") + s;
753                 }
754
755                 if (needs_assets) {
756                         s = _("NEEDS OV: ") + s;
757                 }
758
759                 wxListItem item;
760                 item.SetId (t);
761                 item.SetText (s);
762                 item.SetData (i.get ());
763                 _content->InsertItem (item);
764
765                 if (i.get() == selected_content) {
766                         _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
767                 }
768
769                 if (!valid || needs_kdm || needs_assets) {
770                         _content->SetItemTextColour (t, *wxRED);
771                 }
772         }
773
774         if (!selected_content && !content.empty ()) {
775                 /* Select the item of content if none was selected before */
776                 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
777         }
778
779         setup_sensitivity ();
780 }
781
782
783 void
784 ContentPanel::files_dropped (wxDropFilesEvent& event)
785 {
786         if (!_film) {
787                 return;
788         }
789
790         auto paths = event.GetFiles ();
791         list<boost::filesystem::path> path_list;
792         for (int i = 0; i < event.GetNumberOfFiles(); i++) {
793                 path_list.push_back (wx_to_std (paths[i]));
794         }
795
796         add_files (path_list);
797 }
798
799
800 void
801 ContentPanel::add_files (list<boost::filesystem::path> paths)
802 {
803         /* It has been reported that the paths returned from e.g. wxFileDialog are not always sorted;
804            I can't reproduce that, but sort them anyway.  Don't use ImageFilenameSorter as a normal
805            alphabetical sort is expected here.
806         */
807
808         paths.sort (CaseInsensitiveSorter ());
809
810         /* XXX: check for lots of files here and do something */
811
812         try {
813                 for (auto i: paths) {
814                         for (auto j: content_factory(i)) {
815                                 _film->examine_and_add_content (j);
816                         }
817                 }
818         } catch (exception& e) {
819                 error_dialog (_parent, e.what());
820         }
821 }
822
823
824 list<ContentSubPanel*>
825 ContentPanel::panels () const
826 {
827         list<ContentSubPanel*> p;
828         if (_video_panel) {
829                 p.push_back (_video_panel);
830         }
831         if (_audio_panel) {
832                 p.push_back (_audio_panel);
833         }
834         for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
835                 if (_text_panel[i]) {
836                         p.push_back (_text_panel[i]);
837                 }
838         }
839         p.push_back (_timing_panel);
840         return p;
841 }
842
843
844 LimitedSplitter::LimitedSplitter (wxWindow* parent)
845         : wxSplitterWindow (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_3DSASH | wxSP_LIVE_UPDATE)
846         , _first_shown (false)
847         , _top_panel_minimum_size (350)
848 {
849         /* This value doesn't really mean much but we just want to stop double-click on the
850            divider from shrinking the bottom panel (#1601).
851         */
852         SetMinimumPaneSize (64);
853
854         Bind (wxEVT_SIZE, boost::bind(&LimitedSplitter::sized, this, _1));
855 }
856
857
858 void
859 LimitedSplitter::first_shown (wxWindow* top, wxWindow* bottom)
860 {
861         int const sn = wxDisplay::GetFromWindow(this);
862         if (sn >= 0) {
863                 wxRect const screen = wxDisplay(sn).GetClientArea();
864                 /* This is a hack to try and make the content notebook a sensible size; large on big displays but small
865                    enough on small displays to leave space for the content area.
866                    */
867                 SplitHorizontally (top, bottom, screen.height > 800 ? -600 : -_top_panel_minimum_size);
868         } else {
869                 /* Fallback for when GetFromWindow fails for reasons that aren't clear */
870                 SplitHorizontally (top, bottom, -600);
871         }
872         _first_shown = true;
873 }
874
875
876 void
877 LimitedSplitter::sized (wxSizeEvent& ev)
878 {
879         if (_first_shown && GetSize().GetHeight() > _top_panel_minimum_size && GetSashPosition() < _top_panel_minimum_size) {
880                 /* The window is now fairly big but the top panel is small; this happens when the DCP-o-matic window
881                  * is shrunk and then made larger again.  Try to set a sensible top panel size in this case (#1839).
882                  */
883                 SetSashPosition (_top_panel_minimum_size);
884         }
885
886         ev.Skip ();
887 }