Browse Source

Commit

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
11755ae716
  1. 9
      juci/menu.cc
  2. 6
      juci/notebook.cc
  3. 2
      juci/notebook.h
  4. 33
      juci/source.cc
  5. 5
      juci/source.h
  6. 4
      juci/window.cc

9
juci/menu.cc

@ -4,7 +4,6 @@ Menu::View::View(Gtk::Orientation orientation) :
view_(orientation) { view_(orientation) {
Gtk::MenuBar menutest; Gtk::MenuBar menutest;
view_.pack_end(menutest); view_.pack_end(menutest);
} }
Gtk::Box &Menu::View::view( Gtk::Box &Menu::View::view(
Glib::RefPtr<Gtk::UIManager> ui_manager) { Glib::RefPtr<Gtk::UIManager> ui_manager) {
@ -15,11 +14,9 @@ Gtk::Box &Menu::View::view(
Menu::Controller::Controller(Keybindings::Controller& keybindings) : Menu::Controller::Controller(Keybindings::Controller& keybindings) :
menu_view_(Gtk::ORIENTATION_VERTICAL), menu_view_(Gtk::ORIENTATION_VERTICAL),
keybindings_(keybindings) { keybindings_(keybindings) {
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew",
Gtk::Stock::OPEN), Gtk::Stock::FILE));
[this]() {
OnFileOpenFile();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder",
"Open folder"), "Open folder"),
[this]() { [this]() {

6
juci/notebook.cc

@ -132,12 +132,12 @@ void Notebook::Controller::OnEditCut() {
} }
} }
void Notebook::Controller::OnOpenFile(std::string name, std::string content){ void Notebook::Controller::OnOpenFile(std::string filename) {
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow());
source_vec_.push_back(new Source::Controller); source_vec_.push_back(new Source::Controller);
scrolledwindow_vec_.back()->add(source_vec_.back()->view()); scrolledwindow_vec_.back()->add(source_vec_.back()->view());
source_vec_.back()->view().get_buffer()->set_text(content); source_vec_.back()->OnOpenFile(filename);
view_.notebook().append_page(*scrolledwindow_vec_.back(), name); view_.notebook().append_page(*scrolledwindow_vec_.back(), filename);
view_.notebook().show_all_children(); view_.notebook().show_all_children();
view_.notebook().set_focus_child(*scrolledwindow_vec_.back()); view_.notebook().set_focus_child(*scrolledwindow_vec_.back());
view_.notebook().set_current_page(view_.notebook().get_n_pages()-1); view_.notebook().set_current_page(view_.notebook().get_n_pages()-1);

2
juci/notebook.h

@ -23,6 +23,7 @@ namespace Notebook {
Gtk::Box& entry_view(); Gtk::Box& entry_view();
void OnNewPage(std::string name); void OnNewPage(std::string name);
void OnCloseCurrentPage(); void OnCloseCurrentPage();
void OnOpenFile(std::string filename);
private: private:
View view_; View view_;
Entry::Controller entry_; Entry::Controller entry_;
@ -36,7 +37,6 @@ namespace Notebook {
void OnEditCopy(); void OnEditCopy();
void OnEditPaste(); void OnEditPaste();
void OnEditCut(); void OnEditCut();
void OnOpenFile(std::string name, std::string content);
}; // class controller }; // class controller
} // namespace Notebook } // namespace Notebook

33
juci/source.cc

@ -14,6 +14,7 @@ Source::View::View() {
// returns the new line // returns the new line
string Source::View::UpdateLine() { string Source::View::UpdateLine() {
Gtk::TextIter line(get_buffer()->get_insert()->get_iter()); Gtk::TextIter line(get_buffer()->get_insert()->get_iter());
// std::cout << line.get_line() << std::endl;
// for each word --> check what it is --> apply appropriate tag // for each word --> check what it is --> apply appropriate tag
return ""; return "";
} }
@ -41,9 +42,18 @@ void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
int linum = loc.line_number(); int linum = loc.line_number();
int begin = loc.begin(); int begin = loc.begin();
int end = loc.end(); int end = loc.end();
buffer->apply_tag_by_name(theme.tagtable().at(type), if(end < 0) end = 0;
if(begin < 0) begin = 0;
// for (auto &i : theme.tagtable()) {
// std::cout << "first: "<< i.first << " second: "<< i.second << std::endl;
// }
// std::cout << "type: " << type << std::endl;
buffer->apply_tag_by_name(theme.typetable().at(type),
buffer->get_iter_at_line_offset(linum, begin), buffer->get_iter_at_line_offset(linum, begin),
buffer->get_iter_at_line_offset(linum, end)); buffer->get_iter_at_line_offset(linum, end));
// std::cout << "This is a ans" << std::endl;
} }
} }
// Source::View::Theme::tagtable() // Source::View::Theme::tagtable()
@ -52,11 +62,27 @@ const std::unordered_map<string, string>& Source::Theme::tagtable() const {
return tagtable_; return tagtable_;
} }
// Source::View::Theme::tagtable()
// returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Theme::typetable() const {
return typetable_;
}
void Source::Theme::InsertTag(const string &key, const string &value) { void Source::Theme::InsertTag(const string &key, const string &value) {
tagtable_[key] = value; tagtable_[key] = value;
} }
// Source::View::Theme::SetTagTable() // Source::View::Theme::SetTagTable()
// sets the tagtable for the view // sets the tagtable for the view
void Source::Theme::SetTypeTable(
const std::unordered_map<string, string> &typetable) {
typetable_ = typetable;
}
void Source::Theme::InsertType(const string &key, const string &value) {
typetable_[key] = value;
}
// Source::View::Theme::SetTagTable()
// sets the tagtable for the view
void Source::Theme::SetTagTable( void Source::Theme::SetTagTable(
const std::unordered_map<string, string> &tagtable) { const std::unordered_map<string, string> &tagtable) {
tagtable_ = tagtable; tagtable_ = tagtable;
@ -75,6 +101,11 @@ Source::Model::Model() :
for (auto &pi : props) { for (auto &pi : props) {
if (i.first.compare("syntax")) { // checks the config-file if (i.first.compare("syntax")) { // checks the config-file
theme_.InsertTag(pi.first, pi.second.get_value<std::string>()); theme_.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>());
// std::cout << "inserting type. " << pi.first << pi.second.get_value<std::string>() << std::endl;
} }
} }
} }

