diff --git a/src/config.cc b/src/config.cc index aa5c7c1..b2206fc 100644 --- a/src/config.cc +++ b/src/config.cc @@ -97,18 +97,21 @@ void Config::retrieve_config() { window.version = cfg.get("version"); window.default_size = {cfg.get("default_window_size.width"), cfg.get("default_window_size.height")}; - project.save_on_compile_or_run=cfg.get("project.save_on_compile_or_run"); project.default_build_path=cfg.get("project.default_build_path"); project.debug_build_path=cfg.get("project.debug_build_path"); project.make_command=cfg.get("project.make_command"); project.cmake_command=cfg.get("project.cmake_command"); + project.clear_terminal_on_compile=cfg.get("project.clear_terminal_on_compile"); - terminal.history_size=cfg.get("terminal_history_size"); + terminal.history_size=cfg.get("terminal.history_size"); + terminal.font=cfg.get("terminal.font"); terminal.clang_format_command="clang-format"; #ifdef __linux if(terminal.clang_format_command=="clang-format" && !boost::filesystem::exists("/usr/bin/clang-format") && !boost::filesystem::exists("/usr/local/bin/clang-format")) { - if(boost::filesystem::exists("/usr/bin/clang-format-3.7")) + if(boost::filesystem::exists("/usr/bin/clang-format-3.8")) + terminal.clang_format_command="/usr/bin/clang-format-3.8"; + else if(boost::filesystem::exists("/usr/bin/clang-format-3.7")) terminal.clang_format_command="/usr/bin/clang-format-3.7"; else if(boost::filesystem::exists("/usr/bin/clang-format-3.6")) terminal.clang_format_command="/usr/bin/clang-format-3.6"; @@ -118,10 +121,10 @@ void Config::retrieve_config() { #endif } -bool Config::check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path) { +bool Config::add_missing_nodes(const boost::property_tree::ptree &default_cfg, std::string parent_path) { if(parent_path.size()>0) parent_path+="."; - bool exists=true; + bool unchanged=true; for(auto &node: default_cfg) { auto path=parent_path+node.first; try { @@ -129,15 +132,29 @@ bool Config::check_config_file(const boost::property_tree::ptree &default_cfg, s } catch(const std::exception &e) { cfg.add(path, node.second.data()); - exists=false; + unchanged=false; } + unchanged&=add_missing_nodes(node.second, path); + } + return unchanged; +} + +bool Config::remove_deprecated_nodes(const boost::property_tree::ptree &default_cfg, boost::property_tree::ptree &config_cfg, std::string parent_path) { + if(parent_path.size()>0) + parent_path+="."; + bool unchanged=true; + for(auto &node: config_cfg) { + auto path=parent_path+node.first; try { - exists&=check_config_file(node.second, path); + default_cfg.get(path); + unchanged&=remove_deprecated_nodes(default_cfg, node.second, path); } catch(const std::exception &e) { + config_cfg.erase(node.first); + unchanged=false; } } - return exists; + return unchanged; } void Config::update_config_file() { @@ -159,10 +176,10 @@ void Config::update_config_file() { std::cerr << "Error reading json-file: " << e.what() << std::endl; cfg_ok=false; } - cfg_ok&=check_config_file(default_cfg); - if(!cfg_ok) { + cfg_ok&=add_missing_nodes(default_cfg); + cfg_ok&=remove_deprecated_nodes(default_cfg, cfg); + if(!cfg_ok) boost::property_tree::write_json((home/"config"/"config.json").string(), cfg); - } } void Config::get_source() { diff --git a/src/config.h b/src/config.h index 1add042..e6f6d82 100644 --- a/src/config.h +++ b/src/config.h @@ -26,6 +26,7 @@ public: public: std::string clang_format_command; int history_size; + std::string font; #ifdef _WIN32 boost::filesystem::path msys2_mingw_path; @@ -39,6 +40,7 @@ public: std::string cmake_command; std::string make_command; bool save_on_compile_or_run; + bool clear_terminal_on_compile; }; class Source { @@ -90,7 +92,8 @@ public: private: void find_or_create_config_files(); void retrieve_config(); - bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path=""); + bool add_missing_nodes(const boost::property_tree::ptree &default_cfg, std::string parent_path=""); + bool remove_deprecated_nodes(const boost::property_tree::ptree &default_cfg, boost::property_tree::ptree &config_cfg, std::string parent_path=""); void update_config_file(); void get_source(); diff --git a/src/files.h b/src/files.h index c69c48d..11a09a9 100644 --- a/src/files.h +++ b/src/files.h @@ -2,7 +2,7 @@ #define JUCI_FILES_H_ #include -#define JUCI_VERSION "1.1.1" +#define JUCI_VERSION "1.1.2-rc1" const std::string configjson = "{\n" @@ -11,13 +11,17 @@ const std::string configjson = " \"width\": 800,\n" " \"height\": 600\n" " },\n" -" \"terminal_history_size\": 1000,\n" " \"gtk_theme\": {\n" " \"name_comment\": \"Use \\\"\\\" for default theme, At least these two exist on all systems: Adwaita, Raleigh\",\n" " \"name\": \"Adwaita\",\n" " \"variant_comment\": \"Use \\\"\\\" for default variant, and \\\"dark\\\" for dark theme variant\",\n" " \"variant\": \"\"\n" " },\n" +" \"terminal\": {\n" +" \"history_size\": 1000,\n" +" \"font_comment\": \"Use \\\"\\\" to use source.font with slightly smaller size\",\n" +" \"font\": \"\"\n" +" },\n" " \"source\": {\n" " \"style_comment\": \"Use \\\"\\\" for default style, and for instance juci-dark or juci-dark-blue together with dark gtk_theme variant. Styles from normal gtksourceview install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango\",\n" " \"style\": \"juci-light\",\n" @@ -130,7 +134,8 @@ const std::string configjson = " \"cmake_command\": \"cmake\",\n" #endif " \"make_command\": \"cmake --build .\",\n" -" \"save_on_compile_or_run\": true\n" +" \"save_on_compile_or_run\": true,\n" +" \"clear_terminal_on_compile\": true\n" " },\n" " \"documentation_searches\": {\n" " \"clang\": {\n" diff --git a/src/project.cc b/src/project.cc index 4925bb9..7ebc39f 100644 --- a/src/project.cc +++ b/src/project.cc @@ -167,7 +167,8 @@ void Project::Clang::compile() { if(default_build_path.empty() || !build->update_default_build()) return; - Terminal::get().clear(); + if(Config::get().project.clear_terminal_on_compile) + Terminal::get().clear(); compiling=true; Terminal::get().print("Compiling project "+build->project_path.string()+"\n"); @@ -201,7 +202,8 @@ void Project::Clang::compile_and_run() { arguments=filesystem::escape_argument(arguments); } - Terminal::get().clear(); + if(Config::get().project.clear_terminal_on_compile) + Terminal::get().clear(); compiling=true; Terminal::get().print("Compiling and running "+arguments+"\n"); @@ -282,7 +284,8 @@ void Project::Clang::debug_start() { } } - Terminal::get().clear(); + if(Config::get().project.clear_terminal_on_compile) + Terminal::get().clear(); debugging=true; Terminal::get().print("Compiling and debugging "+run_arguments+"\n"); diff --git a/src/terminal.cc b/src/terminal.cc index a82d0a7..ed9231b 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -9,7 +9,9 @@ Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) { } Terminal::InProgress::~InProgress() { + stop_mutex.lock(); stop=true; + stop_mutex.unlock(); if(wait_thread.joinable()) wait_thread.join(); } @@ -18,7 +20,14 @@ void Terminal::InProgress::start(const std::string& msg) { line_nr=Terminal::get().print(msg+"...\n"); wait_thread=std::thread([this](){ size_t c=0; - while(!stop) { + while(true) { + stop_mutex.lock(); + if(stop) { + stop_mutex.unlock(); + break; + } + else + stop_mutex.unlock(); if(c%100==0) Terminal::get().async_print(line_nr-1, "."); std::this_thread::sleep_for(std::chrono::milliseconds(10)); @@ -28,17 +37,25 @@ void Terminal::InProgress::start(const std::string& msg) { } void Terminal::InProgress::done(const std::string& msg) { + stop_mutex.lock(); if(!stop) { stop=true; + stop_mutex.unlock(); Terminal::get().async_print(line_nr-1, msg); } + else + stop_mutex.unlock(); } void Terminal::InProgress::cancel(const std::string& msg) { + stop_mutex.lock(); if(!stop) { stop=true; + stop_mutex.unlock(); Terminal::get().async_print(line_nr-1, msg); } + else + stop_mutex.unlock(); } Terminal::Terminal() { @@ -241,10 +258,30 @@ void Terminal::async_print(size_t line_nr, const std::string &message) { }); } +void Terminal::configure() { + if(Config::get().terminal.font.size()>0) { + override_font(Pango::FontDescription(Config::get().terminal.font)); + } + else if(Config::get().source.font.size()>0) { + Pango::FontDescription font_description(Config::get().source.font); + auto font_description_size=font_description.get_size(); + if(font_description_size==0) { + Pango::FontDescription default_font_description(Gtk::Settings::get_default()->property_gtk_font_name()); + font_description_size=default_font_description.get_size(); + } + if(font_description_size>0) + font_description.set_size(font_description_size*0.95); + override_font(font_description); + } +} + void Terminal::clear() { in_progresses_mutex.lock(); - for(auto &in_progress: in_progresses) + for(auto &in_progress: in_progresses) { + in_progress->stop_mutex.lock(); in_progress->stop=true; + in_progress->stop_mutex.unlock(); + } in_progresses_mutex.unlock(); while(g_main_context_pending(NULL)) g_main_context_iteration(NULL, false); diff --git a/src/terminal.h b/src/terminal.h index 7fd0c20..2140969 100644 --- a/src/terminal.h +++ b/src/terminal.h @@ -24,7 +24,9 @@ public: private: void start(const std::string& msg); size_t line_nr; - std::atomic stop; + + bool stop; + std::mutex stop_mutex; std::thread wait_thread; }; @@ -48,6 +50,8 @@ public: void async_print(const std::string &message, bool bold=false); void async_print(size_t line_nr, const std::string &message); + void configure(); + void clear(); protected: bool on_key_press_event(GdkEventKey *event); diff --git a/src/window.cc b/src/window.cc index 08b21c4..7c12135 100644 --- a/src/window.cc +++ b/src/window.cc @@ -146,18 +146,7 @@ void Window::configure() { style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS); Directories::get().update(); Menu::get().set_keys(); - - if(Config::get().source.font.size()>0) { - Pango::FontDescription font_description(Config::get().source.font); - auto font_description_size=font_description.get_size(); - if(font_description_size==0) { - Pango::FontDescription default_font_description(Gtk::Settings::get_default()->property_gtk_font_name()); - font_description_size=default_font_description.get_size(); - } - if(font_description_size>0) - font_description.set_size(font_description_size*0.95); - Terminal::get().override_font(font_description); - } + Terminal::get().configure(); } void Window::set_menu_actions() {