Select newly-added content (#455).
[dcpomatic.git] / src / wx / film_editor.cc
1 /*
2     Copyright (C) 2012-2015 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 /** @file src/wx/film_editor.cc
21  *  @brief FilmEditor class.
22  */
23
24 #include "lib/film.h"
25 #include "lib/job_manager.h"
26 #include "lib/content.h"
27 #include "lib/dcp_content.h"
28 #include "wx_util.h"
29 #include "film_editor.h"
30 #include "dcp_panel.h"
31 #include "content_panel.h"
32 #include <wx/wx.h>
33 #include <wx/notebook.h>
34 #include <iostream>
35
36 using std::cout;
37 using boost::shared_ptr;
38
39 /** @param f Film to edit */
40 FilmEditor::FilmEditor (wxWindow* parent, FilmViewer* viewer)
41         : wxPanel (parent)
42 {
43         wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
44
45         _main_notebook = new wxNotebook (this, wxID_ANY);
46         s->Add (_main_notebook, 1);
47
48         _content_panel = new ContentPanel (_main_notebook, _film, viewer);
49         _main_notebook->AddPage (_content_panel->panel (), _("Content"), true);
50         _dcp_panel = new DCPPanel (_main_notebook, _film);
51         _main_notebook->AddPage (_dcp_panel->panel (), _("DCP"), false);
52         
53         JobManager::instance()->ActiveJobsChanged.connect (
54                 bind (&FilmEditor::active_jobs_changed, this, _1)
55                 );
56
57         set_film (shared_ptr<Film> ());
58         SetSizerAndFit (s);
59 }
60
61
62 /** Called when the metadata stored in the Film object has changed;
63  *  so that we can update the GUI.
64  *  @param p Property of the Film that has changed.
65  */
66 void
67 FilmEditor::film_changed (Film::Property p)
68 {
69         ensure_ui_thread ();
70         
71         if (!_film) {
72                 return;
73         }
74
75         _content_panel->film_changed (p);
76         _dcp_panel->film_changed (p);
77
78         if (p == Film::CONTENT && !_film->content().empty ()) {
79                 /* Select newly-added content */
80                 _content_panel->set_selection (_film->content().back ());
81         }
82 }
83
84 void
85 FilmEditor::film_content_changed (int property)
86 {
87         ensure_ui_thread ();
88         
89         if (!_film) {
90                 /* We call this method ourselves (as well as using it as a signal handler)
91                    so _film can be 0.
92                 */
93                 return;
94         }
95
96         _content_panel->film_content_changed (property);
97         _dcp_panel->film_content_changed (property);
98 }
99
100 /** Sets the Film that we are editing */
101 void
102 FilmEditor::set_film (shared_ptr<Film> f)
103 {
104         set_general_sensitivity (f != 0);
105
106         if (_film == f) {
107                 return;
108         }
109         
110         _film = f;
111
112         _content_panel->set_film (_film);
113         _dcp_panel->set_film (_film);
114
115         if (_film) {
116                 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
117                 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _2));
118         }
119
120         if (_film) {
121                 FileChanged (_film->directory ());
122         } else {
123                 FileChanged ("");
124         }
125
126         if (!_film->content().empty ()) {
127                 _content_panel->set_selection (_film->content().front ());
128         }
129 }
130
131 void
132 FilmEditor::set_general_sensitivity (bool s)
133 {
134         _content_panel->set_general_sensitivity (s);
135         _dcp_panel->set_general_sensitivity (s);
136 }
137
138 void
139 FilmEditor::active_jobs_changed (bool a)
140 {
141         set_general_sensitivity (!a);
142 }