5
juci/source.h

@ -13,10 +13,15 @@ namespace Source {
class Theme { class Theme {
public: public:
const std::unordered_map<string, string>& tagtable() const; 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); void SetTagTable(const std::unordered_map<string, string> &tagtable);
void InsertTag(const string &key, const string &value); void InsertTag(const string &key, const string &value);
void SetTypeTable(const std::unordered_map<string, string> &tagtable);
void InsertType(const string &key, const string &value);
private: private:
std::unordered_map<string, string> tagtable_; std::unordered_map<string, string> tagtable_;
std::unordered_map<string, string> typetable_;
string background_; string background_;
}; // class Theme }; // class Theme

4
juci/window.cc

@ -62,11 +62,9 @@ void Window::OnOpenFile() {
switch (result) { switch (result) {
case(Gtk::RESPONSE_OK): { case(Gtk::RESPONSE_OK): {
std::cout << "Open clicked." << std::endl; std::cout << "Open clicked." << std::endl;
std::string path = dialog.get_filename(); std::string path = dialog.get_filename();
std::cout << "File selected: " << path << std::endl; std::cout << "File selected: " << path << std::endl;
Source::Controller sourcefile; notebook_.OnOpenFile(path);
notebook_.OnOpenFile(path, sourcefile.OnOpenFile(path));
break; break;
} }
case(Gtk::RESPONSE_CANCEL): { case(Gtk::RESPONSE_CANCEL): {

Loading…
Cancel
Save