Browse Source

move config file and make file name a member of config

xdg
Jørgen Lien Sellæg 5 years ago
parent
commit
407ea7f735
  1. 15
      src/config.cpp
  2. 1
      src/config.hpp
  3. 4
      src/window.cpp

15
src/config.cpp

@ -23,16 +23,15 @@ Config::Config() {
if(home_path.empty())
throw std::runtime_error("Could not find home path");
home_juci_path = home_path / ".juci";
juci_config_file = home_juci_path / "config.json";
}
void Config::load() {
auto config_dir = home_juci_path / "config";
auto config_json = config_dir / "config.json";
try {
boost::filesystem::create_directories(config_dir);
boost::filesystem::create_directories(home_juci_path);
if(!boost::filesystem::exists(config_json))
filesystem::write(config_json, default_config_file);
if(!boost::filesystem::exists(juci_config_file))
filesystem::write(juci_config_file, default_config_file);
auto juci_style_path = home_juci_path / "styles";
boost::filesystem::create_directories(juci_style_path);
@ -50,12 +49,12 @@ void Config::load() {
filesystem::write(juci_style_path, juci_dark_blue_style);
boost::property_tree::ptree cfg;
boost::property_tree::json_parser::read_json(config_json.string(), cfg);
boost::property_tree::json_parser::read_json(juci_config_file.string(), cfg);
update(cfg);
read(cfg);
}
catch(const std::exception &e) {
dispatcher.post([config_json = std::move(config_json), e_what = std::string(e.what())] {
dispatcher.post([config_json = juci_config_file, e_what = std::string(e.what())] {
::Terminal::get().print("\e[31mError\e[m: could not parse " + config_json.string() + ": " + e_what + "\n", true);
});
std::stringstream ss;
@ -90,7 +89,7 @@ void Config::update(boost::property_tree::ptree &cfg) {
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);
boost::property_tree::write_json(juci_config_file.string(), cfg);
}
void Config::make_version_dependent_corrections(boost::property_tree::ptree &cfg, const boost::property_tree::ptree &default_cfg, const std::string &version) {

1
src/config.hpp

@ -134,6 +134,7 @@ public:
Log log;
boost::filesystem::path home_juci_path;
boost::filesystem::path juci_config_file;
private:
/// Used to dispatch Terminal outputs after juCi++ GUI setup and configuration

4
src/window.cpp

@ -279,7 +279,7 @@ void Window::set_menu_actions() {
about.present();
});
menu.add_action("preferences", []() {
Notebook::get().open(Config::get().home_juci_path / "config" / "config.json");
Notebook::get().open(Config::get().juci_config_file);
});
menu.add_action("snippets", []() {
Notebook::get().open(Config::get().home_juci_path / "snippets.json");
@ -466,7 +466,7 @@ void Window::set_menu_actions() {
menu.add_action("file_save", [this]() {
if(auto view = Notebook::get().get_current_view()) {
if(Notebook::get().save_current()) {
if(view->file_path == Config::get().home_juci_path / "config" / "config.json") {
if(view->file_path == Config::get().juci_config_file) {
configure();
for(size_t c = 0; c < Notebook::get().size(); c++) {
Notebook::get().get_view(c)->configure();

Loading…
Cancel
Save