diff options
-rw-r--r-- | mainwin.cc | 162 | ||||
-rw-r--r-- | openscad.h | 9 |
2 files changed, 104 insertions, 67 deletions
@@ -47,24 +47,19 @@ MainWindow::MainWindow(const char *filename) root_N = NULL; #endif - if (filename) { - this->filename = QString(filename); - setWindowTitle(this->filename); - } else { - setWindowTitle("New Document"); - } - { QMenu *menu = menuBar()->addMenu("&File"); menu->addAction("&New", this, SLOT(actionNew())); menu->addAction("&Open...", this, SLOT(actionOpen())); - menu->addAction("&Save", this, SLOT(actionSave())); + menu->addAction("&Save", this, SLOT(actionSave()), QKeySequence(Qt::Key_F2)); menu->addAction("Save &As...", this, SLOT(actionSaveAs())); + menu->addAction("&Reload", this, SLOT(actionReload()), QKeySequence(Qt::Key_F3)); menu->addAction("&Quit", this, SLOT(close())); } { QMenu *menu = menuBar()->addMenu("&Design"); + menu->addAction("&Reload and Compile", this, SLOT(actionReloadCompile()), QKeySequence(Qt::Key_F4)); menu->addAction("&Compile", this, SLOT(actionCompile()), QKeySequence(Qt::Key_F5)); #ifdef ENABLE_CGAL menu->addAction("Compile and &Render (CGAL)", this, SLOT(actionRenderCGAL()), QKeySequence(Qt::Key_F6)); @@ -125,21 +120,11 @@ MainWindow::MainWindow(const char *filename) editor->setTabStopWidth(30); if (filename) { - QString text; - FILE *fp = fopen(filename, "rt"); - if (!fp) { - PRINTA("Failed to open file: %1 (%2)", QString(filename), QString(strerror(errno))); - } else { - char buffer[513]; - int rc; - while ((rc = fread(buffer, 1, 512, fp)) > 0) { - buffer[rc] = 0; - text += buffer; - } - fclose(fp); - PRINTA("Loaded design `%1'.", QString(filename)); - } - editor->setPlainText(text); + this->filename = QString(filename); + setWindowTitle(this->filename); + load(); + } else { + setWindowTitle("New Document"); } #ifdef ENABLE_OPENCSG @@ -164,26 +149,14 @@ MainWindow::~MainWindow() #endif } -void MainWindow::actionNew() -{ - filename = QString(); - setWindowTitle("New Document"); - editor->setPlainText(""); -} - -void MainWindow::actionOpen() +void MainWindow::load() { - current_win = this; - QString new_filename = QFileDialog::getOpenFileName(this, "Open File", "", "OpenSCAD Designs (*.scad)"); - if (!new_filename.isEmpty()) + if (!filename.isEmpty()) { - filename = new_filename; - setWindowTitle(filename); - QString text; FILE *fp = fopen(filename.toAscii().data(), "rt"); if (!fp) { - PRINTA("Failed to open file: %1 (%2)", QString(filename), QString(strerror(errno))); + PRINTA("Failed to open file: %1 (%2)", filename, QString(strerror(errno))); } else { char buffer[513]; int rc; @@ -192,35 +165,10 @@ void MainWindow::actionOpen() text += buffer; } fclose(fp); - PRINTA("Loaded design `%1'.", QString(filename)); + PRINTA("Loaded design `%1'.", filename); } editor->setPlainText(text); } - current_win = NULL; -} - -void MainWindow::actionSave() -{ - current_win = this; - FILE *fp = fopen(filename.toAscii().data(), "wt"); - if (!fp) { - PRINTA("Failed to open file for writing: %1 (%2)", QString(filename), QString(strerror(errno))); - } else { - fprintf(fp, "%s", editor->toPlainText().toAscii().data()); - fclose(fp); - PRINTA("Saved design `%1'.", QString(filename)); - } - current_win = NULL; -} - -void MainWindow::actionSaveAs() -{ - QString new_filename = QFileDialog::getSaveFileName(this, "Save File", filename, "OpenSCAD Designs (*.scad)"); - if (!new_filename.isEmpty()) { - filename = new_filename; - setWindowTitle(filename); - actionSave(); - } } void MainWindow::compile() @@ -307,6 +255,92 @@ fail: } } +void MainWindow::actionNew() +{ + filename = QString(); + setWindowTitle("New Document"); + editor->setPlainText(""); +} + +void MainWindow::actionOpen() +{ + current_win = this; + QString new_filename = QFileDialog::getOpenFileName(this, "Open File", "", "OpenSCAD Designs (*.scad)"); + if (!new_filename.isEmpty()) + { + filename = new_filename; + setWindowTitle(filename); + + QString text; + FILE *fp = fopen(filename.toAscii().data(), "rt"); + if (!fp) { + PRINTA("Failed to open file: %1 (%2)", QString(filename), QString(strerror(errno))); + } else { + char buffer[513]; + int rc; + while ((rc = fread(buffer, 1, 512, fp)) > 0) { + buffer[rc] = 0; + text += buffer; + } + fclose(fp); + PRINTA("Loaded design `%1'.", QString(filename)); + } + editor->setPlainText(text); + } + current_win = NULL; +} + +void MainWindow::actionSave() +{ + current_win = this; + FILE *fp = fopen(filename.toAscii().data(), "wt"); + if (!fp) { + PRINTA("Failed to open file for writing: %1 (%2)", QString(filename), QString(strerror(errno))); + } else { + fprintf(fp, "%s", editor->toPlainText().toAscii().data()); + fclose(fp); + PRINTA("Saved design `%1'.", QString(filename)); + } + current_win = NULL; +} + +void MainWindow::actionSaveAs() +{ + QString new_filename = QFileDialog::getSaveFileName(this, "Save File", filename, "OpenSCAD Designs (*.scad)"); + if (!new_filename.isEmpty()) { + filename = new_filename; + setWindowTitle(filename); + actionSave(); + } +} + +void MainWindow::actionReload() +{ + current_win = this; + load(); + current_win = NULL; +} + +void MainWindow::actionReloadCompile() +{ + current_win = this; + console->clear(); + + load(); + compile(); + +#ifdef ENABLE_OPENCSG + if (!actViewModeOpenCSG->isChecked() && !actViewModeThrownTogether->isChecked()) { + viewModeOpenCSG(); + } + else +#endif + { + screen->updateGL(); + } + current_win = NULL; +} + void MainWindow::actionCompile() { current_win = this; @@ -474,16 +474,19 @@ public: MainWindow(const char *filename = 0); ~MainWindow(); +private: + void load(); + void compile(); + private slots: void actionNew(); void actionOpen(); void actionSave(); void actionSaveAs(); - -private: - void compile(); + void actionReload(); private slots: + void actionReloadCompile(); void actionCompile(); #ifdef ENABLE_CGAL void actionRenderCGAL(); |