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 01/10] 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 From 374e0a3a55c968cb88776c5f38cba2c61fdb25dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Wed, 5 Aug 2015 17:15:15 +0200 Subject: [PATCH 02/10] wip --- src/config.cc | 8 ++++---- src/juci.cc | 10 +++++++--- src/juci.h | 25 +++++++++++++------------ src/source.cc | 38 ++++++++++++++++++++++++++------------ 4 files changed, 50 insertions(+), 31 deletions(-) diff --git a/src/config.cc b/src/config.cc index 6209822..aad5424 100644 --- a/src/config.cc +++ b/src/config.cc @@ -32,8 +32,8 @@ void MainConfig::GenerateSource() { DEBUG("Fetching source cfg"); // boost::property_tree::ptree auto source_json = cfg.get_child("source"); - auto syntax_json = source_json.get_child("syntax"); - auto colors_json = source_json.get_child("colors"); + auto clang_types_json = source_json.get_child("clang_types"); + auto style_json = source_json.get_child("style"); auto visual_json = source_json.get_child("visual"); for (auto &i : visual_json) { if (i.first == "background") @@ -54,9 +54,9 @@ void MainConfig::GenerateSource() { source_cfg->tab_size = source_json.get("tab_size"); for (unsigned c = 0; c < source_cfg->tab_size; c++) source_cfg->tab+=" "; - for (auto &i : colors_json) + for (auto &i : style_json) source_cfg->tags[i.first]=i.second.get_value(); - for (auto &i : syntax_json) + for (auto &i : clang_types_json) source_cfg->types[i.first]=i.second.get_value(); DEBUG("Source cfg fetched"); } diff --git a/src/juci.cc b/src/juci.cc index 629c22b..99dcf6f 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -8,7 +8,7 @@ void init_logging() { INFO("Logging initalized"); } -int Juci::on_command_line(const Glib::RefPtr &cmd) { +int juci::app::on_command_line(const Glib::RefPtr &cmd) { Glib::set_prgname("juci"); Glib::OptionContext ctx("[PATH ...]"); Glib::OptionGroup gtk_group(gtk_get_option_group(true)); @@ -31,7 +31,7 @@ int Juci::on_command_line(const Glib::RefPtr &cmd) return 0; } -void Juci::on_activate() { +void juci::app::on_activate() { window = std::unique_ptr(new Window()); add_window(*window); window->show(); @@ -43,7 +43,11 @@ void Juci::on_activate() { window->notebook.open(f); } +juci::app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) { + +} + int main(int argc, char *argv[]) { init_logging(); - return Juci().run(argc, argv); + return juci::app().run(argc, argv); } diff --git a/src/juci.h b/src/juci.h index 4ce2cb2..41c0fd2 100644 --- a/src/juci.h +++ b/src/juci.h @@ -3,18 +3,19 @@ #include "window.h" #include "logging.h" - -class Juci : public Gtk::Application { -public: - Juci(): Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) {} +namespace juci { + class app : public Gtk::Application { + public: + app(); - int on_command_line(const Glib::RefPtr &cmd); - void on_activate(); + int on_command_line(const Glib::RefPtr &cmd); + void on_activate(); -private: - std::unique_ptr window; - std::string directory; - std::vector files; -}; + private: + std::unique_ptr window; + std::string directory; + std::vector files; + }; +} -#endif // JUCI_JUCI_H_ \ No newline at end of file +#endif // JUCI_JUCI_H_ diff --git a/src/source.cc b/src/source.cc index 6faea78..1239521 100644 --- a/src/source.cc +++ b/src/source.cc @@ -38,14 +38,10 @@ Glib::RefPtr Source::guess_language(const std::string &file_path) ////////////// Source::View::View(const std::string& file_path, const std::string& project_path): file_path(file_path), project_path(project_path) { - set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); - set_show_line_numbers(Singleton::Config::source()->show_line_numbers); - set_highlight_current_line(Singleton::Config::source()->highlight_current_line); - + set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); get_source_buffer()->begin_not_undoable_action(); juci::filesystem::read(file_path, get_buffer()); get_source_buffer()->end_not_undoable_action(); - get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0)); search_settings = gtk_source_search_settings_new(); gtk_source_search_settings_set_wrap_around(search_settings, true); @@ -66,8 +62,8 @@ file_path(file_path), project_path(project_path) { 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); } } @@ -279,12 +275,29 @@ clang::Index Source::ClangViewParse::clang_index(0, 0); Source::ClangViewParse::ClangViewParse(const std::string& file_path, const std::string& project_path): Source::View(file_path, project_path) { - override_font(Pango::FontDescription(Singleton::Config::source()->font)); - override_background_color(Gdk::RGBA(Singleton::Config::source()->background)); - override_background_color(Gdk::RGBA(Singleton::Config::source()->background_selected), Gtk::StateFlags::STATE_FLAG_SELECTED); + INFO("Tagtable beeing filled"); for (auto &item : Singleton::Config::source()->tags) { - get_source_buffer()->create_tag(item.first)->property_foreground() = item.second; + auto scheme = get_source_buffer()->get_style_scheme(); + auto style = scheme->get_style(item.second); + if (style) { + DEBUG("Style " + item.second + " found in style " + scheme->get_name()); + auto tag = get_source_buffer()->create_tag(item.first); + if (style->property_foreground_set()) + tag->property_foreground() = style->property_foreground(); + if (style->property_background_set()) + tag->property_background() = style->property_background(); + if (style->property_strikethrough_set()) + tag->property_strikethrough() = style->property_strikethrough(); + // // if (style->property_bold_set()) tag->property_weight() = style->property_bold(); + // // if (style->property_italic_set()) tag->property_italic() = style->property_italic(); + // // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background(); + // // if (style->property_underline_set()) tag->property_underline() = style->property_underline(); + } else { + DEBUG("Style " + item.second + " not found in " + scheme->get_name()); + get_source_buffer()->create_tag(item.first)->property_foreground() = item.second; + } } + INFO("Tagtable filled"); //Create underline color tags for diagnostic warnings and errors: auto diagnostic_tag=get_buffer()->get_tag_table()->lookup("diagnostic_warning"); @@ -479,7 +492,7 @@ void Source::ClangViewParse::update_syntax() { buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end()); last_syntax_tags.clear(); for (auto &range : ranges) { - std::string type = std::to_string(range.kind); + auto type = std::to_string(range.kind); try { last_syntax_tags.emplace(Singleton::Config::source()->types.at(type)); } catch (std::exception) { @@ -490,6 +503,7 @@ void Source::ClangViewParse::update_syntax() { Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset); buffer->apply_tag_by_name(Singleton::Config::source()->types.at(type), begin_iter, end_iter); + } } @@ -1099,4 +1113,4 @@ bool Source::ClangView::restart_parse() { return true; } return false; -} \ No newline at end of file +} From 2b6e1b5a8deedf829c945b1057d0bc95d019c87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 6 Aug 2015 09:37:42 +0200 Subject: [PATCH 03/10] Minor cleanup --- src/config.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.cc b/src/config.cc index aad5424..16dd271 100644 --- a/src/config.cc +++ b/src/config.cc @@ -43,9 +43,9 @@ void MainConfig::GenerateSource() { else if (i.first == "background_tooltips") source_cfg->background_tooltips = i.second.get_value(); else if (i.first == "show_line_numbers") - source_cfg->show_line_numbers = i.second.get_value() == "1" ? true : false; + source_cfg->show_line_numbers = i.second.get_value() == "1"; else if (i.first == "highlight_current_line") - source_cfg->highlight_current_line = i.second.get_value() == "1" ? true : false; + source_cfg->highlight_current_line = i.second.get_value() == "1"; else if (i.first == "font") source_cfg->font = i.second.get_value(); else if (i.first == "theme") From 92684ab7efedb3ed2509307ffd39196f2bb65b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 6 Aug 2015 17:06:46 +0200 Subject: [PATCH 04/10] Working css load --- src/juci.cc | 15 ++++++++++----- src/juci.h | 23 +++++++++++------------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/juci.cc b/src/juci.cc index 99dcf6f..9aeadeb 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -8,7 +8,7 @@ void init_logging() { INFO("Logging initalized"); } -int juci::app::on_command_line(const Glib::RefPtr &cmd) { +int app::on_command_line(const Glib::RefPtr &cmd) { Glib::set_prgname("juci"); Glib::OptionContext ctx("[PATH ...]"); Glib::OptionGroup gtk_group(gtk_get_option_group(true)); @@ -31,7 +31,7 @@ int juci::app::on_command_line(const Glib::RefPtr & return 0; } -void juci::app::on_activate() { +void app::on_activate() { window = std::unique_ptr(new Window()); add_window(*window); window->show(); @@ -43,11 +43,16 @@ void juci::app::on_activate() { window->notebook.open(f); } -juci::app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) { - +app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) { + auto css_provider = Gtk::CssProvider::create(); + if (css_provider->load_from_path(Singleton::style_dir() + "juci.css")) { + auto style_context = Gtk::StyleContext::create(); + style_context->add_provider(css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + style_context->add_provider_for_screen(window->get_screen(), css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } } int main(int argc, char *argv[]) { init_logging(); - return juci::app().run(argc, argv); + return app().run(argc, argv); } diff --git a/src/juci.h b/src/juci.h index 41c0fd2..87cadc6 100644 --- a/src/juci.h +++ b/src/juci.h @@ -3,19 +3,18 @@ #include "window.h" #include "logging.h" -namespace juci { - class app : public Gtk::Application { - public: - app(); +class app : public Gtk::Application { + public: + app(); - int on_command_line(const Glib::RefPtr &cmd); - void on_activate(); + int on_command_line(const Glib::RefPtr &cmd); + void on_activate(); - private: - std::unique_ptr window; - std::string directory; - std::vector files; - }; -} + private: + std::unique_ptr window; + std::string directory; + std::vector files; +}; #endif // JUCI_JUCI_H_ + From 2161c76bf408b1f2a534b4aea1e7106b83a90817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 7 Aug 2015 15:18:33 +0200 Subject: [PATCH 05/10] gtk-3.0 theme support and support for gtksourceview styles --- src/config.cc | 46 ++++++++++++---------------------------------- src/config.h | 8 ++++---- src/juci.cc | 13 +++++++------ src/singletons.cc | 5 ++++- src/singletons.h | 7 +++++++ src/theme.h | 14 ++++++++++++++ src/tooltips.cc | 1 - src/window.cc | 15 ++++++++++++--- src/window.h | 8 ++++++-- 9 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 src/theme.h diff --git a/src/config.cc b/src/config.cc index 16dd271..604efd1 100644 --- a/src/config.cc +++ b/src/config.cc @@ -5,15 +5,25 @@ #include "files.h" #include "sourcefile.h" -MainConfig::MainConfig(Menu &menu) : menu(menu) { +MainConfig::MainConfig() { find_or_create_config_files(); boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg); + Singleton::Config::window()->keybindings = cfg.get_child("keybindings"); GenerateSource(); - GenerateKeybindings(); + GenerateTheme(); GenerateDirectoryFilter(); GenerateTerminalCommands(); } +void MainConfig::GenerateTheme() { + auto config = Singleton::Config::theme(); + auto props = cfg.get_child("theme"); + for (auto &prop : props) { + if (prop.first == "theme") config->theme = prop.second.get_value(); + if (prop.first == "main") config->main = prop.second.get_value(); + } +} + void MainConfig::find_or_create_config_files() { std::vector files = {"config.json", "menu.xml", "plugins.py"}; boost::filesystem::create_directories(boost::filesystem::path(Singleton::config_dir())); @@ -34,23 +44,6 @@ void MainConfig::GenerateSource() { auto source_json = cfg.get_child("source"); auto clang_types_json = source_json.get_child("clang_types"); auto style_json = source_json.get_child("style"); - auto visual_json = source_json.get_child("visual"); - for (auto &i : visual_json) { - if (i.first == "background") - source_cfg->background = i.second.get_value(); - else if (i.first == "background_selected") - source_cfg->background_selected = i.second.get_value(); - else if (i.first == "background_tooltips") - source_cfg->background_tooltips = i.second.get_value(); - else if (i.first == "show_line_numbers") - source_cfg->show_line_numbers = i.second.get_value() == "1"; - else if (i.first == "highlight_current_line") - source_cfg->highlight_current_line = i.second.get_value() == "1"; - 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++) source_cfg->tab+=" "; @@ -72,21 +65,6 @@ void MainConfig::GenerateTerminalCommands() { terminal_cfg->run_command=(i.second.get_value()); //TODO: run_commands array->one run_command? } -void MainConfig::GenerateKeybindings() { - boost::filesystem::path path(Singleton::config_dir() + "menu.xml"); - if (!boost::filesystem::is_regular_file(path)) { - std::cerr << "menu.xml not found" << std::endl; - throw; - } - menu.ui = juci::filesystem::read(path); - boost::property_tree::ptree keys_json = cfg.get_child("keybindings"); - for (auto &i : keys_json) { - auto key=i.second.get_value(); - menu.key_map[i.first] = key; - } - DEBUG("Keybindings fetched"); -} - void MainConfig::GenerateDirectoryFilter() { auto dir_cfg=Singleton::Config::directories(); DEBUG("Fetching directory filter"); diff --git a/src/config.h b/src/config.h index d1ea90b..86e8c5d 100644 --- a/src/config.h +++ b/src/config.h @@ -6,16 +6,16 @@ class MainConfig { public: - MainConfig(Menu &menu); + MainConfig(); void find_or_create_config_files(); void PrintMenu(); void GenerateSource(); - void GenerateKeybindings(); void GenerateDirectoryFilter(); + void GenerateTheme(); void GenerateTerminalCommands(); + private: boost::property_tree::ptree cfg; - boost::property_tree::ptree key_tree; - Menu &menu; + }; #endif diff --git a/src/juci.cc b/src/juci.cc index 9aeadeb..5d9cd9a 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -1,5 +1,6 @@ #include "juci.h" #include "singletons.h" +#include "config.h" void init_logging() { add_common_attributes(); @@ -44,12 +45,12 @@ void app::on_activate() { } app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) { - auto css_provider = Gtk::CssProvider::create(); - if (css_provider->load_from_path(Singleton::style_dir() + "juci.css")) { - auto style_context = Gtk::StyleContext::create(); - style_context->add_provider(css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - style_context->add_provider_for_screen(window->get_screen(), css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - } + MainConfig(); // Read the configs here + auto css_provider = Gtk::CssProvider::get_default(); + auto style_context = Gtk::StyleContext::create(); + auto screen = Gdk::Screen::get_default(); + style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + css_provider->load_from_path(Singleton::theme_dir() + Singleton::Config::theme()->current_theme()); } int main(int argc, char *argv[]) { diff --git a/src/singletons.cc b/src/singletons.cc index 076bf46..08e627d 100644 --- a/src/singletons.cc +++ b/src/singletons.cc @@ -3,8 +3,11 @@ std::unique_ptr Singleton::Config::source_=std::unique_ptr(new Source::Config()); std::unique_ptr Singleton::Config::terminal_=std::unique_ptr(new Terminal::Config()); std::unique_ptr Singleton::Config::directories_=std::unique_ptr(new Directories::Config()); - std::unique_ptr Singleton::terminal_=std::unique_ptr(); +std::unique_ptr Singleton::Config::theme_ = std::unique_ptr(new Theme::Config()); +std::unique_ptr Singleton::Config::window_ = std::unique_ptr(new Window::Config()); + + Terminal *Singleton::terminal() { if(!terminal_) terminal_=std::unique_ptr(new Terminal()); diff --git a/src/singletons.h b/src/singletons.h index b449311..4a92eb3 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -2,9 +2,11 @@ #define JUCI_SINGLETONS_H_ #include "source.h" +#include "window.h" #include "directories.h" #include "terminal.h" #include "notebook.h" +#include "theme.h" #include "menu.h" #include #include @@ -16,12 +18,17 @@ public: static Source::Config *source() {return source_.get();} static Terminal::Config *terminal() {return terminal_.get();} static Directories::Config *directories() {return directories_.get();} + static Theme::Config *theme() { return theme_.get(); } + static Window::Config *window() { return window_.get(); } private: static std::unique_ptr source_; + static std::unique_ptr theme_; + static std::unique_ptr window_; static std::unique_ptr terminal_; static std::unique_ptr directories_; }; static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; } + static std::string theme_dir() { return std::string(getenv("HOME")) + "/.juci/gtk-themes/"; } 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(); diff --git a/src/theme.h b/src/theme.h new file mode 100644 index 0000000..7b915ea --- /dev/null +++ b/src/theme.h @@ -0,0 +1,14 @@ +#ifndef JUCI_THEME_H_ +#define JUCI_THEME_H_ + +#include + +namespace Theme { + class Config { + public: + std::string current_theme() { return theme + "/" + main; } + std::string theme, main; + }; +} + +#endif // JUCI_THEME_H_ diff --git a/src/tooltips.cc b/src/tooltips.cc index 5afc1f3..c76e7dc 100644 --- a/src/tooltips.cc +++ b/src/tooltips.cc @@ -54,7 +54,6 @@ void Tooltip::adjust(bool disregard_drawn) { tooltip_widget=std::unique_ptr(new Gtk::TextView(create_tooltip_buffer())); wrap_lines(tooltip_widget->get_buffer()); tooltip_widget->set_editable(false); - tooltip_widget->override_background_color(Gdk::RGBA(Singleton::Config::source()->background_tooltips)); window->add(*tooltip_widget); auto layout=Pango::Layout::create(tooltip_widget->get_pango_context()); diff --git a/src/window.cc b/src/window.cc index b999717..11ee2d5 100644 --- a/src/window.cc +++ b/src/window.cc @@ -12,15 +12,24 @@ namespace sigc { SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE } +void Window::generate_keybindings() { + boost::filesystem::path path(Singleton::config_dir() + "menu.xml"); + menu.ui = juci::filesystem::read(path); + for (auto &i : Singleton::Config::window()->keybindings) { + auto key = i.second.get_value(); + menu.key_map[i.first] = key; + } +} + Window::Window() : box(Gtk::ORIENTATION_VERTICAL) { INFO("Create Window"); set_title("juCi++"); set_default_size(600, 400); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK); add(box); - - MainConfig(this->menu); //Read the configs here - PluginApi(&this->notebook, &this->menu); //Initialise plugins + + generate_keybindings(); + PluginApi(&this->notebook, &this->menu); create_menu(); box.pack_start(menu.get_widget(), Gtk::PACK_SHRINK); diff --git a/src/window.h b/src/window.h index 44c6afb..e7602c9 100644 --- a/src/window.h +++ b/src/window.h @@ -6,12 +6,17 @@ #include "entrybox.h" #include "notebook.h" #include "menu.h" +#include class Window : public Gtk::Window { public: Window(); Notebook notebook; Directories directories; + class Config { + public: + boost::property_tree::ptree keybindings; + }; protected: bool on_key_press_event(GdkEventKey *event); bool on_delete_event (GdkEventAny *event); @@ -32,16 +37,15 @@ private: void open_folder_dialog(); void open_file_dialog(); void save_file_dialog(); - void search_and_replace_entry(); void goto_line_entry(); void rename_token_entry(); + void generate_keybindings(); std::string last_search; std::string last_replace; bool case_sensitive_search=true; bool regex_search=false; bool search_entry_shown=false; - }; #endif // JUCI_WINDOW_H From e30698859fe6d3acf24b7acbddc67bb079b9349a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 7 Aug 2015 16:08:43 +0200 Subject: [PATCH 06/10] Point to correct theme, and some cleanup --- src/source.cc | 2 +- src/source.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/source.cc b/src/source.cc index 1239521..1d1b8fd 100644 --- a/src/source.cc +++ b/src/source.cc @@ -61,7 +61,7 @@ file_path(file_path), project_path(project_path) { 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); + auto scheme = style_scheme_manager->get_scheme(Singleton::Config::theme()->theme); if(scheme) { get_source_buffer()->set_style_scheme(scheme); diff --git a/src/source.h b/src/source.h index 4e78fad..8c68249 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, theme; + std::string tab; char tab_char=' '; std::unordered_map tags, types; }; // class Config From c46e8ed57a353024ddbc754321e457eebd3aed63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 13 Aug 2015 14:17:58 +0200 Subject: [PATCH 07/10] Update source config --- src/config.cc | 16 +++++++--------- src/source.cc | 3 +++ src/source.h | 11 +++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/config.cc b/src/config.cc index ed7d4e9..cf2a7c1 100644 --- a/src/config.cc +++ b/src/config.cc @@ -37,20 +37,18 @@ void MainConfig::find_or_create_config_files() { } void MainConfig::GenerateSource() { - auto source_cfg=Singleton::Config::source(); - DEBUG("Fetching source cfg"); - // boost::property_tree::ptree + auto source_cfg = Singleton::Config::source(); auto source_json = cfg.get_child("source"); auto clang_types_json = source_json.get_child("clang_types"); auto style_json = source_json.get_child("style"); - source_cfg->tab_size = source_json.get("tab_size"); - for (unsigned c = 0; c < source_cfg->tab_size; c++) - source_cfg->tab+=" "; + auto gsv_json = source_json.get_child("sourceview"); + + for (auto &i : gsv_json) + source_cfg->gsv[i.first] = i.second.get_value(); for (auto &i : style_json) - source_cfg->tags[i.first]=i.second.get_value(); + source_cfg->tags[i.first] = i.second.get_value(); for (auto &i : clang_types_json) - source_cfg->types[i.first]=i.second.get_value(); - DEBUG("Source cfg fetched"); + source_cfg->types[i.first] = i.second.get_value(); } void MainConfig::GenerateDirectoryFilter() { diff --git a/src/source.cc b/src/source.cc index 358b43a..aa6cef7 100644 --- a/src/source.cc +++ b/src/source.cc @@ -65,6 +65,9 @@ Source::View::View(const std::string& file_path): file_path(file_path) { if(scheme) { get_source_buffer()->set_style_scheme(scheme); } + + property_highlight_current_line() = Singleton::Config::source()->gsv["highlight_current_line"] == "true"; + property_show_line_numbers() = Singleton::Config::source()->gsv["show_line_numbers"] == "true"; } void Source::View::search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data) { diff --git a/src/source.h b/src/source.h index 40b4b37..b24fb2b 100644 --- a/src/source.h +++ b/src/source.h @@ -20,12 +20,11 @@ namespace Source { class Config { public: - unsigned tab_size; - bool show_line_numbers, highlight_current_line; - std::string tab; - char tab_char=' '; - std::unordered_map tags, types; - }; // class Config + unsigned tab_size = 2; + char tab_char = ' '; + std::string tab = " "; + std::unordered_map tags, types, gsv; + }; class Range { public: From c3c9e09722312132d04111e86768a3c297acd35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 13 Aug 2015 14:50:33 +0200 Subject: [PATCH 08/10] Replace to_string and stoi with lexical_cast --- src/source.cc | 3 ++- src/window.cc | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/source.cc b/src/source.cc index a26e1d8..ca6ca14 100644 --- a/src/source.cc +++ b/src/source.cc @@ -7,6 +7,7 @@ #include #include "singletons.h" #include +#include #include //TODO: remove using namespace std; //TODO: remove @@ -601,7 +602,7 @@ void Source::ClangViewParse::update_syntax() { buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end()); last_syntax_tags.clear(); for (auto &range : ranges) { - auto type = std::to_string(range.kind); + auto type = boost::lexical_cast(range.kind); try { last_syntax_tags.emplace(Singleton::Config::source()->types.at(type)); } catch (std::exception) { diff --git a/src/window.cc b/src/window.cc index 954eacd..cd55b92 100644 --- a/src/window.cc +++ b/src/window.cc @@ -4,6 +4,7 @@ #include "sourcefile.h" #include "config.h" #include "api.h" +#include #include //TODO: remove using namespace std; //TODO: remove @@ -76,7 +77,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil if(notebook.get_current_page()!=-1) { if(search_entry_shown && entry_box.labels.size()>0) { notebook.get_current_view()->update_search_occurrences=[this](int number){ - entry_box.labels.begin()->update(0, std::to_string(number)); + entry_box.labels.begin()->update(0, boost::lexical_cast(number)); }; notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search); } @@ -235,7 +236,7 @@ void Window::create_menu() { compile_success(); //TODO: Windows... Singleton::terminal()->async_execute(executable_path.string(), project_path, [this, executable_path](int exit_code){ - Singleton::terminal()->async_print(executable_path.string()+" returned: "+std::to_string(exit_code)+'\n'); + Singleton::terminal()->async_print(executable_path.string()+" returned: "+boost::lexical_cast(exit_code)+'\n'); }); } }); @@ -270,7 +271,7 @@ void Window::create_menu() { last_run_command=content; Singleton::terminal()->async_print("Running: "+content+'\n'); Singleton::terminal()->async_execute(content, directories.current_path, [this, content](int exit_code){ - Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n'); + Singleton::terminal()->async_print(content+" returned: "+boost::lexical_cast(exit_code)+'\n'); }); } entry_box.hide(); @@ -509,13 +510,13 @@ void Window::search_and_replace_entry() { auto label_it=entry_box.labels.begin(); label_it->update=[label_it](int state, const std::string& message){ if(state==0) { - int number=stoi(message); + auto number = boost::lexical_cast(message); if(number==0) label_it->set_text(""); else if(number==1) label_it->set_text("1 result found"); else if(number>1) - label_it->set_text(std::to_string(number)+" results found"); + label_it->set_text(boost::lexical_cast(number)+" results found"); } }; entry_box.entries.emplace_back(last_search, [this](const std::string& content){ @@ -526,7 +527,7 @@ void Window::search_and_replace_entry() { search_entry_it->set_placeholder_text("Find"); if(notebook.get_current_page()!=-1) { notebook.get_current_view()->update_search_occurrences=[label_it](int number){ - label_it->update(0, std::to_string(number)); + label_it->update(0, boost::lexical_cast(number)); }; notebook.get_current_view()->search_highlight(search_entry_it->get_text(), case_sensitive_search, regex_search); } @@ -642,7 +643,7 @@ void Window::rename_token_entry() { if(notebook.get_view(c)->rename_similar_tokens) { auto number=notebook.get_view(c)->rename_similar_tokens(*token, content); if(number>0) { - Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+notebook.get_view(c)->file_path.string()+"\n"); + Singleton::terminal()->print("Replaced "+boost::lexical_cast(number)+" occurrences in file "+notebook.get_view(c)->file_path.string()+"\n"); notebook.save(c); } } From 894f2e8382c97a9d87896cb48bfcf0680c5b8f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 13 Aug 2015 15:00:37 +0200 Subject: [PATCH 09/10] Change another cast --- src/window.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.cc b/src/window.cc index cd55b92..5314f91 100644 --- a/src/window.cc +++ b/src/window.cc @@ -598,7 +598,7 @@ void Window::goto_line_entry() { if(notebook.get_current_page()!=-1) { auto buffer=notebook.get_current_view()->get_buffer(); try { - auto line=stoul(content); + auto line = boost::lexical_cast(content); if(line>0 && line<=(unsigned long)buffer->get_line_count()) { line--; buffer->place_cursor(buffer->get_iter_at_line(line)); From b106999fe885216e54181b7a9cf4c3d0d53faff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 13 Aug 2015 15:44:59 +0200 Subject: [PATCH 10/10] Fix multiple instances mistake --- src/juci.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/juci.cc b/src/juci.cc index 9f0ce9a..b95da2d 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -47,7 +47,7 @@ void app::on_activate() { window->notebook.open(f); } -app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) { +app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) { MainConfig(); // Read the configs here auto css_provider = Gtk::CssProvider::get_default(); auto style_context = Gtk::StyleContext::create();