From 8284464c537b83b7d9db9a9d0df45292fd245308 Mon Sep 17 00:00:00 2001 From: tedjk Date: Tue, 24 Mar 2015 09:20:44 +0100 Subject: [PATCH 01/12] some minor --- juci/api.cc | 4 ++-- juci/keybindings.cc | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/juci/api.cc b/juci/api.cc index acee2cb..ae7534a 100644 --- a/juci/api.cc +++ b/juci/api.cc @@ -205,13 +205,13 @@ Glib::RefPtr libjuci::BufferFromNotebook() { // int i = 0; // while (!PluginApi::notebook_->source_vec_.at(i)->view().has_focus()) { // i++; - //while(!PluginApi::notebook_->CurrentTextView().has_focus()) { + // while(!PluginApi::notebook_->CurrentTextView().has_focus()) { // i++; // } return Glib::RefPtr(PluginApi::notebook_ // ->source_vec_.at(i) // ->view().get_buffer()); - ->CurrentTextView().get_buffer()); + ->CurrentTextView().get_buffer()); } Gtk::TextIter libjuci::IterFromNotebook() { diff --git a/juci/keybindings.cc b/juci/keybindings.cc index b7b8a36..2408155 100644 --- a/juci/keybindings.cc +++ b/juci/keybindings.cc @@ -50,8 +50,7 @@ Keybindings::Config::Config(Keybindings::Config &original) { Keybindings::Config::Config() { menu_xml_ = ""; - std::unordered_map key_map(); -} + } void Keybindings::Config::AppendXml(std::string &child) { menu_xml_ += child; From 64508d0ee4b4aa369c15131961db8291628a2755 Mon Sep 17 00:00:00 2001 From: oyvang Date: Tue, 24 Mar 2015 14:39:18 +0100 Subject: [PATCH 02/12] Fully working linenumbers --- juci/api.cc | 1 - juci/juci.cc | 2 +- juci/notebook.cc | 99 ++++++++++++++++++++---------------------------- juci/notebook.h | 4 ++ 4 files changed, 46 insertions(+), 60 deletions(-) diff --git a/juci/api.cc b/juci/api.cc index 995d344..83745cc 100644 --- a/juci/api.cc +++ b/juci/api.cc @@ -1,4 +1,3 @@ - #include "api.h" Menu::Controller* PluginApi::menu_; diff --git a/juci/juci.cc b/juci/juci.cc index 84b1e6f..b2afc98 100644 --- a/juci/juci.cc +++ b/juci/juci.cc @@ -1,11 +1,11 @@ #include "window.h" - int main(int argc, char *argv[]) { Glib::RefPtr app = Gtk::Application::create( argc, argv, "no.sout.juci"); + Window window; //api::LoadPlugin("juci_api_test"); diff --git a/juci/notebook.cc b/juci/notebook.cc index bdc0c30..63e3759 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -1,10 +1,12 @@ - +#include #include "notebook.h" + + Notebook::Model::Model() { cc_extension_ = ".cc"; h_extension_ = ".h"; - scrollvalue_ = 20; + scrollvalue_ = 50; }; Notebook::View::View(){ view_.pack_start(notebook_); @@ -94,13 +96,6 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings) { [this]() { Search(false); }); - - text_vec_.back()->view(). - signal_scroll_event().connect(sigc::mem_fun( - this, - &Notebook::Controller:: - scroll_event_callback)); - }//Constructor @@ -116,19 +111,14 @@ bool Notebook::Controller::scroll_event_callback(GdkEventScroll* scroll_event) { get_vscrollbar()->get_adjustment(); if ( direction_y != 0 ) { + int dir_val = direction_y==-1?-model_.scrollvalue_:+model_.scrollvalue_; adj->set_value(adj->get_value()+dir_val); text_vec_.at(page)->view().set_vadjustment(adj); linenumbers_vec_.at(page)->view().set_vadjustment(adj); } - if ( direction_x != 0 ) { - int dir_val = direction_x==-1?-model_.scrollvalue_:+model_.scrollvalue_; - adj->set_value(adj->get_value()+dir_val); - text_vec_.at(page)->view().set_hadjustment(adj); - } return true; } - Notebook::Controller::~Controller() { for (auto &i : text_vec_) delete i; for (auto &i : linenumbers_vec_) delete i; @@ -144,9 +134,9 @@ Gtk::Box& Notebook::Controller::entry_view() { return entry_.view(); } - void Notebook::Controller::OnNewPage(std::string name) { OnCreatePage(); + std::cout << "oppretta pages" << std::endl; text_vec_.back()->OnNewEmptyFile(); Notebook().append_page(*editor_vec_.back(), name); @@ -163,21 +153,19 @@ void Notebook::Controller::OnOpenFile(std::string path) { Notebook().show_all_children(); Notebook().set_current_page(Pages()-1); Notebook().set_focus_child(text_vec_.back()->view()); + lines = Buffer(linenumbers_vec_.back())->get_text(); OnBufferChange(); } void Notebook::Controller::OnCreatePage(){ text_vec_.push_back(new Source::Controller); - std::string temp = "TEXT "; - temp += text_vec_.size(); - text_vec_.back()->view().set_name(temp); linenumbers_vec_.push_back(new Source::Controller); scrolledline_vec_.push_back(new Gtk::ScrolledWindow()); scrolledtext_vec_.push_back(new Gtk::ScrolledWindow()); editor_vec_.push_back(new Gtk::HBox()); scrolledtext_vec_.back()->add(text_vec_.back()->view()); scrolledline_vec_.back()->add(linenumbers_vec_.back()->view()); - linenumbers_vec_.back()->view().get_buffer()->set_text("1 \n"); + linenumbers_vec_.back()->view().get_buffer()->set_text("1 "); linenumbers_vec_.back()->view().override_color(Gdk::RGBA("Black")); linenumbers_vec_.back()-> view().set_justification(Gtk::Justification::JUSTIFY_RIGHT); @@ -186,6 +174,7 @@ void Notebook::Controller::OnCreatePage(){ linenumbers_vec_.back()->view().set_sensitive(false); editor_vec_.back()->pack_start(*scrolledline_vec_.back(),false,false); editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true); + BufferChangeHandler(text_vec_.back()->view().get_buffer()); } @@ -267,7 +256,7 @@ void Notebook::Controller::Search(bool forward){ if ( !forward ) { if ( search_match_start_ == 0 || - search_match_start_.get_line_offset() == 0) { + search_match_start_.get_line_offset() == 0) { search_match_start_= Buffer(text_vec_.at(CurrentPage()))->end(); } search_match_start_. @@ -288,42 +277,35 @@ void Notebook::Controller::Search(bool forward){ search_match_end_); } } -void Notebook::Controller::OnBufferChange() { - int page = CurrentPage(); - int line_nr = Buffer(text_vec_.at(page))->get_line_count(); - - Glib::RefPtr - mark = Gtk::TextBuffer::Mark::create(); - Glib::RefPtr - mark_lines = Gtk::TextBuffer::Mark::create(); - if(Buffer(text_vec_.at(page))->get_insert()->get_iter().starts_line() && - Buffer(text_vec_.at(page))->get_insert()->get_iter().get_line() == - Buffer(text_vec_.at(page))->end().get_line()) { - std::string lines ="1 "; - for ( int it = 2; it <= line_nr; ++it ) { - lines.append("\n"+ std::to_string(it)+" "); - } - Buffer(linenumbers_vec_.at(page))->set_text(lines); - - Buffer(text_vec_.at(page))-> - add_mark( - mark, - Buffer(text_vec_.at(page))->end()); - Buffer(linenumbers_vec_.at(page))-> - add_mark( - mark_lines, - Buffer(linenumbers_vec_.at(page))->end()); - - text_vec_.at(page)->view().scroll_to(mark); - linenumbers_vec_.at(page)->view().scroll_to(mark_lines); - }else{ - Buffer(text_vec_.at(page))-> - add_mark( - mark, - Buffer(text_vec_.at(page))-> - get_insert()->get_iter()); - } +void Notebook::Controller::OnBufferChange() { + int page = CurrentPage(); + int text_nr = Buffer(text_vec_.at(page))->get_line_count(); + int line_nr = Buffer(linenumbers_vec_.at(page))->get_line_count(); + while (line_nr < text_nr ){ + line_nr++; + Buffer(linenumbers_vec_.at(page))-> + insert(Buffer(linenumbers_vec_.at(page))->end(), + "\n"+std::to_string(line_nr)+" "); + } + while (line_nr > text_nr ){ + Gtk::TextIter iter = Buffer(linenumbers_vec_.at(page))->get_iter_at_line(line_nr); + iter.backward_char(); + line_nr--; + Buffer(linenumbers_vec_.at(page))-> + erase(iter, + Buffer(linenumbers_vec_.at(page))->end()); + } + if(Buffer(text_vec_.at(page))->get_insert()->get_iter().starts_line() && + Buffer(text_vec_.at(page))->get_insert()->get_iter().get_line() == + Buffer(text_vec_.at(page))->end().get_line()) { + + GdkEventScroll* scroll = new GdkEventScroll; + scroll->delta_y = 1.0; + scroll->delta_x = 0.0; + scroll_event_callback(scroll); + delete scroll; + } } @@ -350,7 +332,8 @@ Gtk::Notebook& Notebook::Controller::Notebook() { void Notebook::Controller::BufferChangeHandler(Glib::RefPtr buffer) { buffer->signal_changed().connect( - [this]() { - OnBufferChange(); + [this]() { + OnBufferChange(); }); } + diff --git a/juci/notebook.h b/juci/notebook.h index ccfdbb6..e95e0a0 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -65,10 +65,14 @@ namespace Notebook { Gtk::TextIter search_match_end_; Gtk::TextIter search_match_start_; Glib::RefPtr refClipboard_; + std::string + lines="1 "; }; // class controller } // namespace Notebook + + #endif // JUCI_NOTEBOOK_H_ From df6cc6136d5b1c0d8f6395d2e902f93af974fe8c Mon Sep 17 00:00:00 2001 From: tedjk Date: Thu, 9 Apr 2015 15:55:45 +0200 Subject: [PATCH 03/12] added project structure box to the left of the window --- juci/CMakeLists.txt | 4 +- juci/config.json | 3 +- juci/directories.cc | 107 ++++++++++++++++++++++++++++++++++++++++++++ juci/directories.h | 57 +++++++++++++++++++++++ juci/menu.cc | 10 ----- juci/notebook.cc | 10 +++-- juci/notebook.h | 10 +++-- juci/window.cc | 66 ++++++++++++++++++++++++++- juci/window.h | 9 ++++ 9 files changed, 257 insertions(+), 19 deletions(-) create mode 100644 juci/directories.cc create mode 100644 juci/directories.h diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index d4f326d..2f3755a 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -52,7 +52,7 @@ endif() #Boost_INCLUDE_DIRS - Boost include directories #Boost_LIBRARY_DIRS - Link directories for Boost libraries #Boost_LIBRARIES - Boost component libraries to be linked -find_package(Boost 1.5 REQUIRED COMPONENTS python timer system) +find_package(Boost 1.5 REQUIRED COMPONENTS python timer system filesystem) #If boost is not found if(${Boost_FOUND}) @@ -104,6 +104,8 @@ add_executable(${project_name} notebook.h entry.h entry.cc + directories.h + directories.cc ) add_library(${module} SHARED diff --git a/juci/config.json b/juci/config.json index 9f24e39..afc983d 100644 --- a/juci/config.json +++ b/juci/config.json @@ -22,7 +22,8 @@ "split_window": "s", "new_h_file": "h", "new_cc_file": "c", - "close_tab": "w" + "close_tab": "w", + "open_folder": "o" }, "example": { "key": "value", diff --git a/juci/directories.cc b/juci/directories.cc new file mode 100644 index 0000000..3d40a0b --- /dev/null +++ b/juci/directories.cc @@ -0,0 +1,107 @@ +#include "directories.h" + +Directories::Controller::Controller() { + + m_ScrolledWindow.add(m_TreeView); + m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); +} + +bool Directories::Controller::open_folder(const boost::filesystem::path& dir_path) { + m_refTreeModel = Gtk::TreeStore::create(view()); + m_TreeView.set_model(m_refTreeModel); + m_TreeView.remove_all_columns(); + std::string project_name = get_project_name(dir_path); + m_TreeView.append_column(project_name, view().m_col_name); + int row_id = 0; + Gtk::TreeModel::Row row; + std::string col_id("a"+dir_path.filename().string()); + list_dirs(dir_path, row, row_id); + m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING); +} + +bool Directories::Controller::list_dirs( const boost::filesystem::path& dir_path, + Gtk::TreeModel::Row &parent, + unsigned row_id) { + boost::filesystem::directory_iterator end_itr; + unsigned dir_counter = row_id; + unsigned file_counter = 0; + Gtk::TreeModel::Row child; + Gtk::TreeModel::Row row; + + //Fill the TreeView's model + for ( boost::filesystem::directory_iterator itr( dir_path ); + itr != end_itr; + ++itr ) { + if (boost::filesystem::is_directory(itr->status()) ) { + if (count(itr->path().string()) > count(dir_path.string())) { + child = *(m_refTreeModel->append(parent.children())); + std::string col_id("a"+itr->path().filename().string()); + child[view().m_col_id] = col_id; + child[view().m_col_name] = itr->path().filename().string(); + child[view().m_col_path] = itr->path().string(); + list_dirs(itr->path(), child, row_id); + } else { + row = *(m_refTreeModel->append()); + std::string col_id("a"+itr->path().filename().string()); + row[view().m_col_path] = itr->path().string(); + row[view().m_col_id] = col_id; + row[view().m_col_name] = itr->path().filename().string(); + list_dirs(itr->path(), parent, row_id); + } + } else { // is a file + child = *(m_refTreeModel->append(parent.children())); + std::string col_id("b"+itr->path().filename().string()); + child[view().m_col_id] = col_id; + child[view().m_col_name] = itr->path().filename().string(); + child[view().m_col_path] = itr->path().string(); + } + } +} +int Directories::Controller::count(const std::string path) { + int count = 0; + + for (int i = 0; i < path.size(); i++) + if (path[i] == '/') count++; + return count; +} +std::string Directories::Controller::get_project_name(const boost::filesystem::path& dir_path) { + std::string project_name; + std::string project_name_var; + boost::filesystem::directory_iterator end_itr; + + + for (boost::filesystem::directory_iterator itr( dir_path ); + itr != end_itr; + ++itr ) { + std::cout << "not cmakelists.txt" << itr->path().string() << std::endl; + if(itr->path().filename().string() == "CMakeLists.txt"){ + std::cout << "found cmakeliksts.txt" << std::endl; + std::ifstream ifs(itr->path().string()); + std::string line; + while(std::getline(ifs, line)) { + if(line.find("project(", 0) != std::string::npos + || line.find("project (", 0) != std::string::npos ) { + std::cout << "found the variabel for project name: "<< line << std::endl; + size_t variabel_start = line.find("{",0 ); + size_t variabel_end = line.find("}",variabel_start); + project_name_var = line.substr(variabel_start+1, (variabel_end)-variabel_start-1); + std::cout << "it is: "<< project_name_var << std::endl; + break; + } + } + std::ifstream ifs2(itr->path().string()); + while(std::getline(ifs2, line)) { + if(line.find("set("+project_name_var, 0) != std::string::npos) { + std::cout << "the variabel value for project name: " << line << std::endl; + size_t variabel_start = line.find(project_name_var,0) +project_name_var.length(); + size_t variabel_end = line.find(")",variabel_start); + project_name = line.substr(variabel_start, variabel_end-variabel_start); + return project_name; + } + } + break; + } + } + return "no project name"; +} + diff --git a/juci/directories.h b/juci/directories.h new file mode 100644 index 0000000..0c7f9bc --- /dev/null +++ b/juci/directories.h @@ -0,0 +1,57 @@ +#ifndef JUCI_DIRECTIRIES_H_ +#define JUCI_DIRECTIRIES_H_ + +#include +#include +#include "boost/filesystem.hpp" +#include +#include + +namespace Directories { + class View : public Gtk::TreeModel::ColumnRecord { + public: + View() { + add(m_col_id); + add(m_col_name); + add(m_col_path); + } + Gtk::TreeModelColumn m_col_id; + Gtk::TreeModelColumn m_col_name; + Gtk::TreeModelColumn m_col_path; + }; + + class Model { + }; + class Controller { + + public: + Controller(); + View& view() { return view_;}; + Model& model() { return model_;}; + + Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;}; + bool open_folder( const boost::filesystem::path& dir_path); + bool list_dirs( const boost::filesystem::path& dir_path, + Gtk::TreeModel::Row &row, unsigned depth); + std::string get_project_name(const boost::filesystem::path& dir_path); + int count( const std::string path); + + //Child widgets: + Gtk::Box m_VBox; + + Gtk::ScrolledWindow m_ScrolledWindow; + Gtk::TreeView m_TreeView; + Glib::RefPtr m_refTreeModel; + + + private: + View view_; + Model model_; + + protected: + void on_treeview_row_activated(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column); + }; +} + +#endif // JUCI_DIRECTIRIES_H_ diff --git a/juci/menu.cc b/juci/menu.cc index e3e0368..880d7df 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -16,12 +16,6 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) : keybindings_(keybindings) { 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(); - }); keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu", Gtk::Stock::EDIT)); keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", @@ -62,10 +56,6 @@ void Menu::Controller::OnFileOpenFile() { std::cout << "Open file clicked" << std::endl; //TODO(Oyvang) Legg til funksjon } -void Menu::Controller::OnFileOpenFolder() { - std::cout << "Open folder clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} void Menu::Controller::OnEditCut() { std::cout << "Clicked cut" << std::endl; //TODO(Oyvang) Legg til funksjon diff --git a/juci/notebook.cc b/juci/notebook.cc index 675b8d4..7ae7bf5 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -10,7 +10,8 @@ Notebook::Model::Model() { }; Notebook::View::View(){ - view_.pack_start(notebook_); + view_.pack2(notebook_); + view_.set_position(120); } Notebook::Controller::Controller(Keybindings::Controller& keybindings, @@ -20,6 +21,7 @@ source_config_(source_cfg) { refClipboard_ = Gtk::Clipboard::get(); keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", Gtk::Stock::FILE)); + view_.view().pack1(directories_.widget(), true, true); /* File->New files */ keybindings.action_group_menu()->add(Gtk::Action::create("FileNewStandard", @@ -46,6 +48,7 @@ source_config_(source_cfg) { is_new_file_ = true; OnFileNewHeaderFile(); }); + keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", "Close tab"), Gtk::AccelKey(keybindings.config_ @@ -132,7 +135,7 @@ Notebook::Controller::~Controller() { for (auto &i : scrolledline_vec_) delete i; } -Gtk::HBox& Notebook::Controller::view() { +Gtk::Paned& Notebook::Controller::view() { return view_.view(); } Gtk::Box& Notebook::Controller::entry_view() { @@ -156,7 +159,9 @@ void Notebook::Controller::OnOpenFile(std::string path) { unsigned pos = path.find_last_of("/\\"); Notebook().append_page(*editor_vec_.back(), path.substr(pos+1)); Notebook().show_all_children(); + std::cout << "setting current page"<< std::endl; Notebook().set_current_page(Pages()-1); + std::cout << "current page set" << std::endl; Notebook().set_focus_child(text_vec_.back()->view()); OnBufferChange(); } @@ -178,7 +183,6 @@ void Notebook::Controller::OnCreatePage(){ linenumbers_vec_.back()->view().set_sensitive(false); editor_vec_.back()->pack_start(*scrolledline_vec_.back(),false,false); editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true); - BufferChangeHandler(text_vec_.back()->view().get_buffer()); } diff --git a/juci/notebook.h b/juci/notebook.h index e05dfbc..84c2591 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -5,6 +5,7 @@ #include "gtkmm.h" #include "entry.h" #include "source.h" +#include "directories.h" namespace Notebook { class Model { @@ -17,10 +18,10 @@ namespace Notebook { class View { public: View(); - Gtk::HBox& view() {return view_;} + Gtk::Paned& view() {return view_;} Gtk::Notebook& notebook() {return notebook_; } protected: - Gtk::HBox view_; + Gtk::Paned view_; Gtk::Notebook notebook_; }; class Controller { @@ -44,18 +45,21 @@ namespace Notebook { void OnFileNewCCFile(); void OnFileNewEmptyfile(); void OnFileNewHeaderFile(); + void OnFileOpenFolder(); void OnNewPage(std::string name); void OnOpenFile(std::string filename); void OnCreatePage(); bool scroll_event_callback(GdkEventScroll* scroll_event); int Pages(); - Gtk::HBox& view(); + Directories::Controller& directories() { return directories_; } + Gtk::Paned& view(); void Search(bool forward); const Source::Config& source_config() { return source_config_; } protected: void BufferChangeHandler(Glib::RefPtr buffer); private: Source::Config source_config_; + Directories::Controller directories_; View view_; Model model_; bool is_new_file_; diff --git a/juci/window.cc b/juci/window.cc index 8e96e9c..a1fb705 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -9,7 +9,6 @@ Window::Window() : set_title("juCi++"); set_default_size(600, 400); add(window_box_); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), [this]() { @@ -20,6 +19,17 @@ Window::Window() : [this]() { OnOpenFile(); }); + keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", + "Open folder"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["open_folder"]), + [this]() { + OnFileOpenFolder(); + }); + + notebook_.directories().m_TreeView.signal_row_activated() + .connect(sigc::mem_fun(*this, + &Window::OnDirectoryNavigation)); PluginApi::menu_ = &menu_; PluginApi::notebook_ = ¬ebook_; PluginApi::InitPlugins(); @@ -31,13 +41,67 @@ Window::Window() : window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.view()); + show_all_children(); } // Window constructor void Window::OnWindowHide() { hide(); } +void Window::OnFileOpenFolder() { + Gtk::FileChooserDialog dialog("Please choose a folder", + Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); + + dialog.set_transient_for(*this); + //Add response buttons the the dialog: + dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL); + dialog.add_button("Select", Gtk::RESPONSE_OK); + + int result = dialog.run(); + + //Handle the response: + switch(result) + { + case(Gtk::RESPONSE_OK): + { + std::cout << "Folder selected: " << dialog.get_filename() + << std::endl; + notebook_.directories().open_folder(dialog.get_filename()); + break; + } + case(Gtk::RESPONSE_CANCEL): + { + std::cout << "Cancel clicked." << std::endl; + break; + } + default: + { + std::cout << "Unexpected button clicked." << std::endl; + break; + } + } +} +void Window::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column) { + Gtk::TreeModel::iterator iter = notebook_.directories().m_refTreeModel->get_iter(path); + if(iter) { + Gtk::TreeModel::Row row = *iter; + boost::filesystem::path fs_path(Glib::ustring(row[notebook_.directories().view().m_col_path])); + if(boost::filesystem::is_directory(fs_path)) { + std::cout << "Expand folder: " << row[notebook_.directories().view().m_col_path] << std::endl; + notebook_.directories().m_TreeView.row_expanded(path) ? + notebook_.directories().m_TreeView.collapse_row(path) : + notebook_.directories().m_TreeView.expand_row(path, false); + } else { + std::stringstream sstm; + sstm << row[notebook_.directories().view().m_col_path]; + std::string file = sstm.str(); + std::cout << "open file: "<< row[notebook_.directories().view().m_col_path] << std::endl; + notebook_.OnOpenFile(file); + } + } +} void Window::OnOpenFile() { Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN); diff --git a/juci/window.h b/juci/window.h index c95e632..f3a00fa 100644 --- a/juci/window.h +++ b/juci/window.h @@ -4,6 +4,7 @@ #include "api.h" #include "config.h" #include +#include "directories.h" class Window : public Gtk::Window { @@ -11,17 +12,25 @@ 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_; + + Keybindings::Controller& keybindings() { return keybindings_; } private: //signal handlers void OnWindowHide(); void OnOpenFile(); + void OnFileOpenFolder(); + void OnDirectoryNavigation(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column); }; #endif // JUCI_WINDOW_H From 3e156797056778d065d616dcb490ecd358749b89 Mon Sep 17 00:00:00 2001 From: tedjk Date: Fri, 10 Apr 2015 10:39:46 +0200 Subject: [PATCH 04/12] moved directory signal functions to notebook from window --- juci/notebook.cc | 25 ++++++++++++++++++++++++- juci/notebook.h | 2 ++ juci/window.cc | 25 +------------------------ juci/window.h | 3 +-- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 7ae7bf5..4c57857 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -104,6 +104,9 @@ source_config_(source_cfg) { [this]() { Search(false); }); + directories().m_TreeView.signal_row_activated() + .connect(sigc::mem_fun(*this, + &Notebook::Controller::OnDirectoryNavigation)); }//Constructor @@ -315,7 +318,27 @@ void Notebook::Controller::OnBufferChange() { delete scroll; } } - +void Notebook::Controller::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column) { + Gtk::TreeModel::iterator iter = directories().m_refTreeModel->get_iter(path); + if(iter) { + Gtk::TreeModel::Row row = *iter; + boost::filesystem::path fs_path(Glib::ustring(row[directories() + .view().m_col_path])); + if (boost::filesystem::is_directory(fs_path)) { + std::cout << "Expand folder: " << row[directories().view().m_col_path] << std::endl; + directories().m_TreeView.row_expanded(path) ? + directories().m_TreeView.collapse_row(path) : + directories().m_TreeView.expand_row(path, false); + } else { + std::stringstream sstm; + sstm << row[directories().view().m_col_path]; + std::string file = sstm.str(); + std::cout << "open file: "<< row[directories().view().m_col_path] << std::endl; + OnOpenFile(file); + } + } +} Gtk::TextView& Notebook::Controller::CurrentTextView() { return text_vec_.at(CurrentPage())->view(); diff --git a/juci/notebook.h b/juci/notebook.h index 84c2591..3b77beb 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -46,6 +46,8 @@ namespace Notebook { void OnFileNewEmptyfile(); void OnFileNewHeaderFile(); void OnFileOpenFolder(); + void OnDirectoryNavigation(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column); void OnNewPage(std::string name); void OnOpenFile(std::string filename); void OnCreatePage(); diff --git a/juci/window.cc b/juci/window.cc index a1fb705..99485c2 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -26,10 +26,6 @@ Window::Window() : [this]() { OnFileOpenFolder(); }); - - notebook_.directories().m_TreeView.signal_row_activated() - .connect(sigc::mem_fun(*this, - &Window::OnDirectoryNavigation)); PluginApi::menu_ = &menu_; PluginApi::notebook_ = ¬ebook_; PluginApi::InitPlugins(); @@ -82,26 +78,7 @@ void Window::OnFileOpenFolder() { } } -void Window::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* column) { - Gtk::TreeModel::iterator iter = notebook_.directories().m_refTreeModel->get_iter(path); - if(iter) { - Gtk::TreeModel::Row row = *iter; - boost::filesystem::path fs_path(Glib::ustring(row[notebook_.directories().view().m_col_path])); - if(boost::filesystem::is_directory(fs_path)) { - std::cout << "Expand folder: " << row[notebook_.directories().view().m_col_path] << std::endl; - notebook_.directories().m_TreeView.row_expanded(path) ? - notebook_.directories().m_TreeView.collapse_row(path) : - notebook_.directories().m_TreeView.expand_row(path, false); - } else { - std::stringstream sstm; - sstm << row[notebook_.directories().view().m_col_path]; - std::string file = sstm.str(); - std::cout << "open file: "<< row[notebook_.directories().view().m_col_path] << std::endl; - notebook_.OnOpenFile(file); - } - } -} + void Window::OnOpenFile() { Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN); diff --git a/juci/window.h b/juci/window.h index f3a00fa..2b79755 100644 --- a/juci/window.h +++ b/juci/window.h @@ -29,8 +29,7 @@ public: void OnWindowHide(); void OnOpenFile(); void OnFileOpenFolder(); - void OnDirectoryNavigation(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* column); + }; #endif // JUCI_WINDOW_H From be3cdb1dc10a01b1b76e560f968ddb5432fdf971 Mon Sep 17 00:00:00 2001 From: tedjk Date: Fri, 10 Apr 2015 11:16:08 +0200 Subject: [PATCH 05/12] directories.h and .cc code cleanup --- juci/directories.cc | 58 +++++++++++++++++++++------------------------ juci/directories.h | 29 ++++++++++------------- juci/notebook.cc | 5 ++-- 3 files changed, 41 insertions(+), 51 deletions(-) diff --git a/juci/directories.cc b/juci/directories.cc index 3d40a0b..356f555 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -1,12 +1,12 @@ #include "directories.h" Directories::Controller::Controller() { - m_ScrolledWindow.add(m_TreeView); m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); } -bool Directories::Controller::open_folder(const boost::filesystem::path& dir_path) { +bool Directories::Controller:: +open_folder(const boost::filesystem::path& dir_path) { m_refTreeModel = Gtk::TreeStore::create(view()); m_TreeView.set_model(m_refTreeModel); m_TreeView.remove_all_columns(); @@ -14,25 +14,25 @@ bool Directories::Controller::open_folder(const boost::filesystem::path& dir_pat m_TreeView.append_column(project_name, view().m_col_name); int row_id = 0; Gtk::TreeModel::Row row; - std::string col_id("a"+dir_path.filename().string()); list_dirs(dir_path, row, row_id); m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING); } -bool Directories::Controller::list_dirs( const boost::filesystem::path& dir_path, - Gtk::TreeModel::Row &parent, - unsigned row_id) { +void Directories::Controller:: +list_dirs(const boost::filesystem::path& dir_path, + Gtk::TreeModel::Row &parent, + unsigned row_id) { boost::filesystem::directory_iterator end_itr; unsigned dir_counter = row_id; unsigned file_counter = 0; Gtk::TreeModel::Row child; Gtk::TreeModel::Row row; - //Fill the TreeView's model + // Fill the treeview for ( boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; ++itr ) { - if (boost::filesystem::is_directory(itr->status()) ) { + if (boost::filesystem::is_directory(itr->status())) { if (count(itr->path().string()) > count(dir_path.string())) { child = *(m_refTreeModel->append(parent.children())); std::string col_id("a"+itr->path().filename().string()); @@ -47,8 +47,8 @@ bool Directories::Controller::list_dirs( const boost::filesystem::path& dir_path row[view().m_col_id] = col_id; row[view().m_col_name] = itr->path().filename().string(); list_dirs(itr->path(), parent, row_id); - } - } else { // is a file + } + } else { // is a file child = *(m_refTreeModel->append(parent.children())); std::string col_id("b"+itr->path().filename().string()); child[view().m_col_id] = col_id; @@ -59,43 +59,39 @@ bool Directories::Controller::list_dirs( const boost::filesystem::path& dir_path } int Directories::Controller::count(const std::string path) { int count = 0; - for (int i = 0; i < path.size(); i++) if (path[i] == '/') count++; return count; } -std::string Directories::Controller::get_project_name(const boost::filesystem::path& dir_path) { +std::string Directories::Controller:: +get_project_name(const boost::filesystem::path& dir_path) { std::string project_name; std::string project_name_var; boost::filesystem::directory_iterator end_itr; - - for (boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; ++itr ) { - std::cout << "not cmakelists.txt" << itr->path().string() << std::endl; - if(itr->path().filename().string() == "CMakeLists.txt"){ - std::cout << "found cmakeliksts.txt" << std::endl; + if (itr->path().filename().string() == "CMakeLists.txt") { std::ifstream ifs(itr->path().string()); std::string line; - while(std::getline(ifs, line)) { - if(line.find("project(", 0) != std::string::npos - || line.find("project (", 0) != std::string::npos ) { - std::cout << "found the variabel for project name: "<< line << std::endl; - size_t variabel_start = line.find("{",0 ); - size_t variabel_end = line.find("}",variabel_start); - project_name_var = line.substr(variabel_start+1, (variabel_end)-variabel_start-1); - std::cout << "it is: "<< project_name_var << std::endl; + while (std::getline(ifs, line)) { + if (line.find("project(", 0) != std::string::npos + || line.find("project (", 0) != std::string::npos ) { + size_t variabel_start = line.find("{", 0); + size_t variabel_end = line.find("}", variabel_start); + project_name_var = line.substr(variabel_start+1, + (variabel_end)-variabel_start-1); break; } } std::ifstream ifs2(itr->path().string()); - while(std::getline(ifs2, line)) { - if(line.find("set("+project_name_var, 0) != std::string::npos) { - std::cout << "the variabel value for project name: " << line << std::endl; - size_t variabel_start = line.find(project_name_var,0) +project_name_var.length(); - size_t variabel_end = line.find(")",variabel_start); - project_name = line.substr(variabel_start, variabel_end-variabel_start); + while (std::getline(ifs2, line)) { + if (line.find("set("+project_name_var, 0) != std::string::npos) { + size_t variabel_start = line.find(project_name_var, 0) + +project_name_var.length(); + size_t variabel_end = line.find(")", variabel_start); + project_name = line.substr(variabel_start, + variabel_end-variabel_start); return project_name; } } diff --git a/juci/directories.h b/juci/directories.h index 0c7f9bc..c96605a 100644 --- a/juci/directories.h +++ b/juci/directories.h @@ -1,5 +1,5 @@ -#ifndef JUCI_DIRECTIRIES_H_ -#define JUCI_DIRECTIRIES_H_ +#ifndef JUCI_DIRECTORIES_H_ +#define JUCI_DIRECTORIES_H_ #include #include @@ -23,35 +23,30 @@ namespace Directories { class Model { }; class Controller { - public: Controller(); - View& view() { return view_;}; - Model& model() { return model_;}; + View& view() { return view_;} + Model& model() { return model_;} - Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;}; - bool open_folder( const boost::filesystem::path& dir_path); - bool list_dirs( const boost::filesystem::path& dir_path, + Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;} + bool open_folder (const boost::filesystem::path& dir_path); + void list_dirs (const boost::filesystem::path& dir_path, Gtk::TreeModel::Row &row, unsigned depth); std::string get_project_name(const boost::filesystem::path& dir_path); - int count( const std::string path); + int count (const std::string path); //Child widgets: Gtk::Box m_VBox; - Gtk::ScrolledWindow m_ScrolledWindow; Gtk::TreeView m_TreeView; Glib::RefPtr m_refTreeModel; - - private: View view_; Model model_; - protected: - void on_treeview_row_activated(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* column); + void on_treeview_row_activated(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column); }; -} +} // namespace Directories -#endif // JUCI_DIRECTIRIES_H_ +#endif // JUCI_DIRECTORIES_H_ diff --git a/juci/notebook.cc b/juci/notebook.cc index 4c57857..f2d745c 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -318,7 +318,8 @@ void Notebook::Controller::OnBufferChange() { delete scroll; } } -void Notebook::Controller::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, +void Notebook::Controller +::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) { Gtk::TreeModel::iterator iter = directories().m_refTreeModel->get_iter(path); if(iter) { @@ -326,7 +327,6 @@ void Notebook::Controller::OnDirectoryNavigation(const Gtk::TreeModel::Path& pat boost::filesystem::path fs_path(Glib::ustring(row[directories() .view().m_col_path])); if (boost::filesystem::is_directory(fs_path)) { - std::cout << "Expand folder: " << row[directories().view().m_col_path] << std::endl; directories().m_TreeView.row_expanded(path) ? directories().m_TreeView.collapse_row(path) : directories().m_TreeView.expand_row(path, false); @@ -334,7 +334,6 @@ void Notebook::Controller::OnDirectoryNavigation(const Gtk::TreeModel::Path& pat std::stringstream sstm; sstm << row[directories().view().m_col_path]; std::string file = sstm.str(); - std::cout << "open file: "<< row[directories().view().m_col_path] << std::endl; OnOpenFile(file); } } From 32729e7991f9051fd8797dd0bd8fd1256f311bce Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 13 Apr 2015 09:19:58 +0200 Subject: [PATCH 06/12] code cleanup --- juci/directories.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/juci/directories.cc b/juci/directories.cc index 356f555..ce11ccd 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -32,8 +32,9 @@ list_dirs(const boost::filesystem::path& dir_path, for ( boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; ++itr ) { - if (boost::filesystem::is_directory(itr->status())) { - if (count(itr->path().string()) > count(dir_path.string())) { + if (boost::filesystem::is_directory(itr->status()) + && itr->) { + if (count(itr->path().string()) > count(dir_path.string())) { // is child child = *(m_refTreeModel->append(parent.children())); std::string col_id("a"+itr->path().filename().string()); child[view().m_col_id] = col_id; From 7d6d7d6a928ac0bf41a34782de06be70e76053a7 Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 13 Apr 2015 09:28:51 +0200 Subject: [PATCH 07/12] made it work --- juci/directories.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/juci/directories.cc b/juci/directories.cc index ce11ccd..0366b35 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -32,8 +32,7 @@ list_dirs(const boost::filesystem::path& dir_path, for ( boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; ++itr ) { - if (boost::filesystem::is_directory(itr->status()) - && itr->) { + if (boost::filesystem::is_directory(itr->status())) { if (count(itr->path().string()) > count(dir_path.string())) { // is child child = *(m_refTreeModel->append(parent.children())); std::string col_id("a"+itr->path().filename().string()); From 4831d91445524c2d722eeb7dd2963e018cb43236 Mon Sep 17 00:00:00 2001 From: oyvang Date: Mon, 13 Apr 2015 13:06:47 +0200 Subject: [PATCH 08/12] fixed popup, known bug iterator gtkmm error on insert text to buffer --- juci/notebook.cc | 263 ++++++++++++++++++++++++++++++----------------- juci/notebook.h | 12 ++- 2 files changed, 177 insertions(+), 98 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 675b8d4..0cd8ae1 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -1,8 +1,5 @@ -#include #include "notebook.h" - - Notebook::Model::Model() { cc_extension_ = ".cc"; h_extension_ = ".h"; @@ -15,98 +12,159 @@ Notebook::View::View(){ Notebook::Controller::Controller(Keybindings::Controller& keybindings, Source::Config& source_cfg) : -source_config_(source_cfg) { + source_config_(source_cfg) { OnNewPage("juCi++"); refClipboard_ = Gtk::Clipboard::get(); - keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", - Gtk::Stock::FILE)); - /* File->New files */ + CreateKeybindings(keybindings); +}// Constructor - keybindings.action_group_menu()->add(Gtk::Action::create("FileNewStandard", - Gtk::Stock::NEW, - "New empty file", - "Create a new file"), - [this]() { - is_new_file_ = true; - OnFileNewEmptyfile(); - }); - keybindings.action_group_menu()->add(Gtk::Action::create("FileNewCC", - "New cc file"), - Gtk::AccelKey(keybindings.config_ - .key_map()["new_cc_file"]), - [this]() { - is_new_file_ = true; - OnFileNewCCFile(); - }); - keybindings.action_group_menu()->add(Gtk::Action::create("FileNewH", - "New h file"), - Gtk::AccelKey(keybindings.config_ - .key_map()["new_h_file"]), - [this]() { - is_new_file_ = true; - OnFileNewHeaderFile(); - }); - keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", - "Close tab"), - Gtk::AccelKey(keybindings.config_ - .key_map()["close_tab"]), - [this]() { - OnCloseCurrentPage(); - }); - keybindings.action_group_menu()->add(Gtk::Action::create("EditFind", - Gtk::Stock::FIND), - [this]() { - is_new_file_ = false; - OnEditSearch(); - //TODO(Oyvang, Zalox, Forgi)Create function OnEditFind(); - }); - keybindings.action_group_menu()->add(Gtk::Action::create("EditCopy", - Gtk::Stock::COPY), - [this]() { - OnEditCopy(); - }); - keybindings.action_group_menu()->add(Gtk::Action::create("EditCut", - Gtk::Stock::CUT), - [this]() { - OnEditCut(); - }); - keybindings.action_group_menu()->add(Gtk::Action::create("EditPaste", - Gtk::Stock::PASTE), - [this]() { - OnEditPaste(); - }); - entry_.view_.entry().signal_activate().connect( - [this]() { - if(is_new_file_){ - OnNewPage(entry_.text()); - entry_.OnHideEntries(is_new_file_); - }else{ - Search(true); - } - }); - entry_.button_apply().signal_clicked().connect( - [this]() { - OnNewPage(entry_.text()); - entry_.OnHideEntries(is_new_file_); - }); - entry_.button_close().signal_clicked().connect( - [this]() { - entry_.OnHideEntries(is_new_file_); - }); - entry_.button_next().signal_clicked().connect( - [this]() { - Search(true); - }); - entry_.button_prev().signal_clicked().connect( - [this]() { - Search(false); - }); - - -}//Constructor +void Notebook::Controller::CreateKeybindings(Keybindings::Controller + &keybindings){ + keybindings.action_group_menu()-> + add(Gtk::Action::create("FileMenu", + Gtk::Stock::FILE)); + + keybindings.action_group_menu()-> + add(Gtk::Action::create("FileNewStandard", + Gtk::Stock::NEW, + "New empty file", + "Create a new file"), + [this]() { + is_new_file_ = true; + OnFileNewEmptyfile(); + }); + keybindings.action_group_menu()-> + add(Gtk::Action::create("FileNewCC", + "New cc file"), + Gtk::AccelKey(keybindings.config_ + .key_map()["new_cc_file"]), + [this]() { + is_new_file_ = true; + OnFileNewCCFile(); + }); + keybindings.action_group_menu()-> + add(Gtk::Action::create("FileNewH", + "New h file"), + Gtk::AccelKey(keybindings.config_ + .key_map()["new_h_file"]), + [this]() { + is_new_file_ = true; + OnFileNewHeaderFile(); + }); + keybindings.action_group_menu()-> + add(Gtk::Action::create("WindowCloseTab", + "Close tab"), + Gtk::AccelKey(keybindings.config_ + .key_map()["close_tab"]), + [this]() { + OnCloseCurrentPage(); + }); + keybindings.action_group_menu()-> + add(Gtk::Action::create("EditFind", + Gtk::Stock::FIND), + [this]() { + is_new_file_ = false; + OnEditSearch(); + //TODO(Oyvang, Zalox, Forgi)Create function OnEditFind(); + }); + keybindings.action_group_menu()-> + add(Gtk::Action::create("EditCopy", + Gtk::Stock::COPY), + [this]() { + OnEditCopy(); + }); + keybindings.action_group_menu()-> + add(Gtk::Action::create("EditCut", + Gtk::Stock::CUT), + [this]() { + OnEditCut(); + }); + keybindings.action_group_menu()-> + add(Gtk::Action::create("EditPaste", + Gtk::Stock::PASTE), + [this]() { + OnEditPaste(); + }); + keybindings.action_group_hidden()-> + add(Gtk::Action::create("EditPaste", + Gtk::Stock::PASTE), + [this]() { + OnEditPaste(); + }); + entry_.view_.entry().signal_activate(). + connect( + [this]() { + if(is_new_file_){ + OnNewPage(entry_.text()); + entry_.OnHideEntries(is_new_file_); + }else{ + Search(true); + } + }); + entry_.button_apply().signal_clicked(). + connect( + [this]() { + OnNewPage(entry_.text()); + entry_.OnHideEntries(is_new_file_); + }); + entry_.button_close().signal_clicked(). + connect( + [this]() { + entry_.OnHideEntries(is_new_file_); + }); + entry_.button_next().signal_clicked(). + connect( + [this]() { + Search(true); + }); + entry_.button_prev().signal_clicked(). + connect( + [this]() { + Search(false); + }); +} + +void Notebook::Controller::GeneratePopup(std::vector items){ + Gtk::ScrolledWindow popup_scroll_; + Gtk::ListViewText listview_(1,false,Gtk::SelectionMode::SELECTION_SINGLE); + Gtk::Dialog popup_("",true); + listview_.set_enable_search(false); + listview_.set_hscroll_policy(Gtk::ScrollablePolicy::SCROLL_NATURAL); + listview_.set_activate_on_single_click(true); + listview_.signal_row_activated(). + connect([this, &listview_, &popup_](const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn*) { + std::string t = listview_.get_text(listview_.get_selected()[0]); + CurrentTextView().get_buffer()->insert_at_cursor(t); + popup_.response(Gtk::RESPONSE_DELETE_EVENT); + }); + for (auto &i : items) listview_.append(i); + listview_.set_headers_visible(false); + popup_scroll_.add(listview_); + popup_.get_vbox()->pack_start(popup_scroll_); + popup_.set_size_request(80,80); + popup_.show_all(); + Gdk::Rectangle temp1, temp2; + CurrentTextView(). + get_cursor_locations( + CurrentTextView(). + get_buffer()->get_insert()-> + get_iter(), temp1, temp2); + int widht = Notebook().get_width()-88; + int height = Notebook().get_height()-180; + int x = temp1.get_x(); + int y = temp1.get_y(); + if(x>widht){ + x = widht; } + if(y>height){ + y = height; + } + popup_.move(x, y+88); + popup_.run(); +} -bool Notebook::Controller::scroll_event_callback(GdkEventScroll* scroll_event) { +bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) { int page = CurrentPage(); int direction_y = scroll_event->delta_y; int direction_x = scroll_event->delta_x; @@ -141,8 +199,6 @@ Gtk::Box& Notebook::Controller::entry_view() { void Notebook::Controller::OnNewPage(std::string name) { OnCreatePage(); - - std::cout << "oppretta pages" << std::endl; text_vec_.back()->OnNewEmptyFile(); Notebook().append_page(*editor_vec_.back(), name); Notebook().show_all_children(); @@ -162,8 +218,8 @@ void Notebook::Controller::OnOpenFile(std::string path) { } void Notebook::Controller::OnCreatePage(){ - text_vec_.push_back(new Source::Controller(source_config())); // add arguments - linenumbers_vec_.push_back(new Source::Controller(source_config())); // add arguments + text_vec_.push_back(new Source::Controller(source_config())); + linenumbers_vec_.push_back(new Source::Controller(source_config())); scrolledline_vec_.push_back(new Gtk::ScrolledWindow()); scrolledtext_vec_.push_back(new Gtk::ScrolledWindow()); editor_vec_.push_back(new Gtk::HBox()); @@ -198,7 +254,6 @@ void Notebook::Controller::OnCloseCurrentPage() { scrolledline_vec_.erase(scrolledline_vec_.begin()+page); editor_vec_.erase(editor_vec_.begin()+page); } - } void Notebook::Controller::OnFileNewEmptyfile() { entry_.OnShowSetFilenName(""); @@ -307,9 +362,25 @@ void Notebook::Controller::OnBufferChange() { GdkEventScroll* scroll = new GdkEventScroll; scroll->delta_y = 1.0; scroll->delta_x = 0.0; - scroll_event_callback(scroll); + ScrollEventCallback(scroll); delete scroll; } + Gtk::TextIter start,end; + std::string word; + start = Buffer(text_vec_.at(page))->get_insert()->get_iter(); + end = Buffer(text_vec_.at(page))->get_insert()->get_iter(); + start.backward_char(); + word = Buffer(text_vec_.at(page))->get_text(start,end); + if( word == "."){ + //TODO(Oyvang,Zalox,Forgie) Remove TEST + std::vector TEST; + TEST.push_back("toString()"); + TEST.push_back("toLower()"); + TEST.push_back("toUpper()"); + TEST.push_back("fuckOFF()"); + TEST.push_back("fuckOFF()"); + GeneratePopup(TEST); + } } diff --git a/juci/notebook.h b/juci/notebook.h index e05dfbc..0d64920 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -5,6 +5,10 @@ #include "gtkmm.h" #include "entry.h" #include "source.h" +#include + +#include +#include namespace Notebook { class Model { @@ -47,14 +51,18 @@ namespace Notebook { void OnNewPage(std::string name); void OnOpenFile(std::string filename); void OnCreatePage(); - bool scroll_event_callback(GdkEventScroll* scroll_event); + bool ScrollEventCallback(GdkEventScroll* scroll_event); int Pages(); + void GeneratePopup(std::vector items); Gtk::HBox& view(); void Search(bool forward); const Source::Config& source_config() { return source_config_; } protected: void BufferChangeHandler(Glib::RefPtr buffer); - private: + private: + void CreateKeybindings(Keybindings::Controller& keybindings); + Glib::RefPtr m_refBuilder; + Glib::RefPtr refActionGroup; Source::Config source_config_; View view_; Model model_; From 00e29a519fcc6d210056234a2b703ac345c57881 Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 13 Apr 2015 15:01:41 +0200 Subject: [PATCH 09/12] added a directory filter to config --- juci/config.cc | 26 +++++++++------ juci/config.h | 8 +++-- juci/config.json | 13 ++++++++ juci/directories.cc | 79 ++++++++++++++++++++++++++++++++++----------- juci/directories.h | 24 +++++++++++++- juci/notebook.cc | 6 ++-- juci/notebook.h | 3 +- juci/window.cc | 2 +- juci/window.h | 1 - 9 files changed, 125 insertions(+), 37 deletions(-) diff --git a/juci/config.cc b/juci/config.cc index 388fb88..1c1e454 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -1,14 +1,14 @@ #include "config.h" - MainConfig::MainConfig() : -keybindings_cfg_(), source_cfg_() { + keybindings_cfg_(), source_cfg_() { 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"); + GenerateDirectoryFilter(); + // keybindings_cfg_ = cfg_.get_child("keybindings"); + // notebook_cfg_ = cfg_.get_child("notebook"); + // menu_cfg_ = cfg_.get_child("menu"); } void MainConfig::GenerateSource() { @@ -34,9 +34,15 @@ void MainConfig::GenerateKeybindings() { for (auto &i : keys_json) keybindings_cfg_.key_map()[i.first] = i.second.get_value(); } -Keybindings::Config& MainConfig::keybindings_cfg() { - return keybindings_cfg_; -} -Source::Config& MainConfig::source_cfg() { - return source_cfg_; + +void MainConfig::GenerateDirectoryFilter() { + boost::property_tree::ptree dir_json = cfg_.get_child("directoryfilter"); + boost::property_tree::ptree ignore_json = dir_json.get_child("ignore"); + boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); + for ( auto &i : except_json ) + dir_cfg_.AddException(i.second.get_value()); + for ( auto &i : ignore_json ) + dir_cfg_.AddIgnore(i.second.get_value()); } + + diff --git a/juci/config.h b/juci/config.h index ee49224..edcb5fc 100644 --- a/juci/config.h +++ b/juci/config.h @@ -4,18 +4,22 @@ #include #include "keybindings.h" #include "source.h" +#include "directories.h" class MainConfig { public: MainConfig(); - Source::Config& source_cfg(); - Keybindings::Config& keybindings_cfg(); + Source::Config& source_cfg() { return source_cfg_; } + Keybindings::Config& keybindings_cfg() { return keybindings_cfg_; } + Directories::Config& dir_cfg() { return dir_cfg_; } void PrintMenu(); void GenerateSource(); void GenerateKeybindings(); + void GenerateDirectoryFilter(); private: boost::property_tree::ptree cfg_; boost::property_tree::ptree key_tree_; Source::Config source_cfg_; Keybindings::Config keybindings_cfg_; + Directories::Config dir_cfg_; }; diff --git a/juci/config.json b/juci/config.json index afc983d..e4ff1f5 100644 --- a/juci/config.json +++ b/juci/config.json @@ -25,6 +25,19 @@ "close_tab": "w", "open_folder": "o" }, + "directoryfilter": { + "ignore": [ + "cmake", + "#", + "~", + ".idea", + "in-lowercase.pls" + ], + "exceptions": [ + "cmakelists.txt", + "in-lowercase.pls" + ] + }, "example": { "key": "value", "key2": [ diff --git a/juci/directories.cc b/juci/directories.cc index 0366b35..adbc795 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -1,6 +1,7 @@ #include "directories.h" -Directories::Controller::Controller() { +Directories::Controller::Controller(Directories::Config& cfg) : + config_(cfg) { m_ScrolledWindow.add(m_TreeView); m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); } @@ -18,6 +19,17 @@ open_folder(const boost::filesystem::path& dir_path) { m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING); } +bool Directories::Controller::IsIgnored(std::string path) { + std::transform(path.begin(), path.end(), path.begin(), ::tolower); + // std::cout << "ignored?: " << path << std::endl; + if (config().IsException(path)) { + return false; + } + if (config().IsIgnored(path)) { + return true; + } + return false; +} void Directories::Controller:: list_dirs(const boost::filesystem::path& dir_path, Gtk::TreeModel::Row &parent, @@ -32,28 +44,30 @@ list_dirs(const boost::filesystem::path& dir_path, for ( boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; ++itr ) { - if (boost::filesystem::is_directory(itr->status())) { - if (count(itr->path().string()) > count(dir_path.string())) { // is child + if (!IsIgnored(itr->path().filename().string())) { + if (boost::filesystem::is_directory(itr->status())) { + if (count(itr->path().string()) > count(dir_path.string())) { // is child + child = *(m_refTreeModel->append(parent.children())); + std::string col_id("a"+itr->path().filename().string()); + child[view().m_col_id] = col_id; + child[view().m_col_name] = itr->path().filename().string(); + child[view().m_col_path] = itr->path().string(); + list_dirs(itr->path(), child, row_id); + } else { + row = *(m_refTreeModel->append()); + std::string col_id("a"+itr->path().filename().string()); + row[view().m_col_path] = itr->path().string(); + row[view().m_col_id] = col_id; + row[view().m_col_name] = itr->path().filename().string(); + list_dirs(itr->path(), parent, row_id); + } + } else { // is a file child = *(m_refTreeModel->append(parent.children())); - std::string col_id("a"+itr->path().filename().string()); + std::string col_id("b"+itr->path().filename().string()); child[view().m_col_id] = col_id; - child[view().m_col_name] = itr->path().filename().string(); + child[view().m_col_name] = itr->path().filename().string(); child[view().m_col_path] = itr->path().string(); - list_dirs(itr->path(), child, row_id); - } else { - row = *(m_refTreeModel->append()); - std::string col_id("a"+itr->path().filename().string()); - row[view().m_col_path] = itr->path().string(); - row[view().m_col_id] = col_id; - row[view().m_col_name] = itr->path().filename().string(); - list_dirs(itr->path(), parent, row_id); } - } else { // is a file - child = *(m_refTreeModel->append(parent.children())); - std::string col_id("b"+itr->path().filename().string()); - child[view().m_col_id] = col_id; - child[view().m_col_name] = itr->path().filename().string(); - child[view().m_col_path] = itr->path().string(); } } } @@ -101,3 +115,30 @@ get_project_name(const boost::filesystem::path& dir_path) { return "no project name"; } +Directories::Config::Config() { +} +Directories::Config::Config(Directories::Config& cfg) : + ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) { +} + +void Directories::Config::AddIgnore(std::string filter) { + ignore_list_.push_back(filter); +} + +void Directories::Config::AddException(std::string filter) { + exception_list_.push_back(filter); +} + +bool Directories::Config::IsIgnored(std::string str) { + for ( auto &i : ignore_list() ) + if (str.find(i, 0) != std::string::npos) + return true; + return false; +} + +bool Directories::Config::IsException(std::string str) { + for ( std::string &i : exception_list() ) + if (i == str) + return true; + return false; +} diff --git a/juci/directories.h b/juci/directories.h index c96605a..9a6d3b8 100644 --- a/juci/directories.h +++ b/juci/directories.h @@ -4,10 +4,28 @@ #include #include #include "boost/filesystem.hpp" +#include +#include #include #include + namespace Directories { + + class Config { + public: + Config(Config &original); + Config(); + std::vector ignore_list() { return ignore_list_; } + std::vector exception_list() { return exception_list_; } + void AddIgnore(std::string filter); + void AddException(std::string filter); + bool IsException(std::string path); + bool IsIgnored(std::string path); + private: + std::vector ignore_list_; + std::vector exception_list_; + }; class View : public Gtk::TreeModel::ColumnRecord { public: View() { @@ -22,12 +40,14 @@ namespace Directories { class Model { }; + class Controller { public: Controller(); + Controller(Directories::Config& cfg); View& view() { return view_;} Model& model() { return model_;} - + Directories::Config& config() { return config_;} Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;} bool open_folder (const boost::filesystem::path& dir_path); void list_dirs (const boost::filesystem::path& dir_path, @@ -40,9 +60,11 @@ namespace Directories { Gtk::ScrolledWindow m_ScrolledWindow; Gtk::TreeView m_TreeView; Glib::RefPtr m_refTreeModel; + bool IsIgnored(std::string path); private: View view_; Model model_; + Directories::Config config_; protected: void on_treeview_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); diff --git a/juci/notebook.cc b/juci/notebook.cc index f2d745c..03230be 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -15,8 +15,10 @@ Notebook::View::View(){ } Notebook::Controller::Controller(Keybindings::Controller& keybindings, - Source::Config& source_cfg) : -source_config_(source_cfg) { + Source::Config& source_cfg, + Directories::Config& dir_cfg) : + source_config_(source_cfg), + directories_(dir_cfg) { OnNewPage("juCi++"); refClipboard_ = Gtk::Clipboard::get(); keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", diff --git a/juci/notebook.h b/juci/notebook.h index 3b77beb..ce9551a 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -28,7 +28,8 @@ namespace Notebook { public: Controller(Keybindings::Controller& keybindings, - Source::Config& config); + Source::Config& config, + Directories::Config& dir_cfg); ~Controller(); Glib::RefPtr Buffer( Source::Controller *source); Gtk::TextView& CurrentTextView(); diff --git a/juci/window.cc b/juci/window.cc index 99485c2..ec3a174 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -4,7 +4,7 @@ Window::Window() : window_box_(Gtk::ORIENTATION_VERTICAL), main_config_(), keybindings_(main_config_.keybindings_cfg()), - notebook_(keybindings(), main_config_.source_cfg()), + notebook_(keybindings(), main_config_.source_cfg(), main_config_.dir_cfg()), menu_(keybindings()) { set_title("juCi++"); set_default_size(600, 400); diff --git a/juci/window.h b/juci/window.h index 2b79755..a0b810f 100644 --- a/juci/window.h +++ b/juci/window.h @@ -4,7 +4,6 @@ #include "api.h" #include "config.h" #include -#include "directories.h" class Window : public Gtk::Window { From 8c42813bbe3efa7773e70d52a233a7977ccf6d36 Mon Sep 17 00:00:00 2001 From: oyvang Date: Mon, 13 Apr 2015 15:16:21 +0200 Subject: [PATCH 10/12] fixed merge bug with tedsky --- juci/CMakeLists.txt | 2 ++ juci/notebook.cc | 2 ++ juci/notebook.h | 6 +++--- juci/terminal.cc | 6 ++++++ juci/terminal.h | 27 +++++++++++++++++++++++++++ juci/window.cc | 1 - 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 juci/terminal.cc create mode 100644 juci/terminal.h diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index 2f3755a..e4869d0 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -106,6 +106,8 @@ add_executable(${project_name} entry.cc directories.h directories.cc + terminal.h + terminal.cc ) add_library(${module} SHARED diff --git a/juci/notebook.cc b/juci/notebook.cc index ba983fd..ad6362b 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -16,7 +16,9 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings, source_config_(source_cfg) { OnNewPage("juCi++"); refClipboard_ = Gtk::Clipboard::get(); + view().pack1(directories_.widget(),true,true); CreateKeybindings(keybindings); + }// Constructor void Notebook::Controller::CreateKeybindings(Keybindings::Controller diff --git a/juci/notebook.h b/juci/notebook.h index c726748..1d5783c 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -8,10 +8,10 @@ #include "directories.h" - // #include + #include - // #include - // #include + #include + #include namespace Notebook { diff --git a/juci/terminal.cc b/juci/terminal.cc new file mode 100644 index 0000000..e96a21a --- /dev/null +++ b/juci/terminal.cc @@ -0,0 +1,6 @@ +#include "terminal.h" + + + + + diff --git a/juci/terminal.h b/juci/terminal.h new file mode 100644 index 0000000..83d0738 --- /dev/null +++ b/juci/terminal.h @@ -0,0 +1,27 @@ + +#ifndef JUCI_NOTEBOOK_H_ +#define JUCI_NOTEBOOK_H_ + +#include +#include "gtkmm.h" + +namespace Terminal { + + class View { + public: + View(); + //Gtk::HBox view() {return view_;} + private: + Gtk::HBox view_; + Gtk::TextBuffer buffer_; + Gtk::TextView textview_; + }; // class view + + class Controller { + public: + + + }; // class controller +} // namespace Terminal + +#endif // JUCI_NOTEBOOK_H_ diff --git a/juci/window.cc b/juci/window.cc index 99485c2..73f72eb 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -37,7 +37,6 @@ Window::Window() : window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.view()); - show_all_children(); } // Window constructor From eb0e4925130ff73a727b59422909fe1b58449f13 Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 13 Apr 2015 15:17:27 +0200 Subject: [PATCH 11/12] merged again --- juci/.#notebook.h | 1 + juci/notebook.cc | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) create mode 120000 juci/.#notebook.h diff --git a/juci/.#notebook.h b/juci/.#notebook.h new file mode 120000 index 0000000..6989c31 --- /dev/null +++ b/juci/.#notebook.h @@ -0,0 +1 @@ +forgie@surface.6435:1428916838 \ No newline at end of file diff --git a/juci/notebook.cc b/juci/notebook.cc index fdb2059..a377bea 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -188,9 +188,7 @@ bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) { Glib::RefPtr adj = scrolledtext_vec_.at(page)-> get_vscrollbar()->get_adjustment(); - if ( direction_y != 0 ) { - int dir_val = direction_y==-1?-model_.scrollvalue_:+model_.scrollvalue_; adj->set_value(adj->get_value()+dir_val); text_vec_.at(page)->view().set_vadjustment(adj); @@ -405,8 +403,7 @@ void Notebook::Controller Gtk::TreeModel::iterator iter = directories().m_refTreeModel->get_iter(path); if(iter) { Gtk::TreeModel::Row row = *iter; - boost::filesystem::path fs_path(Glib::ustring(row[directories() - .view().m_col_path])); + boost::filesystem::path fs_path(Glib::ustring(row[directories().view().m_col_path])); if (boost::filesystem::is_directory(fs_path)) { directories().m_TreeView.row_expanded(path) ? directories().m_TreeView.collapse_row(path) : From 7eeb0470acdef66fc77bb9fbfc8a1cb2c0ba91bd Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 13 Apr 2015 16:04:01 +0200 Subject: [PATCH 12/12] made project name from cmakelists.txt more flexible --- juci/directories.cc | 17 ++++++++++++++--- juci/directories.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/juci/directories.cc b/juci/directories.cc index adbc795..04aa9f8 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -95,18 +95,29 @@ get_project_name(const boost::filesystem::path& dir_path) { size_t variabel_end = line.find("}", variabel_start); project_name_var = line.substr(variabel_start+1, (variabel_end)-variabel_start-1); + boost::algorithm::trim(project_name_var); + if (variabel_start == std::string::npos) { // not a variabel + variabel_start = line.find("(", 0); + variabel_end = line.find(")", variabel_start); + return line.substr(variabel_start+1, + (variabel_end)-variabel_start-1); + } break; } } std::ifstream ifs2(itr->path().string()); while (std::getline(ifs2, line)) { - if (line.find("set("+project_name_var, 0) != std::string::npos) { + if (line.find("set(", 0) != std::string::npos + || line.find("set (", 0) != std::string::npos) { + if( line.find(project_name_var, 0) != std::string::npos) { size_t variabel_start = line.find(project_name_var, 0) +project_name_var.length(); size_t variabel_end = line.find(")", variabel_start); - project_name = line.substr(variabel_start, - variabel_end-variabel_start); + project_name = line.substr(variabel_start+1, + variabel_end-variabel_start-1); + boost::algorithm::trim(project_name); return project_name; + } } } break; diff --git a/juci/directories.h b/juci/directories.h index 9a6d3b8..c5b3579 100644 --- a/juci/directories.h +++ b/juci/directories.h @@ -4,6 +4,7 @@ #include #include #include "boost/filesystem.hpp" +#include "boost/algorithm/string.hpp" #include #include #include