diff --git a/juci/config.cc b/juci/config.cc index c3cffb4..b4619dd 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -2,7 +2,7 @@ #include "logging.h" MainConfig::MainConfig() : - keybindings_cfg_(), source_cfg_() { + keybindings_cfg_(), source_cfg() { INFO("Reading config file"); boost::property_tree::json_parser::read_json("config.json", cfg_); INFO("Config file read"); @@ -14,21 +14,41 @@ MainConfig::MainConfig() : void MainConfig::GenerateSource() { DEBUG("Fetching source cfg"); - boost::property_tree::ptree source_json = cfg_.get_child("source"); - source_cfg_.tab_size=source_json.get("tab_size"); - for(unsigned c=0;c(); + } + if (i.first == "show_line_numbers") { + source_cfg.show_line_numbers = i.second.get_value() == "1" ? true : false; + std::cout << source_cfg.show_line_numbers << std::endl; + } + if (i.first == "highlight_current_line") { + source_cfg.highlight_current_line = i.second.get_value() == "1" ? true : false; + std::cout << source_cfg.highlight_current_line << std::endl; + } + if (i.first == "font") { + source_cfg.font = i.second.get_value(); + std::cout << source_cfg.font << std::endl; + } + } + 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) { - source_cfg_.InsertTag(i.first, i.second.get_value()); + source_cfg.InsertTag(i.first, i.second.get_value()); } for (auto &i : syntax_json) { - source_cfg_.InsertType(i.first, i.second.get_value()); + source_cfg.InsertType(i.first, i.second.get_value()); } for (auto &i : extensions_json) { - source_cfg_.InsertExtension(i.second.get_value()); + source_cfg.InsertExtension(i.second.get_value()); } DEBUG("Source cfg fetched"); } diff --git a/juci/config.h b/juci/config.h index f6c652e..309e297 100644 --- a/juci/config.h +++ b/juci/config.h @@ -11,8 +11,8 @@ class MainConfig { public: + Source::Config source_cfg; MainConfig(); - Source::Config& source_cfg() { return source_cfg_; } Keybindings::Config& keybindings_cfg() { return keybindings_cfg_; } Directories::Config& dir_cfg() { return dir_cfg_; } Terminal::Config& terminal_cfg() { return terminal_cfg_; } @@ -24,7 +24,6 @@ public: private: boost::property_tree::ptree cfg_; boost::property_tree::ptree key_tree_; - Source::Config source_cfg_; Keybindings::Config keybindings_cfg_; Directories::Config dir_cfg_; Terminal::Config terminal_cfg_; diff --git a/juci/config.json b/juci/config.json index 41bd876..bcb8a45 100644 --- a/juci/config.json +++ b/juci/config.json @@ -21,37 +21,42 @@ "c", "cc", "cpp", - "cxx", - "c++", - "h", - "hh", - "hpp", - "hxx", - "h++" + "cxx", + "c++", + "h", + "hh", + "hpp", + "hxx", + "h++" ], - "tab_size": 2 + "visual": { + "background": "white", + "font": "Monospace", + "show_line_numbers": 1, + "highlight_current_line": 1 + }, + "tab_size": 2, + "tab_char": "" }, "keybindings": { "new_file": "n", - "new_h_file": "h", - "new_cc_file": "c", + "new_h_file": "h", + "new_cc_file": "c", "open_folder": "o", "open_file": "o", - "save": "s", - "save_as": "s", + "save": "s", + "save_as": "s", "quit": "q", - "split_window": "s", - "close_tab": "w", - + "close_tab": "w", "edit_copy": "c", "edit_cut": "x", "edit_paste": "v", "edit_undo": "z", - "edit_redo": "y", + "edit_redo": "y", "edit_find": "f", - "compile_and_run": "r", - "compile": "r" + "compile_and_run": "r", + "compile": "r" }, "directoryfilter": { "ignore": [ @@ -76,16 +81,16 @@ "mkdir ./.build", "cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B./.build -H.", "cd ./.build/; make", - "cp ./.build/compile_commands.json compile_commands.json" + "cp ./.build/compile_commands.json compile_commands.json" ] }, "example": { - "key": "value", - "key2": [ - "val1", - "val2", - 3 - ], - "key3": "value" + "key": "value", + "key2": [ + "val1", + "val2", + 3 + ], + "key3": "value" } } diff --git a/juci/juci.cc b/juci/juci.cc index 8360f06..cedf99d 100644 --- a/juci/juci.cc +++ b/juci/juci.cc @@ -13,7 +13,6 @@ int main(int argc, char *argv[]) { argc, argv, "no.sout.juci"); - Gsv::init(); init_logging(); Window window; return app->run(window); diff --git a/juci/source.cc b/juci/source.cc index c1ff97d..4069891 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -29,9 +29,7 @@ Range(const Source::Range &org) : //// View //// ////////////// Source::View::View() { - override_font(Pango::FontDescription("Monospace")); - set_show_line_numbers(true); - set_highlight_current_line(true); + Gsv::init(); set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); } @@ -54,14 +52,14 @@ string Source::View::GetLineBeforeInsert() { // Source::View::ApplyTheme() // Applies theme in textview void Source::View::ApplyConfig(const Source::Config &config) { + override_font(Pango::FontDescription(config.font)); + set_show_line_numbers(config.show_line_numbers); + set_highlight_current_line(config.highlight_current_line); for (auto &item : config.tagtable()) { get_buffer()->create_tag(item.first)->property_foreground() = item.second; } } - - - // Source::View::Config::tagtable() // returns a const refrence to the tagtable const std::unordered_map& Source::Config::tagtable() const { @@ -355,8 +353,8 @@ void Source::Controller::OnOpenFile(const string &filepath) { buffer()->get_undo_manager()->end_not_undoable_action(); int start_offset = buffer()->begin().get_offset(); int end_offset = buffer()->end().get_offset(); + view().ApplyConfig(model().config()); if (notebook_->LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) { - view().ApplyConfig(model().config()); model().InitSyntaxHighlighting(filepath, extract_file_path(filepath), buffers, @@ -409,7 +407,7 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { const std::regex no_bracket_statement_regex("^( *)(if|for|else if|catch|while) *\\(.*[^;}] *$"); const std::regex no_bracket_no_para_statement_regex("^( *)(else|try|do) *$"); const std::regex spaces_regex("^( *).*$"); - + //Indent as in previous line, and indent right after if/else/etc if(key->keyval==GDK_KEY_Return && key->state==0) { string line(view().GetLineBeforeInsert()); @@ -522,6 +520,5 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) { } } } - return false; -} \ No newline at end of file +} diff --git a/juci/source.h b/juci/source.h index 083fd30..b4b0000 100644 --- a/juci/source.h +++ b/juci/source.h @@ -28,13 +28,12 @@ namespace Source { void InsertType(const std::string &key, const std::string &value); void InsertExtension(const std::string &ext); std::vector extensiontable_; - unsigned tab_size; //TODO: Have to clean away all the simple setter and getter methods at some point. It creates too much unnecessary code - std::string tab; + // TODO: Have to clean away all the simple setter and getter methods at some point. It creates too much unnecessary code + unsigned tab_size; + bool show_line_numbers, highlight_current_line; + std::string tab, background, font; private: - std::unordered_map tagtable_; - std::unordered_map typetable_; - - std::string background_; + std::unordered_map tagtable_, typetable_; }; // class Config class Location { diff --git a/juci/window.cc b/juci/window.cc index d1b7d92..8758903 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -7,7 +7,7 @@ Window::Window() : keybindings_(main_config_.keybindings_cfg()), terminal_(main_config_.terminal_cfg()), notebook_(this,keybindings(), - main_config_.source_cfg(), + main_config_.source_cfg, main_config_.dir_cfg()), menu_(keybindings()), api_(menu_, notebook_) {