Skip to content

Commit 559c3a1

Browse files
committed
[Gtk] Allow closing via Ctrl+Q
1 parent 62b1a15 commit 559c3a1

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

gtk/src/Application.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ private:
4747
add_action("about", [this] { m_mainWindow->showAbout(); });
4848
add_action("quit", [this] { on_quit(); });
4949

50+
set_accel_for_action("app.quit", "<Primary>q");
51+
5052
Glib::RefPtr<Gtk::Builder> appMenuBuilder = Gtk::Builder::create_from_resource("/org/gnome/gimagereader/appmenu.ui");
5153
Glib::RefPtr<Gio::MenuModel> menuModel = Glib::RefPtr<Gio::MenuModel>::cast_static(appMenuBuilder->get_object("appmenu"));
5254

@@ -75,6 +77,9 @@ private:
7577

7678
void on_quit() {
7779
if (m_mainWindow) {
80+
if (!m_mainWindow->canClose()) {
81+
return;
82+
}
7883
remove_window(*m_mainWindow->getWindow());
7984
delete m_mainWindow;
8085
m_mainWindow = nullptr;

gtk/src/MainWindow.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ void MainWindow::progressUpdate() {
307307
}
308308

309309
bool MainWindow::closeEvent(GdkEventAny*) {
310-
if (!m_outputEditor->clear()) {
310+
if (!canClose()) {
311311
return true;
312312
}
313313

@@ -321,6 +321,10 @@ bool MainWindow::closeEvent(GdkEventAny*) {
321321
return false;
322322
}
323323

324+
bool MainWindow::canClose() {
325+
return m_outputEditor->clear();
326+
}
327+
324328
void MainWindow::onSourceChanged() {
325329
std::vector<Source*> sources = m_sourceManager->getSelectedSources();
326330
if (m_displayer->setSources(sources) && !sources.empty()) {

gtk/src/MainWindow.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public:
122122
void popState();
123123
void showProgress(ProgressMonitor* monitor, int updateInterval = 500);
124124
void hideProgress();
125+
bool canClose();
125126

126127
private:
127128
static void signalHandlerExec(int signal, bool tesseractCrash);

0 commit comments

Comments
 (0)