From d288bb5ec6edbff5740ec9df31b8734ffcdb26da Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Mon, 10 Nov 2008 14:53:10 +0000 Subject: [PATCH] adding a way to keep track of the last directory visited. Before this change QT for windows does not remember this for you and so you would have to always navigate from the directory where the .exe file was each time you want to open a file or project. --- src/meshlab/mainwindow.h | 2 ++ src/meshlab/mainwindow_RunTime.cpp | 39 ++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/meshlab/mainwindow.h b/src/meshlab/mainwindow.h index 2d0a64c7d..ba99e1802 100644 --- a/src/meshlab/mainwindow.h +++ b/src/meshlab/mainwindow.h @@ -319,6 +319,8 @@ private: QByteArray toolbarState; //stato delle toolbar e dockwidgets + QDir lastUsedDirectory; //This will hold the last directory that was used to load/save a file/project in + public: GLArea *GLA() const { if(mdiarea->currentSubWindow()==0) return 0; diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index c82f19e76..41bfe50e6 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -798,10 +798,18 @@ bool MainWindow::openIn(QString /* fileName */) void MainWindow::saveProject() { - QString fileName = QFileDialog::getSaveFileName(this,tr("Save Project File"),"untitled.aln", tr("*.aln")); + QString fileName = QFileDialog::getSaveFileName(this,tr("Save Project File"),lastUsedDirectory.path().append("/untitled.aln"), tr("*.aln")); + qDebug("Saving aln file %s\n",qPrintable(fileName)); if (fileName.isEmpty()) return; - + else + { + //save path away so we can use it again + QString path = fileName; + path.truncate(path.lastIndexOf("/")); + lastUsedDirectory.setPath(path); + } + MeshDocument &meshDoc=GLA()->meshDoc; vector meshNameVector; vector transfVector; @@ -822,8 +830,16 @@ bool MainWindow::openProject(QString fileName) { bool openRes=true; if (fileName.isEmpty()) - fileName = QFileDialog::getOpenFileName(this,tr("Open Project File"),".", "*.aln"); + fileName = QFileDialog::getOpenFileName(this,tr("Open Project File"), lastUsedDirectory.path(), "*.aln"); if (fileName.isEmpty()) return false; + else + { + //save path away so we can use it again + QString path = fileName; + path.truncate(path.lastIndexOf("/")); + lastUsedDirectory.setPath(path); + } + vector rmv; ALNParser::ParseALN(rmv,qPrintable(fileName)); @@ -857,10 +873,18 @@ bool MainWindow::open(QString fileName, GLArea *gla) filters.front().append(" *.aln)"); QStringList fileNameList; if (fileName.isEmpty()) - fileNameList = QFileDialog::getOpenFileNames(this,tr("Open File"),".", filters.join("\n")); + fileNameList = QFileDialog::getOpenFileNames(this,tr("Open File"), lastUsedDirectory.path(), filters.join("\n")); else fileNameList.push_back(fileName); - if (fileNameList.isEmpty()) return false; + if (fileNameList.isEmpty()) return false; + else + { + //save path away so we can use it again + QString path = fileNameList.first(); + path.truncate(path.lastIndexOf("/")); + lastUsedDirectory.setPath(path); + } + foreach(fileName,fileNameList) { QFileInfo fi(fileName); @@ -1029,6 +1053,11 @@ bool MainWindow::saveAs(QString fileName) if (!fileName.isEmpty()) { + //save path away so we can use it again + QString path = fileName; + path.truncate(path.lastIndexOf("/")); + lastUsedDirectory.setPath(path); + QString extension = fileName; extension.remove(0, fileName.lastIndexOf('.')+1);