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/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/config.cc b/juci/config.cc index 1adb7df..d316c02 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -9,39 +9,55 @@ MainConfig::MainConfig() : GenerateSource(); GenerateKeybindings(); GenerateDirectoryFilter(); + GenerateTerminalCommands(); } 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::GenerateTerminalCommands() { + boost::property_tree::ptree source_json = cfg_.get_child("project"); + 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() { - INFO("Generating keybindings"); + DEBUG("Fetching keybindings"); 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) 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"); @@ -49,6 +65,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.h b/juci/config.h index edcb5fc..f6c652e 100644 --- a/juci/config.h +++ b/juci/config.h @@ -1,3 +1,5 @@ +#ifndef JUCI_CONFIG_H_ +#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 9344fbb..ca3fa5c 100644 --- a/juci/config.json +++ b/juci/config.json @@ -16,7 +16,19 @@ "702": "keyword", "703": "own", "705": "comment" - } + }, + "extensions": [ + "c", + "cc", + "cpp", + "cxx", + "c++", + "h", + "hh", + "hpp", + "hxx", + "h++" + ] }, "keybindings": { "split_window": "s", @@ -27,7 +39,7 @@ "edit_undo": "z", "save": "s", "save_as": "s", - "compile_and_run": "r>", + "compile_and_run": "r", "compile": "r" }, "directoryfilter": { @@ -43,7 +55,18 @@ "cmakelists.txt", "in-lowercase.pls" ] - }, + }, + "project": { + "run_commands": [ + "./.build/" + ], + "compile_commands": [ + "rm -rf ./.build", + "mkdir ./.build", + "cmake -B./.build -H.", + "cd ./.build/; make" + ] + }, "example": { "key": "value", "key2": [ diff --git a/juci/directories.cc b/juci/directories.cc index 73fb825..199e4dd 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,18 +14,21 @@ 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)) { return false; } @@ -36,17 +40,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(""); // 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 @@ -74,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/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/notebook.cc b/juci/notebook.cc index d6c73eb..ec36acc 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -1,10 +1,10 @@ +#include #include "notebook.h" #include "logging.h" -#include Notebook::Model::Model() { - cc_extension_ = ".cc"; - h_extension_ = ".h"; + cc_extension_ = ".cpp"; + h_extension_ = ".hpp"; scrollvalue_ = 50; } @@ -13,10 +13,10 @@ 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), directories_(dir_cfg), index_(0, 1) { INFO("Create notebook"); @@ -25,12 +25,15 @@ Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& k refClipboard_ = Gtk::Clipboard::get(); ispopup = false; view().pack1(directories_.widget(), true, true); + source_config_ = source_cfg; CreateKeybindings(keybindings); + INFO("Notebook Controller Success"); } // 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)); @@ -140,6 +143,7 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller [this]() { Search(false); }); + INFO("Notebook signal handlers sucsess"); } bool Notebook::Controller:: OnMouseRelease(GdkEventButton* button) { @@ -155,6 +159,9 @@ 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 (!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(); @@ -167,6 +174,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; } @@ -189,6 +197,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 +238,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,7 +273,8 @@ bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) { return true; } Notebook::Controller::~Controller() { - for (auto &i : text_vec_) delete i; + INFO("Notebook destructor"); + 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; @@ -276,6 +289,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 +308,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); @@ -303,12 +318,11 @@ 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() { + 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,9 +343,11 @@ void Notebook::Controller::OnCreatePage() { } void Notebook::Controller::OnCloseCurrentPage() { - // TODO(oyvang) zalox, forgi) - // Save a temp file, in case you close one you dont want to close? + INFO("Notebook close page"); if (Pages() != 0) { + if(text_vec_.back()->is_changed()){ + AskToSaveDialog(); + } int page = CurrentPage(); Notebook().remove_page(page); delete text_vec_.at(page); @@ -372,6 +388,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 +416,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(); @@ -456,10 +474,12 @@ 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, 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 +559,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 +594,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 +624,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,16 +645,23 @@ void Notebook::Controller:: OnSaveFile() { std::string Notebook::Controller::OnSaveFileAs(){ - Gtk::FileChooserDialog dialog("Please choose a file", + 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); @@ -649,3 +679,50 @@ 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; + } + } +} + +bool Notebook::Controller::LegalExtension(std::string e) { + std::transform(e.begin(), e.end(),e.begin(), ::tolower); + std::vector extensions = + source_config().extensiontable(); + if (find(extensions.begin(), extensions.end(), e) != extensions.end()) { + DEBUG("Legal extension"); + return true; + } + DEBUG("Ilegal extension"); + return false; +} + diff --git a/juci/notebook.h b/juci/notebook.h index f3678cd..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(); @@ -88,6 +88,8 @@ namespace Notebook { void PopupSetSize(Gtk::ScrolledWindow& scroll, int ¤t_x, int ¤t_y); + void AskToSaveDialog(); + 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 cc7949c..d9a4036 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:: @@ -295,21 +304,6 @@ string extract_file_path(const std::string &file_path) { return file_path.substr(0, file_path.find_last_of('/')); } -std::vector extentions() { - return {".h", ".cc", ".cpp", ".hpp"}; -} - -bool check_extention(const std::string &file_path) { - std::string extention = file_path.substr(file_path.find_last_of('.'), - file_path.size()); - for (auto &ex : extentions()) { - if (extention == ex) { - return true; - } - } - return false; -} - void Source::View::OnUpdateSyntax(const std::vector &ranges, const Source::Config &config) { if (ranges.empty() || ranges.size() == 0) { @@ -335,8 +329,8 @@ void Source::View::OnUpdateSyntax(const std::vector &ranges, buffer->get_iter_at_line_offset(linum_start, begin); Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end); - buffer->apply_tag_by_name(config.typetable().at(type), - begin_iter, end_iter); + buffer->apply_tag_by_name(config.typetable().at(type), + begin_iter, end_iter); } } @@ -349,7 +343,7 @@ void Source::Controller::OnOpenFile(const string &filepath) { buffer()->set_text(s.get_content()); int start_offset = buffer()->begin().get_offset(); int end_offset = buffer()->end().get_offset(); - if (check_extention(filepath)) { + if (!notebook_->LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) { view().ApplyConfig(model().config()); model().InitSyntaxHighlighting(filepath, extract_file_path(filepath), @@ -359,46 +353,45 @@ void Source::Controller::OnOpenFile(const string &filepath) { notebook_->index()); view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), model().config()); - - - buffer()->signal_end_user_action().connect([this]() { - if (!go) { - std::thread parse([this]() { - if (parsing.try_lock()) { - INFO("Starting parsing"); - while (true) { - const std::string raw = buffer()->get_text().raw(); - std::map buffers; - notebook_->MapBuffers(&buffers); - buffers[model().file_path()] = raw; - if (model().ReParse(buffers) == 0 && - raw == buffer()->get_text().raw()) { - syntax.lock(); - go = true; - syntax.unlock(); - break; + + buffer()->signal_end_user_action().connect([this]() { + if (!go) { + std::thread parse([this]() { + if (parsing.try_lock()) { + INFO("Starting parsing"); + while (true) { + const std::string raw = buffer()->get_text().raw(); + std::map buffers; + notebook_->MapBuffers(&buffers); + buffers[model().file_path()] = raw; + if (model().ReParse(buffers) == 0 && + raw == buffer()->get_text().raw()) { + syntax.lock(); + go = true; + syntax.unlock(); + break; + } } + parsing.unlock(); + INFO("Parsing completed"); } - parsing.unlock(); - INFO("Parsing completed"); - } - }); - parse.detach(); - } - }); - - buffer()->signal_begin_user_action().connect([this]() { - if (go) { - syntax.lock(); - INFO("Updating syntax"); - view(). - OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()), - model().config()); - go = false; - INFO("Syntax updated"); - syntax.unlock(); - } - }); + }); + parse.detach(); + } + }); + + buffer()->signal_begin_user_action().connect([this]() { + if (go) { + syntax.lock(); + INFO("Updating syntax"); + view(). + OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()), + model().config()); + go = false; + INFO("Syntax updated"); + syntax.unlock(); + } + }); } } Glib::RefPtr Source::Controller::buffer() { diff --git a/juci/source.h b/juci/source.h index cab4d5d..ee7ebbf 100644 --- a/juci/source.h +++ b/juci/source.h @@ -20,16 +20,19 @@ 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); + std::vector extensiontable_; private: std::unordered_map tagtable_; std::unordered_map typetable_; + std::string background_; }; // class Config @@ -150,10 +153,11 @@ 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); } - private: void OnLineEdit(); @@ -162,6 +166,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..00c7004 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -1,10 +1,26 @@ #include "terminal.h" #include #include -// #include -// #include +#include "logging.h" +Terminal::Config::Config() { +} +Terminal::Config::Config(Terminal::Config& original) : + run_command_(original.run_command_){ + for (auto it = 0; itset_text(""); - ExecuteCommand("cmake .", "r"); - if (ExistInConsole(cmake_sucsess)){ - ExecuteCommand("make", "r"); - } + DEBUG("Terminal: Compile: running cmake command"); + std::vector commands = config().compile_commands(); + for (auto it = 0; it < commands.size(); ++it) { + ExecuteCommand(commands.at(it), "r"); + + } + PrintMessage("\n"); + DEBUG("Terminal: Compile: compile done"); } void Terminal::Controller::Run(std::string executable) { + INFO("Terminal: Run"); PrintMessage("juCi++ execute: " + executable + "\n"); - ExecuteCommand("./"+executable, "r"); + DEBUG("Terminal: Compile: running run command: "); + DEBUG_VAR(executable); + ExecuteCommand("cd "+config().run_command() + "; ./"+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; @@ -50,17 +81,22 @@ 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; - FILE* p = popen(command.c_str(), mode.c_str()); - + DEBUG("Terminal: PrintMessage: Running command"); + FILE* p = NULL; + std::cout << command << std::endl; + 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/terminal.h b/juci/terminal.h index a3fa6a6..bccf7d2 100644 --- a/juci/terminal.h +++ b/juci/terminal.h @@ -7,6 +7,19 @@ namespace Terminal { + class Config { + public: + Config (); + 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 { public: View(); @@ -20,13 +33,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 3cc5b89..201d4bc 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()), @@ -49,29 +50,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]() { - 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){ - 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()-> @@ -80,9 +81,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){ @@ -95,7 +96,6 @@ Window::Window() : running.unlock(); } }); - this->signal_button_release_event(). connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); terminal_.Terminal().signal_button_release_event(). @@ -122,7 +122,6 @@ void Window::OnWindowHide() { 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);