Browse Source

Merge pull request #2 from cppit/master

Pull from cppit/jucipp
merge-requests/365/head
Ole Christian Eidheim 11 years ago
parent
commit
a1173b98c3
  1. 42
      juci/config.cc
  2. 3
      juci/config.h
  3. 11
      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"
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<unsigned>("tab_size");
for(unsigned c=0;c<source_cfg_.tab_size;c++)
source_cfg_.tab+=" ";
boost::property_tree::ptree syntax_json = source_json.get_child("syntax");
boost::property_tree::ptree colors_json = source_json.get_child("colors");
boost::property_tree::ptree extensions_json = source_json.get_child("extensions");
// 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 extensions_json = source_json.get_child("extensions");
auto visual_json = source_json.get_child("visual");
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 == "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) {
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) {
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) {
source_cfg_.InsertExtension(i.second.get_value<std::string>());
source_cfg.InsertExtension(i.second.get_value<std::string>());
}
DEBUG("Source cfg fetched");
}

3
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_;

11
juci/config.json

@ -29,7 +29,14 @@
"hxx",
"h++"
],
"tab_size": 2
"visual": {
"background": "white",
"font": "Monospace",
"show_line_numbers": 1,
"highlight_current_line": 1
},
"tab_size": 2,
"tab_char": "<space>"
},
"keybindings": {
"new_file": "<control>n",
@ -40,10 +47,8 @@
"save": "<control>s",
"save_as": "<control><shift>s",
"quit": "<control>q",
"split_window": "<control><alt>s",
"close_tab": "<control>w",
"edit_copy": "<control>c",
"edit_cut": "<control>x",
"edit_paste": "<control>v",

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

13
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<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();
int start_offset = buffer()->begin().get_offset();
int end_offset = buffer()->end().get_offset();
if (notebook_->LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) {
view().ApplyConfig(model().config());
if (notebook_->LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) {
model().InitSyntaxHighlighting(filepath,
extract_file_path(filepath),
buffers,
@ -522,6 +520,5 @@ bool Source::Controller::OnKeyPress(GdkEventKey* key) {
}
}
}
return false;
}

11
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<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
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<std::string, std::string> tagtable_;
std::unordered_map<std::string, std::string> typetable_;
std::string background_;
std::unordered_map<std::string, std::string> tagtable_, typetable_;
}; // class Config
class Location {

2
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_) {

Loading…
Cancel
Save