Skip to content

Commit

Permalink
Define shortcuts for Save & Discard buttons of message box that appea…
Browse files Browse the repository at this point in the history
…rs when closing a document
  • Loading branch information
wwmayer committed Aug 22, 2016
1 parent 6f38f91 commit 94f07c8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Gui/Document.cpp
Expand Up @@ -24,10 +24,12 @@
#include "PreCompiled.h"

#ifndef _PreComp_
# include <QAbstractButton>
# include <qapplication.h>
# include <qdir.h>
# include <qfileinfo.h>
# include <QGLWidget>
# include <QKeySequence>
# include <qmessagebox.h>
# include <qstatusbar.h>
# include <boost/signals.hpp>
Expand Down Expand Up @@ -1203,6 +1205,22 @@ bool Document::canClose ()
box.setInformativeText(QObject::tr("If you don't save, your changes will be lost."));
box.setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel | QMessageBox::Save);
box.setDefaultButton(QMessageBox::Save);
box.setEscapeButton(QMessageBox::Cancel);

// add shortcuts
QAbstractButton* saveBtn = box.button(QMessageBox::Save);
if (saveBtn->shortcut().isEmpty()) {
QString text = saveBtn->text();
text.prepend(QLatin1Char('&'));
saveBtn->setShortcut(QKeySequence::mnemonic(text));
}

QAbstractButton* discardBtn = box.button(QMessageBox::Discard);
if (discardBtn->shortcut().isEmpty()) {
QString text = discardBtn->text();
text.prepend(QLatin1Char('&'));
discardBtn->setShortcut(QKeySequence::mnemonic(text));
}

switch (box.exec())
{
Expand Down

0 comments on commit 94f07c8

Please sign in to comment.