Program quits correctly

This commit is contained in:
Pcornat 2024-10-29 18:00:04 +01:00
parent cea2c1296f
commit 46ddac37f5
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD
2 changed files with 15 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include "app_win_2_back.hpp" #include "app_win_2_back.hpp"
#include "hello_world.hpp" #include "hello_world.hpp"
#include <iostream> #include <iostream>
#include <glibmm/miscutils.h>
namespace gui_to_app { namespace gui_to_app {
AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) { AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) {
@ -22,7 +23,7 @@ namespace gui_to_app {
std::cerr << "Error occured while loading menu bar's.\n"; std::cerr << "Error occured while loading menu bar's.\n";
} else { } else {
set_menubar(menu_bar); set_menubar(menu_bar);
add_action("quit", sigc::mem_fun(*this, &AppWin2Back::quit)); add_action("quit", sigc::mem_fun(*this, &AppWin2Back::on_quit));
set_accel_for_action("app.quit", "<Ctrl>q"); set_accel_for_action("app.quit", "<Ctrl>q");
} }
} }
@ -54,8 +55,16 @@ namespace gui_to_app {
main_window->set_show_menubar(true); main_window->set_show_menubar(true);
main_window->set_visible(true); main_window->set_visible(true);
} else { } else {
quit(); on_quit();
} }
} }
void AppWin2Back::on_quit() {
auto windows = get_windows();
for (auto *window: windows) {
window->set_visible(false);
}
quit();
}
} // gui_to_app } // gui_to_app

View File

@ -1,7 +1,8 @@
#ifndef LEARNGTK4_APP_WIN_2_BACK_HPP #ifndef LEARNGTK4_APP_WIN_2_BACK_HPP
#define LEARNGTK4_APP_WIN_2_BACK_HPP #define LEARNGTK4_APP_WIN_2_BACK_HPP
#include <gtkmm.h> #include <gtkmm/application.h>
#include <glibmm/refptr.h>
namespace learn_gtkmm4 { namespace learn_gtkmm4 {
class HelloWorld; class HelloWorld;
@ -23,6 +24,8 @@ namespace gui_to_app {
void on_activate() final; void on_activate() final;
private: private:
void on_quit();
learn_gtkmm4::HelloWorld *main_window{ nullptr }; learn_gtkmm4::HelloWorld *main_window{ nullptr };
}; };