Browse Source

Now tries to run cmake after saving CMakeLists.txt, even if it is outside of opened directory, or directory is not opened.

merge-requests/365/head
eidheim 10 years ago
parent
commit
8becce510f
  1. 25
      src/notebook.cc
  2. 6
      src/source.cc
  3. 4
      src/source.h

25
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"); Singleton::terminal()->print("File saved to: " +view->file_path.string()+"\n");
//If CMakeLists.txt have been modified: //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(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)) { 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) { project_path=directories.cmake->project_path;
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) { }
if(directories.cmake->project_path.string()==source_clang_view->project_path) { else {
if(source_clang_view->restart_parse()) CMake cmake(view->file_path.parent_path());
Singleton::terminal()->async_print("Reparsing "+source_clang_view->file_path.string()+"\n"); if(cmake.project_path!="" && CMake::create_compile_commands(cmake.project_path)) {
else project_path=cmake.project_path;
Singleton::terminal()->async_print("Error: failed to reparse "+source_clang_view->file_path.string()+". Please reopen the file manually.\n"); }
} }
for(auto source_view: source_views) {
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(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");
} }
} }
} }

6
src/source.cc

@ -79,7 +79,7 @@ std::string Source::FixIt::string() {
////////////// //////////////
AspellConfig* Source::View::spellcheck_config=NULL; AspellConfig* Source::View::spellcheck_config=NULL;
Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language): file_path(file_path), language(language) { Source::View::View(const boost::filesystem::path &file_path, const boost::filesystem::path &project_path, Glib::RefPtr<Gsv::Language> language): file_path(file_path), project_path(project_path), language(language) {
get_source_buffer()->begin_not_undoable_action(); get_source_buffer()->begin_not_undoable_action();
if(language) { if(language) {
if(juci::filesystem::read_non_utf8(file_path, get_buffer())==-1) if(juci::filesystem::read_non_utf8(file_path, get_buffer())==-1)
@ -1254,7 +1254,7 @@ std::vector<std::string> Source::View::spellcheck_get_suggestions(const Gtk::Tex
///////////////////// /////////////////////
//// GenericView //// //// GenericView ////
///////////////////// /////////////////////
Source::GenericView::GenericView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language) : View(file_path, language) { Source::GenericView::GenericView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language) : View(file_path, "", language) {
configure(); configure();
spellcheck_all=true; spellcheck_all=true;
@ -1340,7 +1340,7 @@ void Source::GenericView::parse_language_file(Glib::RefPtr<CompletionBuffer> &co
clang::Index Source::ClangViewParse::clang_index(0, 0); 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<Gsv::Language> language): Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> 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"); DEBUG("start");
auto tag_table=get_buffer()->get_tag_table(); auto tag_table=get_buffer()->get_tag_table();

4
src/source.h

@ -82,7 +82,7 @@ namespace Source {
class View : public Gsv::View { class View : public Gsv::View {
public: public:
View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language); View(const boost::filesystem::path &file_path, const boost::filesystem::path &project_path, Glib::RefPtr<Gsv::Language> language);
~View(); ~View();
virtual void configure(); virtual void configure();
@ -98,6 +98,7 @@ namespace Source {
void paste(); void paste();
boost::filesystem::path file_path; boost::filesystem::path file_path;
boost::filesystem::path project_path;
Glib::RefPtr<Gsv::Language> language; Glib::RefPtr<Gsv::Language> language;
std::function<std::pair<std::string, clang::Offset>()> get_declaration_location; std::function<std::pair<std::string, clang::Offset>()> get_declaration_location;
@ -199,7 +200,6 @@ namespace Source {
~ClangViewParse(); ~ClangViewParse();
void configure(); void configure();
boost::filesystem::path project_path;
void start_reparse(); void start_reparse();
bool reparse_needed=false; bool reparse_needed=false;
protected: protected:

Loading…
Cancel
Save