Browse Source

Fixes #179

merge-requests/365/head
eidheim 10 years ago
parent
commit
a6702746b5
  1. 39
      src/config.cc
  2. 5
      src/config.h
  3. 11
      src/files.h
  4. 3
      src/project.cc
  5. 41
      src/terminal.cc
  6. 6
      src/terminal.h
  7. 13
      src/window.cc

39
src/config.cc

@ -97,18 +97,21 @@ void Config::retrieve_config() {
window.version = cfg.get<std::string>("version"); window.version = cfg.get<std::string>("version");
window.default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")}; window.default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")};
project.save_on_compile_or_run=cfg.get<bool>("project.save_on_compile_or_run");
project.default_build_path=cfg.get<std::string>("project.default_build_path"); project.default_build_path=cfg.get<std::string>("project.default_build_path");
project.debug_build_path=cfg.get<std::string>("project.debug_build_path"); project.debug_build_path=cfg.get<std::string>("project.debug_build_path");
project.make_command=cfg.get<std::string>("project.make_command"); project.make_command=cfg.get<std::string>("project.make_command");
project.cmake_command=cfg.get<std::string>("project.cmake_command"); project.cmake_command=cfg.get<std::string>("project.cmake_command");
project.clear_terminal_on_compile=cfg.get<bool>("project.clear_terminal_on_compile");
terminal.history_size=cfg.get<int>("terminal_history_size"); terminal.history_size=cfg.get<int>("terminal.history_size");
terminal.font=cfg.get<std::string>("terminal.font");
terminal.clang_format_command="clang-format"; terminal.clang_format_command="clang-format";
#ifdef __linux #ifdef __linux
if(terminal.clang_format_command=="clang-format" && if(terminal.clang_format_command=="clang-format" &&
!boost::filesystem::exists("/usr/bin/clang-format") && !boost::filesystem::exists("/usr/local/bin/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"; terminal.clang_format_command="/usr/bin/clang-format-3.7";
else if(boost::filesystem::exists("/usr/bin/clang-format-3.6")) else if(boost::filesystem::exists("/usr/bin/clang-format-3.6"))
terminal.clang_format_command="/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 #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) if(parent_path.size()>0)
parent_path+="."; parent_path+=".";
bool exists=true; bool unchanged=true;
for(auto &node: default_cfg) { for(auto &node: default_cfg) {
auto path=parent_path+node.first; auto path=parent_path+node.first;
try { try {
@ -129,15 +132,29 @@ bool Config::check_config_file(const boost::property_tree::ptree &default_cfg, s
} }
catch(const std::exception &e) { catch(const std::exception &e) {
cfg.add(path, node.second.data()); 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 { try {
exists&=check_config_file(node.second, path); default_cfg.get<std::string>(path);
unchanged&=remove_deprecated_nodes(default_cfg, node.second, path);
} }
catch(const std::exception &e) { catch(const std::exception &e) {
config_cfg.erase(node.first);
unchanged=false;
} }
} }
return exists; return unchanged;
} }
void Config::update_config_file() { void Config::update_config_file() {
@ -159,10 +176,10 @@ void Config::update_config_file() {
std::cerr << "Error reading json-file: " << e.what() << std::endl; std::cerr << "Error reading json-file: " << e.what() << std::endl;
cfg_ok=false; cfg_ok=false;
} }
cfg_ok&=check_config_file(default_cfg); cfg_ok&=add_missing_nodes(default_cfg);
if(!cfg_ok) { cfg_ok&=remove_deprecated_nodes(default_cfg, cfg);
if(!cfg_ok)
boost::property_tree::write_json((home/"config"/"config.json").string(), cfg); boost::property_tree::write_json((home/"config"/"config.json").string(), cfg);
}
} }
void Config::get_source() { void Config::get_source() {

5
src/config.h

@ -26,6 +26,7 @@ public:
public: public:
std::string clang_format_command; std::string clang_format_command;
int history_size; int history_size;
std::string font;
#ifdef _WIN32 #ifdef _WIN32
boost::filesystem::path msys2_mingw_path; boost::filesystem::path msys2_mingw_path;
@ -39,6 +40,7 @@ public:
std::string cmake_command; std::string cmake_command;
std::string make_command; std::string make_command;
bool save_on_compile_or_run; bool save_on_compile_or_run;
bool clear_terminal_on_compile;
}; };
class Source { class Source {
@ -90,7 +92,8 @@ public:
private: private:
void find_or_create_config_files(); void find_or_create_config_files();
void retrieve_config(); 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 update_config_file();
void get_source(); void get_source();

11
src/files.h

@ -2,7 +2,7 @@
#define JUCI_FILES_H_ #define JUCI_FILES_H_
#include <string> #include <string>
#define JUCI_VERSION "1.1.1" #define JUCI_VERSION "1.1.2-rc1"
const std::string configjson = const std::string configjson =
"{\n" "{\n"
@ -11,13 +11,17 @@ const std::string configjson =
" \"width\": 800,\n" " \"width\": 800,\n"
" \"height\": 600\n" " \"height\": 600\n"
" },\n" " },\n"
" \"terminal_history_size\": 1000,\n"
" \"gtk_theme\": {\n" " \"gtk_theme\": {\n"
" \"name_comment\": \"Use \\\"\\\" for default theme, At least these two exist on all systems: Adwaita, Raleigh\",\n" " \"name_comment\": \"Use \\\"\\\" for default theme, At least these two exist on all systems: Adwaita, Raleigh\",\n"
" \"name\": \"Adwaita\",\n" " \"name\": \"Adwaita\",\n"
" \"variant_comment\": \"Use \\\"\\\" for default variant, and \\\"dark\\\" for dark theme variant\",\n" " \"variant_comment\": \"Use \\\"\\\" for default variant, and \\\"dark\\\" for dark theme variant\",\n"
" \"variant\": \"\"\n" " \"variant\": \"\"\n"
" },\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" " \"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_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" " \"style\": \"juci-light\",\n"
@ -130,7 +134,8 @@ const std::string configjson =
" \"cmake_command\": \"cmake\",\n" " \"cmake_command\": \"cmake\",\n"
#endif #endif
" \"make_command\": \"cmake --build .\",\n" " \"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" " },\n"
" \"documentation_searches\": {\n" " \"documentation_searches\": {\n"
" \"clang\": {\n" " \"clang\": {\n"

3
src/project.cc

@ -167,6 +167,7 @@ void Project::Clang::compile() {
if(default_build_path.empty() || !build->update_default_build()) if(default_build_path.empty() || !build->update_default_build())
return; return;
if(Config::get().project.clear_terminal_on_compile)
Terminal::get().clear(); Terminal::get().clear();
compiling=true; compiling=true;
@ -201,6 +202,7 @@ void Project::Clang::compile_and_run() {
arguments=filesystem::escape_argument(arguments); arguments=filesystem::escape_argument(arguments);
} }
if(Config::get().project.clear_terminal_on_compile)
Terminal::get().clear(); Terminal::get().clear();
compiling=true; compiling=true;
@ -282,6 +284,7 @@ void Project::Clang::debug_start() {
} }
} }
if(Config::get().project.clear_terminal_on_compile)
Terminal::get().clear(); Terminal::get().clear();
debugging=true; debugging=true;

41
src/terminal.cc

@ -9,7 +9,9 @@ Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {
} }
Terminal::InProgress::~InProgress() { Terminal::InProgress::~InProgress() {
stop_mutex.lock();
stop=true; stop=true;
stop_mutex.unlock();
if(wait_thread.joinable()) if(wait_thread.joinable())
wait_thread.join(); wait_thread.join();
} }
@ -18,7 +20,14 @@ void Terminal::InProgress::start(const std::string& msg) {
line_nr=Terminal::get().print(msg+"...\n"); line_nr=Terminal::get().print(msg+"...\n");
wait_thread=std::thread([this](){ wait_thread=std::thread([this](){
size_t c=0; 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) if(c%100==0)
Terminal::get().async_print(line_nr-1, "."); Terminal::get().async_print(line_nr-1, ".");
std::this_thread::sleep_for(std::chrono::milliseconds(10)); 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) { void Terminal::InProgress::done(const std::string& msg) {
stop_mutex.lock();
if(!stop) { if(!stop) {
stop=true; stop=true;
stop_mutex.unlock();
Terminal::get().async_print(line_nr-1, msg); Terminal::get().async_print(line_nr-1, msg);
} }
else
stop_mutex.unlock();
} }
void Terminal::InProgress::cancel(const std::string& msg) { void Terminal::InProgress::cancel(const std::string& msg) {
stop_mutex.lock();
if(!stop) { if(!stop) {
stop=true; stop=true;
stop_mutex.unlock();
Terminal::get().async_print(line_nr-1, msg); Terminal::get().async_print(line_nr-1, msg);
} }
else
stop_mutex.unlock();
} }
Terminal::Terminal() { 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() { void Terminal::clear() {
in_progresses_mutex.lock(); 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=true;
in_progress->stop_mutex.unlock();
}
in_progresses_mutex.unlock(); in_progresses_mutex.unlock();
while(g_main_context_pending(NULL)) while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false); g_main_context_iteration(NULL, false);

6
src/terminal.h

@ -24,7 +24,9 @@ public:
private: private:
void start(const std::string& msg); void start(const std::string& msg);
size_t line_nr; size_t line_nr;
std::atomic<bool> stop;
bool stop;
std::mutex stop_mutex;
std::thread wait_thread; std::thread wait_thread;
}; };
@ -48,6 +50,8 @@ public:
void async_print(const std::string &message, bool bold=false); void async_print(const std::string &message, bool bold=false);
void async_print(size_t line_nr, const std::string &message); void async_print(size_t line_nr, const std::string &message);
void configure();
void clear(); void clear();
protected: protected:
bool on_key_press_event(GdkEventKey *event); bool on_key_press_event(GdkEventKey *event);

13
src/window.cc

@ -146,18 +146,7 @@ void Window::configure() {
style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS); style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
Directories::get().update(); Directories::get().update();
Menu::get().set_keys(); Menu::get().set_keys();
Terminal::get().configure();
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);
}
} }
void Window::set_menu_actions() { void Window::set_menu_actions() {

Loading…
Cancel
Save