diff options
-rw-r--r-- | src/MainWindow.h | 5 | ||||
-rw-r--r-- | src/MainWindow.ui | 16 | ||||
-rw-r--r-- | src/mainwin.cc | 33 |
3 files changed, 53 insertions, 1 deletions
diff --git a/src/MainWindow.h b/src/MainWindow.h index 9eb1748..6b15889 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -24,6 +24,9 @@ public: QTimer *animate_timer; double tval, fps, fsteps; + QTimer *autoReloadTimer; + QString autoReloadInfo; + Context root_ctx; AbstractModule *root_module; // Result of parsing ModuleInstantiation root_inst; // Top level instance @@ -145,6 +148,8 @@ public slots: void helpManual(); void quit(); void actionReloadCompile(); + void checkAutoReload(); + void autoReloadSet(bool); }; #endif diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 03f8e2d..f61d240 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -23,7 +23,7 @@ <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <widget class="Editor" name="editor"> + <widget class="Editor" name="editor" native="true"> <property name="font"> <font> <family>Monaco</family> @@ -168,6 +168,7 @@ <property name="title"> <string>&Design</string> </property> + <addaction name="designActionAutoReload"/> <addaction name="designActionReloadAndCompile"/> <addaction name="designActionCompile"/> <addaction name="designActionCompileAndRender"/> @@ -642,6 +643,14 @@ <string>OpenSCAD Homepage</string> </property> </action> + <action name="designActionAutoReload"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Automatic Reload and Compile</string> + </property> + </action> </widget> <customwidgets> <customwidget> @@ -650,6 +659,11 @@ <header>GLView.h</header> <container>1</container> </customwidget> + <customwidget> + <class>Editor</class> + <extends>QWidget</extends> + <header>editor.h</header> + </customwidget> </customwidgets> <resources> <include location="../openscad.qrc"/> 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; } } |