From 670d4bba149a282f6925ec32ccaed8482c6b197d Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 3 Apr 2016 21:48:49 +0200 Subject: [PATCH 1/7] Suggestion to #179 --- src/project.cc | 6 ++++++ src/source.cc | 1 - src/terminal.cc | 19 ++++++++++++++++++- src/terminal.h | 7 +++++++ src/window.cc | 4 ++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/project.cc b/src/project.cc index c224d6c..4925bb9 100644 --- a/src/project.cc +++ b/src/project.cc @@ -167,6 +167,8 @@ void Project::Clang::compile() { if(default_build_path.empty() || !build->update_default_build()) return; + Terminal::get().clear(); + compiling=true; Terminal::get().print("Compiling project "+build->project_path.string()+"\n"); Terminal::get().async_process(Config::get().project.make_command, default_build_path, [this](int exit_status) { @@ -199,6 +201,8 @@ void Project::Clang::compile_and_run() { arguments=filesystem::escape_argument(arguments); } + Terminal::get().clear(); + compiling=true; Terminal::get().print("Compiling and running "+arguments+"\n"); Terminal::get().async_process(Config::get().project.make_command, default_build_path, [this, arguments, project_path](int exit_status){ @@ -278,6 +282,8 @@ void Project::Clang::debug_start() { } } + Terminal::get().clear(); + debugging=true; Terminal::get().print("Compiling and debugging "+run_arguments+"\n"); Terminal::get().async_process(Config::get().project.make_command, debug_build_path, [this, breakpoints, run_arguments, project_path](int exit_status){ diff --git a/src/source.cc b/src/source.cc index 8376501..c26fc0f 100644 --- a/src/source.cc +++ b/src/source.cc @@ -284,7 +284,6 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr Terminal::print_in_progress(std::string start_msg) { - std::shared_ptr in_progress=std::shared_ptr(new Terminal::InProgress(start_msg)); + auto in_progress=std::shared_ptr(new Terminal::InProgress(start_msg), [this](Terminal::InProgress *in_progress) { + in_progresses_mutex.lock(); + in_progresses.erase(in_progress); + in_progresses_mutex.unlock(); + }); + in_progresses_mutex.lock(); + in_progresses.emplace(in_progress.get()); + in_progresses_mutex.unlock(); return in_progress; } @@ -234,6 +241,16 @@ void Terminal::async_print(size_t line_nr, const std::string &message) { }); } +void Terminal::clear() { + in_progresses_mutex.lock(); + for(auto &in_progress: in_progresses) + in_progress->stop=true; + in_progresses_mutex.unlock(); + while(g_main_context_pending(NULL)) + g_main_context_iteration(NULL, false); + get_buffer()->set_text(""); +} + bool Terminal::on_key_press_event(GdkEventKey *event) { processes_mutex.lock(); bool debug_is_running=false; diff --git a/src/terminal.h b/src/terminal.h index dd74ad9..7fd0c20 100644 --- a/src/terminal.h +++ b/src/terminal.h @@ -10,10 +10,12 @@ #include #include "process.hpp" #include "dispatcher.h" +#include class Terminal : public Gtk::TextView { public: class InProgress { + friend class Terminal; public: InProgress(const std::string& start_msg); ~InProgress(); @@ -45,6 +47,8 @@ public: std::shared_ptr print_in_progress(std::string start_msg); void async_print(const std::string &message, bool bold=false); void async_print(size_t line_nr, const std::string &message); + + void clear(); protected: bool on_key_press_event(GdkEventKey *event); private: @@ -56,6 +60,9 @@ private: std::string stdin_buffer; size_t deleted_lines=0; + + std::unordered_set in_progresses; + std::mutex in_progresses_mutex; }; #endif // JUCI_TERMINAL_H_ diff --git a/src/window.cc b/src/window.cc index c20fed2..490680c 100644 --- a/src/window.cc +++ b/src/window.cc @@ -146,6 +146,10 @@ 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) { + Terminal::get().override_font(Pango::FontDescription(Config::get().source.font)); + Directories::get().override_font(Pango::FontDescription(Config::get().source.font)); + } } void Window::set_menu_actions() { From 3aed1e2eea6d30dff483e3dbf27e98fb6192a2fc Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 3 Apr 2016 22:17:26 +0200 Subject: [PATCH 2/7] Reverted directories font change --- src/window.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/window.cc b/src/window.cc index 490680c..19239e8 100644 --- a/src/window.cc +++ b/src/window.cc @@ -146,10 +146,8 @@ 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) { + if(Config::get().source.font.size()>0) Terminal::get().override_font(Pango::FontDescription(Config::get().source.font)); - Directories::get().override_font(Pango::FontDescription(Config::get().source.font)); - } } void Window::set_menu_actions() { From 24575797b246ab49aa0f07c87b76e2dd7667b1be Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 3 Apr 2016 22:33:16 +0200 Subject: [PATCH 3/7] Made the terminal font size 95% of the source font size. See #179 --- src/window.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/window.cc b/src/window.cc index 19239e8..644032b 100644 --- a/src/window.cc +++ b/src/window.cc @@ -146,8 +146,11 @@ 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) - Terminal::get().override_font(Pango::FontDescription(Config::get().source.font)); + if(Config::get().source.font.size()>0) { + Pango::FontDescription font_description(Config::get().source.font); + font_description.set_size(font_description.get_size()*0.95); + Terminal::get().override_font(font_description); + } } void Window::set_menu_actions() { From 6d0d832c83a617727772d6fc9a9fb65ba90cd6de Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 3 Apr 2016 22:55:44 +0200 Subject: [PATCH 4/7] Reverted last commit, problematic when size is equal to 0. See #179 --- src/window.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/window.cc b/src/window.cc index 644032b..8dfe8e7 100644 --- a/src/window.cc +++ b/src/window.cc @@ -148,7 +148,6 @@ void Window::configure() { Menu::get().set_keys(); if(Config::get().source.font.size()>0) { Pango::FontDescription font_description(Config::get().source.font); - font_description.set_size(font_description.get_size()*0.95); Terminal::get().override_font(font_description); } } From 0a592c54ab8c2765fb0254cd01e0a6edcdebe211 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 3 Apr 2016 23:19:36 +0200 Subject: [PATCH 5/7] Smaller terminal font size now correctly set. Related to #179 --- src/window.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/window.cc b/src/window.cc index 8dfe8e7..08b21c4 100644 --- a/src/window.cc +++ b/src/window.cc @@ -146,8 +146,16 @@ 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); } } From a6702746b52da1136fdccd4c0ef3c27a161fe9a0 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 4 Apr 2016 09:02:22 +0200 Subject: [PATCH 6/7] Fixes #179 --- src/config.cc | 39 ++++++++++++++++++++++++++++----------- src/config.h | 5 ++++- src/files.h | 11 ++++++++--- src/project.cc | 9 ++++++--- src/terminal.cc | 41 +++++++++++++++++++++++++++++++++++++++-- src/terminal.h | 6 +++++- src/window.cc | 13 +------------ 7 files changed, 91 insertions(+), 33 deletions(-) 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() { From 9da69c8dc850bae1c372a98fb886935e901b8851 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 4 Apr 2016 09:38:55 +0200 Subject: [PATCH 7/7] Added missing line --- src/config.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.cc b/src/config.cc index b2206fc..f6d3849 100644 --- a/src/config.cc +++ b/src/config.cc @@ -101,6 +101,7 @@ void Config::retrieve_config() { 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.save_on_compile_or_run=cfg.get("project.save_on_compile_or_run"); project.clear_terminal_on_compile=cfg.get("project.clear_terminal_on_compile"); terminal.history_size=cfg.get("terminal.history_size");