Browse Source

Quit application fixed, also possible to cancel quit by closing dialog asking if a modified tab should be saved.

merge-requests/365/head
eidheim 11 years ago
parent
commit
ae46741794
  1. 52
      juci/notebook.cc
  2. 4
      juci/notebook.h
  3. 26
      juci/window.cc
  4. 6
      juci/window.h

52
juci/notebook.cc

@ -60,7 +60,7 @@ void Notebook::Controller::CreateKeybindings() {
OnFileNewFile(); OnFileNewFile();
}); });
menu->action_group->add(Gtk::Action::create("WindowCloseTab", "Close tab"), Gtk::AccelKey(menu->key_map["close_tab"]), [this]() { menu->action_group->add(Gtk::Action::create("WindowCloseTab", "Close tab"), Gtk::AccelKey(menu->key_map["close_tab"]), [this]() {
OnCloseCurrentPage(); close_current_page();
}); });
menu->action_group->add(Gtk::Action::create("EditFind", "Find"), Gtk::AccelKey(menu->key_map["edit_find"]), [this]() { menu->action_group->add(Gtk::Action::create("EditFind", "Find"), Gtk::AccelKey(menu->key_map["edit_find"]), [this]() {
show_search_and_replace(); show_search_and_replace();
@ -317,11 +317,12 @@ void Notebook::Controller::open_file(std::string path) {
}); });
} }
void Notebook::Controller::OnCloseCurrentPage() { bool Notebook::Controller::close_current_page() {
INFO("Notebook close page"); INFO("Notebook close page");
if (Pages() != 0) { if (Pages() != 0) {
if(CurrentSourceView()->get_buffer()->get_modified()){ if(CurrentSourceView()->get_buffer()->get_modified()){
AskToSaveDialog(); if(!save_dialog())
return false;
} }
int page = CurrentPage(); int page = CurrentPage();
view.notebook.remove_page(page); view.notebook.remove_page(page);
@ -329,6 +330,7 @@ void Notebook::Controller::OnCloseCurrentPage() {
scrolled_windows.erase(scrolled_windows.begin()+page); scrolled_windows.erase(scrolled_windows.begin()+page);
hboxes.erase(hboxes.begin()+page); hboxes.erase(hboxes.begin()+page);
} }
return true;
} }
void Notebook::Controller::OnFileNewFile() { void Notebook::Controller::OnFileNewFile() {
entry_box.clear(); entry_box.clear();
@ -444,38 +446,20 @@ std::string Notebook::Controller::OnSaveFileAs(){
return ""; return "";
} }
void Notebook::Controller::AskToSaveDialog() { bool Notebook::Controller::save_dialog() {
INFO("AskToSaveDialog"); INFO("Notebook::Controller::save_dialog");
DEBUG("AskToSaveDialog: Finding file path"); Gtk::MessageDialog dialog((Gtk::Window&)(*view.get_toplevel()), "Save file!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Gtk::MessageDialog dialog((Gtk::Window&)(*view.get_toplevel()), "Save file!", dialog.set_secondary_text("Do you want to save: " + CurrentSourceView()->file_path+" ?");
false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text(
"Do you want to save: " +
CurrentSourceView()->file_path+" ?");
DEBUG("AskToSaveDialog: run dialog");
int result = dialog.run(); int result = dialog.run();
if(result==Gtk::RESPONSE_YES) {
//Handle the response: CurrentSourceView()->save();
DEBUG("AskToSaveDialog: switch response"); return true;
switch(result) }
{ else if(result==Gtk::RESPONSE_NO) {
case(Gtk::RESPONSE_YES): return true;
{ }
DEBUG("AskToSaveDialog: save file: yes, trying to save file"); else {
CurrentSourceView()->save(); return false;
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;
}
} }
} }

4
juci/notebook.h

@ -23,7 +23,7 @@ namespace Notebook {
Controller(); Controller();
Source::View* CurrentSourceView(); Source::View* CurrentSourceView();
int CurrentPage(); int CurrentPage();
void OnCloseCurrentPage(); bool close_current_page();
void OnFileNewFile(); void OnFileNewFile();
bool OnSaveFile(std::string path); bool OnSaveFile(std::string path);
void OnDirectoryNavigation(const Gtk::TreeModel::Path& path, void OnDirectoryNavigation(const Gtk::TreeModel::Path& path,
@ -47,7 +47,7 @@ namespace Notebook {
std::vector<std::unique_ptr<Source> > source_views; std::vector<std::unique_ptr<Source> > source_views;
private: private:
void CreateKeybindings(); void CreateKeybindings();
void AskToSaveDialog(); bool save_dialog();
std::vector<std::unique_ptr<Gtk::ScrolledWindow> > scrolled_windows; std::vector<std::unique_ptr<Gtk::ScrolledWindow> > scrolled_windows;
std::vector<std::unique_ptr<Gtk::HBox> > hboxes; std::vector<std::unique_ptr<Gtk::HBox> > hboxes;

26
juci/window.cc

@ -15,7 +15,7 @@ Window::Window() :
add(window_box_); add(window_box_);
auto menu=Singleton::menu(); auto menu=Singleton::menu();
menu->action_group->add(Gtk::Action::create("FileQuit", "Quit juCi++"), Gtk::AccelKey(menu->key_map["quit"]), [this]() { menu->action_group->add(Gtk::Action::create("FileQuit", "Quit juCi++"), Gtk::AccelKey(menu->key_map["quit"]), [this]() {
OnWindowHide(); hide();
}); });
menu->action_group->add(Gtk::Action::create("FileOpenFile", "Open file"), Gtk::AccelKey(menu->key_map["open_file"]), [this]() { menu->action_group->add(Gtk::Action::create("FileOpenFile", "Open file"), Gtk::AccelKey(menu->key_map["open_file"]), [this]() {
OnOpenFile(); OnOpenFile();
@ -24,12 +24,12 @@ Window::Window() :
OnFileOpenFolder(); OnFileOpenFolder();
}); });
menu->action_group->add(Gtk::Action::create("FileSaveAs", "Save as"), Gtk::AccelKey(menu->key_map["save_as"]), [this]() { menu->action_group->add(Gtk::Action::create("FileSaveAs", "Save as"), Gtk::AccelKey(menu->key_map["save_as"]), [this]() {
SaveFileAs(); SaveFileAs();
}); });
menu->action_group->add(Gtk::Action::create("FileSave", "Save"), Gtk::AccelKey(menu->key_map["save"]), [this]() { menu->action_group->add(Gtk::Action::create("FileSave", "Save"), Gtk::AccelKey(menu->key_map["save"]), [this]() {
SaveFile(); SaveFile();
}); });
menu->action_group->add(Gtk::Action::create("ProjectCompileAndRun", "Compile And Run"), Gtk::AccelKey(menu->key_map["compile_and_run"]), [this]() { menu->action_group->add(Gtk::Action::create("ProjectCompileAndRun", "Compile And Run"), Gtk::AccelKey(menu->key_map["compile_and_run"]), [this]() {
SaveFile(); SaveFile();
@ -133,12 +133,20 @@ bool Window::on_key_press_event(GdkEventKey *event) {
return Gtk::Window::on_key_press_event(event); return Gtk::Window::on_key_press_event(event);
} }
void Window::OnWindowHide() { bool Window::on_delete_event (GdkEventAny *event) {
auto size=Singleton::notebook()->source_views.size();
for(size_t c=0;c<size;c++)
Singleton::notebook()->OnCloseCurrentPage();
hide(); hide();
return true;
}
void Window::hide() {
auto size=Singleton::notebook()->source_views.size();
for(size_t c=0;c<size;c++) {
if(!Singleton::notebook()->close_current_page())
return;
}
Gtk::Window::hide();
} }
void Window::OnFileOpenFolder() { void Window::OnFileOpenFolder() {
Gtk::FileChooserDialog dialog("Please choose a folder", Gtk::FileChooserDialog dialog("Please choose a folder",
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);

6
juci/window.h

@ -9,19 +9,17 @@
class Window : public Gtk::Window { class Window : public Gtk::Window {
public: public:
Window(); Window();
// std::string OnSaveFileAs();
Gtk::Box window_box_; Gtk::Box window_box_;
virtual ~Window() { }
MainConfig main_config; MainConfig main_config;
PluginApi api; PluginApi api;
protected: protected:
bool on_key_press_event(GdkEventKey *event); bool on_key_press_event(GdkEventKey *event);
bool on_delete_event (GdkEventAny *event);
private: private:
std::mutex running; std::mutex running;
Gtk::VPaned paned_; Gtk::VPaned paned_;
//signal handlers //signal handlers
void OnWindowHide(); void hide();
void OnOpenFile(); void OnOpenFile();
void OnFileOpenFolder(); void OnFileOpenFolder();
bool SaveFile(); bool SaveFile();

Loading…
Cancel
Save