diff --git a/src/project.cc b/src/project.cc index 3f85f60..f5b46e3 100644 --- a/src/project.cc +++ b/src/project.cc @@ -16,7 +16,7 @@ std::unordered_map Project::debug_run_arguments; std::atomic Project::compiling(false); std::atomic Project::debugging(false); std::pair > Project::debug_stop; -std::unique_ptr Project::current_language; +std::unique_ptr Project::current; Gtk::Label &Project::debug_status_label() { static Gtk::Label label; @@ -47,11 +47,11 @@ void Project::on_save(int page) { cmake_path=filesystem::find_file_in_path_parents("CMakeLists.txt", view->file_path.parent_path()); if(!cmake_path.empty()) { - auto build=get_build(cmake_path); - if(dynamic_cast(build.get())) { - build->update_default_build(true); - if(boost::filesystem::exists(build->get_debug_build_path())) - build->update_debug_build(true); + auto build=Build::create(cmake_path); + if(dynamic_cast(build.get())) { + build->update_default(true); + if(boost::filesystem::exists(build->get_debug_path())) + build->update_debug(true); for(int c=0;cget_buffer()->place_cursor(Notebook::get().get_current_view()->get_buffer()->get_insert()->get_iter()); } -std::unique_ptr Project::get_language() { +std::unique_ptr Project::create() { std::unique_ptr build; if(Notebook::get().get_current_page()!=-1) { auto view=Notebook::get().get_current_view(); - build=get_build(view->file_path); + build=Build::create(view->file_path); if(view->language) { auto language_id=view->language->get_id(); if(language_id=="markdown") - return std::unique_ptr(new Project::Markdown(std::move(build))); + return std::unique_ptr(new Project::Markdown(std::move(build))); if(language_id=="python") - return std::unique_ptr(new Project::Python(std::move(build))); + return std::unique_ptr(new Project::Python(std::move(build))); if(language_id=="js") - return std::unique_ptr(new Project::JavaScript(std::move(build))); + return std::unique_ptr(new Project::JavaScript(std::move(build))); if(language_id=="html") - return std::unique_ptr(new Project::HTML(std::move(build))); + return std::unique_ptr(new Project::HTML(std::move(build))); } } else - build=get_build(Directories::get().path); + build=Build::create(Directories::get().path); - if(dynamic_cast(build.get())) - return std::unique_ptr(new Project::Clang(std::move(build))); + if(dynamic_cast(build.get())) + return std::unique_ptr(new Project::Clang(std::move(build))); else - return std::unique_ptr(new Project::Language(std::move(build))); + return std::unique_ptr(new Project::Base(std::move(build))); } std::pair Project::Clang::get_run_arguments() { - if(build->get_default_build_path().empty() || !build->update_default_build()) + if(build->get_default_path().empty() || !build->update_default()) return {"", ""}; auto project_path=build->project_path.string(); @@ -147,7 +147,7 @@ std::pair Project::Clang::get_run_arguments() { if(executable!="") { auto project_path=build->project_path; - auto build_path=build->get_default_build_path(); + auto build_path=build->get_default_path(); if(!build_path.empty()) { size_t pos=executable.find(project_path.string()); if(pos!=std::string::npos) @@ -156,15 +156,15 @@ std::pair Project::Clang::get_run_arguments() { arguments=filesystem::escape_argument(executable); } else - arguments=filesystem::escape_argument(build->get_default_build_path()); + arguments=filesystem::escape_argument(build->get_default_path()); } return {project_path, arguments}; } void Project::Clang::compile() { - auto default_build_path=build->get_default_build_path(); - if(default_build_path.empty() || !build->update_default_build()) + auto default_build_path=build->get_default_path(); + if(default_build_path.empty() || !build->update_default()) return; if(Config::get().project.clear_terminal_on_compile) @@ -178,8 +178,8 @@ void Project::Clang::compile() { } void Project::Clang::compile_and_run() { - auto default_build_path=build->get_default_build_path(); - if(default_build_path.empty() || !build->update_default_build()) + auto default_build_path=build->get_default_path(); + if(default_build_path.empty() || !build->update_default()) return; auto project_path=build->project_path; @@ -219,7 +219,7 @@ void Project::Clang::compile_and_run() { #ifdef JUCI_ENABLE_DEBUG std::pair Project::Clang::debug_get_run_arguments() { - if(build->get_default_build_path().empty() || !build->update_default_build()) + if(build->get_default_path().empty() || !build->update_default()) return {"", ""}; auto project_path=build->project_path.string(); @@ -233,7 +233,7 @@ std::pair Project::Clang::debug_get_run_arguments() { if(executable!="") { auto project_path=build->project_path; - auto build_path=build->get_debug_build_path(); + auto build_path=build->get_debug_path(); if(!build_path.empty()) { size_t pos=executable.find(project_path.string()); if(pos!=std::string::npos) @@ -242,15 +242,15 @@ std::pair Project::Clang::debug_get_run_arguments() { arguments=filesystem::escape_argument(executable); } else - arguments=filesystem::escape_argument(build->get_debug_build_path()); + arguments=filesystem::escape_argument(build->get_debug_path()); } return {project_path, arguments}; } void Project::Clang::debug_start() { - auto debug_build_path=build->get_debug_build_path(); - if(debug_build_path.empty() || !build->update_debug_build()) + auto debug_build_path=build->get_debug_path(); + if(debug_build_path.empty() || !build->update_debug()) return; auto project_path=build->project_path; diff --git a/src/project.h b/src/project.h index 51d5bde..1bce53e 100644 --- a/src/project.h +++ b/src/project.h @@ -25,10 +25,10 @@ namespace Project { void debug_update_stop(); void debug_update_status(const std::string &debug_status); - class Language { + class Base { public: - Language(std::unique_ptr &&build): build(std::move(build)) {} - virtual ~Language() {} + Base(std::unique_ptr &&build): build(std::move(build)) {} + virtual ~Base() {} std::unique_ptr build; @@ -55,11 +55,11 @@ namespace Project { virtual void debug_delete() {} }; - class Clang : public Language { + class Clang : public Base { private: Dispatcher dispatcher; public: - Clang(std::unique_ptr &&build) : Language(std::move(build)) {} + Clang(std::unique_ptr &&build) : Base(std::move(build)) {} ~Clang() { dispatcher.disconnect(); } std::pair get_run_arguments() override; @@ -87,38 +87,38 @@ namespace Project { #endif }; - class Markdown : public Language { + class Markdown : public Base { public: - Markdown(std::unique_ptr &&build) : Language(std::move(build)) {} + Markdown(std::unique_ptr &&build) : Base(std::move(build)) {} ~Markdown(); boost::filesystem::path last_temp_path; void compile_and_run() override; }; - class Python : public Language { + class Python : public Base { public: - Python(std::unique_ptr &&build) : Language(std::move(build)) {} + Python(std::unique_ptr &&build) : Base(std::move(build)) {} void compile_and_run() override; }; - class JavaScript : public Language { + class JavaScript : public Base { public: - JavaScript(std::unique_ptr &&build) : Language(std::move(build)) {} + JavaScript(std::unique_ptr &&build) : Base(std::move(build)) {} void compile_and_run() override; }; - class HTML : public Language { + class HTML : public Base { public: - HTML(std::unique_ptr &&build) : Language(std::move(build)) {} + HTML(std::unique_ptr &&build) : Base(std::move(build)) {} void compile_and_run() override; }; - std::unique_ptr get_language(); - extern std::unique_ptr current_language; + std::unique_ptr create(); + extern std::unique_ptr current; }; #endif // JUCI_PROJECT_H_ diff --git a/src/project_build.cc b/src/project_build.cc index c7fe338..ff92836 100644 --- a/src/project_build.cc +++ b/src/project_build.cc @@ -2,8 +2,8 @@ #include "config.h" #include "info.h" -std::unique_ptr Project::get_build(const boost::filesystem::path &path) { - std::unique_ptr cmake(new CMake(path)); +std::unique_ptr Project::Build::create(const boost::filesystem::path &path) { + std::unique_ptr cmake(new CMakeBuild(path)); if(!cmake->project_path.empty()) return cmake; else { @@ -12,7 +12,7 @@ std::unique_ptr Project::get_build(const boost::filesystem::path } } -boost::filesystem::path Project::Build::get_default_build_path() { +boost::filesystem::path Project::Build::get_default_path() { if(project_path.empty()) return boost::filesystem::path(); @@ -35,7 +35,7 @@ boost::filesystem::path Project::Build::get_default_build_path() { return default_build_path; } -boost::filesystem::path Project::Build::get_debug_build_path() { +boost::filesystem::path Project::Build::get_debug_path() { if(project_path.empty()) return boost::filesystem::path(); @@ -69,18 +69,18 @@ boost::filesystem::path Project::Build::get_debug_build_path() { return debug_build_path; } -Project::CMake::CMake(const boost::filesystem::path &path) : Project::Build(), cmake(path) { +Project::CMakeBuild::CMakeBuild(const boost::filesystem::path &path) : Project::Build(), cmake(path) { project_path=cmake.project_path; } -bool Project::CMake::update_default_build(bool force) { - return cmake.update_default_build(get_default_build_path(), force); +bool Project::CMakeBuild::update_default(bool force) { + return cmake.update_default_build(get_default_path(), force); } -bool Project::CMake::update_debug_build(bool force) { - return cmake.update_debug_build(get_debug_build_path(), force); +bool Project::CMakeBuild::update_debug(bool force) { + return cmake.update_debug_build(get_debug_path(), force); } -boost::filesystem::path Project::CMake::get_executable(const boost::filesystem::path &path) { +boost::filesystem::path Project::CMakeBuild::get_executable(const boost::filesystem::path &path) { return cmake.get_executable(path); } diff --git a/src/project_build.h b/src/project_build.h index ea12926..964069f 100644 --- a/src/project_build.h +++ b/src/project_build.h @@ -12,26 +12,26 @@ namespace Project { boost::filesystem::path project_path; - boost::filesystem::path get_default_build_path(); - virtual bool update_default_build(bool force=false) {return false;} - boost::filesystem::path get_debug_build_path(); - virtual bool update_debug_build(bool force=false) {return false;} + boost::filesystem::path get_default_path(); + virtual bool update_default(bool force=false) {return false;} + boost::filesystem::path get_debug_path(); + virtual bool update_debug(bool force=false) {return false;} virtual boost::filesystem::path get_executable(const boost::filesystem::path &path) {return boost::filesystem::path();} + + static std::unique_ptr create(const boost::filesystem::path &path); }; - class CMake : public Build { + class CMakeBuild : public Build { ::CMake cmake; public: - CMake(const boost::filesystem::path &path); + CMakeBuild(const boost::filesystem::path &path); - bool update_default_build(bool force=false) override; - bool update_debug_build(bool force=false) override; + bool update_default(bool force=false) override; + bool update_debug(bool force=false) override; boost::filesystem::path get_executable(const boost::filesystem::path &path) override; }; - - std::unique_ptr get_build(const boost::filesystem::path &path); } #endif // JUCI_PROJECT_BUILD_H_ diff --git a/src/source_clang.cc b/src/source_clang.cc index db913f4..5512daf 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -174,9 +174,9 @@ void Source::ClangViewParse::soft_reparse() { } std::vector Source::ClangViewParse::get_compilation_commands() { - auto build=Project::get_build(file_path); - auto default_build_path=build->get_default_build_path(); - build->update_default_build(); + auto build=Project::Build::create(file_path); + auto default_build_path=build->get_default_path(); + build->update_default(); clang::CompilationDatabase db(default_build_path.string()); clang::CompileCommands commands(file_path.string(), db); std::vector cmds = commands.get_commands(); diff --git a/src/terminal.cc b/src/terminal.cc index 36398d8..c3ab213 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -362,8 +362,8 @@ bool Terminal::on_button_press_event(GdkEventButton* button_event) { auto path=boost::filesystem::path(path_str); boost::system::error_code ec; if(path.is_relative()) { - if(Project::current_language) - path=boost::filesystem::canonical(Project::current_language->build->get_default_build_path()/path_str, ec); + if(Project::current) + path=boost::filesystem::canonical(Project::current->build->get_default_path()/path_str, ec); else return Gtk::TextView::on_button_press_event(button_event); } @@ -393,7 +393,7 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { std::unique_lock lock(processes_mutex); bool debug_is_running=false; #ifdef JUCI_ENABLE_DEBUG - debug_is_running=Project::current_language?Project::current_language->debug_is_running():false; + debug_is_running=Project::current?Project::current->debug_is_running():false; #endif if(processes.size()>0 || debug_is_running) { get_buffer()->place_cursor(get_buffer()->end()); @@ -415,7 +415,7 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { stdin_buffer+='\n'; if(debug_is_running) { #ifdef JUCI_ENABLE_DEBUG - Project::current_language->debug_write(stdin_buffer); + Project::current->debug_write(stdin_buffer); #endif } else diff --git a/src/window.cc b/src/window.cc index 12e28f6..60f97ac 100644 --- a/src/window.cc +++ b/src/window.cc @@ -558,7 +558,7 @@ void Window::set_menu_actions() { }); menu.add_action("project_set_run_arguments", [this]() { - auto project_language=Project::get_language(); + auto project_language=Project::create(); auto run_arguments=std::make_shared >(project_language->get_run_arguments()); if(run_arguments->second.empty()) return; @@ -587,12 +587,12 @@ void Window::set_menu_actions() { return; } - Project::current_language=Project::get_language(); + Project::current=Project::create(); if(Config::get().project.save_on_compile_or_run) - Project::save_files(Project::current_language->build->project_path); + Project::save_files(Project::current->build->project_path); - Project::current_language->compile_and_run(); + Project::current->compile_and_run(); }); menu.add_action("compile", [this]() { if(Project::compiling || Project::debugging) { @@ -600,12 +600,12 @@ void Window::set_menu_actions() { return; } - Project::current_language=Project::get_language(); + Project::current=Project::create(); if(Config::get().project.save_on_compile_or_run) - Project::save_files(Project::current_language->build->project_path); + Project::save_files(Project::current->build->project_path); - Project::current_language->compile(); + Project::current->compile(); }); menu.add_action("run_command", [this]() { @@ -645,7 +645,7 @@ void Window::set_menu_actions() { #ifdef JUCI_ENABLE_DEBUG menu.add_action("debug_set_run_arguments", [this]() { - auto project_language=Project::get_language(); + auto project_language=Project::create(); auto run_arguments=std::make_shared >(project_language->debug_get_run_arguments()); if(run_arguments->second.empty()) return; @@ -674,51 +674,51 @@ void Window::set_menu_actions() { return; } else if(Project::debugging) { - Project::current_language->debug_continue(); + Project::current->debug_continue(); return; } - Project::current_language=Project::get_language(); + Project::current=Project::create(); if(Config::get().project.save_on_compile_or_run) - Project::save_files(Project::current_language->build->project_path); + Project::save_files(Project::current->build->project_path); - Project::current_language->debug_start(); + Project::current->debug_start(); }); menu.add_action("debug_stop", [this]() { - if(Project::current_language) - Project::current_language->debug_stop(); + if(Project::current) + Project::current->debug_stop(); }); menu.add_action("debug_kill", [this]() { - if(Project::current_language) - Project::current_language->debug_kill(); + if(Project::current) + Project::current->debug_kill(); }); menu.add_action("debug_step_over", [this]() { - if(Project::current_language) - Project::current_language->debug_step_over(); + if(Project::current) + Project::current->debug_step_over(); }); menu.add_action("debug_step_into", [this]() { - if(Project::current_language) - Project::current_language->debug_step_into(); + if(Project::current) + Project::current->debug_step_into(); }); menu.add_action("debug_step_out", [this]() { - if(Project::current_language) - Project::current_language->debug_step_out(); + if(Project::current) + Project::current->debug_step_out(); }); menu.add_action("debug_backtrace", [this]() { - if(Project::current_language) - Project::current_language->debug_backtrace(); + if(Project::current) + Project::current->debug_backtrace(); }); menu.add_action("debug_show_variables", [this]() { - if(Project::current_language) - Project::current_language->debug_show_variables(); + if(Project::current) + Project::current->debug_show_variables(); }); menu.add_action("debug_run_command", [this]() { EntryBox::get().clear(); EntryBox::get().entries.emplace_back(last_run_debug_command, [this](const std::string& content){ if(content!="") { - if(Project::current_language) - Project::current_language->debug_run_command(content); + if(Project::current) + Project::current->debug_run_command(content); last_run_debug_command=content; } EntryBox::get().hide(); @@ -740,13 +740,13 @@ void Window::set_menu_actions() { auto end_iter=start_iter; while(!end_iter.ends_line() && end_iter.forward_char()) {} view->get_source_buffer()->remove_source_marks(start_iter, end_iter, "debug_breakpoint"); - if(Project::current_language && Project::debugging) - Project::current_language->debug_remove_breakpoint(view->file_path, line_nr+1, view->get_buffer()->get_line_count()+1); + if(Project::current && Project::debugging) + Project::current->debug_remove_breakpoint(view->file_path, line_nr+1, view->get_buffer()->get_line_count()+1); } else { view->get_source_buffer()->create_source_mark("debug_breakpoint", view->get_buffer()->get_insert()->get_iter()); - if(Project::current_language && Project::debugging) - Project::current_language->debug_add_breakpoint(view->file_path, line_nr+1); + if(Project::current && Project::debugging) + Project::current->debug_add_breakpoint(view->file_path, line_nr+1); } } }); @@ -880,8 +880,8 @@ bool Window::on_delete_event(GdkEventAny *event) { } Terminal::get().kill_async_processes(); #ifdef JUCI_ENABLE_DEBUG - if(Project::current_language) - Project::current_language->debug_delete(); + if(Project::current) + Project::current->debug_delete(); #endif return false; }