mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Open URL or filenames from DB cells
A new button is added in the "Edit DB Cell" dock for interpreting the current value as a URL or filename and opening it using the default application for the file or a web browser for the URL. The same can be directly invoked in the table browser using the same shortcut as the FK navigation. Related issue #1597
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <QPainter>
|
||||
#include <QClipboard>
|
||||
#include <QTextDocument>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
#include <json.hpp>
|
||||
@@ -65,6 +66,25 @@ EditDialog::EditDialog(QWidget* parent)
|
||||
ui->editorBinary->addAction(ui->actionPrint);
|
||||
ui->editorBinary->addAction(ui->actionCopyHexAscii);
|
||||
|
||||
connect(ui->actionOpenInApp, &QAction::triggered, this, [&]() {
|
||||
QUrl url;
|
||||
switch (dataSource) {
|
||||
case SciBuffer:
|
||||
url.setUrl(sciEdit->text(), QUrl::TolerantMode);
|
||||
break;
|
||||
case QtBuffer:
|
||||
url.setUrl(ui->qtEdit->toPlainText(), QUrl::TolerantMode);;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if(url.isValid())
|
||||
QDesktopServices::openUrl(url);
|
||||
else
|
||||
QMessageBox::warning(this, QApplication::applicationName(),
|
||||
tr("Content is not a valid URL or filename: %1").arg(url.errorString()));
|
||||
});
|
||||
|
||||
mustIndentAndCompact = Settings::getValue("databrowser", "indent_compact").toBool();
|
||||
ui->actionIndent->setChecked(mustIndentAndCompact);
|
||||
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
<addaction name="actionIndent"/>
|
||||
<addaction name="actionImport"/>
|
||||
<addaction name="actionExport"/>
|
||||
<addaction name="actionOpenInApp"/>
|
||||
<addaction name="actionNull"/>
|
||||
<addaction name="actionPrint"/>
|
||||
</widget>
|
||||
@@ -175,8 +176,8 @@ Errors are indicated with a red squiggle underline.</string>
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>598</width>
|
||||
<height>264</height>
|
||||
<width>84</width>
|
||||
<height>35</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
@@ -402,6 +403,24 @@ Errors are indicated with a red squiggle underline.</string>
|
||||
<string>Wrap lines on word boundaries</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionOpenInApp">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/open_in_app</normaloff>:/icons/open_in_app</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open in default application or browser</string>
|
||||
</property>
|
||||
<property name="iconText">
|
||||
<string>Open in application</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Open in default application or browser</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>The value is interpreted as a file or URL and opened in the default application or web browser.</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>comboMode</tabstop>
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <QCompleter>
|
||||
#include <QComboBox>
|
||||
#include <QShortcut>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include <limits>
|
||||
|
||||
@@ -901,6 +902,17 @@ void ExtendedTableWidget::cellClicked(const QModelIndex& index)
|
||||
emit foreignKeyClicked(sqlb::ObjectIdentifier(m->currentTableName().schema(), fk.table()),
|
||||
fk.columns().size() ? fk.columns().at(0) : "",
|
||||
m->data(index, Qt::EditRole).toByteArray());
|
||||
else {
|
||||
// If this column does not have a foreign-key, try to interpret it as a filename/URL and open it in external application.
|
||||
|
||||
// TODO: Qt is doing a contiguous selection when Control+Click is pressed. It should be disabled, but at least moving the
|
||||
// current index gives better result.
|
||||
setCurrentIndex(index);
|
||||
|
||||
QUrl url (model()->data(index, Qt::EditRole).toString(), QUrl::TolerantMode);
|
||||
if(url.isValid())
|
||||
QDesktopServices::openUrl(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
src/icons/application_link.png
Normal file
BIN
src/icons/application_link.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 701 B |
@@ -98,5 +98,6 @@
|
||||
<file alias="edit_cond_formats">style_edit.png</file>
|
||||
<file alias="clear_cond_formats">style_delete.png</file>
|
||||
<file alias="add_cond_format">style_add.png</file>
|
||||
<file alias="open_in_app">application_link.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Reference in New Issue
Block a user