Browse Source

Add more configurations. Font, background, show line numbers, highlight current line

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
b72d067c83
  1. 42
      juci/config.cc
  2. 3
      juci/config.h
  3. 57
      juci/config.json
  4. 1
      juci/juci.cc
  5. 13
      juci/source.cc
  6. 11
      juci/source.h
  7. 2
      juci/window.cc

42
juci/config.cc

@ -2,7 +2,7 @@
#include "logging.h" #include "logging.h"
MainConfig::MainConfig() : MainConfig::MainConfig() :
keybindings_cfg_(), source_cfg_() { keybindings_cfg_(), source_cfg() {
INFO("Reading config file"); INFO("Reading config file");
boost::property_tree::json_parser::read_json("config.json", cfg_); boost::property_tree::json_parser::read_json("config.json", cfg_);
INFO("Config file read"); INFO("Config file read");
@ -14,21 +14,41 @@ MainConfig::MainConfig() :
void MainConfig::GenerateSource() { void MainConfig::GenerateSource() {
DEBUG("Fetching source cfg"); DEBUG("Fetching source cfg");
boost::property_tree::ptree source_json = cfg_.get_child("source"); // boost::property_tree::ptree
source_cfg_.tab_size=source_json.get<unsigned>("tab_size"); auto source_json = cfg_.get_child("source");
for(unsigned c=0;c<source_cfg_.tab_size;c++) auto syntax_json = source_json.get_child("syntax");
source_cfg_.tab+=" "; auto colors_json = source_json.get_child("colors");
boost::property_tree::ptree syntax_json = source_json.get_child("syntax"); auto extensions_json = source_json.get_child("extensions");
boost::property_tree::ptree colors_json = source_json.get_child("colors"); auto visual_json = source_json.get_child("visual");
boost::property_tree::ptree extensions_json = source_json.get_child("extensions"); for (auto &i : visual_json) {
if (i.first == "background") {
source_cfg.background = i.second.get_value<std::string>();
}
if (i.first == "show_line_numbers") {
source_cfg.show_line_numbers = i.second.get_value<std::string>() == "1" ? true : false;
std::cout << source_cfg.show_line_numbers << std::endl;
}
if (i.first.compare("highlight_current_line")) {
source_cfg.highlight_current_line = i.second.get_value<std::string>() == "1" ? true : false;
std::cout << source_cfg.highlight_current_line << std::endl;
}
if (i.first == "font") {
source_cfg.font = i.second.get_value<std::string>();
std::cout << source_cfg.font << std::endl;
}
}
source_cfg.tab_size = source_json.get<unsigned>("tab_size");
for (unsigned c = 0; c < source_cfg.tab_size; c++) {
source_cfg.tab+=" ";
}
for (auto &i : colors_json) { for (auto &i : colors_json) {
source_cfg_.InsertTag(i.first, i.second.get_value<std::string>()); source_cfg.InsertTag(i.first, i.second.get_value<std::string>());
} }
for (auto &i : syntax_json) { for (auto &i : syntax_json) {
source_cfg_.InsertType(i.first, i.second.get_value<std::string>()); source_cfg.InsertType(i.first, i.second.get_value<std::string>());
} }
for (auto &i : extensions_json) { for (auto &i : extensions_json) {
source_cfg_.InsertExtension(i.second.get_value<std::string>()); source_cfg.InsertExtension(i.second.get_value<std::string>());
} }
DEBUG("Source cfg fetched"); DEBUG("Source cfg fetched");
} }

3
juci/config.h

@ -11,8 +11,8 @@
class MainConfig { class MainConfig {
public: public:
Source::Config source_cfg;
MainConfig(); MainConfig();
Source::Config& source_cfg() { return source_cfg_; }
Keybindings::Config& keybindings_cfg() { return keybindings_cfg_; } Keybindings::Config& keybindings_cfg() { return keybindings_cfg_; }
Directories::Config& dir_cfg() { return dir_cfg_; } Directories::Config& dir_cfg() { return dir_cfg_; }
Terminal::Config& terminal_cfg() { return terminal_cfg_; } Terminal::Config& terminal_cfg() { return terminal_cfg_; }
@ -24,7 +24,6 @@ public:
private: private:
boost::property_tree::ptree cfg_; boost::property_tree::ptree cfg_;
boost::property_tree::ptree key_tree_; boost::property_tree::ptree key_tree_;
Source::Config source_cfg_;
Keybindings::Config keybindings_cfg_; Keybindings::Config keybindings_cfg_;
Directories::Config dir_cfg_; Directories::Config dir_cfg_;
Terminal::Config terminal_cfg_; Terminal::Config terminal_cfg_;

57
juci/config.json

@ -21,37 +21,42 @@
"c", "c",
"cc", "cc",
"cpp", "cpp",
"cxx", "cxx",
"c++", "c++",
"h", "h",
"hh", "hh",
"hpp", "hpp",
"hxx", "hxx",
"h++" "h++"
], ],
"tab_size": 2 "visual": {
"background": "white",
"font": "Monospace",
"show_line_numbers": 1,
"highlight_current_line": 1
},
"tab_size": 2,
"tab_char": "<space>"
}, },
"keybindings": { "keybindings": {
"new_file": "<control>n", "new_file": "<control>n",
"new_h_file": "<control><alt>h", "new_h_file": "<control><alt>h",
"new_cc_file": "<control><alt>c", "new_cc_file": "<control><alt>c",
"open_folder": "<control><alt>o", "open_folder": "<control><alt>o",
"open_file": "<control>o", "open_file": "<control>o",
"save": "<control>s", "save": "<control>s",
"save_as": "<control><shift>s", "save_as": "<control><shift>s",
"quit": "<control>q", "quit": "<control>q",
"split_window": "<control><alt>s", "split_window": "<control><alt>s",
"close_tab": "<control>w", "close_tab": "<control>w",
"edit_copy": "<control>c", "edit_copy": "<control>c",
"edit_cut": "<control>x", "edit_cut": "<control>x",
"edit_paste": "<control>v", "edit_paste": "<control>v",
"edit_undo": "<control>z", "edit_undo": "<control>z",
"edit_redo": "<control>y", "edit_redo": "<control>y",
"edit_find": "<control>f", "edit_find": "<control>f",
"compile_and_run": "<control><alt>r", "compile_and_run": "<control><alt>r",
"compile": "<control>r" "compile": "<control>r"
}, },
"directoryfilter": { "directoryfilter": {
"ignore": [ "ignore": [
@ -76,16 +81,16 @@
"mkdir ./.build", "mkdir ./.build",
"cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B./.build -H.", "cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B./.build -H.",
"cd ./.build/; make", "cd ./.build/; make",
"cp ./.build/compile_commands.json compile_commands.json" "cp ./.build/compile_commands.json compile_commands.json"
] ]
}, },
"example": { "example": {
"key": "value", "key": "value",
"key2": [ "key2": [
"val1", "val1",
"val2", "val2",
3 3
], ],
"key3": "value" "key3": "value"
} }
} }

