From 4987da6bde9dab2741cf5fb0e9270c199b833187 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 9 Oct 2015 10:06:45 +0200 Subject: [PATCH] Project path fix and cleanup. --- src/notebook.cc | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index b255cfe..a18204c 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -69,31 +69,24 @@ void Notebook::open(const boost::filesystem::path &file_path) { can_read.close(); auto language=Source::guess_language(file_path); - if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { - boost::filesystem::path project_path; - if(directories.cmake && directories.cmake->project_path!="" && file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/') { - project_path=directories.cmake->project_path; - if(boost::filesystem::exists(project_path.string()+"/CMakeLists.txt") && !boost::filesystem::exists(project_path.string()+"/compile_commands.json")) - CMake::create_compile_commands(project_path); - } - else { - project_path=file_path.parent_path(); - CMake cmake(project_path); - if(cmake.project_path!="") { - project_path=cmake.project_path; - Singleton::terminal()->print("Project path for "+file_path.string()+" set to "+project_path.string()+"\n"); - } - else - Singleton::terminal()->print("Error: could not find project path for "+file_path.string()+"\n"); + boost::filesystem::path project_path; + if(directories.cmake && directories.cmake->project_path!="" && file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/') + project_path=directories.cmake->project_path; + else { + project_path=file_path.parent_path(); + CMake cmake(project_path); + if(cmake.project_path!="") { + project_path=cmake.project_path; + Singleton::terminal()->print("Project path for "+file_path.string()+" set to "+project_path.string()+"\n"); } + } + if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { + if(boost::filesystem::exists(project_path.string()+"/CMakeLists.txt") && !boost::filesystem::exists(project_path.string()+"/compile_commands.json")) + CMake::create_compile_commands(project_path); source_views.emplace_back(new Source::ClangView(file_path, project_path, language)); } - else { - boost::filesystem::path project_path; - if(directories.cmake && directories.cmake->project_path!="" && file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/') - project_path=directories.cmake->project_path; + else source_views.emplace_back(new Source::GenericView(file_path, project_path, language)); - } source_views.back()->on_update_status=[this](Source::View* view, const std::string &status) { if(get_current_page()!=-1 && get_current_view()==view)