From 0d6ec677206596531b852d67c50c3e99ffc3b7d7 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Mon, 13 Jul 2020 22:23:29 +0200 Subject: [PATCH] Bugfix: prevent selection of previous file if does not exists anymore. --- SystemToolkit.cpp | 3 +++ UserInterfaceManager.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/SystemToolkit.cpp b/SystemToolkit.cpp index 873e032..4f4811a 100644 --- a/SystemToolkit.cpp +++ b/SystemToolkit.cpp @@ -237,6 +237,9 @@ string SystemToolkit::full_filename(const std::string& path, const string &filen bool SystemToolkit::file_exists(const string& path) { + if (path.empty()) + return false; + return access(path.c_str(), R_OK) == 0; // TODO : WIN32 implementation diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 97d9914..de9a7e0 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -1576,12 +1576,14 @@ void Navigator::RenderNewPannel() ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); if (ImGui::BeginCombo("##RecentImport", "Recent files")) { - for (auto path = Settings::application.recentImport.filenames.begin(); + for (std::list::iterator path = Settings::application.recentImport.filenames.begin(); path != Settings::application.recentImport.filenames.end(); path++ ) { - std::string label = path->substr( path->size() - MIN( 35, path->size()) ); - if (ImGui::Selectable( label.c_str() )) { - new_source_preview_.setSource( Mixer::manager().createSourceFile(path->c_str()), label); + if ( SystemToolkit::file_exists(*path)) { + std::string label = path->substr( path->size() - MIN( 35, path->size()) ); + if (ImGui::Selectable( label.c_str() )) { + new_source_preview_.setSource( Mixer::manager().createSourceFile(path->c_str()), label); + } } } ImGui::EndCombo();