From 86bbc0981a60ad9ba7b7bdbf28a34f197f83f6cb Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 19 Feb 2019 14:32:16 +0000 Subject: [PATCH] Don't display non-existant items in the history. --- src/lib/config.cc | 26 ++++++++++++++++++++++++++ src/lib/config.h | 3 +++ src/tools/dcpomatic.cc | 2 ++ src/tools/dcpomatic_player.cc | 2 ++ 4 files changed, 33 insertions(+) diff --git a/src/lib/config.cc b/src/lib/config.cc index bf4b49552..b742756b7 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -1172,12 +1172,26 @@ Config::add_to_history (boost::filesystem::path p) add_to_history_internal (_history, p); } +/** Remove non-existant items from the history */ +void +Config::clean_history () +{ + clean_history_internal (_history); +} + void Config::add_to_player_history (boost::filesystem::path p) { add_to_history_internal (_player_history, p); } +/** Remove non-existant items from the player history */ +void +Config::clean_player_history () +{ + clean_history_internal (_player_history); +} + void Config::add_to_history_internal (vector& h, boost::filesystem::path p) { @@ -1192,6 +1206,18 @@ Config::add_to_history_internal (vector& h, boost::file changed (HISTORY); } +void +Config::clean_history_internal (vector& h) +{ + vector old = h; + h.clear (); + BOOST_FOREACH (boost::filesystem::path i, old) { + if (boost::filesystem::is_directory(i)) { + h.push_back (i); + } + } +} + bool Config::have_existing (string file) { diff --git a/src/lib/config.h b/src/lib/config.h index 21463fdb5..3518dc63f 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -861,7 +861,9 @@ public: } void add_to_history (boost::filesystem::path p); + void clean_history (); void add_to_player_history (boost::filesystem::path p); + void clean_player_history (); void set_jump_to_selected (bool j) { maybe_set (_jump_to_selected, j); @@ -1099,6 +1101,7 @@ private: boost::shared_ptr create_certificate_chain (); boost::filesystem::path directory_or (boost::optional dir, boost::filesystem::path a) const; void add_to_history_internal (std::vector& h, boost::filesystem::path p); + void clean_history_internal (std::vector& h); void backup (); template diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 4505cff84..854c1a3f3 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -1326,6 +1326,8 @@ private: int pos = _history_position; + /* Clear out non-existant history items before we re-build the menu */ + Config::instance()->clean_history (); vector history = Config::instance()->history (); if (!history.empty ()) { diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index b2f95a20f..a1a5a59eb 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -848,6 +848,8 @@ private: int pos = _history_position; + /* Clear out non-existant history items before we re-build the menu */ + Config::instance()->clean_player_history (); vector history = Config::instance()->player_history (); if (!history.empty ()) { -- 2.30.2