Give content menu on both main control and timeline. Fix silly bug on updating edito...
[dcpomatic.git] / src / wx / content_menu.cc
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <wx/wx.h>
21 #include "lib/film.h"
22 #include "content_menu.h"
23 #include "repeat_dialog.h"
24
25 using std::cout;
26 using boost::shared_ptr;
27
28 enum {
29         ID_repeat,
30         ID_remove
31 };
32
33 ContentMenu::ContentMenu (shared_ptr<Film> f, wxWindow* p)
34         : _menu (new wxMenu)
35         , _film (f)
36         , _parent (p)
37 {
38         _menu->Append (ID_repeat, _("Repeat..."));
39         _menu->AppendSeparator ();
40         _menu->Append (ID_remove, _("Remove"));
41
42         _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, &ContentMenu::repeat, this, ID_repeat);
43         _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, &ContentMenu::remove, this, ID_remove);
44 }
45
46 ContentMenu::~ContentMenu ()
47 {
48         delete _menu;
49 }
50
51 void
52 ContentMenu::popup (ContentList c, wxPoint p)
53 {
54         _content = c;
55         _parent->PopupMenu (_menu, p);
56 }
57
58 void
59 ContentMenu::repeat (wxCommandEvent &)
60 {
61         if (_content.empty ()) {
62                 return;
63         }
64                 
65         RepeatDialog d (_parent);
66         d.ShowModal ();
67
68         shared_ptr<const Film> film = _film.lock ();
69         if (!film) {
70                 return;
71         }
72
73         film->playlist()->repeat (_content, d.number ());
74         d.Destroy ();
75
76         _content.clear ();
77 }
78
79 void
80 ContentMenu::remove (wxCommandEvent &)
81 {
82         if (_content.empty ()) {
83                 return;
84         }
85
86         shared_ptr<const Film> film = _film.lock ();
87         if (!film) {
88                 return;
89         }
90
91         film->playlist()->remove (_content);
92
93         _content.clear ();
94 }
95