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