mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-01 01:19:15 -05:00
Open URL or filename: relative filenames are based on DB path and refactor
When opening a relative filename from "Edit DB Cell" or Table Browser the relative paths are interpreted from the DB file location. This allows portability of DB and linked files to a new location. Refactoring so the open URL code is centralised in MainWindow and a status message is displayed with error or opening notification. See issue #1597
This commit is contained in:
+2
-9
@@ -19,7 +19,6 @@
|
||||
#include <QPainter>
|
||||
#include <QClipboard>
|
||||
#include <QTextDocument>
|
||||
#include <QDesktopServices>
|
||||
#include <QMenu>
|
||||
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
@@ -78,22 +77,16 @@ EditDialog::EditDialog(QWidget* parent)
|
||||
});
|
||||
|
||||
connect(ui->actionOpenInApp, &QAction::triggered, this, [&]() {
|
||||
QUrl url;
|
||||
switch (dataSource) {
|
||||
case SciBuffer:
|
||||
url.setUrl(sciEdit->text(), QUrl::TolerantMode);
|
||||
emit requestUrlOrFileOpen(sciEdit->text());
|
||||
break;
|
||||
case QtBuffer:
|
||||
url.setUrl(ui->qtEdit->toPlainText(), QUrl::TolerantMode);;
|
||||
emit requestUrlOrFileOpen(ui->qtEdit->toPlainText());
|
||||
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();
|
||||
|
||||
@@ -51,6 +51,7 @@ private slots:
|
||||
|
||||
signals:
|
||||
void recordTextUpdated(const QPersistentModelIndex& idx, const QByteArray& bArrdata, bool isBlob);
|
||||
void requestUrlOrFileOpen(const QString& urlString);
|
||||
|
||||
private:
|
||||
Ui::EditDialog* ui;
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <QCompleter>
|
||||
#include <QComboBox>
|
||||
#include <QShortcut>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include <limits>
|
||||
|
||||
@@ -912,10 +911,7 @@ void ExtendedTableWidget::cellClicked(const QModelIndex& index)
|
||||
// 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);
|
||||
emit requestUrlOrFileOpen(model()->data(index, Qt::EditRole).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ signals:
|
||||
void selectedRowsToBeDeleted();
|
||||
void editCondFormats(int column);
|
||||
void currentIndexChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void requestUrlOrFileOpen(const QString& urlString);
|
||||
|
||||
private:
|
||||
void copyMimeData(const QModelIndexList& fromIndices, QMimeData* mimeData, const bool withHeaders, const bool inSQL);
|
||||
|
||||
@@ -400,6 +400,7 @@ void MainWindow::init()
|
||||
|
||||
// Connect some more signals and slots
|
||||
connect(editDock, &EditDialog::recordTextUpdated, this, &MainWindow::updateRecordText);
|
||||
connect(editDock, &EditDialog::requestUrlOrFileOpen, this, &MainWindow::openUrlOrFile);
|
||||
connect(ui->dbTreeWidget->selectionModel(), &QItemSelectionModel::currentChanged, this, &MainWindow::changeTreeSelection);
|
||||
connect(ui->dockEdit, &QDockWidget::visibilityChanged, this, &MainWindow::toggleEditDock);
|
||||
connect(m_remoteDb, SIGNAL(openFile(QString)), this, SLOT(fileOpen(QString)));
|
||||
@@ -749,6 +750,9 @@ void MainWindow::attachPlot(ExtendedTableWidget* tableWidget, SqliteTableModel*
|
||||
// Connect plot selection to the current table results widget.
|
||||
connect(plotDock, SIGNAL(pointsSelected(int,int)), tableWidget, SLOT(selectTableLines(int, int)));
|
||||
connect(tableWidget, &ExtendedTableWidget::destroyed, plotDock, &PlotDock::resetPlot);
|
||||
// Disconnect requestUrlOrFileOpen in order to make sure that there is only one connection. Otherwise we can open it several times.
|
||||
disconnect(tableWidget, &ExtendedTableWidget::requestUrlOrFileOpen, this, &MainWindow::openUrlOrFile);
|
||||
connect(tableWidget, &ExtendedTableWidget::requestUrlOrFileOpen, this, &MainWindow::openUrlOrFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3326,3 +3330,16 @@ void MainWindow::showContextMenuSqlTabBar(const QPoint& pos)
|
||||
menuTabs->addAction(actionClose);
|
||||
menuTabs->exec(ui->tabSqlAreas->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void MainWindow::openUrlOrFile(const QString& urlString)
|
||||
{
|
||||
QUrl url = QUrl::fromUserInput(urlString, QFileInfo(db.currentFile()).path(), QUrl::AssumeLocalFile);
|
||||
if(url.isValid()) {
|
||||
if(QDesktopServices::openUrl(url))
|
||||
showStatusMessage5s(tr("Opening '%1'...").arg(url.toDisplayString()));
|
||||
else
|
||||
showStatusMessage5s(tr("There was an error opening '%1'...").arg(url.toDisplayString()));
|
||||
|
||||
} else
|
||||
showStatusMessage5s(tr("Value is not a valid URL or filename: %1").arg(url.errorString()));
|
||||
}
|
||||
|
||||
@@ -204,6 +204,7 @@ private slots:
|
||||
void saveSqlFile(int tabIndex);
|
||||
void saveAll();
|
||||
void showContextMenuSqlTabBar(const QPoint& pos);
|
||||
void openUrlOrFile(const QString& urlString);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user