mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Good deal of code Cleanup.
Rewrite of the way we handle the last used directory for the loading / saving of files. we didn't reuse anything for the code, and that's error prone and also dumb =p. Reworked that so we have a nice method to help us out on that. lastUsedDir and updateLastUsedDir Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
e2a4da767d
commit
b28237309a
2 changed files with 23 additions and 30 deletions
|
@ -99,27 +99,11 @@ void MainWindow::on_actionNew_triggered()
|
||||||
|
|
||||||
void MainWindow::on_actionOpen_triggered()
|
void MainWindow::on_actionOpen_triggered()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QString lastDir = lastUsedDir();
|
||||||
QString lastDir = QDir::homePath();
|
|
||||||
|
|
||||||
settings.beginGroup("FileDialog");
|
|
||||||
if (settings.contains("LastDir")) {
|
|
||||||
if(QDir::setCurrent(settings.value("LastDir").toString())) {
|
|
||||||
lastDir = settings.value("LastDir").toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), lastDir, filter());
|
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), lastDir, filter());
|
||||||
if (filename.isEmpty())
|
if (filename.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
updateLastUsedDir(filename);
|
||||||
// Keep last open dir
|
|
||||||
QFileInfo fileInfo(filename);
|
|
||||||
settings.beginGroup("FileDialog");
|
|
||||||
settings.setValue("LastDir",fileInfo.dir().path());
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
on_actionClose_triggered();
|
on_actionClose_triggered();
|
||||||
loadFiles( QStringList() << filename );
|
loadFiles( QStringList() << filename );
|
||||||
}
|
}
|
||||||
|
@ -165,6 +149,18 @@ void MainWindow::on_actionClose_triggered()
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionImport_triggered()
|
void MainWindow::on_actionImport_triggered()
|
||||||
|
{
|
||||||
|
QString lastDir = lastUsedDir();
|
||||||
|
|
||||||
|
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Import Files"), lastDir, filter());
|
||||||
|
if (!fileNames.size())
|
||||||
|
return; // no selection
|
||||||
|
|
||||||
|
updateLastUsedDir(QFileInfo(fileNames.at(0)).dir().path());
|
||||||
|
importFiles(fileNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MainWindow::lastUsedDir()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString lastDir = QDir::homePath();
|
QString lastDir = QDir::homePath();
|
||||||
|
@ -173,19 +169,14 @@ void MainWindow::on_actionImport_triggered()
|
||||||
if (settings.contains("LastDir"))
|
if (settings.contains("LastDir"))
|
||||||
if (QDir::setCurrent(settings.value("LastDir").toString()))
|
if (QDir::setCurrent(settings.value("LastDir").toString()))
|
||||||
lastDir = settings.value("LastDir").toString();
|
lastDir = settings.value("LastDir").toString();
|
||||||
settings.endGroup();
|
return lastDir;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Import Files"), lastDir, filter());
|
void MainWindow::updateLastUsedDir(const QString& dir)
|
||||||
if (!fileNames.size())
|
{
|
||||||
return; // no selection
|
QSettings s;
|
||||||
|
s.beginGroup("FileDialog");
|
||||||
// Keep last open dir
|
s.setValue("LastDir", dir);
|
||||||
QFileInfo fileInfo(fileNames.at(0));
|
|
||||||
settings.beginGroup("FileDialog");
|
|
||||||
settings.setValue("LastDir", fileInfo.dir().path());
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
importFiles(fileNames);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionExportUDDF_triggered()
|
void MainWindow::on_actionExportUDDF_triggered()
|
||||||
|
|
|
@ -126,6 +126,8 @@ private:
|
||||||
void file_save_as();
|
void file_save_as();
|
||||||
void beginChangeState(CurrentState s);
|
void beginChangeState(CurrentState s);
|
||||||
void saveSplitterSizes();
|
void saveSplitterSizes();
|
||||||
|
QString lastUsedDir();
|
||||||
|
void updateLastUsedDir(const QString& s);
|
||||||
};
|
};
|
||||||
|
|
||||||
MainWindow *mainWindow();
|
MainWindow *mainWindow();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue