summaryrefslogtreecommitdiff
path: root/mainwin.cc
diff options
context:
space:
mode:
authorkintel <kintel@b57f626f-c46c-0410-a088-ec61d464b74c>2009-12-14 04:24:51 (GMT)
committerkintel <kintel@b57f626f-c46c-0410-a088-ec61d464b74c>2009-12-14 04:24:51 (GMT)
commit4d5084ea27f1f020671340b9a60f1660eae7eb67 (patch)
tree02a218b4d1fc93df2902f749b7a44ddbde159845 /mainwin.cc
parent084c60bbd1e6090a9496296d98eba9ee85f121d1 (diff)
Handles document changes when exiting, bugfix: calls Save As if no document name is given
git-svn-id: http://svn.clifford.at/openscad/trunk@175 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'mainwin.cc')
-rw-r--r--mainwin.cc68
1 files changed, 54 insertions, 14 deletions
diff --git a/mainwin.cc b/mainwin.cc
index 6ba7ae1..9b342c9 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -251,6 +251,8 @@ MainWindow::MainWindow(const char *filename)
}
connect(editor->document(), SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged()));
+ connect(editor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool)));
+ connect(editor->document(), SIGNAL(modificationChanged(bool)), fileActionSave, SLOT(setEnabled(bool)));
connect(screen, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate()));
// display this window and check for OpenGL 2.0 (OpenCSG) support
@@ -310,6 +312,7 @@ MainWindow::openFile(const QString &new_filename)
}
#endif
setFileName(new_filename);
+
load();
}
@@ -379,8 +382,8 @@ void MainWindow::updateTVal()
void MainWindow::load()
{
- if (!this->fileName.isEmpty())
- {
+ current_win = this;
+ if (!this->fileName.isEmpty()) {
QString text;
FILE *fp = fopen(this->fileName.toUtf8(), "rt");
if (!fp) {
@@ -397,6 +400,7 @@ void MainWindow::load()
}
editor->setPlainText(text);
}
+ current_win = this;
}
void MainWindow::find_root_tag(AbstractNode *n)
@@ -671,16 +675,21 @@ void MainWindow::updateRecentFileActions()
void MainWindow::actionSave()
{
- current_win = this;
- FILE *fp = fopen(this->fileName.toUtf8(), "wt");
- if (!fp) {
- PRINTA("Failed to open file for writing: %1 (%2)", this->fileName, QString(strerror(errno)));
- } else {
- fprintf(fp, "%s", editor->toPlainText().toAscii().data());
- fclose(fp);
- PRINTA("Saved design `%1'.", this->fileName);
+ if (this->fileName.isEmpty()) {
+ actionSaveAs();
+ }
+ else {
+ current_win = this;
+ FILE *fp = fopen(this->fileName.toUtf8(), "wt");
+ if (!fp) {
+ PRINTA("Failed to open file for writing: %1 (%2)", this->fileName, QString(strerror(errno)));
+ } else {
+ fprintf(fp, "%s", editor->toPlainText().toAscii().data());
+ fclose(fp);
+ PRINTA("Saved design `%1'.", this->fileName);
+ }
+ current_win = NULL;
}
- current_win = NULL;
}
void MainWindow::actionSaveAs()
@@ -694,9 +703,7 @@ void MainWindow::actionSaveAs()
void MainWindow::actionReload()
{
- current_win = this;
load();
- current_win = NULL;
}
void MainWindow::editIndent()
@@ -788,10 +795,11 @@ void MainWindow::pasteViewportRotation()
void MainWindow::actionReloadCompile()
{
- current_win = this;
console->clear();
load();
+
+ current_win = this;
compile(true);
#ifdef ENABLE_OPENCSG
@@ -1431,3 +1439,35 @@ MainWindow::helpManual()
QDesktopServices::openUrl(QUrl("http://en.wikibooks.org/wiki/OpenSCAD_User_Manual"));
}
+/*!
+ FIXME: In SDI mode, this should be called also on New and Open
+ In MDI mode; also call on both reload functions?
+ */
+bool
+MainWindow::maybeSave()
+{
+ if (editor->document()->isModified()) {
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, "Application",
+ "The document has been modified.\n"
+ "Do you want to save your changes?",
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save) {
+ actionSave();
+ return true; // FIXME: Should return false on error
+ }
+ else if (ret == QMessageBox::Cancel) {
+ return false;
+ }
+ }
+ return true;
+}
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ if (maybeSave()) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
contact: Jan Huwald // Impressum