diff --git a/src/files.h b/src/files.h index ff84cfc..127816e 100644 --- a/src/files.h +++ b/src/files.h @@ -2,7 +2,7 @@ #define JUCI_FILES_H_ #include -#define JUCI_VERSION "1.1.0-1" +#define JUCI_VERSION "1.1.0-2" const std::string configjson = "{\n" @@ -92,12 +92,14 @@ const std::string configjson = " \"source_rename\": \"r\",\n" " \"source_goto_next_diagnostic\": \"e\",\n" " \"source_apply_fix_its\": \"space\",\n" +" \"project_set_run_arguments\": \"\",\n" " \"compile_and_run\": \"Return\",\n" " \"compile\": \"Return\",\n" " \"compile_and_run\": \"Return\",\n" " \"run_command\": \"Return\",\n" " \"kill_last_running\": \"Escape\",\n" " \"force_kill_last_running\": \"Escape\",\n" +" \"debug_set_run_arguments\": \"\",\n" " \"debug_start_continue\": \"y\",\n" " \"debug_stop\": \"y\",\n" " \"debug_kill\": \"k\",\n" diff --git a/src/menu.cc b/src/menu.cc index c1c76a7..a7adb2d 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -239,6 +239,11 @@ Menu::Menu() { " _Project" "
" " " + " _Set _Run _Arguments" + " app.project_set_run_arguments" + +accels["project_set_run_arguments"]+ //For Ubuntu... + " " + " " " _Compile _and _Run" " app.compile_and_run" +accels["compile_and_run"]+ //For Ubuntu... @@ -272,6 +277,11 @@ Menu::Menu() { " _Debug" "
" " " + " _Set _Run _Arguments" + " app.debug_set_run_arguments" + +accels["debug_set_run_arguments"]+ //For Ubuntu... + " " + " " " _Start/_Continue" " app.debug_start_continue" +accels["debug_start_continue"]+ //For Ubuntu... diff --git a/src/window.cc b/src/window.cc index d23a4be..876f1e8 100644 --- a/src/window.cc +++ b/src/window.cc @@ -167,6 +167,17 @@ Window::Window() : compiling(false), debugging(false) { JDEBUG("end"); } // Window constructor +std::unique_ptr Window::get_cmake() { + boost::filesystem::path path; + if(notebook.get_current_page()!=-1) + path=notebook.get_current_view()->file_path.parent_path(); + else + path=Directories::get().current_path; + if(path.empty()) + return nullptr; + return std::unique_ptr(new CMake(path)); +} + void Window::configure() { Config::get().load(); auto style_context = Gtk::StyleContext::create(); @@ -546,57 +557,111 @@ void Window::set_menu_actions() { } }); + menu.add_action("project_set_run_arguments", [this]() { + auto cmake=get_cmake(); + if(!cmake) + return; + auto project_path=std::make_shared(cmake->project_path); + if(project_path->empty()) + return; + auto run_arguments_it=project_run_arguments.find(project_path->string()); + std::string run_arguments; + if(run_arguments_it!=project_run_arguments.end()) + run_arguments=run_arguments_it->second; + + if(run_arguments.empty()) { + boost::filesystem::path cmake_path; + if(notebook.get_current_page()!=-1) + cmake_path=notebook.get_current_view()->file_path.parent_path(); + else + cmake_path=Directories::get().current_path; + if(cmake_path.empty()) + return; + CMake cmake(cmake_path); + if(cmake.project_path.empty()) + return; + auto executable_path=cmake.get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:""); + + if(executable_path!="") { + auto project_path=cmake.project_path; + auto default_build_path=CMake::get_default_build_path(project_path); + if(!default_build_path.empty()) { + auto executable_path_string=executable_path.string(); + size_t pos=executable_path_string.find(project_path.string()); + if(pos!=std::string::npos) { + executable_path_string.replace(pos, project_path.string().size(), default_build_path.string()); + executable_path=executable_path_string; + } + } + run_arguments=executable_path.string(); + } + } + + entry_box.clear(); + entry_box.labels.emplace_back(); + auto label_it=entry_box.labels.begin(); + label_it->update=[label_it](int state, const std::string& message){ + label_it->set_text("testing"); + }; + label_it->update(0, ""); + entry_box.entries.emplace_back(run_arguments, [this, project_path](const std::string& content){ + project_run_arguments[project_path->string()]=content; + entry_box.hide(); + }, 50); + auto entry_it=entry_box.entries.begin(); + entry_it->set_placeholder_text("Project: Set Run Arguments"); + entry_box.buttons.emplace_back("Project: set run arguments", [this, entry_it](){ + entry_it->activate(); + }); + entry_box.show(); + }); menu.add_action("compile_and_run", [this]() { if(compiling) return; - boost::filesystem::path cmake_path; - if(notebook.get_current_page()!=-1) - cmake_path=notebook.get_current_view()->file_path.parent_path(); - else - cmake_path=Directories::get().current_path; - if(cmake_path.empty()) + + auto cmake=get_cmake(); + if(!cmake) return; - CMake cmake(cmake_path); - if(cmake.project_path.empty()) + auto project_path=cmake->project_path; + if(project_path.empty()) return; - auto executable_path=cmake.get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:""); - if(executable_path!="") { - auto project_path=cmake.project_path; - auto default_build_path=CMake::get_default_build_path(project_path); - if(default_build_path.empty()) - return; - compiling=true; - auto executable_path_string=executable_path.string(); - size_t pos=executable_path_string.find(project_path.string()); - if(pos!=std::string::npos) { - executable_path_string.replace(pos, project_path.string().size(), default_build_path.string()); - executable_path=executable_path_string; - } - Terminal::get().print("Compiling and running "+executable_path.string()+"\n"); - Terminal::get().async_process(Config::get().terminal.make_command, default_build_path, [this, executable_path, default_build_path](int exit_status){ - compiling=false; - if(exit_status==EXIT_SUCCESS) { - auto executable_path_spaces_fixed=executable_path.string(); - char last_char=0; - for(size_t c=0;csecond; + + std::string command; + if(!run_arguments.empty()) { + command=run_arguments; } else { - Terminal::get().print("Could not find add_executable in the following paths:\n"); - for(auto &path: cmake.paths) - Terminal::get().print(" "+path.string()+"\n"); + command=cmake->get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:"").string(); + if(command.empty()) { + Terminal::get().print("Could not find add_executable in the following paths:\n"); + for(auto &path: cmake->paths) + Terminal::get().print(" "+path.string()+"\n"); + return; + } + size_t pos=command.find(project_path.string()); + if(pos!=std::string::npos) + command.replace(pos, project_path.string().size(), default_build_path.string()); } + + compiling=true; + Terminal::get().print("Compiling and running "+command+"\n"); + Terminal::get().async_process(Config::get().terminal.make_command, default_build_path, [this, command, default_build_path](int exit_status){ + compiling=false; + if(exit_status==EXIT_SUCCESS) { + Terminal::get().async_process(command, default_build_path, [this, command](int exit_status){ + Terminal::get().async_print(command+" returned: "+std::to_string(exit_status)+'\n'); + }); + } + }); }); menu.add_action("compile", [this]() { if(compiling) @@ -659,90 +724,82 @@ void Window::set_menu_actions() { #ifdef JUCI_ENABLE_DEBUG menu.add_action("debug_start_continue", [this](){ if(debugging) { - //Continue - if(notebook.get_current_page()!=-1) { - Debug::get().continue_debug(); - } + Debug::get().continue_debug(); return; } - boost::filesystem::path cmake_path; - if(notebook.get_current_page()!=-1) - cmake_path=notebook.get_current_view()->file_path.parent_path(); - else - cmake_path=Directories::get().current_path; - if(cmake_path.empty()) + + auto cmake=get_cmake(); + if(!cmake) return; - CMake cmake(cmake_path); - if(cmake.project_path.empty()) + auto project_path=cmake->project_path; + if(project_path.empty()) + return; + + auto debug_build_path=CMake::get_debug_build_path(project_path); + if(debug_build_path.empty()) + return; + if(!CMake::create_debug_build(project_path)) return; - auto executable_path=cmake.get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:""); - if(executable_path!="") { - auto project_path=cmake.project_path; - auto debug_build_path=CMake::get_debug_build_path(project_path); - if(debug_build_path.empty()) - return; - if(!CMake::create_debug_build(project_path)) + /*auto run_arguments_it=project_run_arguments.find(project_path.string()); + std::string run_arguments; + if(run_arguments_it!=project_run_arguments.end()) + run_arguments=run_arguments_it->second;*/ + + std::string command; + /*if(!run_arguments.empty()) { + command=run_arguments; + } + else {*/ + command=cmake->get_executable(notebook.get_current_page()!=-1?notebook.get_current_view()->file_path:"").string(); + if(command.empty()) { + Terminal::get().print("Could not find add_executable in the following paths:\n"); + for(auto &path: cmake->paths) + Terminal::get().print(" "+path.string()+"\n"); return; - debugging=true; - auto executable_path_string=executable_path.string(); - size_t pos=executable_path_string.find(project_path.string()); - if(pos!=std::string::npos) { - executable_path_string.replace(pos, project_path.string().size(), debug_build_path.string()); - executable_path=executable_path_string; } - - auto breakpoints=std::make_shared > >(); - for(int c=0;cproject_path) { - auto iter=view->get_buffer()->begin(); - if(view->get_source_buffer()->get_source_marks_at_iter(iter, "debug_breakpoint").size()>0) - breakpoints->emplace_back(view->file_path, iter.get_line()+1); - while(view->get_source_buffer()->forward_iter_to_source_mark(iter, "debug_breakpoint")) - breakpoints->emplace_back(view->file_path, iter.get_line()+1); - } + size_t pos=command.find(project_path.string()); + if(pos!=std::string::npos) + command.replace(pos, project_path.string().size(), debug_build_path.string()); + //} + + auto breakpoints=std::make_shared > >(); + for(int c=0;cproject_path) { + auto iter=view->get_buffer()->begin(); + if(view->get_source_buffer()->get_source_marks_at_iter(iter, "debug_breakpoint").size()>0) + breakpoints->emplace_back(view->file_path, iter.get_line()+1); + while(view->get_source_buffer()->forward_iter_to_source_mark(iter, "debug_breakpoint")) + breakpoints->emplace_back(view->file_path, iter.get_line()+1); } - Terminal::get().print("Compiling and debugging "+executable_path.string()+"\n"); - Terminal::get().async_process(Config::get().terminal.make_command, debug_build_path, [this, breakpoints, executable_path, debug_build_path](int exit_status){ - if(exit_status!=EXIT_SUCCESS) - debugging=false; - else { - auto executable_path_spaces_fixed=executable_path.string(); - char last_char=0; - for(size_t c=0;c class Window : public Gtk::ApplicationWindow { @@ -45,6 +46,10 @@ private: std::mutex debug_status_mutex; Glib::Dispatcher debug_update_status; + std::unique_ptr get_cmake(); + std::unordered_map project_run_arguments; + std::unordered_map debug_run_arguments; + void configure(); void set_menu_actions(); void activate_menu_items(bool activate=true);