diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-06-21 16:28:38 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-21 16:28:38 -0700 |
commit | 152eeb45d64db1398145ef7a935a132707b75e43 (patch) | |
tree | f2d38d27bb8be33fc3699ae27454f388c45f4377 /qt-ui | |
parent | 48aa0bdfd0450b6a51b4f2aa18f65b91b8b361b0 (diff) | |
download | subsurface-152eeb45d64db1398145ef7a935a132707b75e43.tar.gz |
Some file dialogs insist on adding a default extension
We already had code to deal with this in the Save As case, but similar
handling is needed in the Open case.
This commit also makes the regular expression handling a bit stricter and
identical between the two cases.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/mainwindow.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index d9a2769c2..349b84aec 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -315,6 +315,7 @@ void MainWindow::on_actionOpen_triggered() dialog.setViewMode(QFileDialog::Detail); dialog.setLabelText(QFileDialog::Accept, tr("Open")); dialog.setLabelText(QFileDialog::Reject, tr("Cancel")); + dialog.setAcceptMode(QFileDialog::AcceptSave); QStringList filenames; if (dialog.exec()) filenames = dialog.selectedFiles(); @@ -322,7 +323,18 @@ void MainWindow::on_actionOpen_triggered() return; updateLastUsedDir(QFileInfo(filenames.first()).dir().path()); closeCurrentFile(); - loadFiles(filenames); + // some file dialogs decide to add the default extension to a filename without extension + // so we would get dir[branch].ssrf when trying to select dir[branch]. + // let's detect that and remove the incorrect extension + QStringList cleanFilenames; + QRegularExpression reg(".*\\[[^]]+]\\.ssrf", QRegularExpression::CaseInsensitiveOption); + + Q_FOREACH (QString filename, filenames) { + if (reg.match(filename).hasMatch()) + filename.remove(QRegularExpression("\\.ssrf$", QRegularExpression::CaseInsensitiveOption)); + cleanFilenames << filename; + } + loadFiles(cleanFilenames); } void MainWindow::on_actionSave_triggered() @@ -1376,9 +1388,9 @@ int MainWindow::file_save_as(void) /* now for reasons I don't understand we appear to add a .ssrf to * git style filenames <path>/directory[branch] * so let's remove that */ - QRegExp r("\\[.*\\]\\.ssrf$", Qt::CaseInsensitive); - if (filename.contains(r)) - filename.remove(QRegExp("\\.ssrf$", Qt::CaseInsensitive)); + QRegularExpression reg(".*\\[[^]]+]\\.ssrf", QRegularExpression::CaseInsensitiveOption); + if (reg.match(filename).hasMatch()) + filename.remove(QRegularExpression("\\.ssrf$", QRegularExpression::CaseInsensitiveOption)); if (filename.isNull() || filename.isEmpty()) return report_error("No filename to save into"); |