diff --git a/src/config.h b/src/config.h index 47a032a..c84ded6 100644 --- a/src/config.h +++ b/src/config.h @@ -1,11 +1,15 @@ #ifndef JUCI_CONFIG_H_ #define JUCI_CONFIG_H_ #include +#include #include "menu.h" class MainConfig { public: MainConfig(); + const boost::filesystem::path& juci_home_path() const { return home; } + +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=""); @@ -13,9 +17,7 @@ public: void PrintMenu(); void GenerateSource(); void GenerateDirectoryFilter(); - const boost::filesystem::path& juci_home_path() { return home; } const; -private: std::vector init_home_path(); boost::property_tree::ptree cfg; boost::filesystem::path home; diff --git a/src/directories.cc b/src/directories.cc index f8303b3..1fe8459 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -120,8 +120,8 @@ Directories::~Directories() { void Directories::open(const boost::filesystem::path& dir_path) { JDEBUG("start"); - if(dir_path=="") - return; + if(dir_path.empty()) + return; tree_store->clear(); update_mutex.lock(); diff --git a/src/juci.cc b/src/juci.cc index 6348538..aaa43c4 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -5,8 +5,7 @@ using namespace std; //TODO: remove void app::init_logging() { boost::log::add_common_attributes(); - auto log_dir = Singleton::log_dir(); - log_dir /= "juci.log"; + auto log_dir = Singleton::Config::main()->juci_home_path()/"log"/"juci.log"; boost::log::add_file_log(boost::log::keywords::file_name = log_dir, boost::log::keywords::auto_flush = true); JINFO("Logging initalized"); diff --git a/src/singletons.cc b/src/singletons.cc index 32a44cb..1c99230 100644 --- a/src/singletons.cc +++ b/src/singletons.cc @@ -7,6 +7,7 @@ std::unique_ptr Singleton::Config::window_ = std::unique_ptr Singleton::terminal_=std::unique_ptr(); std::unique_ptr Singleton::directories_=std::unique_ptr(); std::unique_ptr Singleton::window_=std::unique_ptr(); +std::unique_ptr Singleton::Config::main_=std::unique_ptr(new MainConfig()); Terminal *Singleton::terminal() { if(!terminal_) diff --git a/src/singletons.h b/src/singletons.h index 3ac440d..2d58fe5 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -11,6 +11,7 @@ #include "notebook.h" #include "menu.h" #include "window.h" +#include "config.h" class Singleton { public: @@ -20,23 +21,21 @@ public: static Directories::Config *directories() {return directories_.get();} static Window::Config *window() { return window_.get(); } static Terminal::Config *terminal() {return terminal_.get();} + static MainConfig *main() { return main_.get(); } private: static std::unique_ptr source_; static std::unique_ptr window_; static std::unique_ptr directories_; static std::unique_ptr terminal_; + static std::unique_ptr main_; }; - static boost::filesystem::path create_config_path(const std::string &subfolder); - static boost::filesystem::path config_dir(); - static boost::filesystem::path log_dir(); - static boost::filesystem::path style_dir(); - static std::string config_json(); static Terminal *terminal(); static Directories *directories(); static Gtk::Label *status(); static Gtk::Label *info(); static Window *window(); + private: static std::unique_ptr terminal_; static std::unique_ptr status_; diff --git a/src/source.cc b/src/source.cc index 3e9e8a7..ce453d4 100644 --- a/src/source.cc +++ b/src/source.cc @@ -295,7 +295,7 @@ void Source::View::set_tab_char_and_size(char tab_char, unsigned tab_size) { void Source::View::configure() { //TODO: Move this to notebook? Might take up too much memory doing this for every tab. auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); - style_scheme_manager->prepend_search_path(Singleton::style_dir().string()); + style_scheme_manager->prepend_search_path((Singleton::Config::main()->juci_home_path()/"styles").string()); if(Singleton::Config::source()->style.size()>0) { auto scheme = style_scheme_manager->get_scheme(Singleton::Config::source()->style); diff --git a/src/window.cc b/src/window.cc index 31974da..fa72035 100644 --- a/src/window.cc +++ b/src/window.cc @@ -158,7 +158,6 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), compiling(false) { } // Window constructor void Window::configure() { - MainConfig(); // Read the configs here auto style_context = Gtk::StyleContext::create(); auto screen = Gdk::Screen::get_default(); auto css_provider = Gtk::CssProvider::get_named(Singleton::Config::window()->theme_name, Singleton::Config::window()->theme_variant); @@ -235,7 +234,7 @@ void Window::create_menu() { Singleton::terminal()->print("Error: Could not create project "+project_path.string()+"\n"); }); menu.action_group->add(Gtk::Action::create("FileOpenFile", "Open File"), Gtk::AccelKey(menu.key_map["open_file"]), [this]() { - notebook.open(Dialog::select_file()); + notebook.open(Dialog::select_file()); }); menu.action_group->add(Gtk::Action::create("FileOpenFolder", "Open Folder"), Gtk::AccelKey(menu.key_map["open_folder"]), [this]() { auto path = Dialog::select_folder(); @@ -259,13 +258,13 @@ void Window::create_menu() { } }); menu.action_group->add(Gtk::Action::create("Preferences", "Preferences..."), Gtk::AccelKey(menu.key_map["preferences"]), [this]() { - notebook.open(Singleton::config_json()); + notebook.open(Singleton::Config::main()->juci_home_path()/"config"/"config.json"); }); menu.action_group->add(Gtk::Action::create("FileSave", "Save"), Gtk::AccelKey(menu.key_map["save"]), [this]() { if(notebook.save_current()) { if(notebook.get_current_page()!=-1) { - if(notebook.get_current_view()->file_path==Singleton::config_json()) { + if(notebook.get_current_view()->file_path==Singleton::Config::main()->juci_home_path()/"config"/"config.json") { configure(); for(int c=0;cconfigure();