diff --git a/juci/api_ext.cc b/juci/api_ext.cc index e69de29..9b8b1ba 100644 --- a/juci/api_ext.cc +++ b/juci/api_ext.cc @@ -0,0 +1,15 @@ +#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.json b/juci/config.json index ca3fa5c..9b3e661 100644 --- a/juci/config.json +++ b/juci/config.json @@ -31,14 +31,23 @@ ] }, "keybindings": { - "split_window": "s", + "new_file": "n", "new_h_file": "h", - "new_cc_file": "c", - "close_tab": "w", + "new_cc_file": "c", "open_folder": "o", - "edit_undo": "z", + "open_file": "o", "save": "s", "save_as": "s", + "quit": "q", + + "split_window": "s", + "close_tab": "w", + + "edit_copy": "c", + "edit_cut": "x", + "edit_paste": "v", + "edit_undo": "z", + "edit_find": "f", "compile_and_run": "r", "compile": "r" }, diff --git a/juci/menu.cc b/juci/menu.cc index 4fba192..0f09906 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -15,7 +15,7 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) : menu_view_(Gtk::ORIENTATION_VERTICAL), keybindings_(keybindings) { keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew", - Gtk::Stock::FILE)); + "New File")); keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu", Gtk::Stock::EDIT)); keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", diff --git a/juci/menu.xml b/juci/menu.xml index eb7bd04..dbe4b12 100644 --- a/juci/menu.xml +++ b/juci/menu.xml @@ -6,7 +6,7 @@ - + diff --git a/juci/notebook.cc b/juci/notebook.cc index bab2830..909ed36 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -43,17 +43,17 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller Gtk::Stock::FILE)); keybindings.action_group_menu()-> - add(Gtk::Action::create("FileNewStandard", - Gtk::Stock::NEW, - "New empty file", - "Create a new file"), + add(Gtk::Action::create("FileNewStandard", + "New empty file"), + Gtk::AccelKey(keybindings.config_ + .key_map()["new_file"]), [this]() { is_new_file_ = true; OnFileNewEmptyfile(); }); keybindings.action_group_menu()-> add(Gtk::Action::create("FileNewCC", - "New cc file"), + "New source file"), Gtk::AccelKey(keybindings.config_ .key_map()["new_cc_file"]), [this]() { @@ -62,7 +62,7 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller }); keybindings.action_group_menu()-> add(Gtk::Action::create("FileNewH", - "New h file"), + "New header file"), Gtk::AccelKey(keybindings.config_ .key_map()["new_h_file"]), [this]() { @@ -79,7 +79,9 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller }); keybindings.action_group_menu()-> add(Gtk::Action::create("EditFind", - Gtk::Stock::FIND), + "Find"), + Gtk::AccelKey(keybindings.config_ + .key_map()["edit_find"]), [this]() { is_new_file_ = false; OnEditSearch(); @@ -87,19 +89,26 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller }); keybindings.action_group_menu()-> add(Gtk::Action::create("EditCopy", - Gtk::Stock::COPY), + "Copy"), + Gtk::AccelKey(keybindings.config_ + .key_map()["edit_copy"]), + [this]() { OnEditCopy(); }); keybindings.action_group_menu()-> add(Gtk::Action::create("EditCut", - Gtk::Stock::CUT), + "Cut"), + Gtk::AccelKey(keybindings.config_ + .key_map()["edit_cut"]), [this]() { OnEditCut(); }); keybindings.action_group_menu()-> add(Gtk::Action::create("EditPaste", - Gtk::Stock::PASTE), + "Paste"), + Gtk::AccelKey(keybindings.config_ + .key_map()["edit_paste"]), [this]() { OnEditPaste(); }); @@ -623,15 +632,21 @@ void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview, } } -void Notebook::Controller:: OnSaveFile() { +bool Notebook::Controller:: OnSaveFile() { INFO("Notebook save file"); if (text_vec_.at(CurrentPage())->is_saved()) { std::ofstream file; file.open (text_vec_.at(CurrentPage())->path()); file << CurrentTextView().get_buffer()->get_text(); file.close(); + return true; } else { - std::string path = OnSaveFileAs(); + return OnSaveFile(OnSaveFileAs()); + } + return false; +} +bool Notebook::Controller:: OnSaveFile(std::string path) { + INFO("Notebook save file with path"); if (path != "") { std::ofstream file; file.open (path); @@ -639,8 +654,9 @@ void Notebook::Controller:: OnSaveFile() { file.close(); text_vec_.at(CurrentPage())->set_file_path(path); text_vec_.at(CurrentPage())->set_is_saved(true); + return true; } - } + return false; } @@ -657,26 +673,22 @@ std::string Notebook::Controller::OnSaveFileAs(){ 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); - return path; - break; - } - case(Gtk::RESPONSE_CANCEL): { - break; - } - default: { - std::cout << "Unexpected button clicked." << std::endl; - break; - } - } - return ""; + switch (result) { + case(Gtk::RESPONSE_OK): { + DEBUG("get_filename()"); + std::string path = dialog.get_filename(); + unsigned pos = path.find_last_of("/\\"); + return path; + } + case(Gtk::RESPONSE_CANCEL): { + break; + } + default: { + DEBUG("Unexpected button clicked."); + break; + } + } + return ""; } void Notebook::Controller::AskToSaveDialog() { diff --git a/juci/notebook.h b/juci/notebook.h index 12c78ea..e2521a9 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -54,7 +54,8 @@ namespace Notebook { void OnFileNewEmptyfile(); void OnFileNewHeaderFile(); void OnFileOpenFolder(); - void OnSaveFile(); + bool OnSaveFile(); + bool OnSaveFile(std::string path); void OnDirectoryNavigation(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void OnNewPage(std::string name); diff --git a/juci/terminal.h b/juci/terminal.h index bccf7d2..a07d5a5 100644 --- a/juci/terminal.h +++ b/juci/terminal.h @@ -40,12 +40,12 @@ namespace Terminal { void Run(std::string executable); void Compile(); Terminal::Config& config() { return config_; } + void PrintMessage(std::string message); private: Terminal::Config config_; void ExecuteCommand(std::string command, std::string mode); bool OnButtonRealeaseEvent(GdkEventKey* key); bool ExistInConsole(std::string string); - void PrintMessage(std::string message); Terminal::View view_; std::string folder_command_; std::string path_; diff --git a/juci/window.cc b/juci/window.cc index 201d4bc..64f3c92 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -16,12 +16,16 @@ Window::Window() : set_default_size(600, 400); add(window_box_); keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", - Gtk::Stock::QUIT), + "Quit juCi++"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["quit"]), [this]() { OnWindowHide(); }); keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", - Gtk::Stock::OPEN), + "Open file"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["open_file"]), [this]() { OnOpenFile(); }); @@ -32,30 +36,34 @@ Window::Window() : [this]() { OnFileOpenFolder(); }); + keybindings_. + action_group_menu()-> + add(Gtk::Action::create("FileSaveAs", + "Save as"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["save_as"]), + [this]() { + SaveFileAs(); + }); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileSaveAs", - "Save as"), - Gtk::AccelKey(keybindings_.config_ - .key_map()["save_as"]), - [this]() { - notebook_.OnSaveFile(); - }); - - keybindings_.action_group_menu()->add(Gtk::Action::create("FileSave", - "Save"), - Gtk::AccelKey(keybindings_.config_ - .key_map()["save"]), - [this]() { - notebook_.OnSaveFile(); - }); keybindings_. - action_group_menu()-> + action_group_menu()-> + add(Gtk::Action::create("FileSave", + "Save"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["save"]), + [this]() { + SaveFile(); + }); + + keybindings_. + action_group_menu()-> add(Gtk::Action::create("ProjectCompileAndRun", "Compile And Run"), Gtk::AccelKey(keybindings_.config_ .key_map()["compile_and_run"]), [this]() { - notebook_.OnSaveFile(); + SaveFile(); if (running.try_lock()) { std::thread execute([=]() { std::string path = notebook_.CurrentPagePath(); @@ -81,7 +89,7 @@ Window::Window() : Gtk::AccelKey(keybindings_.config_ .key_map()["compile"]), [this]() { - notebook_.OnSaveFile(); + SaveFile(); if (running.try_lock()) { std::thread execute([=]() { std::string path = notebook_.CurrentPagePath(); @@ -206,3 +214,22 @@ void Window::OnOpenFile() { bool Window::OnMouseRelease(GdkEventButton *button){ return notebook_.OnMouseRelease(button); } + +bool Window::SaveFile() { + if(notebook_.OnSaveFile()) { + terminal_.PrintMessage("File saved to: " + + notebook_.CurrentPagePath()+"\n"); + return true; + } + terminal_.PrintMessage("File not saved"); + return false; +} +bool Window::SaveFileAs() { + if(notebook_.OnSaveFile(notebook_.OnSaveFileAs())){ + terminal_.PrintMessage("File saved to: " + + notebook_.CurrentPagePath()+"\n"); + return true; + } + terminal_.PrintMessage("File not saved"); + return false; +} diff --git a/juci/window.h b/juci/window.h index 7f2b3f7..d60dfdb 100644 --- a/juci/window.h +++ b/juci/window.h @@ -32,7 +32,9 @@ public: void OnWindowHide(); void OnOpenFile(); void OnFileOpenFolder(); - bool OnMouseRelease(GdkEventButton* button); + bool OnMouseRelease(GdkEventButton* button); + bool SaveFile(); + bool SaveFileAs(); }; #endif // JUCI_WINDOW_H