From f7253f498f52e045ff752b2d733a792e0221a44f Mon Sep 17 00:00:00 2001 From: oyvang Date: Fri, 15 May 2015 11:03:21 +0200 Subject: [PATCH] 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_ + "; "; }