tycho: add save confirmation dialogue
parent
68b4939a15
commit
82d0d378b0
|
@ -26,6 +26,9 @@ public slots:
|
||||||
void openMapProperties();
|
void openMapProperties();
|
||||||
void updateActions();
|
void updateActions();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProjectView *activeProject() const;
|
ProjectView *activeProject() const;
|
||||||
QMdiSubWindow *activeSubWindow() const;
|
QMdiSubWindow *activeSubWindow() const;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "bindings.h"
|
#include "bindings.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QMdiSubWindow>
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
|
@ -17,13 +17,17 @@ public:
|
||||||
explicit ProjectModel();
|
explicit ProjectModel();
|
||||||
~ProjectModel();
|
~ProjectModel();
|
||||||
|
|
||||||
bool open(QString fname);
|
bool isDirty() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
bool open(const QString &fname);
|
||||||
|
void save();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Project data;
|
Project data;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProjectView : public QWidget
|
class ProjectView : public QMdiSubWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -33,6 +37,9 @@ public:
|
||||||
|
|
||||||
QSharedPointer<ProjectModel> model();
|
QSharedPointer<ProjectModel> model();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<Ui::ProjectView> ui;
|
QSharedPointer<Ui::ProjectView> ui;
|
||||||
QSharedPointer<ProjectModel> proj;
|
QSharedPointer<ProjectModel> proj;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "../ui/ui_menu.h"
|
#include "../ui/ui_menu.h"
|
||||||
#include "../ui/ui_about.h"
|
#include "../ui/ui_about.h"
|
||||||
|
|
||||||
|
#include <QCloseEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMdiSubWindow>
|
#include <QMdiSubWindow>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -14,6 +15,13 @@ Menu::Menu(QWidget *parent) :
|
||||||
ui(new Ui::Menu)
|
ui(new Ui::Menu)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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();
|
dbgPrintFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +83,18 @@ void Menu::updateActions()
|
||||||
ui->actionMapProps->setEnabled(active);
|
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
|
ProjectView *Menu::activeProject() const
|
||||||
{
|
{
|
||||||
auto win = activeSubWindow();
|
auto win = activeSubWindow();
|
||||||
|
|
|
@ -11,9 +11,19 @@ ProjectModel::~ProjectModel()
|
||||||
dbgPrintFunc();
|
dbgPrintFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectModel::open(QString fname)
|
bool ProjectModel::isDirty() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProjectModel::open(const QString &fname)
|
||||||
{
|
{
|
||||||
return data.open(fname);
|
return data.open(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectModel::save()
|
||||||
|
{
|
||||||
|
dbgPrintFunc();
|
||||||
|
}
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -2,12 +2,18 @@
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "../ui/ui_projectview.h"
|
#include "../ui/ui_projectview.h"
|
||||||
|
|
||||||
|
#include <QCloseEvent>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
ProjectView::ProjectView(QWidget *parent) :
|
ProjectView::ProjectView(QWidget *parent) :
|
||||||
QWidget(parent),
|
QMdiSubWindow(parent),
|
||||||
ui(new Ui::ProjectView),
|
ui(new Ui::ProjectView),
|
||||||
proj(new ProjectModel)
|
proj(new ProjectModel)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
auto widget = new QWidget(this);
|
||||||
|
ui->setupUi(widget);
|
||||||
|
setWidget(widget);
|
||||||
|
|
||||||
dbgPrintFunc();
|
dbgPrintFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,4 +27,33 @@ QSharedPointer<ProjectModel> ProjectView::model()
|
||||||
return proj;
|
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
|
// EOF
|
||||||
|
|
|
@ -88,9 +88,6 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Open Project</string>
|
<string>&Open Project</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+O</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
</action>
|
||||||
<action name="actionNew">
|
<action name="actionNew">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
|
@ -100,9 +97,6 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&New Project</string>
|
<string>&New Project</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+N</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
</action>
|
||||||
<action name="actionMapProps">
|
<action name="actionMapProps">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
|
@ -124,9 +118,6 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Quit</string>
|
<string>&Quit</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+Q</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
</action>
|
||||||
<action name="actionAbout">
|
<action name="actionAbout">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
|
@ -136,9 +127,6 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&About Tycho</string>
|
<string>&About Tycho</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
|
||||||
<string>F1</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
|
Loading…
Reference in New Issue