diff --git a/src/config.cpp b/src/config.cpp index a8c7ddc..55c571a 100644 --- a/src/config.cpp +++ b/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) { diff --git a/src/config.hpp b/src/config.hpp index bf65414..28b3a90 100644 --- a/src/config.hpp +++ b/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 diff --git a/src/window.cpp b/src/window.cpp index 14fdfa8..e5cf75b 100644 --- a/src/window.cpp +++ b/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();