Skip to content

Commit 7b9a120

Browse files
committed
EditDialog: Improve handling of binary data in text mode
Make the EditDialog a bit more user friendly when editing binary data in text mode: Don't change back to the hex editor after changing any character. Show the full binary data even if it contains a NULL byte. Also (though a bit unrelated) disable rich text input for the text widget. This partially fixes issue sqlitebrowser#19.
1 parent 516d71f commit 7b9a120

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/EditDialog.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ void EditDialog::loadText(const QByteArray& data, int row, int col)
5454
curCol = col;
5555
oldData = data;
5656

57-
ui->editorText->setPlainText(data);
57+
QString textData = QString::fromUtf8(data.constData(), data.size());
58+
ui->editorText->setPlainText(textData);
5859
ui->editorText->setFocus();
5960
ui->editorText->selectAll();
6061
hexEdit->setData(data);
62+
63+
// Assume it's binary data and only call checkDatyType afterwards. This means the correct input widget is selected here in all cases
64+
// but once the user changed it to text input it will stay there.
65+
ui->editorStack->setCurrentIndex(1);
6166
checkDataType();
6267
}
6368

@@ -162,7 +167,6 @@ void EditDialog::checkDataType()
162167
ui->comboEditor->setVisible(false);
163168
} else {
164169
// It's not. So it's probably some random binary data.
165-
ui->editorStack->setCurrentIndex(1);
166170

167171
ui->labelType->setText(tr("Type of data currently in cell: Binary"));
168172
ui->labelSize->setText(tr("%n byte(s)", "", hexEdit->data().length()));

src/EditDialog.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
<property name="whatsThis">
9494
<string>This area displays information about the data present in this database cell</string>
9595
</property>
96+
<property name="acceptRichText">
97+
<bool>false</bool>
98+
</property>
9699
</widget>
97100
<widget class="QWidget" name="editorBinary"/>
98101
<widget class="QScrollArea" name="editorImageScrollArea">

0 commit comments

Comments
 (0)