1
juci/juci.cc

@ -13,7 +13,6 @@ int main(int argc, char *argv[]) {
argc, argc,
argv, argv,
"no.sout.juci"); "no.sout.juci");
Gsv::init();
init_logging(); init_logging();
Window window; Window window;
return app->run(window); return app->run(window);

13
juci/source.cc

@ -29,9 +29,7 @@ Range(const Source::Range &org) :
//// View //// //// View ////
////////////// //////////////
Source::View::View() { Source::View::View() {
override_font(Pango::FontDescription("Monospace")); Gsv::init();
set_show_line_numbers(true);
set_highlight_current_line(true);
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
} }
@ -54,14 +52,14 @@ string Source::View::GetLineBeforeInsert() {
// Source::View::ApplyTheme() // Source::View::ApplyTheme()
// Applies theme in textview // Applies theme in textview
void Source::View::ApplyConfig(const Source::Config &config) { 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()) { for (auto &item : config.tagtable()) {
get_buffer()->create_tag(item.first)->property_foreground() = item.second; get_buffer()->create_tag(item.first)->property_foreground() = item.second;
} }
} }
// Source::View::Config::tagtable() // Source::View::Config::tagtable()
// returns a const refrence to the tagtable // returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Config::tagtable() const { const std::unordered_map<string, string>& Source::Config::tagtable() const {
@ -355,8 +353,8 @@ void Source::Controller::OnOpenFile(const string &filepath) {
buffer()->get_undo_manager()->end_not_undoable_action(); buffer()->get_undo_manager()->end_not_undoable_action();
int start_offset = buffer()->begin().get_offset(); int start_offset = buffer()->begin().get_offset();
int end_offset = buffer()->end().get_offset(); int end_offset = buffer()->end().get_offset();
view().ApplyConfig(model().config());
if (notebook_->LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) { if (notebook_->LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) {
view().ApplyConfig(model().config());
model().InitSyntaxHighlighting(filepath, model().InitSyntaxHighlighting(filepath,
extract_file_path(filepath), extract_file_path(filepath),
buffers, buffers,
@ -522,6 +520,5 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) {
} }
} }
} }
return false; return false;
} }

11
juci/source.h

@ -28,13 +28,12 @@ namespace Source {
void InsertType(const std::string &key, const std::string &value); void InsertType(const std::string &key, const std::string &value);
void InsertExtension(const std::string &ext); void InsertExtension(const std::string &ext);
std::vector<std::string> extensiontable_; std::vector<std::string> 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 // TODO: Have to clean away all the simple setter and getter methods at some point. It creates too much unnecessary code
std::string tab; unsigned tab_size;
bool show_line_numbers, highlight_current_line;
std::string tab, background, font;
private: private:
std::unordered_map<std::string, std::string> tagtable_; std::unordered_map<std::string, std::string> tagtable_, typetable_;
std::unordered_map<std::string, std::string> typetable_;
std::string background_;
}; // class Config }; // class Config
class Location { class Location {

2
juci/window.cc

@ -7,7 +7,7 @@ Window::Window() :
keybindings_(main_config_.keybindings_cfg()), keybindings_(main_config_.keybindings_cfg()),
terminal_(main_config_.terminal_cfg()), terminal_(main_config_.terminal_cfg()),
notebook_(this,keybindings(), notebook_(this,keybindings(),
main_config_.source_cfg(), main_config_.source_cfg,
main_config_.dir_cfg()), main_config_.dir_cfg()),
menu_(keybindings()), menu_(keybindings()),
api_(menu_, notebook_) { api_(menu_, notebook_) {

Loading…
Cancel
Save