From 30682d9fb4fdb256fd5da4dcf337da920f5197f6 Mon Sep 17 00:00:00 2001 From: clifford Date: Sat, 25 Jul 2009 19:45:38 +0000 Subject: Clifford Wolf: Automatically change dir on file open or saveAs git-svn-id: http://svn.clifford.at/openscad/trunk@79 b57f626f-c46c-0410-a088-ec61d464b74c diff --git a/examples/example010.scad b/examples/example010.scad index 8e5be21..cb449e7 100644 --- a/examples/example010.scad +++ b/examples/example010.scad @@ -3,6 +3,12 @@ // d = (sin(1:0.2:10)' * cos(1:0.2:10)) * 10; // save("example010.dat", "d"); -surface(file = "example010.dat", - center = true, convexity = 5); - +intersection() +{ + surface(file = "example010.dat", + center = true, convexity = 5); + + rotate(45, [0 0 1]) + surface(file = "example010.dat", + center = true, convexity = 5); +} diff --git a/mainwin.cc b/mainwin.cc index 8032ff5..144959e 100644 --- a/mainwin.cc +++ b/mainwin.cc @@ -150,6 +150,7 @@ MainWindow::MainWindow(const char *filename) if (filename) { this->filename = QString(filename); + maybe_change_dir(); setWindowTitle(this->filename); load(); } else { @@ -200,6 +201,22 @@ void MainWindow::load() } } +void MainWindow::maybe_change_dir() +{ + if (filename.isEmpty()) + return; + + int dir_end_index = filename.lastIndexOf("/"); + if (dir_end_index < 0) + return; + + QString dirname = filename.mid(0, dir_end_index); + if (chdir(dirname.toAscii().data()) < 0) + return; + + filename = filename.mid(dir_end_index+1); +} + void MainWindow::find_root_tag(AbstractNode *n) { foreach(AbstractNode *v, n->children) { @@ -380,6 +397,7 @@ void MainWindow::actionOpen() if (!new_filename.isEmpty()) { filename = new_filename; + maybe_change_dir(); setWindowTitle(filename); QString text; @@ -420,6 +438,7 @@ void MainWindow::actionSaveAs() QString new_filename = QFileDialog::getSaveFileName(this, "Save File", filename, "OpenSCAD Designs (*.scad)"); if (!new_filename.isEmpty()) { filename = new_filename; + maybe_change_dir(); setWindowTitle(filename); actionSave(); } diff --git a/openscad.h b/openscad.h index 056f355..133a99f 100644 --- a/openscad.h +++ b/openscad.h @@ -673,6 +673,7 @@ public: private: void load(); + void maybe_change_dir(); void find_root_tag(AbstractNode *n); void compile(); -- cgit v0.10.1