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();
});
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]() {
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");
if (Pages() != 0) {
if(CurrentSourceView()->get_buffer()->get_modified()){
AskToSaveDialog();
if(!save_dialog())
return false;
}
int page = CurrentPage();
view.notebook.remove_page(page);
@ -329,6 +330,7 @@ void Notebook::Controller::OnCloseCurrentPage() {
scrolled_windows.erase(scrolled_windows.begin()+page);
hboxes.erase(hboxes.begin()+page);
}
return true;
}
void Notebook::Controller::OnFileNewFile() {
entry_box.clear();
@ -444,38 +446,20 @@ std::string Notebook::Controller::OnSaveFileAs(){
return "";
}
void Notebook::Controller::AskToSaveDialog() {
INFO("AskToSaveDialog");
DEBUG("AskToSaveDialog: Finding file path");
Gtk::MessageDialog dialog((Gtk::Window&)(*view.get_toplevel()), "Save file!",
false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text(
"Do you want to save: " +
CurrentSourceView()->file_path+" ?");
DEBUG("AskToSaveDialog: run dialog");
bool Notebook::Controller::save_dialog() {
INFO("Notebook::Controller::save_dialog");
Gtk::MessageDialog dialog((Gtk::Window&)(*view.get_toplevel()), "Save file!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text("Do you want to save: " + CurrentSourceView()->file_path+" ?");
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");
CurrentSourceView()->save();
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;
}
if(result==Gtk::RESPONSE_YES) {
CurrentSourceView()->save();
return true;
}
else if(result==Gtk::RESPONSE_NO) {
return true;
}
else {
return false;
}
}

4
juci/notebook.h

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

26
juci/window.cc

@ -15,7 +15,7 @@ Window::Window() :
add(window_box_);
auto menu=Singleton::menu();
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]() {
OnOpenFile();
@ -24,12 +24,12 @@ Window::Window() :
OnFileOpenFolder();
});
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]() {
SaveFile();
});
SaveFile();
});
menu->action_group->add(Gtk::Action::create("ProjectCompileAndRun", "Compile And Run"), Gtk::AccelKey(menu->key_map["compile_and_run"]), [this]() {
SaveFile();
@ -133,12 +133,20 @@ bool Window::on_key_press_event(GdkEventKey *event) {
return Gtk::Window::on_key_press_event(event);
}
void Window::OnWindowHide() {
auto size=Singleton::notebook()->source_views.size();
for(size_t c=0;c<size;c++)
Singleton::notebook()->OnCloseCurrentPage();
bool Window::on_delete_event (GdkEventAny *event) {
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() {
Gtk::FileChooserDialog dialog("Please choose a folder",
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);

6
juci/window.h

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

Loading…
Cancel
Save