Don't display non-existant items in the history.
authorCarl Hetherington <cth@carlh.net>
Tue, 19 Feb 2019 14:32:16 +0000 (14:32 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 19 Feb 2019 14:32:16 +0000 (14:32 +0000)
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic.cc
src/tools/dcpomatic_player.cc

index bf4b495523cd10433e3b80549fd5ac7db67ff279..b742756b7eb55197205a85fe6a69acbbdb0cf2ce 100644 (file)
@@ -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<boost::filesystem::path>& h, boost::filesystem::path p)
 {
@@ -1192,6 +1206,18 @@ Config::add_to_history_internal (vector<boost::filesystem::path>& h, boost::file
        changed (HISTORY);
 }
 
+void
+Config::clean_history_internal (vector<boost::filesystem::path>& h)
+{
+       vector<boost::filesystem::path> 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)
 {
index 21463fdb5bc44500ca16827acbfc6f766ee06b7c..3518dc63fc4ea4a62985d03c161d9f260433e6c8 100644 (file)
@@ -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<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);
+       void clean_history_internal (std::vector<boost::filesystem::path>& h);
        void backup ();
 
        template <class T>
index 4505cff84cfea5b8e7fb91cc554310dedda39f2e..854c1a3f37cdc60d732fe06f4ae2c6d413ab262b 100644 (file)
@@ -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<boost::filesystem::path> history = Config::instance()->history ();
 
                if (!history.empty ()) {
index b2f95a20f6f7c01a4052fe830ffe1828358c89df..a1a5a59eb99db36a5190ff83076268692582bd8f 100644 (file)
@@ -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<boost::filesystem::path> history = Config::instance()->player_history ();
 
                if (!history.empty ()) {