|
|
|
@ -35,20 +35,20 @@ Config::Config() { |
|
|
|
|
|
|
|
|
|
|
|
void Config::load() { |
|
|
|
void Config::load() { |
|
|
|
auto config_json = (home_juci_path/"config"/"config.json").string(); // This causes some redundant copies, but assures windows support
|
|
|
|
auto config_json = (home_juci_path/"config"/"config.json").string(); // This causes some redundant copies, but assures windows support
|
|
|
|
|
|
|
|
boost::property_tree::ptree cfg; |
|
|
|
try { |
|
|
|
try { |
|
|
|
find_or_create_config_files(); |
|
|
|
find_or_create_config_files(); |
|
|
|
boost::property_tree::json_parser::read_json(config_json, cfg); |
|
|
|
boost::property_tree::json_parser::read_json(config_json, cfg); |
|
|
|
update_config_file(); |
|
|
|
update(cfg); |
|
|
|
retrieve_config(); |
|
|
|
read(cfg); |
|
|
|
} |
|
|
|
} |
|
|
|
catch(const std::exception &e) { |
|
|
|
catch(const std::exception &e) { |
|
|
|
::Terminal::get().print("Error: could not parse "+config_json+": "+e.what()+"\n", true); |
|
|
|
::Terminal::get().print("Error: could not parse "+config_json+": "+e.what()+"\n", true); |
|
|
|
std::stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << default_config_file; |
|
|
|
ss << default_config_file; |
|
|
|
boost::property_tree::read_json(ss, cfg); |
|
|
|
boost::property_tree::read_json(ss, cfg); |
|
|
|
retrieve_config(); |
|
|
|
read(cfg); |
|
|
|
} |
|
|
|
} |
|
|
|
cfg.clear(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Config::find_or_create_config_files() { |
|
|
|
void Config::find_or_create_config_files() { |
|
|
|
@ -76,50 +76,41 @@ void Config::find_or_create_config_files() { |
|
|
|
filesystem::write(juci_style_path, juci_dark_blue_style); |
|
|
|
filesystem::write(juci_style_path, juci_dark_blue_style); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Config::retrieve_config() { |
|
|
|
void Config::update(boost::property_tree::ptree &cfg) { |
|
|
|
auto keybindings_pt = cfg.get_child("keybindings"); |
|
|
|
boost::property_tree::ptree default_cfg; |
|
|
|
for (auto &i : keybindings_pt) { |
|
|
|
bool cfg_ok=true; |
|
|
|
menu.keys[i.first] = i.second.get_value<std::string>(); |
|
|
|
if(cfg.get<std::string>("version")!=JUCI_VERSION) { |
|
|
|
|
|
|
|
std::stringstream ss; |
|
|
|
|
|
|
|
ss << default_config_file; |
|
|
|
|
|
|
|
boost::property_tree::read_json(ss, default_cfg); |
|
|
|
|
|
|
|
cfg_ok=false; |
|
|
|
|
|
|
|
auto it_version=cfg.find("version"); |
|
|
|
|
|
|
|
if(it_version!=cfg.not_found()) { |
|
|
|
|
|
|
|
make_version_dependent_corrections(cfg, default_cfg, it_version->second.data()); |
|
|
|
|
|
|
|
it_version->second.data()=JUCI_VERSION; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto style_path=home_juci_path/"styles"; |
|
|
|
|
|
|
|
filesystem::write(style_path/"juci-light.xml", juci_light_style); |
|
|
|
|
|
|
|
filesystem::write(style_path/"juci-dark.xml", juci_dark_style); |
|
|
|
|
|
|
|
filesystem::write(style_path/"juci-dark-blue.xml", juci_dark_blue_style); |
|
|
|
} |
|
|
|
} |
|
|
|
get_source(); |
|
|
|
else |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
cfg_ok&=add_missing_nodes(cfg, default_cfg); |
|
|
|
|
|
|
|
cfg_ok&=remove_deprecated_nodes(cfg, default_cfg); |
|
|
|
|
|
|
|
if(!cfg_ok) |
|
|
|
|
|
|
|
boost::property_tree::write_json((home_juci_path/"config"/"config.json").string(), cfg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.theme_name=cfg.get<std::string>("gtk_theme.name"); |
|
|
|
void Config::make_version_dependent_corrections(boost::property_tree::ptree &cfg, const boost::property_tree::ptree &default_cfg, const std::string &version) { |
|
|
|
window.theme_variant=cfg.get<std::string>("gtk_theme.variant"); |
|
|
|
try { |
|
|
|
window.version = cfg.get<std::string>("version"); |
|
|
|
|
|
|
|
window.default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.cmake.command=cfg.get<std::string>("project.cmake.command"); |
|
|
|
|
|
|
|
project.cmake.compile_command=cfg.get<std::string>("project.cmake.compile_command"); |
|
|
|
|
|
|
|
project.meson.command=cfg.get<std::string>("project.meson.command"); |
|
|
|
|
|
|
|
project.meson.compile_command=cfg.get<std::string>("project.meson.compile_command"); |
|
|
|
|
|
|
|
project.save_on_compile_or_run=cfg.get<bool>("project.save_on_compile_or_run"); |
|
|
|
|
|
|
|
project.clear_terminal_on_compile=cfg.get<bool>("project.clear_terminal_on_compile"); |
|
|
|
|
|
|
|
project.ctags_command=cfg.get<std::string>("project.ctags_command"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
terminal.history_size=cfg.get<int>("terminal.history_size"); |
|
|
|
|
|
|
|
terminal.font=cfg.get<std::string>("terminal.font"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
terminal.show_progress=cfg.get<bool>("terminal.show_progress"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")) { |
|
|
|
|
|
|
|
auto versions={"4.0", "3.9", "3.8", "3.7", "3.6", "3.5"}; |
|
|
|
|
|
|
|
for(auto &version: versions) { |
|
|
|
|
|
|
|
auto corrected_command=std::string("/usr/bin/clang-format-")+version; |
|
|
|
|
|
|
|
if(boost::filesystem::exists(corrected_command)) { |
|
|
|
|
|
|
|
terminal.clang_format_command=corrected_command; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
catch(...) {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Config::add_missing_nodes(const boost::property_tree::ptree &default_cfg, std::string parent_path) { |
|
|
|
bool Config::add_missing_nodes(boost::property_tree::ptree &cfg, 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 unchanged=true; |
|
|
|
bool unchanged=true; |
|
|
|
@ -132,104 +123,65 @@ bool Config::add_missing_nodes(const boost::property_tree::ptree &default_cfg, s |
|
|
|
cfg.add(path, node.second.data()); |
|
|
|
cfg.add(path, node.second.data()); |
|
|
|
unchanged=false; |
|
|
|
unchanged=false; |
|
|
|
} |
|
|
|
} |
|
|
|
unchanged&=add_missing_nodes(node.second, path); |
|
|
|
unchanged&=add_missing_nodes(cfg, node.second, path); |
|
|
|
} |
|
|
|
} |
|
|
|
return unchanged; |
|
|
|
return unchanged; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Config::remove_deprecated_nodes(const boost::property_tree::ptree &default_cfg, boost::property_tree::ptree &config_cfg, std::string parent_path) { |
|
|
|
bool Config::remove_deprecated_nodes(boost::property_tree::ptree &cfg, 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 unchanged=true; |
|
|
|
bool unchanged=true; |
|
|
|
for(auto it=config_cfg.begin();it!=config_cfg.end();) { |
|
|
|
for(auto it=cfg.begin();it!=cfg.end();) { |
|
|
|
auto path=parent_path+it->first; |
|
|
|
auto path=parent_path+it->first; |
|
|
|
try { |
|
|
|
try { |
|
|
|
default_cfg.get<std::string>(path); |
|
|
|
default_cfg.get<std::string>(path); |
|
|
|
unchanged&=remove_deprecated_nodes(default_cfg, it->second, path); |
|
|
|
unchanged&=remove_deprecated_nodes(it->second, default_cfg, path); |
|
|
|
++it; |
|
|
|
++it; |
|
|
|
} |
|
|
|
} |
|
|
|
catch(const std::exception &e) { |
|
|
|
catch(const std::exception &e) { |
|
|
|
it=config_cfg.erase(it); |
|
|
|
it=cfg.erase(it); |
|
|
|
unchanged=false; |
|
|
|
unchanged=false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return unchanged; |
|
|
|
return unchanged; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Config::update_config_file() { |
|
|
|
void Config::read(const boost::property_tree::ptree &cfg) { |
|
|
|
boost::property_tree::ptree default_cfg; |
|
|
|
auto keybindings_pt = cfg.get_child("keybindings"); |
|
|
|
bool cfg_ok=true; |
|
|
|
for (auto &i : keybindings_pt) { |
|
|
|
try { |
|
|
|
menu.keys[i.first] = i.second.get_value<std::string>(); |
|
|
|
if(cfg.get<std::string>("version")!=JUCI_VERSION) { |
|
|
|
|
|
|
|
std::stringstream ss; |
|
|
|
|
|
|
|
ss << default_config_file; |
|
|
|
|
|
|
|
boost::property_tree::read_json(ss, default_cfg); |
|
|
|
|
|
|
|
cfg_ok=false; |
|
|
|
|
|
|
|
if(cfg.count("version")>0) |
|
|
|
|
|
|
|
cfg.find("version")->second.data()=default_cfg.get<std::string>("version"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto style_path=home_juci_path/"styles"; |
|
|
|
|
|
|
|
filesystem::write(style_path/"juci-light.xml", juci_light_style); |
|
|
|
|
|
|
|
filesystem::write(style_path/"juci-dark.xml", juci_dark_style); |
|
|
|
|
|
|
|
filesystem::write(style_path/"juci-dark-blue.xml", juci_dark_blue_style); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch(const std::exception &e) { |
|
|
|
|
|
|
|
std::cerr << "Error reading json-file: " << e.what() << std::endl; |
|
|
|
|
|
|
|
cfg_ok=false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
cfg_ok&=add_missing_nodes(default_cfg); |
|
|
|
|
|
|
|
cfg_ok&=remove_deprecated_nodes(default_cfg, cfg); |
|
|
|
|
|
|
|
if(!cfg_ok) |
|
|
|
|
|
|
|
boost::property_tree::write_json((home_juci_path/"config"/"config.json").string(), cfg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Config::get_source() { |
|
|
|
|
|
|
|
auto source_json = cfg.get_child("source"); |
|
|
|
auto source_json = cfg.get_child("source"); |
|
|
|
|
|
|
|
|
|
|
|
source.style=source_json.get<std::string>("style"); |
|
|
|
source.style=source_json.get<std::string>("style"); |
|
|
|
source.font=source_json.get<std::string>("font"); |
|
|
|
source.font=source_json.get<std::string>("font"); |
|
|
|
|
|
|
|
|
|
|
|
source.cleanup_whitespace_characters=source_json.get<bool>("cleanup_whitespace_characters"); |
|
|
|
source.cleanup_whitespace_characters=source_json.get<bool>("cleanup_whitespace_characters"); |
|
|
|
source.show_whitespace_characters=source_json.get<std::string>("show_whitespace_characters"); |
|
|
|
source.show_whitespace_characters=source_json.get<std::string>("show_whitespace_characters"); |
|
|
|
|
|
|
|
|
|
|
|
source.format_style_on_save=source_json.get<bool>("format_style_on_save"); |
|
|
|
source.format_style_on_save=source_json.get<bool>("format_style_on_save"); |
|
|
|
|
|
|
|
|
|
|
|
source.smart_brackets=source_json.get<bool>("smart_brackets"); |
|
|
|
source.smart_brackets=source_json.get<bool>("smart_brackets"); |
|
|
|
source.smart_inserts=source_json.get<bool>("smart_inserts"); |
|
|
|
source.smart_inserts=source_json.get<bool>("smart_inserts"); |
|
|
|
if(source.smart_inserts) |
|
|
|
if(source.smart_inserts) |
|
|
|
source.smart_brackets=true; |
|
|
|
source.smart_brackets=true; |
|
|
|
|
|
|
|
|
|
|
|
source.show_map = source_json.get<bool>("show_map"); |
|
|
|
source.show_map = source_json.get<bool>("show_map"); |
|
|
|
source.map_font_size = source_json.get<std::string>("map_font_size"); |
|
|
|
source.map_font_size = source_json.get<std::string>("map_font_size"); |
|
|
|
|
|
|
|
|
|
|
|
source.show_git_diff = source_json.get<bool>("show_git_diff"); |
|
|
|
source.show_git_diff = source_json.get<bool>("show_git_diff"); |
|
|
|
|
|
|
|
|
|
|
|
source.show_background_pattern = source_json.get<bool>("show_background_pattern"); |
|
|
|
source.show_background_pattern = source_json.get<bool>("show_background_pattern"); |
|
|
|
|
|
|
|
|
|
|
|
source.spellcheck_language = source_json.get<std::string>("spellcheck_language"); |
|
|
|
source.spellcheck_language = source_json.get<std::string>("spellcheck_language"); |
|
|
|
|
|
|
|
|
|
|
|
source.default_tab_char = source_json.get<char>("default_tab_char"); |
|
|
|
source.default_tab_char = source_json.get<char>("default_tab_char"); |
|
|
|
source.default_tab_size = source_json.get<unsigned>("default_tab_size"); |
|
|
|
source.default_tab_size = source_json.get<unsigned>("default_tab_size"); |
|
|
|
source.auto_tab_char_and_size = source_json.get<bool>("auto_tab_char_and_size"); |
|
|
|
source.auto_tab_char_and_size = source_json.get<bool>("auto_tab_char_and_size"); |
|
|
|
source.tab_indents_line = source_json.get<bool>("tab_indents_line"); |
|
|
|
source.tab_indents_line = source_json.get<bool>("tab_indents_line"); |
|
|
|
|
|
|
|
|
|
|
|
source.wrap_lines = source_json.get<bool>("wrap_lines"); |
|
|
|
source.wrap_lines = source_json.get<bool>("wrap_lines"); |
|
|
|
|
|
|
|
|
|
|
|
source.highlight_current_line = source_json.get<bool>("highlight_current_line"); |
|
|
|
source.highlight_current_line = source_json.get<bool>("highlight_current_line"); |
|
|
|
source.show_line_numbers = source_json.get<bool>("show_line_numbers"); |
|
|
|
source.show_line_numbers = source_json.get<bool>("show_line_numbers"); |
|
|
|
|
|
|
|
|
|
|
|
for (auto &i : source_json.get_child("clang_types")) { |
|
|
|
for (auto &i : source_json.get_child("clang_types")) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
source.clang_types[std::stoi(i.first)] = i.second.get_value<std::string>(); |
|
|
|
source.clang_types[std::stoi(i.first)] = i.second.get_value<std::string>(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch(const std::exception &) {} |
|
|
|
catch(const std::exception &) {} |
|
|
|
} |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
source.clang_format_style = source_json.get<std::string>("clang_format_style"); |
|
|
|
source.clang_format_style = source_json.get<std::string>("clang_format_style"); |
|
|
|
|
|
|
|
|
|
|
|
auto pt_doc_search=cfg.get_child("documentation_searches"); |
|
|
|
auto pt_doc_search=cfg.get_child("documentation_searches"); |
|
|
|
for(auto &pt_doc_search_lang: pt_doc_search) { |
|
|
|
for(auto &pt_doc_search_lang: pt_doc_search) { |
|
|
|
source.documentation_searches[pt_doc_search_lang.first].separator=pt_doc_search_lang.second.get<std::string>("separator"); |
|
|
|
source.documentation_searches[pt_doc_search_lang.first].separator=pt_doc_search_lang.second.get<std::string>("separator"); |
|
|
|
@ -238,4 +190,39 @@ void Config::get_source() { |
|
|
|
queries[i.first]=i.second.get_value<std::string>(); |
|
|
|
queries[i.first]=i.second.get_value<std::string>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.theme_name=cfg.get<std::string>("gtk_theme.name"); |
|
|
|
|
|
|
|
window.theme_variant=cfg.get<std::string>("gtk_theme.variant"); |
|
|
|
|
|
|
|
window.version = cfg.get<std::string>("version"); |
|
|
|
|
|
|
|
window.default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.cmake.command=cfg.get<std::string>("project.cmake.command"); |
|
|
|
|
|
|
|
project.cmake.compile_command=cfg.get<std::string>("project.cmake.compile_command"); |
|
|
|
|
|
|
|
project.meson.command=cfg.get<std::string>("project.meson.command"); |
|
|
|
|
|
|
|
project.meson.compile_command=cfg.get<std::string>("project.meson.compile_command"); |
|
|
|
|
|
|
|
project.save_on_compile_or_run=cfg.get<bool>("project.save_on_compile_or_run"); |
|
|
|
|
|
|
|
project.clear_terminal_on_compile=cfg.get<bool>("project.clear_terminal_on_compile"); |
|
|
|
|
|
|
|
project.ctags_command=cfg.get<std::string>("project.ctags_command"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
terminal.history_size=cfg.get<int>("terminal.history_size"); |
|
|
|
|
|
|
|
terminal.font=cfg.get<std::string>("terminal.font"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
terminal.show_progress=cfg.get<bool>("terminal.show_progress"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")) { |
|
|
|
|
|
|
|
auto versions={"4.0", "3.9", "3.8", "3.7", "3.6", "3.5"}; |
|
|
|
|
|
|
|
for(auto &version: versions) { |
|
|
|
|
|
|
|
auto corrected_command=std::string("/usr/bin/clang-format-")+version; |
|
|
|
|
|
|
|
if(boost::filesystem::exists(corrected_command)) { |
|
|
|
|
|
|
|
terminal.clang_format_command=corrected_command; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|