diff options
author | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-05-09 13:27:05 (GMT) |
---|---|---|
committer | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-05-09 13:27:05 (GMT) |
commit | 3e8e5fa925814c847f6778b5ff1fc9606a99ade0 (patch) | |
tree | 2c3f576bdc910c97600af95768deebc961924dfc /src/mainwin.cc | |
parent | 4750ae35cb68c4cd77c9aaf25c1dcf3995920f37 (diff) |
Clifford Wolf:
Added "Design -> Automatic Reload and Compile"
(for use with external editor)
git-svn-id: http://svn.clifford.at/openscad/trunk@540 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'src/mainwin.cc')
-rw-r--r-- | src/mainwin.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/mainwin.cc b/src/mainwin.cc index 72b3d7a..cdd7c6f 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -71,9 +71,14 @@ #include "qformatscheme.h" #include "qlanguagefactory.h" #endif + //for chdir #include <unistd.h> +// for stat() +#include <sys/types.h> +#include <sys/stat.h> + #ifdef ENABLE_CGAL #if 1 @@ -178,6 +183,10 @@ MainWindow::MainWindow(const QString &filename) animate_timer = new QTimer(this); connect(animate_timer, SIGNAL(timeout()), this, SLOT(updateTVal())); + autoReloadTimer = new QTimer(this); + autoReloadTimer->setSingleShot(false); + connect(autoReloadTimer, SIGNAL(timeout()), this, SLOT(checkAutoReload())); + connect(e_tval, SIGNAL(textChanged(QString)), this, SLOT(actionCompile())); connect(e_fps, SIGNAL(textChanged(QString)), this, SLOT(updatedFps())); @@ -242,6 +251,7 @@ MainWindow::MainWindow(const QString &filename) connect(this->editActionPreferences, SIGNAL(triggered()), this, SLOT(preferences())); // Design menu + connect(this->designActionAutoReload, SIGNAL(toggled(bool)), this, SLOT(autoReloadSet(bool))); connect(this->designActionReloadAndCompile, SIGNAL(triggered()), this, SLOT(actionReloadCompile())); connect(this->designActionCompile, SIGNAL(triggered()), this, SLOT(actionCompile())); #ifdef ENABLE_CGAL @@ -959,6 +969,28 @@ void MainWindow::pasteViewportRotation() cursor.insertText(txt); } +void MainWindow::checkAutoReload() +{ + QString new_stinfo; + struct stat st; + memset(&st, 0, sizeof(struct stat)); + stat(this->fileName.toAscii().data(), &st); + new_stinfo.sprintf("%x.%x", (int)st.st_mtime, (int)st.st_size); + if (new_stinfo != autoReloadInfo) + actionReloadCompile(); + autoReloadInfo = new_stinfo; +} + +void MainWindow::autoReloadSet(bool on) +{ + if (on) { + autoReloadInfo = QString(); + autoReloadTimer->start(200); + } else { + autoReloadTimer->stop(); + } +} + void MainWindow::actionReloadCompile() { if (editor->isContentModified()) { @@ -968,6 +1000,7 @@ void MainWindow::actionReloadCompile() "Do you really want to reload the file?", QMessageBox::Yes | QMessageBox::No); if (ret != QMessageBox::Yes) { + designActionAutoReload->setChecked(false); return; } } |