tycho: add save confirmation dialogue
parent
68b4939a15
commit
82d0d378b0
|
@ -26,6 +26,9 @@ public slots:
|
|||
void openMapProperties();
|
||||
void updateActions();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
ProjectView *activeProject() const;
|
||||
QMdiSubWindow *activeSubWindow() const;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "bindings.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMdiSubWindow>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
|
@ -17,13 +17,17 @@ public:
|
|||
explicit ProjectModel();
|
||||
~ProjectModel();
|
||||
|
||||
bool open(QString fname);
|
||||
bool isDirty() const;
|
||||
|
||||
public slots:
|
||||
bool open(const QString &fname);
|
||||
void save();
|
||||
|
||||
private:
|
||||
Project data;
|
||||
};
|
||||
|
||||
class ProjectView : public QWidget
|
||||
class ProjectView : public QMdiSubWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -33,6 +37,9 @@ public:
|
|||
|
||||
QSharedPointer<ProjectModel> model();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
QSharedPointer<Ui::ProjectView> ui;
|
||||
QSharedPointer<ProjectModel> proj;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "../ui/ui_menu.h"
|
||||
#include "../ui/ui_about.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QMdiSubWindow>
|
||||
#include <iostream>
|
||||
|
@ -14,6 +15,13 @@ Menu::Menu(QWidget *parent) :
|
|||
ui(new Ui::Menu)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->actionOpen->setShortcut(QKeySequence(QKeySequence::Open));
|
||||
ui->actionNew->setShortcut(QKeySequence(QKeySequence::New));
|
||||
ui->actionQuit->setShortcut(QKeySequence(QKeySequence::Quit));
|
||||
ui->actionAbout->setShortcut(QKeySequence(QKeySequence::HelpContents));
|
||||
ui->actionMapProps->setShortcut(QKeySequence(tr("Ctrl+P")));
|
||||
|
||||
dbgPrintFunc();
|
||||
}
|
||||
|
||||
|
@ -75,6 +83,18 @@ void Menu::updateActions()
|
|||
ui->actionMapProps->setEnabled(active);
|
||||
}
|
||||
|
||||
void Menu::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
for(auto *win : ui->mdiArea->subWindowList()) {
|
||||
if(!win->close()) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
ProjectView *Menu::activeProject() const
|
||||
{
|
||||
auto win = activeSubWindow();
|
||||
|
|
|
@ -11,9 +11,19 @@ ProjectModel::~ProjectModel()
|
|||
dbgPrintFunc();
|
||||
}
|
||||
|
||||
bool ProjectModel::open(QString fname)
|
||||
bool ProjectModel::isDirty() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectModel::open(const QString &fname)
|
||||
{
|
||||
return data.open(fname);
|
||||
}
|
||||
|
||||
void ProjectModel::save()
|
||||
{
|
||||
dbgPrintFunc();
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -2,12 +2,18 @@
|
|||
#include "project.h"
|
||||
#include "../ui/ui_projectview.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QMessageBox>
|
||||
|
||||
ProjectView::ProjectView(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
QMdiSubWindow(parent),
|
||||
ui(new Ui::ProjectView),
|
||||
proj(new ProjectModel)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
auto widget = new QWidget(this);
|
||||
ui->setupUi(widget);
|
||||
setWidget(widget);
|
||||
|
||||
dbgPrintFunc();
|
||||
}
|
||||
|
||||
|
@ -21,4 +27,33 @@ QSharedPointer<ProjectModel> ProjectView::model()
|
|||
return proj;
|
||||
}
|
||||
|
||||
void ProjectView::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if(proj->isDirty()) {
|
||||
QMessageBox msg;
|
||||
msg.setText(tr("Do you want to save your changes to this project before closing it?"));
|
||||
msg.setInformativeText(tr("Unsaved changes will be lost unless you save."));
|
||||
msg.setStandardButtons(QMessageBox::Save |
|
||||
QMessageBox::Discard |
|
||||
QMessageBox::Cancel);
|
||||
msg.setDefaultButton(QMessageBox::Save);
|
||||
|
||||
switch(msg.exec()) {
|
||||
case QMessageBox::Save:
|
||||
proj->save();
|
||||
break;
|
||||
case QMessageBox::Discard:
|
||||
break;
|
||||
case QMessageBox::Cancel:
|
||||
event->ignore();
|
||||
return;
|
||||
default:
|
||||
assert(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -88,9 +88,6 @@
|
|||
<property name="text">
|
||||
<string>&Open Project</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionNew">
|
||||
<property name="icon">
|
||||
|
@ -100,9 +97,6 @@
|
|||
<property name="text">
|
||||
<string>&New Project</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+N</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionMapProps">
|
||||
<property name="enabled">
|
||||
|
@ -124,9 +118,6 @@
|
|||
<property name="text">
|
||||
<string>&Quit</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Q</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="icon">
|
||||
|
@ -136,9 +127,6 @@
|
|||
<property name="text">
|
||||
<string>&About Tycho</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>F1</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
|
|
Loading…
Reference in New Issue