From ca1d6d5f466272ac7e906b589e2804b12568fa96 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Sun, 4 Feb 2018 14:54:32 +0100 Subject: [PATCH] MainBar: fixup file extension filter in "Import File" dialog The previous implementation used a "*" filter when a file of any other format than srzip got imported. This happened to be a duplicate of "All files", and ignored the list of filename extensions provided by the input formats. This change does respect the input format's file extensions, and copes with the lack of such a list (raw binary), as well as lists that have one (most formats), or multiple extensions (raw analog). This fixes bug #1039. Another byproduct of the change is that extensions and their decoration (separators, parentheses) move outside of tr() calls. These technical details shall not concern translators, and translations for human languages shall not break the filter mechanism. This implementation might be "too complex, computationally expensive". But it works, and fixes an issue, and the code path executes seldom and waits for user interaction anyway. Cost reduction can get applied later. --- pv/toolbars/mainbar.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index c7b37334..1879693d 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -668,16 +668,19 @@ void MainBar::import_file(shared_ptr format) // Construct the filter const vector exts = format->extensions(); - const QString filter = exts.empty() ? "" : - tr("%1 files (*.%2)").arg( - QString::fromStdString(format->description()), - QString::fromStdString(join(exts, ", *."))); + const QString filter_exts = exts.empty() ? "" : QString::fromStdString("%1 (%2)").arg( + tr("%1 files").arg(QString::fromStdString(format->description())), + QString::fromStdString("*.%1").arg(QString::fromStdString(join(exts, " *.")))); + const QString filter_all = QString::fromStdString("%1 (%2)").arg( + tr("All Files"), QString::fromStdString("*")); + const QString filter = QString::fromStdString("%1%2%3").arg( + exts.empty() ? "" : filter_exts, + exts.empty() ? "" : ";;", + filter_all); // Show the file dialog const QString file_name = QFileDialog::getOpenFileName( - this, tr("Import File"), dir, tr( - "%1 files (*);;All Files (*)").arg( - QString::fromStdString(format->description()))); + this, tr("Import File"), dir, filter); if (file_name.isEmpty()) return; -- 2.30.2