Skip to content

Commit 749e7ed

Browse files
committed
Add "Hex dump files" as an export option when data source is hex editor
When the data source is the hex editor we are able to save whatever data type as shown in the widget, so additionally to set the filters according to the data type a "Hex dump files (*.txt)" filter option is added. If the user selects this option for saving, the hexadecimal dump of the widget content is saved to the file. Note that the check must be performed using the selected filter by the user and not the file ending, which would be the same for text data exported as plain text. The Null case is disregarded as it is useless for exporting. See issues #1438 and #1485
1 parent f42b614 commit 749e7ed

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/EditDialog.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ void EditDialog::exportData()
364364
break;
365365
}
366366
case Binary:
367-
case Null:
368-
filters << tr("Binary files (*.bin)") << tr("Text files (*.txt)");
367+
filters << tr("Binary files (*.bin)");
369368
break;
370369
case Text:
371370
// Base the XML case on the mode, not the data type since XML detection is currently not implemented.
@@ -380,14 +379,22 @@ void EditDialog::exportData()
380379
case SVG:
381380
filters << tr("SVG files (*.svg)");
382381
break;
382+
case Null:
383+
return;
383384
}
384385

386+
if (dataSource == HexBuffer)
387+
filters << tr("Hex dump files (*.txt)");
388+
385389
filters << tr("All files (*)");
386390

391+
QString selectedFilter = filters.first();
387392
QString fileName = FileDialog::getSaveFileName(
388393
this,
389394
tr("Choose a filename to export data"),
390-
filters.join(";;"));
395+
filters.join(";;"),
396+
/* defaultFileName */ QString(),
397+
&selectedFilter);
391398
if(fileName.size() > 0)
392399
{
393400
QFile file(fileName);
@@ -397,7 +404,7 @@ void EditDialog::exportData()
397404
case HexBuffer:
398405
// Data source is the hex buffer
399406
// If text option has been selected, the readable representation of the content is saved to file.
400-
if (fileName.endsWith(".txt", Qt::CaseInsensitive))
407+
if (selectedFilter == tr("Hex dump files (*.txt)"))
401408
file.write(hexEdit->toReadableString().toUtf8());
402409
else
403410
file.write(hexEdit->data());

0 commit comments

Comments
 (0)