Commit 5850022c authored by Gregor Mi's avatar Gregor Mi

Fix crash introduced with a7ba6eb0

Summary:
Reason for the crash: with "Quick Open: Remove "file:///" prefix from file paths"
(a7ba6eb0) the Url prefix file:///
was removed and therefore we hit an assertion (missing protocol) when
trying to open a file from the Quick Open view.

Reviewers: #kate, cullmann

Reviewed By: #kate, cullmann

Subscribers: cullmann, kwrite-devel

Tags: #kate

Differential Revision: https://phabricator.kde.org/D16831
parent d88b0b63
......@@ -159,7 +159,7 @@ void KateQuickOpen::update()
void KateQuickOpen::slotReturnPressed()
{
const auto index = m_listView->model()->index(m_listView->currentIndex().row(), KateQuickOpenModel::Columns::FilePath);
auto url = QUrl(index.data(Qt::DisplayRole).toString());
auto url = index.data(Qt::UserRole).toUrl();
m_mainWindow->wrapper()->openUrl(url);
m_mainWindow->slotWindowActivated();
m_inputLine->clear();
......
......@@ -51,7 +51,7 @@ QVariant KateQuickOpenModel::data(const QModelIndex& idx, int role) const
return {};
}
if (role != Qt::DisplayRole && role != Qt::FontRole) {
if (role != Qt::DisplayRole && role != Qt::FontRole && role != Qt::UserRole) {
return {};
}
......@@ -67,6 +67,8 @@ QVariant KateQuickOpenModel::data(const QModelIndex& idx, int role) const
font.setBold(true);
return font;
}
} else if (role == Qt::UserRole) {
return entry.url;
}
return {};
......@@ -84,21 +86,21 @@ void KateQuickOpenModel::refresh()
for (auto *view : qAsConst(sortedViews)) {
auto doc = view->document();
allDocuments.push_back({ doc->documentName(), doc->url().toDisplayString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile), false });
allDocuments.push_back({ doc->url(), doc->documentName(), doc->url().toDisplayString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile), false });
}
QStringList openedUrls;
openedUrls.reserve(openDocs.size());
for (auto *doc : qAsConst(openDocs)) {
const auto normalizedUrl = doc->url().toString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile);
allDocuments.push_back({ doc->documentName(), normalizedUrl, false });
allDocuments.push_back({ doc->url(), doc->documentName(), normalizedUrl, false });
openedUrls.push_back(normalizedUrl);
}
for (const auto& file : qAsConst(projectDocs)) {
QFileInfo fi(file);
// example of file: "/home/user/projects/myfile.txt" which is consistent with QUrl::toDisplayString(QUrl::PreferLocalFile)
allDocuments.push_back({ fi.fileName(), file, false });
allDocuments.push_back({ QUrl::fromLocalFile(fi.absoluteFilePath()), fi.fileName(), file, false });
}
/** Sort the arrays by filePath. */
......
......@@ -28,9 +28,10 @@
#include "katemainwindow.h"
struct ModelEntry {
QString fileName;
QString filePath;
bool bold;
QUrl url; // used for actually opening a selected file (local or remote)
QString fileName; // display string for left column
QString filePath; // display string for right column
bool bold; // format line in bold text or not
};
class KateQuickOpenModel : public QAbstractTableModel {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment