From 61c8f47861c22350df677775516f2479dffa2ca7 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 22 Dec 2019 00:12:04 +0100 Subject: [PATCH] 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 --- src/EditDialog.cpp | 20 ++++++++++++++++++++ src/EditDialog.ui | 23 +++++++++++++++++++++-- src/ExtendedTableWidget.cpp | 12 ++++++++++++ src/icons/application_link.png | Bin 0 -> 701 bytes src/icons/icons.qrc | 1 + 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/icons/application_link.png diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index f80033b6..9895a49b 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/src/EditDialog.ui b/src/EditDialog.ui index aa3fc552..b2c4838c 100644 --- a/src/EditDialog.ui +++ b/src/EditDialog.ui @@ -124,6 +124,7 @@ + @@ -175,8 +176,8 @@ Errors are indicated with a red squiggle underline. 0 0 - 598 - 264 + 84 + 35 @@ -402,6 +403,24 @@ Errors are indicated with a red squiggle underline. Wrap lines on word boundaries + + + + :/icons/open_in_app:/icons/open_in_app + + + Open in default application or browser + + + Open in application + + + Open in default application or browser + + + The value is interpreted as a file or URL and opened in the default application or web browser. + + comboMode diff --git a/src/ExtendedTableWidget.cpp b/src/ExtendedTableWidget.cpp index 2f67b481..e9cb0502 100644 --- a/src/ExtendedTableWidget.cpp +++ b/src/ExtendedTableWidget.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -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); + } } } diff --git a/src/icons/application_link.png b/src/icons/application_link.png new file mode 100644 index 0000000000000000000000000000000000000000..f8fbb3ed94ca7686a3acc052b06f2d8ea4034a4b GIT binary patch literal 701 zcmV;u0z&gFy@`WU!f)*0Mw4O9TnqBr{Y-GHDVuib)O%q7o!E zKlFxCD=Me;C78Guop0xOj_&HYpW_Dm*t+3@`&{>Re&;#QbB+dp=6|HIxRxBDrUi@fE_t7hH*d!sYoQrtW@#bM76y@j{#K^yGu+Y%mKB@Gh?6AT=?YQ30NZKe^FU`jD8!o`SZhpef2|bb8oqiKx}PSX=Ml zPpyStYfYXXpH2?}Y{RJJ!2oi<&p};TK}S+S+g$})Z3*j525N|?ZghFxdh>+}pxvhG zGk`)6rXB-{4Ai03Fi?wD)KO4x$=GO0Jb&iKa}_{G#Q{4z9Iy-OF-d*(m3BeRA&BbK z^=B$Txc7MvKx%ipc$rQk6bd1cNFW#tVzpdGZF38^haSzwg)nqF-C@mC?4t@`l4KbR zED(uAP_0%`sZ@~5<@oh{JdRSS#JxhHz`fDY(Oa5JbMN<#=5;m;pU;Ql$_i!!0hrBZ z*ladLqfvM~9^R7|U^9XUg3!=7qi^>B;cyr;Gcz0@NfL}kBQlu`ip3)G`8-mo6!&OG z0KeZa(!a2D?#>(jWtk`Zu%CBwz)9;x96LS&gTVlc#ll5Bc_&U^-~hYbUf=g;9bv_m z_?>N1J()~yE-x=57K_24C(^PW7KQHHYn09vi~kY2ApYBHIAPfkv@9S(=c)EgTc jvoejazDXXstyle_edit.png style_delete.png style_add.png + application_link.png