diff options
author | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2009-07-25 19:45:38 (GMT) |
---|---|---|
committer | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2009-07-25 19:45:38 (GMT) |
commit | 30682d9fb4fdb256fd5da4dcf337da920f5197f6 (patch) | |
tree | d26cbd28d7861d60d5e2ca9d563fc173e53133a1 | |
parent | 1dde2be94e63be2f9ab48942da031277b116a948 (diff) |
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
-rw-r--r-- | examples/example010.scad | 12 | ||||
-rw-r--r-- | mainwin.cc | 19 | ||||
-rw-r--r-- | openscad.h | 1 |
3 files changed, 29 insertions, 3 deletions
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); +} @@ -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(); } @@ -673,6 +673,7 @@ public: private: void load(); + void maybe_change_dir(); void find_root_tag(AbstractNode *n); void compile(); |