From e597f1e222b157f2b0cabe37312f81556678241a Mon Sep 17 00:00:00 2001 From: oyvang Date: Wed, 13 May 2015 15:57:41 +0200 Subject: [PATCH 01/19] add logs to notebook --- juci/notebook.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 4c6888e..9785cf0 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -1,5 +1,6 @@ -#include "notebook.h" #include +#include "notebook.h" +#include "logging.h" Notebook::Model::Model() { cc_extension_ = ".cc"; @@ -24,11 +25,13 @@ Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& k ispopup = false; view().pack1(directories_.widget(), true, true); CreateKeybindings(keybindings); + INFO("Notebook Controller Sucsess"); } // Constructor void Notebook::Controller::CreateKeybindings(Keybindings::Controller &keybindings) { + INFO("Notebook create signal handlers"); directories().m_TreeView.signal_row_activated() .connect(sigc::mem_fun(*this, &Notebook::Controller::OnDirectoryNavigation)); @@ -138,6 +141,7 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller [this]() { Search(false); }); + INFO("Notebook signal handlers sucsess"); } bool Notebook::Controller:: OnMouseRelease(GdkEventButton* button) { @@ -153,6 +157,7 @@ bool Notebook::Controller::OnKeyRelease(GdkEventKey* key) { } bool Notebook::Controller::GeneratePopup(int key_id) { + INFO("Notebook genereate popup, getting iters"); // Get function to fill popup with suggests item vector under is for testing Gtk::TextIter beg = CurrentTextView().get_buffer()->get_insert()->get_iter(); Gtk::TextIter end = CurrentTextView().get_buffer()->get_insert()->get_iter(); @@ -165,6 +170,7 @@ bool Notebook::Controller::GeneratePopup(int key_id) { end.backward_search("\"", Gtk::TEXT_SEARCH_VISIBLE_ONLY, tmp, tmp1, line) || end.backward_search("//", Gtk::TEXT_SEARCH_VISIBLE_ONLY, tmp, tmp1, line); + INFO("Notebook genereate popup, checking key_id"); if (illegal_chars) { return false; } @@ -187,6 +193,7 @@ bool Notebook::Controller::GeneratePopup(int key_id) { } else { return false; } + INFO("Notebook genereate popup, getting autocompletions"); std::vector acdata; text_vec_.at(CurrentPage())-> GetAutoCompleteSuggestions(beg.get_line()+1, @@ -229,16 +236,19 @@ bool Notebook::Controller::GeneratePopup(int key_id) { popup_.get_vbox()->pack_start(popup_scroll_); popup_.set_transient_for(*window_); popup_.show_all(); - + INFO("Notebook genereate popup, moving popup"); int popup_x = popup_.get_width(); int popup_y = items.size() * 20; PopupSetSize(popup_scroll_, popup_x, popup_y); int x, y; FindPopupPosition(CurrentTextView(), popup_x, popup_y, x, y); popup_.move(x, y+15); + INFO("Notebook genereate popup, create handler"); PopupSelectHandler(popup_, listview_, &items); ispopup = true; + INFO("Notebook genereate popup, run popup"); popup_.run(); + INFO("Notebook genereate popup, hide popup"); popup_.hide(); ispopup = false; return true; @@ -261,6 +271,7 @@ bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) { return true; } Notebook::Controller::~Controller() { + INFO("Notebook destructor"); for (auto &i : text_vec_) delete i; for (auto &i : linenumbers_vec_) delete i; for (auto &i : editor_vec_) delete i; @@ -276,6 +287,7 @@ Gtk::Box& Notebook::Controller::entry_view() { } void Notebook::Controller::OnNewPage(std::string name) { + INFO("Notebook Generate new page"); OnCreatePage(); text_vec_.back()->OnNewEmptyFile(); Notebook().append_page(*editor_vec_.back(), name); @@ -294,6 +306,7 @@ MapBuffers(std::map *buffers) { } void Notebook::Controller::OnOpenFile(std::string path) { + INFO("Notebook open file"); OnCreatePage(); text_vec_.back()->OnOpenFile(path); text_vec_.back()->set_is_saved(true); @@ -309,6 +322,7 @@ void Notebook::Controller::OnOpenFile(std::string path) { } void Notebook::Controller::OnCreatePage() { + INFO("Notebook create page"); text_vec_.push_back(new Source::Controller(source_config(), this)); linenumbers_vec_.push_back(new Source::Controller(source_config(), this)); scrolledline_vec_.push_back(new Gtk::ScrolledWindow()); @@ -329,6 +343,7 @@ void Notebook::Controller::OnCreatePage() { } void Notebook::Controller::OnCloseCurrentPage() { + INFO("Notebook close page"); // TODO(oyvang) zalox, forgi) // Save a temp file, in case you close one you dont want to close? if (Pages() != 0) { @@ -372,6 +387,7 @@ void Notebook::Controller::OnEditCut() { } std::string Notebook::Controller::GetCursorWord() { + INFO("Notebook get cursor word"); int page = CurrentPage(); std::string word; Gtk::TextIter start, end; @@ -399,6 +415,7 @@ void Notebook::Controller::OnEditSearch() { } void Notebook::Controller::Search(bool forward) { + INFO("Notebook search"); int page = CurrentPage(); std::string search_word; search_word = entry_.text(); @@ -460,6 +477,7 @@ void Notebook::Controller::OnBufferChange() { void Notebook::Controller ::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) { + INFO("Notebook directory navigation"); Gtk::TreeModel::iterator iter = directories().m_refTreeModel->get_iter(path); if (iter) { Gtk::TreeModel::Row row = *iter; @@ -539,6 +557,7 @@ void Notebook::Controller::PopupSelectHandler(Gtk::Dialog &popup, void Notebook::Controller::PopupSetSize(Gtk::ScrolledWindow &scroll, int ¤t_x, int ¤t_y) { + INFO("Notebook popup set size"); int textview_x = CurrentTextView().get_width(); int textview_y = 150; bool is_never_scroll_x = true; @@ -573,6 +592,7 @@ void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview, int popup_y, int &x, int &y) { + INFO("Notebook popup find position"); Gdk::Rectangle temp1, temp2; textview.get_cursor_locations( CurrentTextView(). @@ -602,6 +622,7 @@ void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview, } void Notebook::Controller:: OnSaveFile() { + INFO("Notebook save file"); if (text_vec_.at(CurrentPage())->is_saved()) { std::ofstream file; file.open (text_vec_.at(CurrentPage())->path()); @@ -622,6 +643,7 @@ void Notebook::Controller:: OnSaveFile() { std::string Notebook::Controller::OnSaveFileAs(){ + INFO("Notebook save as"); Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_SAVE); dialog.set_transient_for(*window_); From 9087f660ca8647d069cbe0c4f51ec82bfac8e6db Mon Sep 17 00:00:00 2001 From: oyvang Date: Wed, 13 May 2015 16:18:09 +0200 Subject: [PATCH 02/19] fixed bug with complie and run --- juci/notebook.cc | 8 +++++++- juci/window.cc | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 9785cf0..cb3e159 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -643,17 +643,23 @@ void Notebook::Controller:: OnSaveFile() { std::string Notebook::Controller::OnSaveFileAs(){ - INFO("Notebook save as"); + INFO("Notebook save as"); Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_SAVE); + DEBUG("SET TRANSISTEN FPR"); dialog.set_transient_for(*window_); dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL); dialog.add_button("_Save", Gtk::RESPONSE_OK); + //dialog.set_current_name("Untitled"); + DEBUG("RUN DIALOG"); int result = dialog.run(); + DEBUG("DIALOG RUNNING"); switch (result) { case(Gtk::RESPONSE_OK): { + DEBUG("get_filename()"); std::string path = dialog.get_filename(); + DEBUG_VAR(path); unsigned pos = path.find_last_of("/\\"); std::cout << path<< std::endl; //notebook_.OnSaveFile(path); diff --git a/juci/window.cc b/juci/window.cc index 3cc5b89..ba4c391 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -54,9 +54,9 @@ Window::Window() : Gtk::AccelKey(keybindings_.config_ .key_map()["compile_and_run"]), [this]() { + notebook_.OnSaveFile(); if (running.try_lock()) { std::thread execute([=]() { - notebook_.OnSaveFile(); std::string path = notebook_.CurrentPagePath(); int pos = path.find_last_of("/\\"); if(pos != std::string::npos){ @@ -80,9 +80,9 @@ Window::Window() : Gtk::AccelKey(keybindings_.config_ .key_map()["compile"]), [this]() { + notebook_.OnSaveFile(); if (running.try_lock()) { - std::thread execute([=]() { - notebook_.OnSaveFile(); + std::thread execute([=]() { std::string path = notebook_.CurrentPagePath(); int pos = path.find_last_of("/\\"); if(pos != std::string::npos){ From 8b2698cfa5359fc8193f60bf6f6ee27019dbc5cb Mon Sep 17 00:00:00 2001 From: tedjk Date: Thu, 14 May 2015 09:42:28 +0200 Subject: [PATCH 03/19] commit for merge --- juci/config.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/juci/config.cc b/juci/config.cc index 22dbffb..0b9cd6a 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -4,6 +4,7 @@ MainConfig::MainConfig() : keybindings_cfg_(), source_cfg_() { boost::property_tree::json_parser::read_json("config.json", cfg_); + GenerateSource(); GenerateKeybindings(); GenerateDirectoryFilter(); @@ -28,10 +29,8 @@ void MainConfig::GenerateKeybindings() { std::string line; std::ifstream menu_xml("menu.xml"); if (menu_xml.is_open()) { - while (getline(menu_xml, line)) { - keybindings_cfg_.AppendXml(line); - } - + while (getline(menu_xml, line)) + keybindings_cfg_.AppendXml(line); } boost::property_tree::ptree keys_json = cfg_.get_child("keybindings"); for (auto &i : keys_json) From 242a2c6556bea1b9c2150d4a55069a1285ec4968 Mon Sep 17 00:00:00 2001 From: tedjk Date: Fri, 15 May 2015 09:44:51 +0200 Subject: [PATCH 04/19] some typo --- juci/notebook.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index cb3e159..407eb2c 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -25,7 +25,7 @@ Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& k ispopup = false; view().pack1(directories_.widget(), true, true); CreateKeybindings(keybindings); - INFO("Notebook Controller Sucsess"); + INFO("Notebook Controller Success"); } // Constructor From f7253f498f52e045ff752b2d733a792e0221a44f Mon Sep 17 00:00:00 2001 From: oyvang Date: Fri, 15 May 2015 11:03:21 +0200 Subject: [PATCH 05/19] implemented AskSaveFileDialog --- juci/api_ext.cc | 15 --------------- juci/notebook.cc | 47 +++++++++++++++++++++++++++++++++++++++++------ juci/notebook.h | 1 + juci/source.h | 3 +++ juci/terminal.cc | 1 + 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/juci/api_ext.cc b/juci/api_ext.cc index 9b8b1ba..e69de29 100644 --- a/juci/api_ext.cc +++ b/juci/api_ext.cc @@ -1,15 +0,0 @@ -#include "api.h" - -BOOST_PYTHON_MODULE(juci_to_python_api) { - using namespace boost::python; - // plugin inclusion - def("addMenuElement", &libjuci::AddMenuElement); - def("addSubMenuElement", &libjuci::AddSubMenuElement); - def("loadPlugin", &libjuci::LoadPlugin); - def("initPlugin", &libjuci::InitPlugin); - - // text editing - def("replaceLine", &libjuci::ReplaceLine); - def("replaceWord", &libjuci::ReplaceWord); - def("getWord", &libjuci::GetWord); - } // module::juci_to_python_api diff --git a/juci/notebook.cc b/juci/notebook.cc index cb3e159..53c4d8b 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -316,9 +316,7 @@ void Notebook::Controller::OnOpenFile(std::string path) { Notebook().set_current_page(Pages()-1); Notebook().set_focus_child(text_vec_.back()->view()); OnBufferChange(); - - - + text_vec_.back()->set_is_changed(false); } void Notebook::Controller::OnCreatePage() { @@ -344,9 +342,10 @@ void Notebook::Controller::OnCreatePage() { void Notebook::Controller::OnCloseCurrentPage() { INFO("Notebook close page"); - // TODO(oyvang) zalox, forgi) - // Save a temp file, in case you close one you dont want to close? if (Pages() != 0) { + if(text_vec_.back()->is_changed()){ + AskToSaveDialog(); + } int page = CurrentPage(); Notebook().remove_page(page); delete text_vec_.at(page); @@ -473,6 +472,7 @@ void Notebook::Controller::OnBufferChange() { ScrollEventCallback(scroll); delete scroll; } + text_vec_.at(page)->set_is_changed(true); } void Notebook::Controller ::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, @@ -644,7 +644,7 @@ void Notebook::Controller:: OnSaveFile() { std::string Notebook::Controller::OnSaveFileAs(){ INFO("Notebook save as"); - Gtk::FileChooserDialog dialog("Please choose a file", + Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_SAVE); DEBUG("SET TRANSISTEN FPR"); dialog.set_transient_for(*window_); @@ -677,3 +677,38 @@ std::string Notebook::Controller::OnSaveFileAs(){ return ""; } +void Notebook::Controller::AskToSaveDialog() { + INFO("AskToSaveDialog"); + DEBUG("AskToSaveDialog: Finding file path"); + Gtk::MessageDialog dialog(*window_, "Save file!", + false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); + dialog.set_secondary_text( + "Do you want to save: " + + text_vec_.at(CurrentPage())->path()+" ?"); + DEBUG("AskToSaveDialog: run dialog"); + int result = dialog.run(); + + //Handle the response: + DEBUG("AskToSaveDialog: switch response"); + switch(result) + { + case(Gtk::RESPONSE_YES): + { + DEBUG("AskToSaveDialog: save file: yes, trying to save file"); + OnSaveFile(); + DEBUG("AskToSaveDialog: save file: yes, saved sucess"); + break; + } + case(Gtk::RESPONSE_NO): + { + DEBUG("AskToSaveDialog: save file: no"); + break; + } + default: + { + DEBUG("AskToSaveDialog: unexpected action: Default switch"); + break; + } + } +} + diff --git a/juci/notebook.h b/juci/notebook.h index f3678cd..bf5440c 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -88,6 +88,7 @@ namespace Notebook { void PopupSetSize(Gtk::ScrolledWindow& scroll, int ¤t_x, int ¤t_y); + void AskToSaveDialog(); Glib::RefPtr m_refBuilder; Glib::RefPtr refActionGroup; Source::Config source_config_; diff --git a/juci/source.h b/juci/source.h index cab4d5d..f9b45bd 100644 --- a/juci/source.h +++ b/juci/source.h @@ -150,8 +150,10 @@ namespace Source { *suggestions); Glib::RefPtr buffer(); bool is_saved() { return is_saved_; } + bool is_changed() { return is_changed_; } std::string path() { return model().file_path(); } void set_is_saved(bool isSaved) { is_saved_ = isSaved; } + void set_is_changed(bool isChanged) { is_changed_ = isChanged; } void set_file_path(std::string path) { model().set_file_path(path); } @@ -162,6 +164,7 @@ namespace Source { std::mutex parsing; bool go = false; bool is_saved_ = false; + bool is_changed_ = false; protected: View view_; diff --git a/juci/terminal.cc b/juci/terminal.cc index 4e7a28e..cd916d8 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -19,6 +19,7 @@ Terminal::Controller::Controller() { void Terminal::Controller::SetFolderCommand( boost::filesystem::path CMake_path) { + path_ = CMake_path.string(); folder_command_ = "cd "+ path_ + "; "; } From ff1261b000d7699dad19e2432af1690dc8d7f4d5 Mon Sep 17 00:00:00 2001 From: tedjk Date: Fri, 15 May 2015 12:00:33 +0200 Subject: [PATCH 06/19] added some debugging in directories --- juci/directories.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/juci/directories.cc b/juci/directories.cc index 73fb825..b213187 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -3,6 +3,7 @@ Directories::Controller::Controller(Directories::Config& cfg) : config_(cfg) { + DEBUG("adding treeview to scrolledwindow"); m_ScrolledWindow.add(m_TreeView); m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); } @@ -13,16 +14,20 @@ 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(); + DEBUG("Getting project name from CMakeLists.txt"); std::string project_name = GetCmakeVarValue(dir_path, "project"); m_TreeView.append_column(project_name, view().m_col_name); int row_id = 0; Gtk::TreeModel::Row row; + DEBUG("Listing directories"); list_dirs(dir_path, row, row_id); + DEBUG("Sorting directories"); m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING); - INFO("Folder opened"); + DEBUG("Folder opened"); } bool Directories::Controller::IsIgnored(std::string path) { + DEBUG("Checking if file-/directory is filtered"); std::transform(path.begin(), path.end(), path.begin(), ::tolower); // std::cout << "ignored?: " << path << std::endl; if (config().IsException(path)) { @@ -36,17 +41,18 @@ bool Directories::Controller::IsIgnored(std::string path) { void Directories::Controller:: list_dirs(const boost::filesystem::path& dir_path, Gtk::TreeModel::Row &parent, - unsigned row_id) { + 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; - + DEBUG_VAR(dir_path); // Fill the treeview for ( boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; - ++itr ) { + ++itr ) { if (!IsIgnored(itr->path().filename().string())) { if (boost::filesystem::is_directory(itr->status())) { if (count(itr->path().string()) > count(dir_path.string())) { // is child From 0678ac68c8deec8a013fcc9afe18ec388a391ba2 Mon Sep 17 00:00:00 2001 From: oyvang Date: Fri, 15 May 2015 12:49:28 +0200 Subject: [PATCH 07/19] Fixed keybinding on compile and run --- juci/config.json | 2 +- juci/notebook.cc | 2 +- juci/terminal.cc | 23 ++++++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/juci/config.json b/juci/config.json index 9344fbb..bf406f5 100644 --- a/juci/config.json +++ b/juci/config.json @@ -27,7 +27,7 @@ "edit_undo": "z", "save": "s", "save_as": "s", - "compile_and_run": "r>", + "compile_and_run": "r", "compile": "r" }, "directoryfilter": { diff --git a/juci/notebook.cc b/juci/notebook.cc index 44470e9..47dd4ef 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -272,7 +272,7 @@ bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) { } Notebook::Controller::~Controller() { INFO("Notebook destructor"); - for (auto &i : text_vec_) delete i; + for (auto &i : text_vec_) delete i; for (auto &i : linenumbers_vec_) delete i; for (auto &i : editor_vec_) delete i; for (auto &i : scrolledtext_vec_) delete i; diff --git a/juci/terminal.cc b/juci/terminal.cc index cd916d8..1ea2029 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -1,8 +1,7 @@ #include "terminal.h" #include #include -// #include -// #include +#include "logging.h" Terminal::View::View(){ @@ -19,31 +18,43 @@ Terminal::Controller::Controller() { void Terminal::Controller::SetFolderCommand( boost::filesystem::path CMake_path) { - + INFO("Terminal: SetFolderCommand"); path_ = CMake_path.string(); folder_command_ = "cd "+ path_ + "; "; } void Terminal::Controller::Compile(){ + INFO("Terminal: Compile"); Terminal().get_buffer()->set_text(""); + DEBUG("Terminal: Compile: running cmake command"); ExecuteCommand("cmake .", "r"); if (ExistInConsole(cmake_sucsess)){ + DEBUG("Terminal: Compile: running make command"); ExecuteCommand("make", "r"); - } + } + PrintMessage("\n"); + DEBUG("Terminal: Compile: compile done"); } void Terminal::Controller::Run(std::string executable) { + INFO("Terminal: Run"); PrintMessage("juCi++ execute: " + executable + "\n"); + DEBUG("Terminal: Compile: running run command: "); + DEBUG_VAR(executable); ExecuteCommand("./"+executable, "r"); + PrintMessage("\n"); } void Terminal::Controller::PrintMessage(std::string message){ + INFO("Terminal: PrintMessage"); Terminal().get_buffer()-> insert(Terminal().get_buffer()-> end(),"> "+message); } bool Terminal::Controller::ExistInConsole(std::string string) { + INFO("Terminal: ExistInConsole"); + DEBUG("Terminal: PrintMessage: finding string in buffer"); double pos = Terminal().get_buffer()-> get_text().find(string); if (pos == std::string::npos) return false; @@ -51,8 +62,10 @@ bool Terminal::Controller::ExistInConsole(std::string string) { } void Terminal::Controller::ExecuteCommand(std::string command, std::string mode) { + INFO("Terminal: ExecuteCommand"); command = folder_command_+command; - std::cout << "EXECUTE COMMAND: "<< command << std::endl; + DEBUG("Terminal: PrintMessage: Running command"); + DEBUG_VAR(command); FILE* p = popen(command.c_str(), mode.c_str()); if (p == NULL) { From 41b745b83d5c3a8c195ea6504c0b4e13f9cf4697 Mon Sep 17 00:00:00 2001 From: tedjk Date: Fri, 15 May 2015 13:49:50 +0200 Subject: [PATCH 08/19] added legal file-extensions to source --- juci/api.cc | 4 ++ juci/config.cc | 17 +++-- juci/config.json | 7 +- juci/directories.cc | 167 ++++++++++++++++++++++---------------------- juci/notebook.cc | 3 +- juci/source.cc | 9 +++ juci/source.h | 4 +- juci/window.cc | 2 +- 8 files changed, 120 insertions(+), 93 deletions(-) diff --git a/juci/api.cc b/juci/api.cc index 6a5f0a4..ee5a634 100644 --- a/juci/api.cc +++ b/juci/api.cc @@ -8,9 +8,12 @@ Notebook::Controller* PluginApi::notebook_; ///////////////////////////// PluginApi::PluginApi(Menu::Controller& menu_ctl_, Notebook::Controller& notebook_ctl_) { + DEBUG("Adding pointers for the API"); menu_ = &menu_ctl_; notebook_ = ¬ebook_ctl_; + DEBUG("Initiating plugins(from plugins.py).."); InitPlugins(); + DEBUG("Plugins initiated.."); } PluginApi::~PluginApi() { @@ -61,6 +64,7 @@ void PluginApi::InitPlugins() { } void PluginApi::AddMenuElement(std::string plugin_name) { + DEBUG("Adding menu element for "+plugin_name); AddMenuXml(plugin_name, "PluginMenu"); std::string plugin_action_name = plugin_name+"Menu"; menu_->keybindings_.action_group_menu() diff --git a/juci/config.cc b/juci/config.cc index 0b9cd6a..b320a6c 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -11,21 +11,26 @@ MainConfig::MainConfig() : } void MainConfig::GenerateSource() { - INFO("Generating source cfg"); + DEBUG("Fetching source cfg"); 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"); + boost::property_tree::ptree extensions_json = source_json.get_child("extensions"); for (auto &i : colors_json) { source_cfg_.InsertTag(i.first, i.second.get_value()); } for (auto &i : syntax_json) { source_cfg_.InsertType(i.first, i.second.get_value()); } - INFO("Source cfg generated"); + for (auto &i : extensions_json) { + source_cfg_.InsertExtension(i.second.get_value()); + } + + DEBUG("Source cfg fetched"); } void MainConfig::GenerateKeybindings() { - INFO("Generating keybindings"); + DEBUG("Fetching keybindings"); std::string line; std::ifstream menu_xml("menu.xml"); if (menu_xml.is_open()) { @@ -35,10 +40,11 @@ void MainConfig::GenerateKeybindings() { boost::property_tree::ptree keys_json = cfg_.get_child("keybindings"); for (auto &i : keys_json) keybindings_cfg_.key_map()[i.first] = i.second.get_value(); - INFO("Keybindings generated"); + DEBUG("Keybindings fetched"); } void MainConfig::GenerateDirectoryFilter() { + DEBUG("Fetching directory filter"); 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"); @@ -46,6 +52,5 @@ void MainConfig::GenerateDirectoryFilter() { dir_cfg_.AddException(i.second.get_value()); for ( auto &i : ignore_json ) dir_cfg_.AddIgnore(i.second.get_value()); + DEBUG("Directory filter fetched"); } - - diff --git a/juci/config.json b/juci/config.json index 9344fbb..d2621a7 100644 --- a/juci/config.json +++ b/juci/config.json @@ -16,7 +16,12 @@ "702": "keyword", "703": "own", "705": "comment" - } + }, + "extensions": [ + "ext1", + "ext2", + "ext3" + ] }, "keybindings": { "split_window": "s", diff --git a/juci/directories.cc b/juci/directories.cc index b213187..199e4dd 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -29,7 +29,6 @@ open_folder(const boost::filesystem::path& dir_path) { bool Directories::Controller::IsIgnored(std::string path) { DEBUG("Checking if file-/directory is filtered"); std::transform(path.begin(), path.end(), path.begin(), ::tolower); - // std::cout << "ignored?: " << path << std::endl; if (config().IsException(path)) { return false; } @@ -48,7 +47,7 @@ list_dirs(const boost::filesystem::path& dir_path, unsigned file_counter = 0; Gtk::TreeModel::Row child; Gtk::TreeModel::Row row; - DEBUG_VAR(dir_path); + DEBUG(""); // Fill the treeview for ( boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; @@ -80,107 +79,109 @@ 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++; + if (path[i] == '/') + count++; return count; } - std::string Directories::Controller:: - GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) { - INFO("fetches cmake variable value for: "+command_name); - 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 ) { - if (itr->path().filename().string() == "CMakeLists.txt") { - std::ifstream ifs(itr->path().string()); - std::string line; - while (std::getline(ifs, line)) { - if (line.find(command_name+"(", 0) != std::string::npos - || line.find(command_name+" (", 0) != std::string::npos ) { - size_t variable_start = line.find("{", 0); - size_t variable_end = line.find("}", variable_start); - project_name_var = line.substr(variable_start+1, - (variable_end)-variable_start-1); - boost::algorithm::trim(project_name_var); - if (variable_start == std::string::npos) { // not a variabel - variable_start = line.find("(", 0); +std::string Directories::Controller:: +GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) { + INFO("fetches cmake variable value for: "+command_name); + 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 ) { + if (itr->path().filename().string() == "CMakeLists.txt") { + std::ifstream ifs(itr->path().string()); + std::string line; + while (std::getline(ifs, line)) { + if (line.find(command_name+"(", 0) != std::string::npos + || line.find(command_name+" (", 0) != std::string::npos ) { + size_t variable_start = line.find("{", 0); + size_t variable_end = line.find("}", variable_start); + project_name_var = line.substr(variable_start+1, + (variable_end)-variable_start-1); + boost::algorithm::trim(project_name_var); + if (variable_start == std::string::npos) { // not a variabel + variable_start = line.find("(", 0); - variable_end = line.find(' ', variable_start); - if(variable_end != std::string::npos){ - return line.substr(variable_start+1, - (variable_end)-variable_start-1); - } - variable_end = line.find("#", variable_start); - if(variable_end != std::string::npos){ - return line.substr(variable_start+1, - (variable_end)-variable_start-1); - } - variable_end = line.find(")", variable_start); + variable_end = line.find(' ', variable_start); + if(variable_end != std::string::npos){ + return line.substr(variable_start+1, + (variable_end)-variable_start-1); + } + variable_end = line.find("#", variable_start); + if(variable_end != std::string::npos){ + return line.substr(variable_start+1, + (variable_end)-variable_start-1); + } + variable_end = line.find(")", variable_start); + return line.substr(variable_start+1, + (variable_end)-variable_start-1); + if (variable_start == std::string::npos) { // not a variable + variable_start = line.find("(", 0); + variable_end = line.find(")", variable_start); + INFO("Wasn't a variable, returning value"); return line.substr(variable_start+1, (variable_end)-variable_start-1); - if (variable_start == std::string::npos) { // not a variable - variable_start = line.find("(", 0); - variable_end = line.find(")", variable_start); - INFO("Wasn't a variable, returning value"); - return line.substr(variable_start+1, - (variable_end)-variable_start-1); } break; } } - } - std::ifstream ifs2(itr->path().string()); - while (std::getline(ifs2, line)) { - 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 variable_start = line.find(project_name_var, 0) - +project_name_var.length(); - size_t variable_end = line.find(")", variable_start); - project_name = line.substr(variable_start+1, - variable_end-variable_start-1); - boost::algorithm::trim(project_name); - INFO("found variable, returning value"); - return project_name; - } + } + std::ifstream ifs2(itr->path().string()); + while (std::getline(ifs2, line)) { + 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 variable_start = line.find(project_name_var, 0) + +project_name_var.length(); + size_t variable_end = line.find(")", variable_start); + project_name = line.substr(variable_start+1, + variable_end-variable_start-1); + boost::algorithm::trim(project_name); + INFO("found variable, returning value"); + return project_name; } } - break; } + break; } - INFO("Couldn't find value in CMakeLists.txt"); - return "no project name"; } + INFO("Couldn't find value in CMakeLists.txt"); + return "no project name"; +} - Directories::Config::Config() { - } - Directories::Config::Config(Directories::Config& cfg) : - ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) { - } +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::AddIgnore(std::string filter) { + ignore_list_.push_back(filter); +} - void Directories::Config::AddException(std::string filter) { - exception_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::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; - } +bool Directories::Config::IsException(std::string str) { + for ( std::string &i : exception_list() ) + if (i == str) + return true; + return false; +} diff --git a/juci/notebook.cc b/juci/notebook.cc index 44470e9..c76409a 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -13,7 +13,8 @@ Notebook::View::View() : notebook_() { view_.set_position(120); } -Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& keybindings, +Notebook::Controller::Controller(Gtk::Window* window, + Keybindings::Controller& keybindings, Source::Config& source_cfg, Directories::Config& dir_cfg) : source_config_(source_cfg), diff --git a/juci/source.cc b/juci/source.cc index d2fed65..7b2dde2 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -70,9 +70,18 @@ const std::unordered_map& Source::Config::typetable() const { return typetable_; } + std::vector& Source::Config::extensiontable() { + return extensiontable_; +} + void Source::Config::InsertTag(const string &key, const string &value) { tagtable_[key] = value; } + +void Source::Config::InsertExtension(const string &ext) { + extensiontable_.push_back(ext); +} + // Source::View::Config::SetTagTable() // sets the tagtable for the view void Source::Config:: diff --git a/juci/source.h b/juci/source.h index f9b45bd..cbdcfc1 100644 --- a/juci/source.h +++ b/juci/source.h @@ -20,16 +20,18 @@ namespace Source { Config(); const std::unordered_map& tagtable() const; const std::unordered_map& typetable() const; + std::vector& extensiontable(); void SetTagTable(const std::unordered_map &tagtable); void InsertTag(const std::string &key, const std::string &value); void SetTypeTable(const std::unordered_map &tagtable); void InsertType(const std::string &key, const std::string &value); - + void InsertExtension(const std::string &ext); private: std::unordered_map tagtable_; std::unordered_map typetable_; + std::vector extensiontable_; std::string background_; }; // class Config diff --git a/juci/window.cc b/juci/window.cc index ba4c391..d714702 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -59,7 +59,7 @@ Window::Window() : std::thread execute([=]() { std::string path = notebook_.CurrentPagePath(); int pos = path.find_last_of("/\\"); - if(pos != std::string::npos){ + if(pos != std::string::npos) { path.erase(path.begin()+pos,path.end()); terminal_.SetFolderCommand(path); } From 68d04753183f2a9402d3f37355089cc4fc9ee700 Mon Sep 17 00:00:00 2001 From: oyvang Date: Fri, 15 May 2015 13:56:53 +0200 Subject: [PATCH 09/19] fixing crash bug on dot in json files --- juci/notebook.cc | 20 +++++++++++++++++++- juci/notebook.h | 1 + juci/window.cc | 1 - 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 47dd4ef..c14f17b 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -157,7 +157,9 @@ bool Notebook::Controller::OnKeyRelease(GdkEventKey* key) { } bool Notebook::Controller::GeneratePopup(int key_id) { - INFO("Notebook genereate popup, getting iters"); + INFO("Notebook genereate popup, getting iters"); + std::string path = text_vec_.at(CurrentPage())->path(); + if(!LeagalExtension(path.substr(path.find_last_of(".") + 1))) return false; // Get function to fill popup with suggests item vector under is for testing Gtk::TextIter beg = CurrentTextView().get_buffer()->get_insert()->get_iter(); Gtk::TextIter end = CurrentTextView().get_buffer()->get_insert()->get_iter(); @@ -712,3 +714,19 @@ void Notebook::Controller::AskToSaveDialog() { } } +bool Notebook::Controller::LeagalExtension(std::string e) { + std::transform(e.begin(), e.end(),e.begin(), ::tolower); + std::vector extensions = + text_vec_.at(CurrentPage).leagalParseExtensions(); + + if(std::find(extensions.begin(), extensions.end(), e)) { + + // if(e=="c" ||e=="cc" ||e=="cpp" ||e=="cxx" || e=="c++"|| + // e=="h" ||e=="hh" ||e=="hpp" ||e=="hxx" || e=="h++"){ + DEBUG("Leagal extension"); + return true; + } + DEBUG("Ileagal extension"); + return false; +} + diff --git a/juci/notebook.h b/juci/notebook.h index bf5440c..f5ef2ba 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -89,6 +89,7 @@ namespace Notebook { int ¤t_x, int ¤t_y); void AskToSaveDialog(); + bool LeagalExtension(std::string extension); Glib::RefPtr m_refBuilder; Glib::RefPtr refActionGroup; Source::Config source_config_; diff --git a/juci/window.cc b/juci/window.cc index ba4c391..b88fe0a 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -95,7 +95,6 @@ Window::Window() : running.unlock(); } }); - this->signal_button_release_event(). connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); terminal_.Terminal().signal_button_release_event(). From 136e70d15b6fb24fbedf05205ba0682497e46eb0 Mon Sep 17 00:00:00 2001 From: tedjk Date: Fri, 15 May 2015 14:31:01 +0200 Subject: [PATCH 10/19] fixed legal extensions to parse in source and notebook, with GM --- juci/config.json | 13 ++++++++++--- juci/notebook.cc | 22 +++++++++++----------- juci/notebook.h | 4 ++-- juci/source.cc | 2 +- juci/source.h | 2 +- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/juci/config.json b/juci/config.json index 743f9f3..cc39637 100644 --- a/juci/config.json +++ b/juci/config.json @@ -18,9 +18,16 @@ "705": "comment" }, "extensions": [ - "ext1", - "ext2", - "ext3" + "c", + "cc", + "cpp", + "cxx", + "c++", + "h", + "hh", + "hpp", + "hxx", + "h++" ] }, "keybindings": { diff --git a/juci/notebook.cc b/juci/notebook.cc index 238b42b..0f16e40 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -160,7 +160,7 @@ bool Notebook::Controller::OnKeyRelease(GdkEventKey* key) { bool Notebook::Controller::GeneratePopup(int key_id) { INFO("Notebook genereate popup, getting iters"); std::string path = text_vec_.at(CurrentPage())->path(); - if(!LeagalExtension(path.substr(path.find_last_of(".") + 1))) return false; + if (!LegalExtension(path.substr(path.find_last_of(".") + 1))) return false; // Get function to fill popup with suggests item vector under is for testing Gtk::TextIter beg = CurrentTextView().get_buffer()->get_insert()->get_iter(); Gtk::TextIter end = CurrentTextView().get_buffer()->get_insert()->get_iter(); @@ -715,19 +715,19 @@ void Notebook::Controller::AskToSaveDialog() { } } -bool Notebook::Controller::LeagalExtension(std::string e) { +bool Notebook::Controller::LegalExtension(std::string e) { std::transform(e.begin(), e.end(),e.begin(), ::tolower); std::vector extensions = - text_vec_.at(CurrentPage).leagalParseExtensions(); - - if(std::find(extensions.begin(), extensions.end(), e)) { + source_config().extensiontable(); - // if(e=="c" ||e=="cc" ||e=="cpp" ||e=="cxx" || e=="c++"|| - // e=="h" ||e=="hh" ||e=="hpp" ||e=="hxx" || e=="h++"){ - DEBUG("Leagal extension"); - return true; - } - DEBUG("Ileagal extension"); + if (find(extensions.begin(), extensions.end(), e) != extensions.end()) { + DEBUG("Legal extension"); + return true; + + // if(e=="c" ||e=="cc" ||e=="cpp" ||e=="cxx" || e=="c++"|| + // e=="h" ||e=="hh" ||e=="hpp" ||e=="hxx" || e=="h++"){ + } + DEBUG("Ilegal extension"); return false; } diff --git a/juci/notebook.h b/juci/notebook.h index f5ef2ba..6991b32 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -68,7 +68,7 @@ namespace Notebook { Gtk::Paned& view(); bool GeneratePopup(int key); void Search(bool forward); - const Source::Config& source_config() { return source_config_; } + Source::Config& source_config() { return source_config_; } bool OnMouseRelease(GdkEventButton* button); bool OnKeyRelease(GdkEventKey* key); std::string OnSaveFileAs(); @@ -89,7 +89,7 @@ namespace Notebook { int ¤t_x, int ¤t_y); void AskToSaveDialog(); - bool LeagalExtension(std::string extension); + bool LegalExtension(std::string extension); Glib::RefPtr m_refBuilder; Glib::RefPtr refActionGroup; Source::Config source_config_; diff --git a/juci/source.cc b/juci/source.cc index 7b2dde2..6667450 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -70,7 +70,7 @@ const std::unordered_map& Source::Config::typetable() const { return typetable_; } - std::vector& Source::Config::extensiontable() { +const std::vector& Source::Config::extensiontable() const{ return extensiontable_; } diff --git a/juci/source.h b/juci/source.h index cbdcfc1..64b7618 100644 --- a/juci/source.h +++ b/juci/source.h @@ -20,7 +20,7 @@ namespace Source { Config(); const std::unordered_map& tagtable() const; const std::unordered_map& typetable() const; - std::vector& extensiontable(); + const std::vector& extensiontable() const; void SetTagTable(const std::unordered_map &tagtable); void InsertTag(const std::string &key, const std::string &value); From f3f14aada609ea624d9fea9e8c171c317245ff80 Mon Sep 17 00:00:00 2001 From: tedjk Date: Fri, 15 May 2015 14:35:03 +0200 Subject: [PATCH 11/19] fixed nasty syntax indent error in config.json --- juci/config.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/juci/config.json b/juci/config.json index cc39637..bdbbeec 100644 --- a/juci/config.json +++ b/juci/config.json @@ -21,13 +21,13 @@ "c", "cc", "cpp", - "cxx", - "c++", - "h", - "hh", - "hpp", - "hxx", - "h++" + "cxx", + "c++", + "h", + "hh", + "hpp", + "hxx", + "h++" ] }, "keybindings": { From 81dd9e5a5d1495542b652fa6b63a133235dc50da Mon Sep 17 00:00:00 2001 From: oyvang Date: Fri, 15 May 2015 15:12:28 +0200 Subject: [PATCH 12/19] removed commen in LegalExtension --- juci/notebook.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 0f16e40..dcd7c54 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -723,9 +723,6 @@ bool Notebook::Controller::LegalExtension(std::string e) { if (find(extensions.begin(), extensions.end(), e) != extensions.end()) { DEBUG("Legal extension"); return true; - - // if(e=="c" ||e=="cc" ||e=="cpp" ||e=="cxx" || e=="c++"|| - // e=="h" ||e=="hh" ||e=="hpp" ||e=="hxx" || e=="h++"){ } DEBUG("Ilegal extension"); return false; From 6bb936e059155832a6415d4125fd3395120c305a Mon Sep 17 00:00:00 2001 From: oyvang Date: Mon, 18 May 2015 10:46:27 +0200 Subject: [PATCH 13/19] Fixed extensions and compile bug --- juci/config.cc | 1 - juci/notebook.cc | 8 ++++---- juci/source.cc | 2 +- juci/source.h | 5 +++-- juci/terminal.cc | 16 ++++++++++------ juci/window.cc | 46 +++++++++++++++++++++++----------------------- 6 files changed, 41 insertions(+), 37 deletions(-) diff --git a/juci/config.cc b/juci/config.cc index b320a6c..727904a 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -25,7 +25,6 @@ void MainConfig::GenerateSource() { for (auto &i : extensions_json) { source_cfg_.InsertExtension(i.second.get_value()); } - DEBUG("Source cfg fetched"); } diff --git a/juci/notebook.cc b/juci/notebook.cc index dcd7c54..3590d49 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -3,8 +3,8 @@ #include "logging.h" Notebook::Model::Model() { - cc_extension_ = ".cc"; - h_extension_ = ".h"; + cc_extension_ = ".cpp"; + h_extension_ = ".hpp"; scrollvalue_ = 50; } @@ -17,7 +17,6 @@ Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& keybindings, Source::Config& source_cfg, Directories::Config& dir_cfg) : - source_config_(source_cfg), directories_(dir_cfg), index_(0, 1) { window_ = window; @@ -25,6 +24,7 @@ Notebook::Controller::Controller(Gtk::Window* window, refClipboard_ = Gtk::Clipboard::get(); ispopup = false; view().pack1(directories_.widget(), true, true); + source_config_ = source_cfg; CreateKeybindings(keybindings); INFO("Notebook Controller Success"); } // Constructor @@ -719,7 +719,7 @@ bool Notebook::Controller::LegalExtension(std::string e) { std::transform(e.begin(), e.end(),e.begin(), ::tolower); std::vector extensions = source_config().extensiontable(); - + std::cout << e << std::endl; if (find(extensions.begin(), extensions.end(), e) != extensions.end()) { DEBUG("Legal extension"); return true; diff --git a/juci/source.cc b/juci/source.cc index 6667450..36b2ade 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -70,7 +70,7 @@ const std::unordered_map& Source::Config::typetable() const { return typetable_; } -const std::vector& Source::Config::extensiontable() const{ +std::vector& Source::Config::extensiontable(){ return extensiontable_; } diff --git a/juci/source.h b/juci/source.h index 64b7618..8db62f3 100644 --- a/juci/source.h +++ b/juci/source.h @@ -20,7 +20,7 @@ namespace Source { Config(); const std::unordered_map& tagtable() const; const std::unordered_map& typetable() const; - const std::vector& extensiontable() const; + std::vector& extensiontable(); void SetTagTable(const std::unordered_map &tagtable); void InsertTag(const std::string &key, const std::string &value); @@ -28,10 +28,11 @@ namespace Source { &tagtable); void InsertType(const std::string &key, const std::string &value); void InsertExtension(const std::string &ext); + std::vector extensiontable_; private: std::unordered_map tagtable_; std::unordered_map typetable_; - std::vector extensiontable_; + std::string background_; }; // class Config diff --git a/juci/terminal.cc b/juci/terminal.cc index 1ea2029..98971c2 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -27,10 +27,12 @@ void Terminal::Controller::Compile(){ INFO("Terminal: Compile"); Terminal().get_buffer()->set_text(""); DEBUG("Terminal: Compile: running cmake command"); - ExecuteCommand("cmake .", "r"); + ExecuteCommand("rm -rf ./build", "r"); + ExecuteCommand("mkdir ./build", "r"); + ExecuteCommand("cmake -B./build -H.", "r"); if (ExistInConsole(cmake_sucsess)){ DEBUG("Terminal: Compile: running make command"); - ExecuteCommand("make", "r"); + ExecuteCommand("cd ./build/; make", "r"); } PrintMessage("\n"); DEBUG("Terminal: Compile: compile done"); @@ -41,7 +43,7 @@ void Terminal::Controller::Run(std::string executable) { PrintMessage("juCi++ execute: " + executable + "\n"); DEBUG("Terminal: Compile: running run command: "); DEBUG_VAR(executable); - ExecuteCommand("./"+executable, "r"); + ExecuteCommand("cd ./build/; ./"+executable, "r"); PrintMessage("\n"); } @@ -65,16 +67,18 @@ void Terminal::Controller::ExecuteCommand(std::string command, std::string mode) INFO("Terminal: ExecuteCommand"); command = folder_command_+command; DEBUG("Terminal: PrintMessage: Running command"); - DEBUG_VAR(command); - FILE* p = popen(command.c_str(), mode.c_str()); - + FILE* p = NULL; + p = popen(command.c_str(), mode.c_str()); + std::cout << "KJØRTE FINT!" << std::endl; if (p == NULL) { PrintMessage("juCi++ ERROR: Failed to run command" + command + "\n"); }else { + std::cout << "SKRIVER UT KOMMANDO RESULAT" << std::endl; char buffer[1028]; while (fgets(buffer, 1028, p) != NULL) { PrintMessage(buffer); } pclose(p); } + } diff --git a/juci/window.cc b/juci/window.cc index 1ed2936..c48be55 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -49,29 +49,29 @@ Window::Window() : }); keybindings_. action_group_menu()-> - add(Gtk::Action::create("ProjectCompileAndRun", - "Compile And Run"), - Gtk::AccelKey(keybindings_.config_ - .key_map()["compile_and_run"]), - [this]() { - notebook_.OnSaveFile(); - if (running.try_lock()) { - std::thread execute([=]() { - std::string path = notebook_.CurrentPagePath(); - int pos = path.find_last_of("/\\"); - if(pos != std::string::npos) { - path.erase(path.begin()+pos,path.end()); - terminal_.SetFolderCommand(path); - } - terminal_.Compile(); - std::string executable = notebook_.directories(). - GetCmakeVarValue(path,"add_executable"); - terminal_.Run(executable); - }); - execute.detach(); - running.unlock(); - } - }); + add(Gtk::Action::create("ProjectCompileAndRun", + "Compile And Run"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["compile_and_run"]), + [this]() { + notebook_.OnSaveFile(); + if (running.try_lock()) { + std::thread execute([=]() { + std::string path = notebook_.CurrentPagePath(); + int pos = path.find_last_of("/\\"); + if(pos != std::string::npos) { + path.erase(path.begin()+pos,path.end()); + terminal_.SetFolderCommand(path); + } + terminal_.Compile(); + std::string executable = notebook_.directories(). + GetCmakeVarValue(path,"add_executable"); + terminal_.Run(executable); + }); + execute.detach(); + running.unlock(); + } + }); keybindings_. action_group_menu()-> From 98d187611a17c0916901e3a2256ac4823eee1b18 Mon Sep 17 00:00:00 2001 From: oyvang Date: Mon, 18 May 2015 11:36:36 +0200 Subject: [PATCH 14/19] fixing config bugs --- juci/notebook.cc | 1 - juci/terminal.cc | 29 +++++++++++++++++++++++------ juci/terminal.h | 10 ++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 3590d49..6992658 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -719,7 +719,6 @@ bool Notebook::Controller::LegalExtension(std::string e) { std::transform(e.begin(), e.end(),e.begin(), ::tolower); std::vector extensions = source_config().extensiontable(); - std::cout << e << std::endl; if (find(extensions.begin(), extensions.end(), e) != extensions.end()) { DEBUG("Legal extension"); return true; diff --git a/juci/terminal.cc b/juci/terminal.cc index 98971c2..beab086 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -4,6 +4,18 @@ #include "logging.h" +Terminal::Config::Config() { +} +Terminal::Config::Config(Terminal::Config& original) { + for (auto it = 0; original.compile_commands().size(); ++it) { + InsertCompileCommand(original.compile_commands().at(it)); + } +} + +void Terminal::Config::InsertCompileCommand(std::string command){ + compile_commands_.push_back(command); +} + Terminal::View::View(){ scrolledwindow_.add(textview_); scrolledwindow_.set_size_request(-1,150); @@ -27,13 +39,18 @@ void Terminal::Controller::Compile(){ INFO("Terminal: Compile"); Terminal().get_buffer()->set_text(""); DEBUG("Terminal: Compile: running cmake command"); - ExecuteCommand("rm -rf ./build", "r"); - ExecuteCommand("mkdir ./build", "r"); - ExecuteCommand("cmake -B./build -H.", "r"); - if (ExistInConsole(cmake_sucsess)){ - DEBUG("Terminal: Compile: running make command"); - ExecuteCommand("cd ./build/; make", "r"); + std::vector commands = config().compile_commands(); + for (auto it = 0; it < commands.size(); ++it) { + ExecuteCommand(commands.at(it), "r"); + } + // ExecuteCommand("rm -rf ./.build", "r"); + // ExecuteCommand("mkdir ./.build", "r"); + // ExecuteCommand("cmake -B./build -H.", "r"); + // if (ExistInConsole(cmake_sucsess)){ + // DEBUG("Terminal: Compile: running make command"); + // ExecuteCommand("cd ./.build/; make", "r"); + // } PrintMessage("\n"); DEBUG("Terminal: Compile: compile done"); } diff --git a/juci/terminal.h b/juci/terminal.h index a3fa6a6..4caa429 100644 --- a/juci/terminal.h +++ b/juci/terminal.h @@ -7,6 +7,16 @@ namespace Terminal { + class Config { + public: + Config (); + Config(Terminal::Config& original); + std::vector& compile_commands() {return &compile_commands_;} + void InsertCompileCommand(std::string command); + private: + std::vector compile_commands_; + }; + class View { public: View(); From ff3442896cabcac70e870894080c88653bd7ee17 Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 18 May 2015 11:39:08 +0200 Subject: [PATCH 15/19] fixing bugs with config, with --- juci/config.cc | 9 +++++++++ juci/config.h | 9 ++++++++- juci/config.json | 10 +++++++++- juci/keybindings.h | 2 +- juci/source.h | 1 - juci/terminal.cc | 3 ++- juci/terminal.h | 4 +++- juci/window.cc | 1 + 8 files changed, 33 insertions(+), 6 deletions(-) diff --git a/juci/config.cc b/juci/config.cc index b320a6c..74c450f 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -8,6 +8,7 @@ MainConfig::MainConfig() : GenerateSource(); GenerateKeybindings(); GenerateDirectoryFilter(); + GenerateTerminalCommands(); } void MainConfig::GenerateSource() { @@ -29,6 +30,14 @@ void MainConfig::GenerateSource() { DEBUG("Source cfg fetched"); } +void MainConfig::GenerateTerminalCommands() { + boost::property_tree::ptree source_json = cfg_.get_child("project"); + boost::property_tree::ptree commands_json = source_json.get_child("compile_commands"); + for (auto &i : commands_json) { + terminal_cfg_.InsertCompileCommand(i.second.get_value()); + } +} + void MainConfig::GenerateKeybindings() { DEBUG("Fetching keybindings"); std::string line; diff --git a/juci/config.h b/juci/config.h index edcb5fc..2b7b596 100644 --- a/juci/config.h +++ b/juci/config.h @@ -1,3 +1,5 @@ +#ifndef +#define JUCI_CONFIG_H_ #include #include #include @@ -5,21 +7,26 @@ #include "keybindings.h" #include "source.h" #include "directories.h" +#include "terminal.h" class MainConfig { public: MainConfig(); Source::Config& source_cfg() { return source_cfg_; } Keybindings::Config& keybindings_cfg() { return keybindings_cfg_; } - Directories::Config& dir_cfg() { return dir_cfg_; } + Directories::Config& dir_cfg() { return dir_cfg_; } + Terminal::Config& terminal_cfg() { return terminal_cfg_; } void PrintMenu(); void GenerateSource(); void GenerateKeybindings(); void GenerateDirectoryFilter(); + void GenerateTerminalCommands(); private: boost::property_tree::ptree cfg_; boost::property_tree::ptree key_tree_; Source::Config source_cfg_; Keybindings::Config keybindings_cfg_; Directories::Config dir_cfg_; + Terminal::Config terminal_cfg_; }; +#endif diff --git a/juci/config.json b/juci/config.json index bdbbeec..e4dc14b 100644 --- a/juci/config.json +++ b/juci/config.json @@ -55,7 +55,15 @@ "cmakelists.txt", "in-lowercase.pls" ] - }, + }, + "project": { + "compile_commands": [ + "rm -rf ./build", + "mkdir build", + "cmake -B./build -H.", + "cd ./.build/; make" + ] + }, "example": { "key": "value", "key2": [ diff --git a/juci/keybindings.h b/juci/keybindings.h index 8273a38..eafccd5 100644 --- a/juci/keybindings.h +++ b/juci/keybindings.h @@ -15,7 +15,7 @@ namespace Keybindings { Config(); std::string& menu_xml() { return menu_xml_; } std::unordered_map& key_map() { return key_map_; } - void AppendXml(std::string &child); + void AppendXml(std::string &child); void SetMenu(std::string &menu_xml); void SetKeyMap(std::unordered_map &key_map); private: diff --git a/juci/source.h b/juci/source.h index 64b7618..3bb3c12 100644 --- a/juci/source.h +++ b/juci/source.h @@ -157,7 +157,6 @@ namespace Source { void set_is_saved(bool isSaved) { is_saved_ = isSaved; } void set_is_changed(bool isChanged) { is_changed_ = isChanged; } void set_file_path(std::string path) { model().set_file_path(path); } - private: void OnLineEdit(); diff --git a/juci/terminal.cc b/juci/terminal.cc index 1ea2029..8d65303 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -12,7 +12,8 @@ Terminal::View::View(){ } -Terminal::Controller::Controller() { +Terminal::Controller::Controller(Terminal::Config& cfg) : + config_(cfg) { folder_command_ = ""; } diff --git a/juci/terminal.h b/juci/terminal.h index a3fa6a6..b3cdca0 100644 --- a/juci/terminal.h +++ b/juci/terminal.h @@ -20,13 +20,15 @@ namespace Terminal { class Controller { public: - Controller(); + Controller(Terminal::Config& cfg); Gtk::HBox& view() {return view_.view();} Gtk::TextView& Terminal(){return view_.textview();} void SetFolderCommand(boost::filesystem::path CMake_path); void Run(std::string executable); void Compile(); + Terminal::Config& config() { return config_; } private: + Terminal::Config config_; void ExecuteCommand(std::string command, std::string mode); bool OnButtonRealeaseEvent(GdkEventKey* key); bool ExistInConsole(std::string string); diff --git a/juci/window.cc b/juci/window.cc index 1ed2936..cae5b5e 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -5,6 +5,7 @@ Window::Window() : window_box_(Gtk::ORIENTATION_VERTICAL), main_config_(), keybindings_(main_config_.keybindings_cfg()), + terminal_(main_config_.terminal_cfg()), notebook_(this,keybindings(), main_config_.source_cfg(), main_config_.dir_cfg()), From 26dc5d44ddf4eade757e8fa220a2d3f04f4d804b Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 18 May 2015 11:46:46 +0200 Subject: [PATCH 16/19] merged with gm --- juci/config.h | 2 +- juci/terminal.cc | 2 +- juci/terminal.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/juci/config.h b/juci/config.h index 2b7b596..f6c652e 100644 --- a/juci/config.h +++ b/juci/config.h @@ -1,4 +1,4 @@ -#ifndef +#ifndef JUCI_CONFIG_H_ #define JUCI_CONFIG_H_ #include #include diff --git a/juci/terminal.cc b/juci/terminal.cc index 7984532..52cdcdc 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -7,7 +7,7 @@ Terminal::Config::Config() { } Terminal::Config::Config(Terminal::Config& original) { - for (auto it = 0; original.compile_commands().size(); ++it) { + for (auto it = 0; it& compile_commands() {return &compile_commands_;} + std::vector& compile_commands() { return compile_commands_; } void InsertCompileCommand(std::string command); private: std::vector compile_commands_; From 2e59a5f294579f3c6efe8829ff707a61927024fd Mon Sep 17 00:00:00 2001 From: oyvang Date: Mon, 18 May 2015 11:53:14 +0200 Subject: [PATCH 17/19] fixing bugs config term --- juci/config.json | 4 ++-- juci/terminal.cc | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/juci/config.json b/juci/config.json index e4dc14b..a9553f6 100644 --- a/juci/config.json +++ b/juci/config.json @@ -58,9 +58,9 @@ }, "project": { "compile_commands": [ - "rm -rf ./build", + "rm -rf ./.build", "mkdir build", - "cmake -B./build -H.", + "cmake -B./.build -H.", "cd ./.build/; make" ] }, diff --git a/juci/terminal.cc b/juci/terminal.cc index 52cdcdc..85f9047 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -38,6 +38,7 @@ void Terminal::Controller::SetFolderCommand( boost::filesystem::path void Terminal::Controller::Compile(){ INFO("Terminal: Compile"); + Terminal().get_buffer()->set_text(""); DEBUG("Terminal: Compile: running cmake command"); std::vector commands = config().compile_commands(); @@ -45,13 +46,6 @@ void Terminal::Controller::Compile(){ ExecuteCommand(commands.at(it), "r"); } - // ExecuteCommand("rm -rf ./.build", "r"); - // ExecuteCommand("mkdir ./.build", "r"); - // ExecuteCommand("cmake -B./build -H.", "r"); - // if (ExistInConsole(cmake_sucsess)){ - // DEBUG("Terminal: Compile: running make command"); - // ExecuteCommand("cd ./.build/; make", "r"); - // } PrintMessage("\n"); DEBUG("Terminal: Compile: compile done"); } @@ -61,7 +55,7 @@ void Terminal::Controller::Run(std::string executable) { PrintMessage("juCi++ execute: " + executable + "\n"); DEBUG("Terminal: Compile: running run command: "); DEBUG_VAR(executable); - ExecuteCommand("cd ./build/; ./"+executable, "r"); + ExecuteCommand("cd ./.build/; ./"+executable, "r"); PrintMessage("\n"); } From 7ef8ff0893179bbbd61279288216491c3eb2ac0d Mon Sep 17 00:00:00 2001 From: oyvang Date: Mon, 18 May 2015 12:04:36 +0200 Subject: [PATCH 18/19] fixing terminal bugs --- juci/config.json | 1 + juci/terminal.cc | 2 +- juci/terminal.h | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/juci/config.json b/juci/config.json index a9553f6..09cb5a2 100644 --- a/juci/config.json +++ b/juci/config.json @@ -57,6 +57,7 @@ ] }, "project": { + "compile_commands": [ "rm -rf ./.build", "mkdir build", diff --git a/juci/terminal.cc b/juci/terminal.cc index 85f9047..45670d2 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -55,7 +55,7 @@ void Terminal::Controller::Run(std::string executable) { PrintMessage("juCi++ execute: " + executable + "\n"); DEBUG("Terminal: Compile: running run command: "); DEBUG_VAR(executable); - ExecuteCommand("cd ./.build/; ./"+executable, "r"); + ExecuteCommand("cd"+config().run_command() + "; ./"+executable, "r"); PrintMessage("\n"); } diff --git a/juci/terminal.h b/juci/terminal.h index 5fb7f7e..bccf7d2 100644 --- a/juci/terminal.h +++ b/juci/terminal.h @@ -13,8 +13,11 @@ namespace Terminal { Config(Terminal::Config& original); std::vector& compile_commands() { return compile_commands_; } void InsertCompileCommand(std::string command); + std::string& run_command() { return run_command_; } + void SetRunCommand(std::string command); private: std::vector compile_commands_; + std::string run_command_; }; class View { From bc94a3bb3f9f20aac1cd4e7c97c5ffd584c468f4 Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 18 May 2015 12:04:49 +0200 Subject: [PATCH 19/19] added run commands to config --- juci/config.cc | 11 ++++++++--- juci/config.json | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/juci/config.cc b/juci/config.cc index 8d54a65..0e60ef4 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -31,11 +31,16 @@ void MainConfig::GenerateSource() { void MainConfig::GenerateTerminalCommands() { boost::property_tree::ptree source_json = cfg_.get_child("project"); - boost::property_tree::ptree commands_json = source_json.get_child("compile_commands"); - for (auto &i : commands_json) { - terminal_cfg_.InsertCompileCommand(i.second.get_value()); + boost::property_tree::ptree compile_commands_json = source_json.get_child("compile_commands"); + boost::property_tree::ptree run_commands_json = source_json.get_child("run_commands"); + for (auto &i : compile_commands_json) { + terminal_cfg_.InsertCompileCommand(i.second.get_value()); + } + for (auto &i : run_commands_json) { + terminal_cfg_.SetRunCommand(i.second.get_value()); } } + } void MainConfig::GenerateKeybindings() { DEBUG("Fetching keybindings"); diff --git a/juci/config.json b/juci/config.json index a9553f6..a9ac5d3 100644 --- a/juci/config.json +++ b/juci/config.json @@ -57,6 +57,9 @@ ] }, "project": { + "run_path": [ + ".build" + ], "compile_commands": [ "rm -rf ./.build", "mkdir build",