Fix playhead position after trim-up-to (#1847).
[dcpomatic.git] / src / wx / timing_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 "timing_panel.h"
22 #include "wx_util.h"
23 #include "film_viewer.h"
24 #include "timecode.h"
25 #include "content_panel.h"
26 #include "move_to_dialog.h"
27 #include "static_text.h"
28 #include "dcpomatic_button.h"
29 #include "lib/content.h"
30 #include "lib/image_content.h"
31 #include "lib/text_content.h"
32 #include "lib/dcp_subtitle_content.h"
33 #include "lib/audio_content.h"
34 #include "lib/string_text_file_content.h"
35 #include "lib/video_content.h"
36 #include "lib/dcp_content.h"
37 #include "lib/ffmpeg_content.h"
38 #include <dcp/locale_convert.h>
39 #include "lib/warnings.h"
40 #if defined(__WXGTK20__) && !defined(__WXGTK3__)
41 #define TIMING_PANEL_ALIGNMENT_HACK 1
42 DCPOMATIC_DISABLE_WARNINGS
43 #include <gtk/gtk.h>
44 DCPOMATIC_ENABLE_WARNINGS
45 #endif
46 #include <boost/foreach.hpp>
47 #include <set>
48 #include <iostream>
49
50 using std::cout;
51 using std::string;
52 using std::set;
53 using boost::shared_ptr;
54 using boost::weak_ptr;
55 using boost::dynamic_pointer_cast;
56 using boost::optional;
57 #if BOOST_VERSION >= 106100
58 using namespace boost::placeholders;
59 #endif
60 using dcp::locale_convert;
61 using namespace dcpomatic;
62
63 TimingPanel::TimingPanel (ContentPanel* p, weak_ptr<FilmViewer> viewer)
64         /* horrid hack for apparent lack of context support with wxWidgets i18n code */
65         /// TRANSLATORS: translate the word "Timing" here; do not include the "Timing|" prefix
66         : ContentSubPanel (p, S_("Timing|Timing"))
67         , _viewer (viewer)
68         , _film_content_changed_suspender (boost::bind(&TimingPanel::film_content_changed, this, _1))
69 {
70         wxSize size = TimecodeBase::size (this);
71
72         for (int i = 0; i < 3; ++i) {
73                 _colon[i] = create_label (this, wxT(":"), false);
74         }
75
76         //// TRANSLATORS: this is an abbreviation for "hours"
77         _h_label = new StaticText (this, _("h"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
78 #ifdef TIMING_PANEL_ALIGNMENT_HACK
79         /* Hack to work around failure to centre text on GTK */
80         gtk_label_set_line_wrap (GTK_LABEL(_h_label->GetHandle()), FALSE);
81 #endif
82         //// TRANSLATORS: this is an abbreviation for "minutes"
83         _m_label = new StaticText (this, _("m"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
84 #ifdef TIMING_PANEL_ALIGNMENT_HACK
85         gtk_label_set_line_wrap (GTK_LABEL (_m_label->GetHandle()), FALSE);
86 #endif
87         //// TRANSLATORS: this is an abbreviation for "seconds"
88         _s_label = new StaticText (this, _("s"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
89 #ifdef TIMING_PANEL_ALIGNMENT_HACK
90         gtk_label_set_line_wrap (GTK_LABEL(_s_label->GetHandle()), FALSE);
91 #endif
92         //// TRANSLATORS: this is an abbreviation for "frames"
93         _f_label = new StaticText (this, _("f"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
94 #ifdef TIMING_PANEL_ALIGNMENT_HACK
95         gtk_label_set_line_wrap (GTK_LABEL(_f_label->GetHandle()), FALSE);
96 #endif
97
98         _position_label = create_label (this, _("Position"), true);
99         _position = new Timecode<DCPTime> (this);
100         _move_to_start_of_reel = new Button (this, _("Move to start of reel"));
101         _full_length_label = create_label (this, _("Full length"), true);
102         _full_length = new Timecode<DCPTime> (this);
103         _trim_start_label = create_label (this, _("Trim from start"), true);
104         _trim_start = new Timecode<ContentTime> (this);
105         _trim_start_to_playhead = new Button (this, _("Trim up to current position"));
106         _trim_end_label = create_label (this, _("Trim from end"), true);
107         _trim_end = new Timecode<ContentTime> (this);
108         _trim_end_to_playhead = new Button (this, _("Trim after current position"));
109         _play_length_label = create_label (this, _("Play length"), true);
110         _play_length = new Timecode<DCPTime> (this);
111
112         _video_frame_rate_label = create_label (this, _("Video frame rate"), true);
113         _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
114         _set_video_frame_rate = new Button (this, _("Set"));
115         _set_video_frame_rate->Enable (false);
116
117         /* We can't use Wrap() here as it doesn't work with markup:
118          * http://trac.wxwidgets.org/ticket/13389
119          */
120
121         wxString in = _("<i>Only change this if the content's frame rate has been read incorrectly.</i>");
122         wxString out;
123         int const width = 20;
124         int current = 0;
125         for (size_t i = 0; i < in.Length(); ++i) {
126                 if (in[i] == ' ' && current >= width) {
127                         out += '\n';
128                         current = 0;
129                 } else {
130                         out += in[i];
131                         ++current;
132                 }
133         }
134
135         _tip = new StaticText (this, wxT (""));
136         _tip->SetLabelMarkup (out);
137 #ifdef DCPOMATIC_OSX
138         /* Hack to stop hidden text on some versions of OS X */
139         _tip->SetMinSize (wxSize (-1, 256));
140 #endif
141
142         _position->Changed.connect    (boost::bind (&TimingPanel::position_changed, this));
143         _move_to_start_of_reel->Bind  (wxEVT_BUTTON, boost::bind (&TimingPanel::move_to_start_of_reel_clicked, this));
144         _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
145         _trim_start->Changed.connect  (boost::bind (&TimingPanel::trim_start_changed, this));
146         _trim_start_to_playhead->Bind (wxEVT_BUTTON, boost::bind (&TimingPanel::trim_start_to_playhead_clicked, this));
147         _trim_end->Changed.connect    (boost::bind (&TimingPanel::trim_end_changed, this));
148         _trim_end_to_playhead->Bind   (wxEVT_BUTTON, boost::bind (&TimingPanel::trim_end_to_playhead_clicked, this));
149         _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
150         _video_frame_rate->Bind       (wxEVT_TEXT, boost::bind (&TimingPanel::video_frame_rate_changed, this));
151         _set_video_frame_rate->Bind   (wxEVT_BUTTON, boost::bind (&TimingPanel::set_video_frame_rate, this));
152
153         shared_ptr<FilmViewer> fv = _viewer.lock ();
154         DCPOMATIC_ASSERT (fv);
155         fv->ImageChanged.connect (boost::bind (&TimingPanel::setup_sensitivity, this));
156
157         setup_sensitivity ();
158         add_to_grid ();
159 }
160
161 void
162 TimingPanel::add_to_grid ()
163 {
164         bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
165
166         int r = 0;
167
168         wxSizer* labels = new wxBoxSizer (wxHORIZONTAL);
169         labels->Add (_h_label, 1, wxEXPAND);
170         add_label_to_sizer (labels, _colon[0], false);
171         labels->Add (_m_label, 1, wxEXPAND);
172         add_label_to_sizer (labels, _colon[1], false);
173         labels->Add (_s_label, 1, wxEXPAND);
174         add_label_to_sizer (labels, _colon[2], false);
175         labels->Add (_f_label, 1, wxEXPAND);
176         _grid->Add (labels, wxGBPosition(r, 1));
177         ++r;
178
179         add_label_to_sizer (_grid, _position_label, true, wxGBPosition(r, 0));
180         _grid->Add (_position, wxGBPosition(r, 1));
181         ++r;
182
183         _move_to_start_of_reel->Show (full);
184         _full_length_label->Show (full);
185         _full_length->Show (full);
186         _play_length_label->Show (full);
187         _play_length->Show (full);
188         _video_frame_rate_label->Show (full);
189         _video_frame_rate->Show (full);
190         _set_video_frame_rate->Show (full);
191         _tip->Show (full);
192
193         if (full) {
194                 _grid->Add (_move_to_start_of_reel, wxGBPosition(r, 1));
195                 ++r;
196
197                 add_label_to_sizer (_grid, _full_length_label, true, wxGBPosition(r, 0));
198                 _grid->Add (_full_length, wxGBPosition(r, 1));
199                 ++r;
200         }
201
202         add_label_to_sizer (_grid, _trim_start_label, true, wxGBPosition(r, 0));
203         _grid->Add (_trim_start, wxGBPosition(r, 1));
204         ++r;
205
206         _grid->Add (_trim_start_to_playhead, wxGBPosition(r, 1));
207         ++r;
208
209         add_label_to_sizer (_grid, _trim_end_label, true, wxGBPosition(r, 0));
210         _grid->Add (_trim_end, wxGBPosition(r, 1));
211         ++r;
212
213         _grid->Add (_trim_end_to_playhead, wxGBPosition(r, 1));
214         ++r;
215
216         if (full) {
217                 add_label_to_sizer (_grid, _play_length_label, true, wxGBPosition(r, 0));
218                 _grid->Add (_play_length, wxGBPosition(r, 1));
219                 ++r;
220
221                 {
222                         add_label_to_sizer (_grid, _video_frame_rate_label, true, wxGBPosition(r, 0));
223                         wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
224                         s->Add (_video_frame_rate, 1, wxEXPAND);
225                         s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
226                         _grid->Add (s, wxGBPosition(r, 1), wxGBSpan(1, 2));
227                 }
228                 ++r;
229
230                 _grid->Add (_tip, wxGBPosition(r, 1), wxGBSpan(1, 2));
231         }
232
233         /* Completely speculative fix for #891 */
234         _grid->Layout ();
235 }
236
237 void
238 TimingPanel::update_full_length ()
239 {
240         set<DCPTime> check;
241         BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
242                 check.insert (i->full_length(_parent->film()));
243         }
244
245         if (check.size() == 1) {
246                 _full_length->set (_parent->selected().front()->full_length(_parent->film()), _parent->film()->video_frame_rate());
247         } else {
248                 _full_length->clear ();
249         }
250 }
251
252 void
253 TimingPanel::update_play_length ()
254 {
255         set<DCPTime> check;
256         BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
257                 check.insert (i->length_after_trim(_parent->film()));
258         }
259
260         if (check.size() == 1) {
261                 _play_length->set (_parent->selected().front()->length_after_trim(_parent->film()), _parent->film()->video_frame_rate());
262         } else {
263                 _play_length->clear ();
264         }
265 }
266
267 void
268 TimingPanel::film_content_changed (int property)
269 {
270         if (_film_content_changed_suspender.check(property)) {
271                 return;
272         }
273
274         int const film_video_frame_rate = _parent->film()->video_frame_rate ();
275
276         /* Here we check to see if we have exactly one different value of various
277            properties, and fill the controls with that value if so.
278         */
279
280         if (property == ContentProperty::POSITION) {
281
282                 set<DCPTime> check;
283                 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
284                         check.insert (i->position ());
285                 }
286
287                 if (check.size() == 1) {
288                         _position->set (_parent->selected().front()->position(), film_video_frame_rate);
289                 } else {
290                         _position->clear ();
291                 }
292
293         } else if (
294                 property == ContentProperty::LENGTH ||
295                 property == ContentProperty::VIDEO_FRAME_RATE ||
296                 property == VideoContentProperty::FRAME_TYPE
297                 ) {
298
299                 update_full_length ();
300
301         } else if (property == ContentProperty::TRIM_START) {
302
303                 set<ContentTime> check;
304                 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
305                         check.insert (i->trim_start ());
306                 }
307
308                 if (check.size() == 1) {
309                         _trim_start->set (_parent->selected().front()->trim_start (), film_video_frame_rate);
310                 } else {
311                         _trim_start->clear ();
312                 }
313
314         } else if (property == ContentProperty::TRIM_END) {
315
316                 set<ContentTime> check;
317                 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
318                         check.insert (i->trim_end ());
319                 }
320
321                 if (check.size() == 1) {
322                         _trim_end->set (_parent->selected().front()->trim_end (), film_video_frame_rate);
323                 } else {
324                         _trim_end->clear ();
325                 }
326         }
327
328         if (
329                 property == ContentProperty::LENGTH ||
330                 property == ContentProperty::TRIM_START ||
331                 property == ContentProperty::TRIM_END ||
332                 property == ContentProperty::VIDEO_FRAME_RATE ||
333                 property == VideoContentProperty::FRAME_TYPE
334                 ) {
335
336                 update_play_length ();
337         }
338
339         if (property == ContentProperty::VIDEO_FRAME_RATE) {
340                 set<double> check_vc;
341                 shared_ptr<const Content> content;
342                 int count_ac = 0;
343                 int count_sc = 0;
344                 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
345                         if (i->video && i->video_frame_rate()) {
346                                 check_vc.insert (i->video_frame_rate().get());
347                                 content = i;
348                         }
349                         if (i->audio && i->video_frame_rate()) {
350                                 ++count_ac;
351                                 content = i;
352                         }
353                         if (!i->text.empty() && i->video_frame_rate()) {
354                                 ++count_sc;
355                                 content = i;
356                         }
357
358                 }
359
360                 bool const single_frame_image_content = content && dynamic_pointer_cast<const ImageContent> (content) && content->number_of_paths() == 1;
361
362                 if ((check_vc.size() == 1 || count_ac == 1 || count_sc == 1) && !single_frame_image_content) {
363                         checked_set (_video_frame_rate, locale_convert<string> (content->video_frame_rate().get(), 5));
364                         _video_frame_rate->Enable (true);
365                 } else {
366                         checked_set (_video_frame_rate, wxT (""));
367                         _video_frame_rate->Enable (false);
368                 }
369         }
370
371         bool have_still = false;
372         BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
373                 shared_ptr<const ImageContent> ic = dynamic_pointer_cast<const ImageContent> (i);
374                 if (ic && ic->still ()) {
375                         have_still = true;
376                 }
377         }
378
379         _full_length->set_editable (have_still);
380         _play_length->set_editable (!have_still);
381         _set_video_frame_rate->Enable (false);
382         setup_sensitivity ();
383 }
384
385 void
386 TimingPanel::position_changed ()
387 {
388         DCPTime const pos = _position->get (_parent->film()->video_frame_rate ());
389         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
390                 i->set_position (_parent->film(), pos);
391         }
392 }
393
394 void
395 TimingPanel::full_length_changed ()
396 {
397         int const vfr = _parent->film()->video_frame_rate ();
398         Frame const len = _full_length->get (vfr).frames_round (vfr);
399         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
400                 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (i);
401                 if (ic && ic->still ()) {
402                         ic->video->set_length (len);
403                 }
404         }
405 }
406
407 void
408 TimingPanel::trim_start_changed ()
409 {
410         shared_ptr<FilmViewer> fv = _viewer.lock ();
411         if (!fv) {
412                 return;
413         }
414
415         DCPTime const ph = fv->position ();
416
417         fv->set_coalesce_player_changes (true);
418
419         shared_ptr<Content> ref;
420         optional<FrameRateChange> ref_frc;
421         optional<DCPTime> ref_ph;
422
423         Suspender::Block bl = _film_content_changed_suspender.block ();
424         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
425                 if (i->position() <= ph && ph < i->end(_parent->film())) {
426                         /* The playhead is in i.  Use it as a reference to work out
427                            where to put the playhead post-trim; we're trying to keep the playhead
428                            at the same frame of content that we're looking at pre-trim.
429                         */
430                         ref = i;
431                         ref_frc = _parent->film()->active_frame_rate_change (i->position ());
432                         ref_ph = ph - i->position() + DCPTime (i->trim_start(), ref_frc.get());
433                 }
434
435                 ContentTime const trim = _trim_start->get (i->video_frame_rate().get_value_or(_parent->film()->video_frame_rate()));
436                 i->set_trim_start (trim);
437         }
438
439         if (ref) {
440                 fv->seek (max(DCPTime(), ref_ph.get() + ref->position() - DCPTime(ref->trim_start(), ref_frc.get())), true);
441         }
442
443         fv->set_coalesce_player_changes (false);
444 }
445
446 void
447 TimingPanel::trim_end_changed ()
448 {
449         shared_ptr<FilmViewer> fv = _viewer.lock ();
450         if (!fv) {
451                 return;
452         }
453
454         fv->set_coalesce_player_changes (true);
455
456         Suspender::Block bl = _film_content_changed_suspender.block ();
457         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
458                 ContentTime const trim = _trim_end->get (i->video_frame_rate().get_value_or(_parent->film()->video_frame_rate()));
459                 i->set_trim_end (trim);
460         }
461
462         /* XXX: maybe playhead-off-the-end-of-the-film should be handled elsewhere */
463         if (fv->position() >= _parent->film()->length()) {
464                 fv->seek (_parent->film()->length() - DCPTime::from_frames(1, _parent->film()->video_frame_rate()), true);
465         }
466
467         fv->set_coalesce_player_changes (false);
468 }
469
470 void
471 TimingPanel::play_length_changed ()
472 {
473         DCPTime const play_length = _play_length->get (_parent->film()->video_frame_rate());
474         Suspender::Block bl = _film_content_changed_suspender.block ();
475         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
476                 FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
477                 i->set_trim_end (
478                         ContentTime (max(DCPTime(), i->full_length(_parent->film()) - play_length), frc) - i->trim_start()
479                         );
480         }
481 }
482
483 void
484 TimingPanel::video_frame_rate_changed ()
485 {
486         bool enable = true;
487         if (_video_frame_rate->GetValue() == wxT("")) {
488                 /* No frame rate has been entered; if the user clicks "set" now it would unset the video
489                    frame rate in the selected content.  This can't be allowed for some content types.
490                 */
491                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected()) {
492                         if (
493                                 dynamic_pointer_cast<DCPContent>(i) ||
494                                 dynamic_pointer_cast<FFmpegContent>(i)
495                                 ) {
496                                 enable = false;
497                         }
498                 }
499         }
500
501         _set_video_frame_rate->Enable (enable);
502 }
503
504 void
505 TimingPanel::set_video_frame_rate ()
506 {
507         optional<double> fr;
508         if (_video_frame_rate->GetValue() != wxT("")) {
509                 fr = locale_convert<double> (wx_to_std (_video_frame_rate->GetValue ()));
510         }
511         Suspender::Block bl = _film_content_changed_suspender.block ();
512         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
513                 if (fr) {
514                         i->set_video_frame_rate (*fr);
515                 } else {
516                         i->unset_video_frame_rate ();
517                 }
518         }
519
520         _set_video_frame_rate->Enable (false);
521 }
522
523 void
524 TimingPanel::content_selection_changed ()
525 {
526         setup_sensitivity ();
527
528         film_content_changed (ContentProperty::POSITION);
529         film_content_changed (ContentProperty::LENGTH);
530         film_content_changed (ContentProperty::TRIM_START);
531         film_content_changed (ContentProperty::TRIM_END);
532         film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
533 }
534
535 void
536 TimingPanel::film_changed (Film::Property p)
537 {
538         if (p == Film::VIDEO_FRAME_RATE) {
539                 update_full_length ();
540                 update_play_length ();
541         }
542 }
543
544 void
545 TimingPanel::trim_start_to_playhead_clicked ()
546 {
547         shared_ptr<FilmViewer> fv = _viewer.lock ();
548         if (!fv) {
549                 return;
550         }
551
552         shared_ptr<const Film> film = _parent->film ();
553         DCPTime const ph = fv->position().floor (film->video_frame_rate ());
554         optional<DCPTime> new_ph;
555
556         fv->set_coalesce_player_changes (true);
557
558         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
559                 if (i->position() < ph && ph < i->end(film)) {
560                         FrameRateChange const frc = film->active_frame_rate_change (i->position());
561                         i->set_trim_start (i->trim_start() + ContentTime (ph - i->position(), frc));
562                         new_ph = i->position ();
563                 }
564         }
565
566         fv->set_coalesce_player_changes (false);
567
568         if (new_ph) {
569                 fv->seek (new_ph.get(), true);
570         }
571 }
572
573 void
574 TimingPanel::trim_end_to_playhead_clicked ()
575 {
576         shared_ptr<FilmViewer> fv = _viewer.lock ();
577         if (!fv) {
578                 return;
579         }
580
581         shared_ptr<const Film> film = _parent->film ();
582         DCPTime const ph = fv->position().floor (film->video_frame_rate ());
583         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
584                 if (i->position() < ph && ph < i->end(film)) {
585                         FrameRateChange const frc = film->active_frame_rate_change (i->position ());
586                         i->set_trim_end (ContentTime(i->position() + i->full_length(film) - ph - DCPTime::from_frames(1, frc.dcp), frc) - i->trim_start());
587                 }
588         }
589 }
590
591 void
592 TimingPanel::setup_sensitivity ()
593 {
594         bool const e = !_parent->selected().empty ();
595
596         _position->Enable (e);
597         _move_to_start_of_reel->Enable (e);
598         _full_length->Enable (e);
599         _trim_start->Enable (e);
600         _trim_end->Enable (e);
601         _play_length->Enable (e);
602         _video_frame_rate->Enable (e);
603
604         shared_ptr<FilmViewer> fv = _viewer.lock ();
605         DCPOMATIC_ASSERT (fv);
606         DCPTime const ph = fv->position ();
607         bool any_over_ph = false;
608         BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
609                 if (i->position() <= ph && ph < i->end(_parent->film())) {
610                         any_over_ph = true;
611                 }
612         }
613
614         _trim_start_to_playhead->Enable (any_over_ph);
615         _trim_end_to_playhead->Enable (any_over_ph);
616 }
617
618 void
619 TimingPanel::move_to_start_of_reel_clicked ()
620 {
621         /* Find common position of all selected content, if it exists */
622
623         optional<DCPTime> position;
624         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
625                 if (!position) {
626                         position = i->position();
627                 } else {
628                         if (position.get() != i->position()) {
629                                 position.reset ();
630                                 break;
631                         }
632                 }
633         }
634
635         MoveToDialog* d = new MoveToDialog (this, position, _parent->film());
636
637         if (d->ShowModal() == wxID_OK) {
638                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected()) {
639                         i->set_position (_parent->film(), d->position());
640                 }
641         }
642         d->Destroy ();
643 }