diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-01-17 00:03:43 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-01-17 00:03:43 +0000 |
| commit | dd353e14791138fc44b55b6f234567d706d313ff (patch) | |
| tree | 129fd07a8d93fc9930181e53ebf1b78f614af3b2 /src | |
| parent | 0ca36c0d2b238a9e2165b5d113c22f144835a672 (diff) | |
Add recent files list to player.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/config.cc | 29 | ||||
| -rw-r--r-- | src/lib/config.h | 12 | ||||
| -rw-r--r-- | src/tools/dcpomatic_player.cc | 83 |
3 files changed, 106 insertions, 18 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 9106a9559..e5fd9d17a 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -309,11 +309,14 @@ try _win32_console = f.optional_bool_child ("Win32Console").get_value_or (false); #endif - list<cxml::NodePtr> his = f.node_children ("History"); BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("History")) { _history.push_back (i->content ()); } + BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("PlayerHistory")) { + _player_history.push_back (i->content ()); + } + cxml::NodePtr signer = f.optional_node_child ("Signer"); if (signer) { shared_ptr<dcp::CertificateChain> c (new dcp::CertificateChain ()); @@ -632,6 +635,10 @@ Config::write_config () const root->add_child("History")->add_child_text (i.string ()); } + BOOST_FOREACH (boost::filesystem::path i, _player_history) { + root->add_child("PlayerHistory")->add_child_text (i.string ()); + } + /* [XML] DKDMGroup A group of DKDMs, each with a <code>Name</code> attribute, containing other <code><DKDMGroup></code> or <code><DKDM></code> tags. */ @@ -799,12 +806,24 @@ Config::set_cover_sheet_to_default () void Config::add_to_history (boost::filesystem::path p) { + add_to_history_internal (_history, p); +} + +void +Config::add_to_player_history (boost::filesystem::path p) +{ + add_to_history_internal (_player_history, p); +} + +void +Config::add_to_history_internal (vector<boost::filesystem::path>& h, boost::filesystem::path p) +{ /* Remove existing instances of this path in the history */ - _history.erase (remove (_history.begin(), _history.end(), p), _history.end ()); + h.erase (remove (h.begin(), h.end(), p), h.end ()); - _history.insert (_history.begin (), p); - if (_history.size() > HISTORY_SIZE) { - _history.pop_back (); + h.insert (h.begin (), p); + if (h.size() > HISTORY_SIZE) { + h.pop_back (); } changed (); diff --git a/src/lib/config.h b/src/lib/config.h index dae1924a8..f32b17106 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -286,6 +286,10 @@ public: return _history; } + std::vector<boost::filesystem::path> player_history () const { + return _player_history; + } + boost::shared_ptr<DKDMGroup> dkdms () const { return _dkdms; } @@ -639,7 +643,13 @@ public: changed (); } + void clear_player_history () { + _player_history.clear (); + changed (); + } + void add_to_history (boost::filesystem::path p); + void add_to_player_history (boost::filesystem::path p); void set_jump_to_selected (bool j) { maybe_set (_jump_to_selected, j); @@ -695,6 +705,7 @@ private: void read_cinemas (cxml::Document const & f); boost::shared_ptr<dcp::CertificateChain> create_certificate_chain (); boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const; + void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p); template <class T> void maybe_set (T& member, T new_value, Property prop = OTHER) { @@ -789,6 +800,7 @@ private: bool _win32_console; #endif std::vector<boost::filesystem::path> _history; + std::vector<boost::filesystem::path> _player_history; boost::shared_ptr<DKDMGroup> _dkdms; boost::filesystem::path _cinemas_file; bool _show_hints_before_make_dcp; diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index a75f6b9f4..4388ebbc3 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2017 Carl Hetherington <cth@carlh.net> + Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -55,6 +55,7 @@ using std::string; using std::cout; using std::exception; +using std::vector; using boost::shared_ptr; using boost::optional; @@ -62,7 +63,9 @@ enum { ID_file_open = 1, ID_file_add_ov, ID_file_add_kdm, - ID_file_close, + ID_file_history, + /* Allow spare IDs after _history for the recent files list */ + ID_file_close = 100, ID_view_scale_appropriate, ID_view_scale_full, ID_view_scale_half, @@ -79,6 +82,10 @@ public: , _update_news_requested (false) , _info (0) , _config_dialog (0) + , _file_menu (0) + , _history_items (0) + , _history_position (0) + , _history_separator (0) , _viewer (0) { @@ -97,10 +104,12 @@ public: #endif _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this)); + config_changed (); Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open); Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov); Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm); + Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE); Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close); Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT); Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES); @@ -166,6 +175,8 @@ public: _viewer->set_position (DCPTime ()); _info->triggered_update (); + Config::instance()->add_to_player_history (dir); + set_menu_sensitivity (); } @@ -173,22 +184,25 @@ private: void setup_menu (wxMenuBar* m) { - wxMenu* file = new wxMenu; - file->Append (ID_file_open, _("&Open...\tCtrl-O")); - _file_add_ov = file->Append (ID_file_add_ov, _("&Add OV...")); - _file_add_kdm = file->Append (ID_file_add_kdm, _("&Add KDM...")); - file->AppendSeparator (); - file->Append (ID_file_close, _("&Close")); - file->AppendSeparator (); + _file_menu = new wxMenu; + _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O")); + _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV...")); + _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM...")); + + _history_position = _file_menu->GetMenuItems().GetCount(); + + _file_menu->AppendSeparator (); + _file_menu->Append (ID_file_close, _("&Close")); + _file_menu->AppendSeparator (); #ifdef __WXOSX__ - file->Append (wxID_EXIT, _("&Exit")); + _file_menu->Append (wxID_EXIT, _("&Exit")); #else - file->Append (wxID_EXIT, _("&Quit")); + _file_menu->Append (wxID_EXIT, _("&Quit")); #endif #ifdef __WXOSX__ - file->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P")); + _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P")); #else wxMenu* edit = new wxMenu; edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P")); @@ -211,7 +225,7 @@ private: #endif help->Append (ID_help_report_a_problem, _("Report a problem...")); - m->Append (file, _("&File")); + m->Append (_file_menu, _("&File")); #ifndef __WXOSX__ m->Append (edit, _("&Edit")); #endif @@ -301,6 +315,15 @@ private: _info->triggered_update (); } + void file_history (wxCommandEvent& event) + { + vector<boost::filesystem::path> history = Config::instance()->player_history (); + int n = event.GetId() - ID_file_history; + if (n >= 0 && n < static_cast<int> (history.size ())) { + load_dcp (history[n]); + } + } + void file_close () { _viewer->set_film (shared_ptr<Film>()); @@ -386,6 +409,36 @@ private: ) ); } + + for (int i = 0; i < _history_items; ++i) { + delete _file_menu->Remove (ID_file_history + i); + } + + if (_history_separator) { + _file_menu->Remove (_history_separator); + } + delete _history_separator; + _history_separator = 0; + + int pos = _history_position; + + vector<boost::filesystem::path> history = Config::instance()->player_history (); + + if (!history.empty ()) { + _history_separator = _file_menu->InsertSeparator (pos++); + } + + for (size_t i = 0; i < history.size(); ++i) { + string s; + if (i < 9) { + s = String::compose ("&%1 %2", i + 1, history[i].string()); + } else { + s = history[i].string(); + } + _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s)); + } + + _history_items = history.size (); } void set_menu_sensitivity () @@ -397,6 +450,10 @@ private: bool _update_news_requested; PlayerInformation* _info; wxPreferencesEditor* _config_dialog; + wxMenu* _file_menu; + int _history_items; + int _history_position; + wxMenuItem* _history_separator; FilmViewer* _viewer; boost::shared_ptr<Film> _film; boost::signals2::scoped_connection _config_changed_connection; |
