From 0e3c551c53f438dcbef7203a88b2f6d0476f9e7e Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 18 May 2015 16:05:15 +0200 Subject: [PATCH 1/7] added custom keyindings where stock gtk bindings were used. --- juci/api_ext.cc | 15 +++++++++++++++ juci/config.json | 2 ++ juci/menu.cc | 2 +- juci/menu.xml | 2 +- juci/notebook.cc | 12 ++++++------ juci/window.cc | 6 ++++-- 6 files changed, 29 insertions(+), 10 deletions(-) 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..8a557f7 100644 --- a/juci/config.json +++ b/juci/config.json @@ -32,10 +32,12 @@ }, "keybindings": { "split_window": "s", + "new_file": "n", "new_h_file": "h", "new_cc_file": "c", "close_tab": "w", "open_folder": "o", + "open_file": "o", "edit_undo": "z", "save": "s", "save_as": "s", 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 6992658..14ed7b8 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -42,17 +42,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]() { @@ -61,7 +61,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]() { diff --git a/juci/window.cc b/juci/window.cc index 201d4bc..7504fb7 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -21,7 +21,9 @@ Window::Window() : 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(); }); @@ -42,7 +44,7 @@ Window::Window() : }); keybindings_.action_group_menu()->add(Gtk::Action::create("FileSave", - "Save"), + "Save file"), Gtk::AccelKey(keybindings_.config_ .key_map()["save"]), [this]() { From 08bf0cf806d850ea9bbe4a54ccb21770c7f98af9 Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 18 May 2015 16:21:48 +0200 Subject: [PATCH 2/7] removed all stock gtk bindings. --- juci/config.json | 14 ++++++++++---- juci/notebook.cc | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/juci/config.json b/juci/config.json index 8a557f7..a97637f 100644 --- a/juci/config.json +++ b/juci/config.json @@ -31,16 +31,22 @@ ] }, "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", "open_file": "o", - "edit_undo": "z", "save": "s", "save_as": "s", + + "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/notebook.cc b/juci/notebook.cc index 14ed7b8..45ba31f 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -78,7 +78,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(); @@ -86,19 +88,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(); }); From d93b864fdb1f5bb8812444d872a8ac46335af328 Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 18 May 2015 16:50:56 +0200 Subject: [PATCH 3/7] removed the last stock gtk binding --- juci/config.json | 1 + juci/window.cc | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/juci/config.json b/juci/config.json index a97637f..9b3e661 100644 --- a/juci/config.json +++ b/juci/config.json @@ -38,6 +38,7 @@ "open_file": "o", "save": "s", "save_as": "s", + "quit": "q", "split_window": "s", "close_tab": "w", diff --git a/juci/window.cc b/juci/window.cc index 7504fb7..bf084f1 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -16,7 +16,9 @@ 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(); }); From 81cd2ef6d40714235e6cbf0b4a8d6dc0e941427a Mon Sep 17 00:00:00 2001 From: oyvang Date: Tue, 19 May 2015 09:09:01 +0200 Subject: [PATCH 4/7] fixed output on save file and save as --- juci/notebook.cc | 49 ++++++++++++++++++++++--------------------- juci/notebook.h | 3 ++- juci/terminal.h | 2 +- juci/window.cc | 54 ++++++++++++++++++++++++++++++++++-------------- juci/window.h | 4 +++- 5 files changed, 70 insertions(+), 42 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 6992658..56fd5ba 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -624,15 +624,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); @@ -640,8 +646,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; } @@ -658,26 +665,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 6991b32..13c14dd 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..bd97d5e 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -33,23 +33,28 @@ Window::Window() : OnFileOpenFolder(); }); - 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("FileSaveAs", + "Save as"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["save_as"]), + [this]() { + SaveFileAs(); + }); + + keybindings_. + 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_ @@ -206,3 +211,20 @@ 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; + } + return false; +} +bool Window::SaveFileAs() { + if(notebook_.OnSaveFile(notebook_.OnSaveFileAs())){ + terminal_.PrintMessage("File saved to: " + + notebook_.CurrentPagePath()+"\n"); + return true; + } + 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 From 6401f94465174b2da91cb41abf18af416bdb86c9 Mon Sep 17 00:00:00 2001 From: oyvang Date: Tue, 19 May 2015 09:12:38 +0200 Subject: [PATCH 5/7] fixed feedback when file is not saved --- juci/window.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/juci/window.cc b/juci/window.cc index bd97d5e..ae62171 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -218,6 +218,7 @@ bool Window::SaveFile() { notebook_.CurrentPagePath()+"\n"); return true; } + terminal_.PrintMessage("File not saved"); return false; } bool Window::SaveFileAs() { @@ -226,5 +227,6 @@ bool Window::SaveFileAs() { notebook_.CurrentPagePath()+"\n"); return true; } + terminal_.PrintMessage("File not saved"); return false; } From 78b2de3924fcf2b70781cf61eb99dbdc4e66fc02 Mon Sep 17 00:00:00 2001 From: oyvang Date: Tue, 19 May 2015 09:15:09 +0200 Subject: [PATCH 6/7] fixed save on compile --- juci/window.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/juci/window.cc b/juci/window.cc index ae62171..f8a150f 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -60,7 +60,7 @@ Window::Window() : 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(); @@ -86,7 +86,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(); From 765b28cf35e6e1f4408d6e8bbe451a58c9cafcba Mon Sep 17 00:00:00 2001 From: oyvang Date: Tue, 19 May 2015 11:31:39 +0200 Subject: [PATCH 7/7] fixed bug with two save listeners --- juci/window.cc | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/juci/window.cc b/juci/window.cc index 277eed9..64f3c92 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -36,22 +36,6 @@ Window::Window() : [this]() { OnFileOpenFolder(); }); - - 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 file"), - Gtk::AccelKey(keybindings_.config_ - .key_map()["save"]), - [this]() { - notebook_.OnSaveFile(); - }); keybindings_. action_group_menu()-> add(Gtk::Action::create("FileSaveAs",