From 6779ad8e7a7384c2f3e39ecdc01798029c6c6583 Mon Sep 17 00:00:00 2001 From: mgr Date: Sat, 15 Sep 2018 13:28:22 +0200 Subject: [PATCH] Issue #1535: select appropriate file filter corresponding to "Mode" This reorders the filters in the import file dialog of the Edit Cell dock so the first entry is always in accordance to the currently selected mode. This will also facilitate the translation of the filters, because the translations can be reused and written without special syntax characters (";;"). "%1 Image" is also used instead of a concatenation, because the word order in translations will vary. --- src/EditDialog.cpp | 69 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 1f219fff..7f15b5f9 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -290,11 +290,54 @@ void EditDialog::importData() for(int i=0;icomboMode->currentIndex(); + + // Order the filters according to the mode. First the appropriate for the current mode, + // and then the others in similarity order. + switch (mode) { + case TextEditor: + filters << tr("Text files (*.txt)") << + tr("JSON files (*.json)") << + tr("XML files (*.xml)") << + tr("Image files (%1)").arg(image_formats) << + tr("Binary files (*.bin)") << tr("All files (*)"); + break; + case HexEditor: + filters << tr("Binary files (*.bin)") << + tr("Image files (%1)").arg(image_formats) << + tr("Text files (*.txt)") << + tr("JSON files (*.json)") << + tr("XML files (*.xml)") << + tr("All files (*)"); + break; + case ImageViewer: + filters << tr("Image files (%1)").arg(image_formats) << + tr("Binary files (*.bin)") << + tr("Text files (*.txt)") << + tr("JSON files (*.json)") << + tr("XML files (*.xml)") << + tr("All files (*)"); + break; + case JsonEditor: + filters << tr("JSON files (*.json)") << + tr("Text files (*.txt)") << + tr("XML files (*.xml)") << + tr("Image files (%1)").arg(image_formats) << + tr("Binary files (*.bin)") << + tr("All files (*)"); + break; + case XmlEditor: + sciEdit->setFocus(); + break; + } QString fileName = FileDialog::getOpenFileName( this, tr("Choose a file to import") #ifndef Q_OS_MAC // Filters on OS X are buggy - , tr("Text files (*.txt);;Image files (%1);;JSON files (*.json);;XML files (*.xml);;Binary files (*.bin);;All files (*)").arg(image_formats) + , filters.join(";;") #endif ); if(QFile::exists(fileName)) @@ -314,37 +357,43 @@ void EditDialog::importData() void EditDialog::exportData() { - // Images get special treatment - QString fileExt; + QStringList filters; switch (dataType) { case Image: { - // Determine the likely filename extension + // Images get special treatment. + // Determine the likely filename extension. QByteArray cellData = hexEdit->data(); QBuffer imageBuffer(&cellData); QImageReader imageReader(&imageBuffer); QString imageFormat = imageReader.format(); - fileExt = imageFormat.toUpper() % " " % tr("Image") % "(*." % imageFormat.toLower() % ");;All files(*)"; + filters << tr("%1 Image").arg(imageFormat.toUpper()) % " (*." % imageFormat.toLower() % ")"; break; } case Binary: case Null: - fileExt = tr("Binary files(*.bin);;All files(*)"); + filters << tr("Binary files (*.bin)"); break; case Text: - fileExt = tr("Text files(*.txt);;All files(*)"); + // Base the XML case on the mode, not the data type since XML detection is currently not implemented. + if (ui->comboMode->currentIndex() == XmlEditor) + filters << tr("XML files (*.xml)") << tr("Text files (*.txt)"); + else + filters << tr("Text files (*.txt)") << tr("XML files (*.xml)"); break; case JSON: - fileExt = tr("JSON files(*.json);;All files(*)"); + filters << tr("JSON files (*.json)"); break; case SVG: - fileExt = tr("SVG files(*.svg);;All files(*)"); + filters << tr("SVG files (*.svg)"); break; } + filters << tr("All files (*)"); + QString fileName = FileDialog::getSaveFileName( this, tr("Choose a filename to export data"), - fileExt); + filters.join(";;")); if(fileName.size() > 0) { QFile file(fileName);