Browse Source

Remove the rest of the references to the removed singletons and adding main config as singleton

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
94bc501ab6
  1. 6
      src/config.h
  2. 4
      src/directories.cc
  3. 3
      src/juci.cc
  4. 1
      src/singletons.cc
  5. 9
      src/singletons.h
  6. 2
      src/source.cc
  7. 7
      src/window.cc

6
src/config.h

@ -1,11 +1,15 @@
#ifndef JUCI_CONFIG_H_
#define JUCI_CONFIG_H_
#include <boost/property_tree/json_parser.hpp>
#include <boost/filesystem.hpp>
#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<std::string> init_home_path();
boost::property_tree::ptree cfg;
boost::filesystem::path home;

4
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();

3
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");

1
src/singletons.cc

@ -7,6 +7,7 @@ std::unique_ptr<Window::Config> Singleton::Config::window_ = std::unique_ptr<Win
std::unique_ptr<Terminal> Singleton::terminal_=std::unique_ptr<Terminal>();
std::unique_ptr<Directories> Singleton::directories_=std::unique_ptr<Directories>();
std::unique_ptr<Window> Singleton::window_=std::unique_ptr<Window>();
std::unique_ptr<MainConfig> Singleton::Config::main_=std::unique_ptr<MainConfig>(new MainConfig());
Terminal *Singleton::terminal() {
if(!terminal_)

9
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::Config> source_;
static std::unique_ptr<Window::Config> window_;
static std::unique_ptr<Directories::Config> directories_;
static std::unique_ptr<Terminal::Config> terminal_;
static std::unique_ptr<MainConfig> 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> terminal_;
static std::unique_ptr<Gtk::Label> status_;

2
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);

7
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;c<notebook.size();c++) {
notebook.get_view(c)->configure();

Loading…
Cancel
Save