Commit 094b7259 authored by Marcell Fülöp's avatar Marcell Fülöp
Browse files

Lambda slot for document loaded

parent 1c8f1603
......@@ -325,29 +325,23 @@ KTextEditor::Document *KateApp::openDocUrl(const QUrl &url, const QString &encod
KMessageBox::sorry(mainWindow, i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.", url.url()));
}
// When opening from remote url, 'completed' is emitted once loading has finished.
// Connect to each remote document's completed signal for post-load operations.
// When opening from remote url, 'textChanged' is emitted once loading has finished.
// Connect to each remote document's signal for post-load operations.
if (doc && !doc->url().isLocalFile()) {
connect(doc, SIGNAL(completed()), this, SLOT(remoteDocumentLoaded()));
auto *connCtx = new QObject(this); // use a dummy object as signal receiver
connect(doc, &KTextEditor::Document::textChanged, connCtx, [this, connCtx](KTextEditor::Document *doc) {
connCtx->deleteLater();
if (doc->url().hasQuery()) {
setCursorFromQueryString(doc->views().empty() ? nullptr : doc->views().at(0));
} else {
setCursorFromArgs(doc->views().empty() ? nullptr : doc->views().at(0));
}
});
}
return doc;
}
void KateApp::remoteDocumentLoaded()
{
// disconnect sender doc
auto doc = dynamic_cast<KTextEditor::Document *>(QObject::sender());
disconnect(doc, SIGNAL(completed()), this, SLOT(remoteDocumentLoaded()));
// respect order (query then args)
if (doc->url().hasQuery()) {
setCursorFromQueryString(doc->views().at(0));
} else {
setCursorFromArgs(doc->views().at(0));
}
}
void KateApp::setCursorFromArgs(KTextEditor::View *view)
{
int line = 0;
......@@ -387,7 +381,8 @@ void KateApp::setCursorFromQueryString(KTextEditor::View *view)
QUrlQuery urlQuery;
if (!view->document()->url().hasQuery()) {
// find orig url with query string in m_args
// Find orig url with query string in m_args. It's necessary because positional arguments
// are cleaned (in normaliseUrl() in KateDocManager::openUrl()) for local files but not for remote ones.
QRegExp pattern(QLatin1String(view->document()->url().toString().toUtf8().append(".*").constData()));
if ((pos = m_args.positionalArguments().indexOf(pattern)) < 0) {
return;
......
......@@ -408,12 +408,6 @@ private:
*/
void setCursorFromQueryString(KTextEditor::View *view = nullptr);
private Q_SLOTS:
/**
* Executed when a document from a remote URL has finished loading.
*/
void remoteDocumentLoaded();
#ifdef WITH_KUSERFEEDBACK
/**
* user feedback provider
......
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