Browse Source

config ready to test on source, starting with keybindings

merge-requests/365/head
tedjk 11 years ago
parent
commit
d970407447
  1. 2
      juci/CMakeLists.txt
  2. 25
      juci/config.cc
  3. 30
      juci/config.h
  4. 20
      juci/config.json
  5. 21
      juci/keybindings.cc
  6. 24
      juci/keybindings.h
  7. 10
      juci/notebook.cc
  8. 5
      juci/notebook.h
  9. 72
      juci/source.cc
  10. 28
      juci/source.h
  11. 13
      juci/window.cc
  12. 10
      juci/window.h

2
juci/CMakeLists.txt

@ -76,6 +76,8 @@ add_executable(${project_name}
keybindings
menu
source
config.h
config.cc
sourcefile.h
sourcefile.cc
window

25
juci/config.cc

@ -0,0 +1,25 @@
#include "config.h"
MainConfig::MainConfig() {
boost::property_tree::json_parser::read_json("config.json", cfg_);
GenerateSource();
GenerateKeybindings();
// keybindings_cfg_ = cfg_.get_child("keybindings");
// notebook_cfg_ = cfg_.get_child("notebook");
// menu_cfg_ = cfg_.get_child("menu");
}
void MainConfig::GenerateSource(){
boost::property_tree::ptree source_json = cfg_.get_child("source");
boost::property_tree::ptree syntax_json = source_json.get_child("syntax");
boost::property_tree::ptree colors_json = source_json.get_child("colors");
for ( auto &i : syntax_json )
source_cfg_.InsertTag(i.first, i.second.get_value<std::string>());
for ( auto &i : colors_json )
source_cfg_.InsertType(i.first, i.second.get_value<std::string>());
}
void MainConfig::GenerateKeybindings(){
}

30
juci/config.h

@ -0,0 +1,30 @@
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <fstream>
#include "source.h"
#include "keybindings.h"
class MainConfig {
public:
MainConfig();
const Source::Config& source_cfg() {return source_cfg_; }
const Keybindings::Config& keybindings_cfg() {return keybindings_cfg_; }
void PrintMenu();
//boost::property_tree::ptree& source_cfg();
//boost::property_tree::ptree& keybindings_cfg();
//boost::property_tree::ptree& notebookk_cfg();
//boost::property_tree::ptree& menu_cfg();
boost::property_tree::ptree cfg_;
// boost::property_tree::ptree sourcecfg_;
// boost::property_tree::ptree keybindings_cfg_;
// boost::property_tree::ptree notebook_cfg_;
// boost::property_tree::ptree menu_cfg_;
Source::Config source_cfg_;
Keybindings::Config keybindings_cfg_;
void GenerateSource();
void GenerateKeybindings();
};

20
juci/config.json

@ -1,9 +1,10 @@
{
"source": {
"colors": {
"text_color": "#333333",
"string" : "#CC0000",
"namespace_ref" : "#990099",
"type" : "#0066FF",
"string": "#CC0000",
"namespace_ref": "#990099",
"type": "#0066FF",
"keyword": "blue",
"comment": "grey",
"own": "pink"
@ -16,4 +17,17 @@
"703": "own",
"705": "comment"
}
},
"example": {
"key": "value",
"key2": [
"val1",
"val2",
3
],
"key3": "value"
},
"keybindings": {
"path" : "keybindings.xml"
}
}

21
juci/keybindings.cc

@ -1,7 +1,8 @@
#include "keybindings.h"
Keybindings::Model::Model() {
menu_ui_string_ =
Keybindings::Model::Model(const Keybindings::Config &config) :
menu_ui_string_(config.menu_xml()) {
/* menu_ui_string_ =
"<ui> "
" <menubar name='MenuBar'> "
" <menu action='FileMenu'> "
@ -28,14 +29,14 @@ Keybindings::Model::Model() {
" </menu> "
" <menu action='PluginMenu'> "
// " <menu action='PluginSnippet'> "
// " <menuitem action='PluginAddSnippet'/> "
// " <menuitem action='PluginAddSnippet'/>"
// " </menu> "
" </menu> "
" <menu action='HelpMenu'> "
" <menuitem action='HelpAbout'/> "
" </menu> "
" </menubar> "
"</ui> ";
"</ui> ";*/
hidden_ui_string_ =
"<ui> "
@ -43,12 +44,13 @@ Keybindings::Model::Model() {
" <menuitem action='Test'/> "
" </menubar> "
"</ui> ";
};
}
Keybindings::Model::~Model() {
}
Keybindings::Controller::Controller() {
Keybindings::Controller::Controller(const Keybindings::Config &config) :
config_(config), model_(config) {
action_group_menu_ = Gtk::ActionGroup::create();
ui_manager_menu_ = Gtk::UIManager::create();
action_group_hidden_ = Gtk::ActionGroup::create();
@ -75,3 +77,10 @@ void Keybindings::Controller::BuildHiddenMenu() {
ui_manager_hidden_->insert_action_group(action_group_hidden_);
}
Keybindings::Config::Config(const Keybindings::Config &original) :
menu_xml_(original.menu_xml()) {
}
void Keybindings::Config::SetMenu(std::string &menu_xml) {
menu_xml_ = menu_xml;
}

24
juci/keybindings.h

@ -6,9 +6,22 @@
#include "gtkmm.h"
namespace Keybindings {
class Config{
public:
Config(const Config &original);
Config();
const std::string& menu_xml() const {return menu_xml_;}
void SetMenu(std::string &menu_xml);
private:
std::string menu_xml_;
std::string hidden_ui_string_;
};//Config
class Model {
public:
Model();
Model(const Keybindings::Config &config);
virtual ~Model();
std::string menu_ui_string(){return menu_ui_string_;}
std::string hidden_ui_string(){return hidden_ui_string_;}
@ -16,9 +29,10 @@ namespace Keybindings {
std::string menu_ui_string_;
std::string hidden_ui_string_;
}; // Model
class Controller {
public:
Controller();
Controller(const Keybindings::Config &config);
virtual ~Controller();
Glib::RefPtr<Gtk::ActionGroup> action_group_menu() {
return action_group_menu_;
@ -40,8 +54,14 @@ namespace Keybindings {
Glib::RefPtr<Gtk::UIManager> ui_manager_hidden_;
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden_;
// private:
Keybindings::Config config_;
Keybindings::Model model_;
};//Controller
}
#endif // JUCI_KEYBINDINGS_H_

10
juci/notebook.cc

@ -12,16 +12,16 @@ Gtk::Box& Notebook::View::view() {
view_.pack_start(notebook_);
return view_;
}
Notebook::Controller::Controller(Keybindings::Controller& keybindings){
Notebook::Controller::Controller(Keybindings::Controller& keybindings,
const Source::Config &source_cfg) {
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow());
source_vec_.push_back(new Source::Controller);
source_vec_.push_back(new Source::Controller(source_cfg));
scrolledwindow_vec_.back()->add(source_vec_.back()->view());
source_vec_.back()->OnNewEmptyFile();
notebook().append_page(*scrolledwindow_vec_.back(), "juCi++");
notebook().set_focus_child(*scrolledwindow_vec_.back());
refClipboard = Gtk::Clipboard::get();
keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu",
Gtk::Stock::FILE));
/* File->New files */
@ -114,7 +114,7 @@ Gtk::Box& Notebook::Controller::entry_view(){
}
void Notebook::Controller::OnNewPage(std::string name) {
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow());
source_vec_.push_back(new Source::Controller);
source_vec_.push_back(new Source::Controller(source_config_));
scrolledwindow_vec_.back()->add(source_vec_.back()->view());
source_vec_.back()->OnNewEmptyFile();
notebook().append_page(*scrolledwindow_vec_.back(), name);
@ -158,7 +158,7 @@ void Notebook::Controller::OnEditCut() {
void Notebook::Controller::OnOpenFile(std::string path) {
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow());
source_vec_.push_back(new Source::Controller);
source_vec_.push_back(new Source::Controller(source_config_));
scrolledwindow_vec_.back()->add(source_vec_.back()->view());
source_vec_.back()->OnOpenFile(path);
unsigned pos = path.find_last_of("/\\");

5
juci/notebook.h

@ -18,13 +18,14 @@ namespace Notebook {
View();
Gtk::Box& view();
Gtk::Notebook& notebook() { return notebook_; }
protected:
Gtk::Box view_;
Gtk::Notebook notebook_;
};
class Controller {
public:
Controller(Keybindings::Controller& keybindings);
Controller(Keybindings::Controller& keybindings,const Source::Config& config);
Gtk::Box& view();
Gtk::Box& entry_view();
void OnNewPage(std::string name);
@ -50,7 +51,9 @@ namespace Notebook {
void OnEditCut();
void OnEditSearch();
void Search(bool forward);
Source::Config& source_config() { return source_config_; }
private:
Source::Config source_config_;
bool is_new_file;
Gtk::TextIter search_match_end_;
Gtk::TextIter search_match_start_;

72
juci/source.cc

@ -29,8 +29,8 @@ string Source::View::GetLine(const Gtk::TextIter &begin) {
// Source::View::ApplyTheme()
// Applies theme in textview
void Source::View::ApplyTheme(const Source::Theme &theme) {
for (auto &item : theme.tagtable()) {
void Source::View::ApplyConfig(const Source::Config &config) {
for (auto &item : config.tagtable()) {
// std::cout << "Apply: f: " << item.first << ", s: " <<
// item.second << std::endl;
get_buffer()->create_tag(item.first)->property_foreground() = item.second;
@ -38,13 +38,13 @@ void Source::View::ApplyTheme(const Source::Theme &theme) {
}
void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
const Source::Theme &theme) {
ApplyTheme(theme);
const Source::Config &config) {
ApplyConfig(config);
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
for (auto &loc : locations) {
string type = std::to_string(loc.kind());
try {
theme.typetable().at(type);
config.typetable().at(type);
} catch (std::exception) {
continue;
}
@ -66,40 +66,51 @@ void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end);
// std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl;
if (begin_iter.get_line() == end_iter.get_line()) {
buffer->apply_tag_by_name(theme.typetable().at(type),
buffer->apply_tag_by_name(config.typetable().at(type),
begin_iter, end_iter);
}
}
}
// Source::View::Theme::tagtable()
// Source::View::Config::Config(Config &config)
// copy-constructor
Source::Config::Config(const Source::Config &original) {
SetTagTable(original.tagtable());
SetTypeTable(original.typetable());
}
Source::Config::Config(){}
// Source::View::Config::tagtable()
// returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Theme::tagtable() const {
const std::unordered_map<string, string>& Source::Config::tagtable() const {
return tagtable_;
}
// Source::View::Theme::tagtable()
// Source::View::Config::tagtable()
// returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Theme::typetable() const {
const std::unordered_map<string, string>& Source::Config::typetable() const {
return typetable_;
}
void Source::Theme::InsertTag(const string &key, const string &value) {
void Source::Config::InsertTag(const string &key, const string &value) {
tagtable_[key] = value;
}
// Source::View::Theme::SetTagTable()
// Source::View::Config::SetTagTable()
// sets the tagtable for the view
void Source::Theme::SetTypeTable(
void Source::Config::SetTypeTable(
const std::unordered_map<string, string> &typetable) {
typetable_ = typetable;
}
void Source::Theme::InsertType(const string &key, const string &value) {
void Source::Config::InsertType(const string &key, const string &value) {
typetable_[key] = value;
}
// Source::View::Theme::SetTagTable()
// Source::View::Config::SetTagTable()
// sets the tagtable for the view
void Source::Theme::SetTagTable(
void Source::Config::SetTagTable(
const std::unordered_map<string, string> &tagtable) {
tagtable_ = tagtable;
}
@ -107,8 +118,7 @@ void Source::Theme::SetTagTable(
///////////////
//// Model ////
///////////////
Source::Model::Model() :
theme_() {
/*Source::Model::Model() {
std::cout << "Model constructor run" << std::endl;
boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json("config.json", pt);
@ -116,19 +126,23 @@ Source::Model::Model() :
boost::property_tree::ptree props = pt.get_child(i.first);
for (auto &pi : props) {
if (i.first.compare("syntax")) { // checks the config-file
theme_.InsertTag(pi.first, pi.second.get_value<std::string>());
config_.InsertTag(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting tag. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
if (i.first.compare("colors")) { // checks the config-file
theme_.InsertType(pi.first, pi.second.get_value<std::string>());
config_.InsertType(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting type. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
}
}
}*/
Source::Model::Model(const Source::Config &config) :
config_(config) {
}
Source::Theme& Source::Model::theme() {
return theme_;
Source::Config& Source::Model::config() {
return config_;
}
const string Source::Model::filepath() {
@ -149,12 +163,20 @@ SetSourceLocations(const std::vector<Clang::SourceLocation> &locations) {
// Source::Controller::Controller()
// Constructor for Controller
Source::Controller::Controller() {
//std::cout << "Controller constructor run" << std::endl;
Source::Controller::Controller(const Source::Config &config) :
model_(config) {
view().get_buffer()->signal_changed().connect([this](){
this->OnLineEdit();
});
}
/*Source::Controller::Controller(){
//std::cout << "Controller constructor run" << std::endl;
view().get_buffer()->signal_changed().connect([this](){
this->OnLineEdit();
});
}*/
// Source::Controller::view()
// return shared_ptr to the view
Source::View& Source::Controller::view() {
@ -185,7 +207,7 @@ void Source::Controller::OnOpenFile(const string &filename) {
int offset = view().get_buffer()->end().get_line_offset();
Clang::TranslationUnit tu(filename.c_str(), linums, offset);
model().SetSourceLocations(tu.getSourceLocations());
view().OnOpenFile(model().getSourceLocations(), model().theme());
view().OnOpenFile(model().getSourceLocations(), model().config());
}
Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer(){

28
juci/source.h

@ -11,18 +11,10 @@ using std::string;
namespace Source {
class Config() {
// læs json
//
private:
}
class Config {
public:
Config(const Config &original);
Config();
const std::unordered_map<string, string>& tagtable() const;
const std::unordered_map<string, string>& typetable() const;
void SetTagTable(const std::unordered_map<string, string> &tagtable);
@ -33,24 +25,24 @@ namespace Source {
private:
std::unordered_map<string, string> tagtable_;
std::unordered_map<string, string> typetable_;
string background_;
}; // class Theme
}; // class Config
class View : public Gtk::TextView {
public:
View();
string UpdateLine();
void ApplyTheme(const Theme &theme);
void ApplyConfig(const Config &config);
void OnOpenFile(std::vector<Clang::SourceLocation> &locations,
const Theme &theme);
const Config &config);
private:
string GetLine(const Gtk::TextIter &begin);
}; // class View
class Model{
public:
Model();
Theme& theme();
Model(const Source::Config &config);
//Model();
Config& config();
const string filepath();
void SetFilePath(const string &filepath);
void SetSourceLocations(
@ -60,13 +52,14 @@ namespace Source {
}
private:
Theme theme_;
Source::Config config_;
string filepath_;
std::vector<Clang::SourceLocation> locations_;
};
class Controller {
public:
Controller(const Source::Config &config);
Controller();
View& view();
Model& model();
@ -77,7 +70,6 @@ namespace Source {
private:
void OnLineEdit();
void OnSaveFile();
protected:
View view_;
Model model_;

13
juci/window.cc

@ -2,11 +2,13 @@
Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL),
notebook_(keybindings_),
menu_(keybindings_){
main_config_(),
notebook_(keybindings_(main_config().keybindings_cfg()), main_config().source_cfg()),
menu_(keybindings_(main_config().keybindings_cfg())) {
set_title("juCi++");
set_default_size(600, 400);
add(window_box_);
keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit",
Gtk::Stock::QUIT),
[this]() {
@ -34,12 +36,6 @@ Window::Window() :
} // Window constructor
void Window::OnWindowHide(){
//TODO forgie: find out how to 'remove' the pointers
//TODO forgie: Make shared_ptr
//libjuci::PluginApi::notebook_ =
// std::shared_ptr<Notebook::Controller>(nullptr);
// libjuci::PluginApi::menu_ =
// std::shared_ptr<Menu::Controller>(nullptr);
hide();
}
@ -90,5 +86,4 @@ void Window::OnOpenFile() {
break;
}
}
}

10
juci/window.h

@ -4,21 +4,27 @@
#include <iostream>
#include "gtkmm.h"
#include "api.h"
#include "config.h"
#include <cstddef>
class Window : public Gtk::Window {
public:
Window();
MainConfig& main_config() {return main_config_;}
Gtk::Box window_box_;
//private:
MainConfig main_config_;
Keybindings::Controller keybindings_;
Menu::Controller menu_;
Notebook::Controller notebook_;
private:
//signal handlers
void OnWindowHide();
void OnOpenFile();
};
#endif // JUCI_WINDOW_H_
};
#endif // JUCI_WINDOW_H

Loading…
Cancel
Save