mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-19 18:40:13 -06:00
Enhancement: save to temporary file, open external application and reload
A new button has been added in "Edit DB Cell" dock, which saves the cell data to a temporary file with extension according to detected data and opens default external application for the file type. It then asks user to reload the data in a dialog when they have finished editing the data. It can be also used for viewing if the user cancels the reload. See related issues #1791 and #1746
This commit is contained in:
@@ -88,6 +88,7 @@ EditDialog::EditDialog(QWidget* parent)
|
||||
return;
|
||||
}
|
||||
});
|
||||
connect(ui->actionOpenInExternal, &QAction::triggered, this, &EditDialog::openDataWithExternal);
|
||||
|
||||
mustIndentAndCompact = Settings::getValue("databrowser", "indent_compact").toBool();
|
||||
ui->actionIndent->setChecked(mustIndentAndCompact);
|
||||
@@ -1177,3 +1178,76 @@ void EditDialog::setWordWrapping(bool value)
|
||||
sciEdit->setWrapMode(value ? QsciScintilla::WrapWord : QsciScintilla::WrapNone);
|
||||
ui->qtEdit->setWordWrapMode(value ? QTextOption::WrapAtWordBoundaryOrAnywhere : QTextOption::NoWrap);
|
||||
}
|
||||
|
||||
void EditDialog::openDataWithExternal()
|
||||
{
|
||||
QString extension;
|
||||
QStringList filters;
|
||||
switch (dataType) {
|
||||
case Image: {
|
||||
// Images get special treatment.
|
||||
// Determine the likely filename extension.
|
||||
QByteArray cellData = hexEdit->data();
|
||||
QBuffer imageBuffer(&cellData);
|
||||
QImageReader imageReader(&imageBuffer);
|
||||
extension = imageReader.format().toLower().prepend(".");
|
||||
break;
|
||||
}
|
||||
case Binary:
|
||||
extension = FILE_EXT_BIN_DEFAULT;
|
||||
break;
|
||||
case RtlText:
|
||||
case Text:
|
||||
if (ui->comboMode->currentIndex() == XmlEditor)
|
||||
extension = FILE_EXT_XML_DEFAULT;
|
||||
else
|
||||
extension = FILE_EXT_TXT_DEFAULT;
|
||||
break;
|
||||
case JSON:
|
||||
extension = FILE_EXT_JSON_DEFAULT;
|
||||
break;
|
||||
case SVG:
|
||||
extension = FILE_EXT_SVG_DEFAULT;
|
||||
break;
|
||||
case XML:
|
||||
extension = FILE_EXT_XML_DEFAULT;
|
||||
break;
|
||||
case Null:
|
||||
return;
|
||||
}
|
||||
QTemporaryFile file (QDir::tempPath() + QString("/DB4S-XXXXXX") + extension);
|
||||
|
||||
if(file.open())
|
||||
{
|
||||
switch (dataSource) {
|
||||
case HexBuffer:
|
||||
file.write(hexEdit->data());
|
||||
break;
|
||||
case SciBuffer:
|
||||
// Data source is the Scintilla buffer
|
||||
file.write(sciEdit->text().toUtf8());
|
||||
break;
|
||||
case QtBuffer:
|
||||
// Data source is the text buffer
|
||||
file.write(ui->qtEdit->toPlainText().toUtf8());
|
||||
break;
|
||||
}
|
||||
file.close();
|
||||
|
||||
emit requestUrlOrFileOpen(file.fileName());
|
||||
|
||||
QMessageBox::StandardButton reply = QMessageBox::information
|
||||
(nullptr,
|
||||
QApplication::applicationName(),
|
||||
tr("The data has been saved to a temporary file and has been opened with the default application."
|
||||
"You can edit now the file and when your are ready, you can apply the saved new data to the cell or cancel any changes."),
|
||||
QMessageBox::Apply | QMessageBox::Cancel);
|
||||
|
||||
QFile readFile(file.fileName());
|
||||
if(reply == QMessageBox::Apply && readFile.open(QIODevice::ReadOnly)){
|
||||
QByteArray d = readFile.readAll();
|
||||
loadData(d);
|
||||
readFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ private:
|
||||
bool promptInvalidData(const QString& data_type, const QString& errorString);
|
||||
void setDataInBuffer(const QByteArray& bArrdata, DataSources source);
|
||||
void setStackCurrentIndex(int editMode);
|
||||
void openDataWithExternal();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
<addaction name="actionIndent"/>
|
||||
<addaction name="actionImport"/>
|
||||
<addaction name="actionExport"/>
|
||||
<addaction name="actionOpenInExternal"/>
|
||||
<addaction name="actionOpenInApp"/>
|
||||
<addaction name="actionNull"/>
|
||||
<addaction name="actionPrint"/>
|
||||
@@ -448,6 +449,18 @@ Errors are indicated with a red squiggle underline.</string>
|
||||
<string>Opens a file dialog used to import any kind of data to this database cell.</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionOpenInExternal">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/open_data_in_app</normaloff>:/icons/open_data_in_app</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open in external application</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Open in external application</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>comboMode</tabstop>
|
||||
|
||||
@@ -25,6 +25,7 @@ static const QString FILE_FILTER_ALL(QObject::tr("All Files (*)"));
|
||||
|
||||
// Text Files Extensions Filter
|
||||
static const QString FILE_FILTER_TXT(QObject::tr("Text Files (*.txt)"));
|
||||
static const QString FILE_EXT_TXT_DEFAULT(".txt");
|
||||
|
||||
// Comma,Tab,or Delimiter-Separated Values File Extensions Filter
|
||||
static const QString FILE_FILTER_CSV(QObject::tr("Comma-Separated Values Files (*.csv)"));
|
||||
@@ -38,12 +39,15 @@ static const QString FILE_EXT_JSON_DEFAULT(".json");
|
||||
|
||||
// XML File Extensions Filter
|
||||
static const QString FILE_FILTER_XML(QObject::tr("XML Files (*.xml)"));
|
||||
static const QString FILE_EXT_XML_DEFAULT(".xml");
|
||||
|
||||
// Binary File Extensions Filter
|
||||
static const QString FILE_FILTER_BIN(QObject::tr("Binary Files (*.bin *.dat)"));
|
||||
static const QString FILE_EXT_BIN_DEFAULT(".bin");
|
||||
|
||||
// Scalar Vector Graphics File Extensions Filter
|
||||
static const QString FILE_FILTER_SVG(QObject::tr("SVG Files (*.svg)"));
|
||||
static const QString FILE_EXT_SVG_DEFAULT(".svg");
|
||||
|
||||
// Hex-Dump File Extension Filter
|
||||
static const QString FILE_FILTER_HEX(QObject::tr("Hex Dump Files (*.dat *.bin)"));
|
||||
|
||||
BIN
src/icons/application_go.png
Normal file
BIN
src/icons/application_go.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 634 B |
@@ -100,5 +100,6 @@
|
||||
<file alias="add_cond_format">style_add.png</file>
|
||||
<file alias="open_in_app">application_link.png</file>
|
||||
<file alias="document_link">document-link.png</file>
|
||||
<file alias="open_data_in_app">application_go.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Reference in New Issue
Block a user