Merge 1.0 in.
[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/playlist.h"
22 #include "lib/film.h"
23 #include "content_menu.h"
24 #include "repeat_dialog.h"
25
26 using std::cout;
27 using boost::shared_ptr;
28
29 enum {
30         ID_repeat,
31         ID_remove
32 };
33
34 ContentMenu::ContentMenu (shared_ptr<Film> f, wxWindow* p)
35         : _menu (new wxMenu)
36         , _film (f)
37         , _parent (p)
38 {
39         _menu->Append (ID_repeat, _("Repeat..."));
40         _menu->AppendSeparator ();
41         _menu->Append (ID_remove, _("Remove"));
42
43         _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, &ContentMenu::repeat, this, ID_repeat);
44         _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, &ContentMenu::remove, this, ID_remove);
45 }
46
47 ContentMenu::~ContentMenu ()
48 {
49         delete _menu;
50 }
51
52 void
53 ContentMenu::popup (ContentList c, wxPoint p)
54 {
55         _content = c;
56         _parent->PopupMenu (_menu, p);
57 }
58
59 void
60 ContentMenu::repeat (wxCommandEvent &)
61 {
62         if (_content.empty ()) {
63                 return;
64         }
65                 
66         RepeatDialog d (_parent);
67         d.ShowModal ();
68
69         shared_ptr<const Film> film = _film.lock ();
70         if (!film) {
71                 return;
72         }
73
74         film->playlist()->repeat (_content, d.number ());
75         d.Destroy ();
76
77         _content.clear ();
78 }
79
80 void
81 ContentMenu::remove (wxCommandEvent &)
82 {
83         if (_content.empty ()) {
84                 return;
85         }
86
87         shared_ptr<const Film> film = _film.lock ();
88         if (!film) {
89                 return;
90         }
91
92         film->playlist()->remove (_content);
93
94         _content.clear ();
95 }
96