diff --git a/src/notebook.cc b/src/notebook.cc index 1feebaf..45d1f2a 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -180,17 +180,24 @@ bool Notebook::save(int page, bool reparse_needed) { Singleton::terminal()->print("File saved to: " +view->file_path.string()+"\n"); //If CMakeLists.txt have been modified: - //TODO: recreate cmake even without directories open? + boost::filesystem::path project_path; if(view->file_path.filename()=="CMakeLists.txt") { if(directories.cmake && directories.cmake->project_path!="" && view->file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/' && CMake::create_compile_commands(directories.cmake->project_path)) { - for(auto source_view: source_views) { - if(auto source_clang_view=dynamic_cast(source_view)) { - if(directories.cmake->project_path.string()==source_clang_view->project_path) { - if(source_clang_view->restart_parse()) - Singleton::terminal()->async_print("Reparsing "+source_clang_view->file_path.string()+"\n"); - else - Singleton::terminal()->async_print("Error: failed to reparse "+source_clang_view->file_path.string()+". Please reopen the file manually.\n"); - } + project_path=directories.cmake->project_path; + } + else { + CMake cmake(view->file_path.parent_path()); + if(cmake.project_path!="" && CMake::create_compile_commands(cmake.project_path)) { + project_path=cmake.project_path; + } + } + for(auto source_view: source_views) { + if(auto source_clang_view=dynamic_cast(source_view)) { + if(project_path==source_clang_view->project_path) { + if(source_clang_view->restart_parse()) + Singleton::terminal()->async_print("Reparsing "+source_clang_view->file_path.string()+"\n"); + else + Singleton::terminal()->async_print("Error: failed to reparse "+source_clang_view->file_path.string()+". Please reopen the file manually.\n"); } } } diff --git a/src/source.cc b/src/source.cc index 7af245f..1fb536a 100644 --- a/src/source.cc +++ b/src/source.cc @@ -79,7 +79,7 @@ std::string Source::FixIt::string() { ////////////// AspellConfig* Source::View::spellcheck_config=NULL; -Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr language): file_path(file_path), language(language) { +Source::View::View(const boost::filesystem::path &file_path, const boost::filesystem::path &project_path, Glib::RefPtr language): file_path(file_path), project_path(project_path), language(language) { get_source_buffer()->begin_not_undoable_action(); if(language) { if(juci::filesystem::read_non_utf8(file_path, get_buffer())==-1) @@ -1254,7 +1254,7 @@ std::vector Source::View::spellcheck_get_suggestions(const Gtk::Tex ///////////////////// //// GenericView //// ///////////////////// -Source::GenericView::GenericView(const boost::filesystem::path &file_path, Glib::RefPtr language) : View(file_path, language) { +Source::GenericView::GenericView(const boost::filesystem::path &file_path, Glib::RefPtr language) : View(file_path, "", language) { configure(); spellcheck_all=true; @@ -1340,7 +1340,7 @@ void Source::GenericView::parse_language_file(Glib::RefPtr &co clang::Index Source::ClangViewParse::clang_index(0, 0); Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language): -Source::View(file_path, language), project_path(project_path), parse_error(false) { +Source::View(file_path, project_path, language), parse_error(false) { DEBUG("start"); auto tag_table=get_buffer()->get_tag_table(); diff --git a/src/source.h b/src/source.h index ce34929..acb9180 100644 --- a/src/source.h +++ b/src/source.h @@ -82,7 +82,7 @@ namespace Source { class View : public Gsv::View { public: - View(const boost::filesystem::path &file_path, Glib::RefPtr language); + View(const boost::filesystem::path &file_path, const boost::filesystem::path &project_path, Glib::RefPtr language); ~View(); virtual void configure(); @@ -98,6 +98,7 @@ namespace Source { void paste(); boost::filesystem::path file_path; + boost::filesystem::path project_path; Glib::RefPtr language; std::function()> get_declaration_location; @@ -199,7 +200,6 @@ namespace Source { ~ClangViewParse(); void configure(); - boost::filesystem::path project_path; void start_reparse(); bool reparse_needed=false; protected: