From 11755ae716bf5769302f57776e38047ef89040db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 20 Feb 2015 10:57:32 +0100 Subject: [PATCH] Commit --- juci/keybindings.cc | 2 +- juci/menu.cc | 65 +++++++++++++++++++++------------------------ juci/notebook.cc | 12 ++++----- juci/notebook.h | 4 +-- juci/source.cc | 33 ++++++++++++++++++++++- juci/source.h | 5 ++++ juci/window.cc | 4 +-- 7 files changed, 78 insertions(+), 47 deletions(-) diff --git a/juci/keybindings.cc b/juci/keybindings.cc index dd5b45d..d24bf47 100644 --- a/juci/keybindings.cc +++ b/juci/keybindings.cc @@ -54,7 +54,7 @@ Keybindings::Controller::Controller() { action_group_hidden_ = Gtk::ActionGroup::create(); ui_manager_hidden_ = Gtk::UIManager::create(); } -Keybindings::Controller::~Controller(){ +Keybindings::Controller::~Controller() { } void Keybindings::Controller::BuildMenu() { try { diff --git a/juci/menu.cc b/juci/menu.cc index be004ca..8f7bd15 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -4,10 +4,9 @@ Menu::View::View(Gtk::Orientation orientation) : view_(orientation) { Gtk::MenuBar menutest; view_.pack_end(menutest); - } Gtk::Box &Menu::View::view( - Glib::RefPtr ui_manager) { + Glib::RefPtr ui_manager) { view_.pack_start(*ui_manager->get_widget("/MenuBar"), Gtk::PACK_SHRINK); return view_; } @@ -15,48 +14,46 @@ Gtk::Box &Menu::View::view( Menu::Controller::Controller(Keybindings::Controller& keybindings) : menu_view_(Gtk::ORIENTATION_VERTICAL), keybindings_(keybindings) { - keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", - Gtk::Stock::OPEN), - [this]() { - OnFileOpenFile(); - }); + keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew", + Gtk::Stock::FILE)); + keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", - "Open folder"), - [this]() { - OnFileOpenFolder(); - }); + "Open folder"), + [this]() { + OnFileOpenFolder(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu", - Gtk::Stock::EDIT)); + Gtk::Stock::EDIT)); keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", - "_Window")); + "_Window")); keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow", - "Split window"), - Gtk::AccelKey("S"), - [this]() { - OnWindowSplitWindow(); - }); + "Split window"), + Gtk::AccelKey("S"), + [this]() { + OnWindowSplitWindow(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu", - "_Plugins")); + "_Plugins")); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet", - "Snippet")); + "Snippet")); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet", - "Add snippet"), - Gtk::AccelKey("space"), - [this]() { - OnPluginAddSnippet(); - }); + "Add snippet"), + Gtk::AccelKey("space"), + [this]() { + OnPluginAddSnippet(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu", - Gtk::Stock::HELP)); + Gtk::Stock::HELP)); keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout", - Gtk::Stock::ABOUT), - [this]() { - OnHelpAbout(); - }); + Gtk::Stock::ABOUT), + [this]() { + OnHelpAbout(); + }); keybindings_.action_group_hidden()->add(Gtk::Action::create("Test"), - Gtk::AccelKey("K"), - [this]() { - OnHelpAbout(); - }); + Gtk::AccelKey("K"), + [this]() { + OnHelpAbout(); + }); keybindings_.BuildMenu(); keybindings_.BuildHiddenMenu(); } // Controller diff --git a/juci/notebook.cc b/juci/notebook.cc index 93cf561..cad945d 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -108,7 +108,7 @@ void Notebook::Controller::OnFileNewHeaderFile() { entry_.OnShowSetFilenName(".h"); } void Notebook::Controller::OnEditCopy() { - if(view_.notebook().get_n_pages()!=0){ + if (view_.notebook().get_n_pages() != 0) { int source_pos = view_.notebook().get_current_page(); Glib::RefPtr buffer = source_vec_.at(source_pos) ->view().get_buffer(); @@ -116,7 +116,7 @@ void Notebook::Controller::OnEditCopy() { } } void Notebook::Controller::OnEditPaste() { - if(view_.notebook().get_n_pages()!=0){ + if (view_.notebook().get_n_pages() != 0) { int source_pos = view_.notebook().get_current_page(); Glib::RefPtr buffer = source_vec_.at(source_pos) ->view().get_buffer(); @@ -124,7 +124,7 @@ void Notebook::Controller::OnEditPaste() { } } void Notebook::Controller::OnEditCut() { - if(view_.notebook().get_n_pages()!=0){ + if (view_.notebook().get_n_pages() != 0) { int source_pos = view_.notebook().get_current_page(); Glib::RefPtr buffer = source_vec_.at(source_pos) ->view().get_buffer(); @@ -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()); source_vec_.push_back(new Source::Controller); scrolledwindow_vec_.back()->add(source_vec_.back()->view()); - source_vec_.back()->view().get_buffer()->set_text(content); - view_.notebook().append_page(*scrolledwindow_vec_.back(), name); + source_vec_.back()->OnOpenFile(filename); + view_.notebook().append_page(*scrolledwindow_vec_.back(), filename); view_.notebook().show_all_children(); view_.notebook().set_focus_child(*scrolledwindow_vec_.back()); view_.notebook().set_current_page(view_.notebook().get_n_pages()-1); diff --git a/juci/notebook.h b/juci/notebook.h index 7afb31f..7dfe02f 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -11,7 +11,7 @@ namespace Notebook { public: View(); Gtk::Box& view(); - Gtk::Notebook& notebook(){return notebook_;} + Gtk::Notebook& notebook() { return notebook_; } protected: Gtk::Box view_; Gtk::Notebook notebook_; @@ -23,6 +23,7 @@ namespace Notebook { Gtk::Box& entry_view(); void OnNewPage(std::string name); void OnCloseCurrentPage(); + void OnOpenFile(std::string filename); private: View view_; Entry::Controller entry_; @@ -36,7 +37,6 @@ namespace Notebook { void OnEditCopy(); void OnEditPaste(); void OnEditCut(); - void OnOpenFile(std::string name, std::string content); }; // class controller } // namespace Notebook diff --git a/juci/source.cc b/juci/source.cc index e813fd9..7b12dc1 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -14,6 +14,7 @@ Source::View::View() { // returns the new line string Source::View::UpdateLine() { 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 return ""; } @@ -41,9 +42,18 @@ void Source::View::OnOpenFile(std::vector &locations, int linum = loc.line_number(); int begin = loc.begin(); 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, end)); + // std::cout << "This is a ans" << std::endl; } } // Source::View::Theme::tagtable() @@ -52,11 +62,27 @@ const std::unordered_map& Source::Theme::tagtable() const { return tagtable_; } +// Source::View::Theme::tagtable() +// returns a const refrence to the tagtable +const std::unordered_map& Source::Theme::typetable() const { + return typetable_; +} + void Source::Theme::InsertTag(const string &key, const string &value) { tagtable_[key] = value; } // Source::View::Theme::SetTagTable() // sets the tagtable for the view +void Source::Theme::SetTypeTable( + const std::unordered_map &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( const std::unordered_map &tagtable) { tagtable_ = tagtable; @@ -75,6 +101,11 @@ Source::Model::Model() : for (auto &pi : props) { if (i.first.compare("syntax")) { // checks the config-file theme_.InsertTag(pi.first, pi.second.get_value()); + // std::cout << "inserting tag. " << pi.first << pi.second.get_value() << std::endl; + } + if (i.first.compare("colors")) { // checks the config-file + theme_.InsertType(pi.first, pi.second.get_value()); + // std::cout << "inserting type. " << pi.first << pi.second.get_value() << std::endl; } } } diff --git a/juci/source.h b/juci/source.h index 888db11..8b7011f 100644 --- a/juci/source.h +++ b/juci/source.h @@ -13,10 +13,15 @@ namespace Source { class Theme { public: const std::unordered_map& tagtable() const; + const std::unordered_map& typetable() const; void SetTagTable(const std::unordered_map &tagtable); void InsertTag(const string &key, const string &value); + void SetTypeTable(const std::unordered_map &tagtable); + void InsertType(const string &key, const string &value); + private: std::unordered_map tagtable_; + std::unordered_map typetable_; string background_; }; // class Theme diff --git a/juci/window.cc b/juci/window.cc index 2e3942d..5db176e 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -62,11 +62,9 @@ void Window::OnOpenFile() { switch (result) { case(Gtk::RESPONSE_OK): { std::cout << "Open clicked." << std::endl; - std::string path = dialog.get_filename(); std::cout << "File selected: " << path << std::endl; - Source::Controller sourcefile; - notebook_.OnOpenFile(path, sourcefile.OnOpenFile(path)); + notebook_.OnOpenFile(path); break; } case(Gtk::RESPONSE_CANCEL): {