From 3e8e5fa925814c847f6778b5ff1fc9606a99ade0 Mon Sep 17 00:00:00 2001 From: clifford Date: Sun, 9 May 2010 13:27:05 +0000 Subject: 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 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 @@ Qt::Horizontal - + Monaco @@ -168,6 +168,7 @@ &Design + @@ -642,6 +643,14 @@ OpenSCAD Homepage + + + true + + + Automatic Reload and Compile + + @@ -650,6 +659,11 @@
GLView.h
1
+ + Editor + QWidget +
editor.h
+
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 +// for stat() +#include +#include + #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; } } -- cgit v0.10.1