From 18edc231fd9913d0ee88b73347ed05a4f7750557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 3 Aug 2015 15:12:26 +0200 Subject: [PATCH] Move theming to higher class --- src/config.cc | 2 ++ src/singletons.h | 1 + src/source.cc | 20 ++++++++++---------- src/source.h | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/config.cc b/src/config.cc index fd40399..6209822 100644 --- a/src/config.cc +++ b/src/config.cc @@ -48,6 +48,8 @@ void MainConfig::GenerateSource() { source_cfg->highlight_current_line = i.second.get_value() == "1" ? true : false; else if (i.first == "font") source_cfg->font = i.second.get_value(); + else if (i.first == "theme") + source_cfg->theme = i.second.get_value(); } source_cfg->tab_size = source_json.get("tab_size"); for (unsigned c = 0; c < source_cfg->tab_size; c++) diff --git a/src/singletons.h b/src/singletons.h index d305e85..b449311 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -23,6 +23,7 @@ public: }; static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; } static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; } + static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; } static Terminal *terminal(); static Gtk::Label *status(); private: diff --git a/src/source.cc b/src/source.cc index b78c6f9..6faea78 100644 --- a/src/source.cc +++ b/src/source.cc @@ -60,6 +60,16 @@ file_path(file_path), project_path(project_path) { //TODO: either use lambda if possible or create a gtkmm wrapper around search_context (including search_settings): //TODO: (gtkmm's Gtk::Object has connect_property_changed, so subclassing this might be an idea) g_signal_connect(search_context, "notify::occurrences-count", G_CALLBACK(search_occurrences_updated), this); + + // style + auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); + style_scheme_manager->prepend_search_path(Singleton::style_dir()); + + auto scheme = style_scheme_manager->get_scheme(Singleton::Config::source()->theme); + if(scheme) { +scheme->_cpp_destruction_is_in_progress() + get_source_buffer()->set_style_scheme(scheme); + } } void Source::View::search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data) { @@ -249,16 +259,6 @@ bool Source::View::on_key_press_event(GdkEventKey* key) { //// GenericView //// ///////////////////// Source::GenericView::GenericView(const std::string& file_path, const std::string& project_path, Glib::RefPtr language) : View(file_path, project_path) { - auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); - //TODO: add?: style_scheme_manager->prepend_search_path("~/.juci/"); - auto scheme=style_scheme_manager->get_scheme("classic"); - if(scheme) { - get_source_buffer()->set_style_scheme(scheme); - auto style=scheme->get_style("def:comment"); - if(style) - cout << "TODO, in progress: def:comment in scheme " << scheme->get_name() << " has color " << style->property_foreground() << endl; - } - if(language) { get_source_buffer()->set_language(language); Singleton::terminal()->print("Language for file "+file_path+" set to "+language->get_name()+".\n"); diff --git a/src/source.h b/src/source.h index 4c6b8cc..4e78fad 100644 --- a/src/source.h +++ b/src/source.h @@ -22,7 +22,7 @@ namespace Source { public: unsigned tab_size; bool show_line_numbers, highlight_current_line; - std::string tab, background, background_selected, background_tooltips, font; + std::string tab, background, background_selected, background_tooltips, font, theme; char tab_char=' '; std::unordered_map tags, types; }; // class Config