From: Joel Holdsworth Date: Wed, 21 Jan 2015 06:53:29 +0000 (-0500) Subject: MainWindow: Use extension to populate filter X-Git-Tag: pulseview-0.3.0~239 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ea2dbfea21a4c02854c5ffa0d97e14e3483c42c0;p=pulseview.git MainWindow: Use extension to populate filter --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 81112aba..7dcf8958 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -27,6 +27,8 @@ #include #include +#include + #include #include #include @@ -66,6 +68,9 @@ using std::list; using std::map; using std::shared_ptr; using std::string; +using std::vector; + +using boost::algorithm::join; using sigrok::Device; using sigrok::Error; @@ -203,10 +208,21 @@ void MainWindow::export_file(shared_ptr format) QSettings settings; const QString dir = settings.value(SettingSaveDirectory).toString(); + // Construct the filter + const vector exts = format->extensions(); + QString filter = tr("%1 files ").arg( + QString::fromStdString(format->description())); + + if (exts.empty()) + filter += "(*.*)"; + else + filter += QString("(*.%1);;%2 (*.*)").arg( + QString::fromStdString(join(exts, ", *."))).arg( + tr("All Files")); + // Show the file dialog const QString file_name = QFileDialog::getSaveFileName( - this, tr("Save File"), dir, tr("%1 files (*.*)").arg( - QString::fromStdString(format->description()))); + this, tr("Save File"), dir, filter); if (file_name.isEmpty()) return;