Commit ded94b65 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Don't use a nested eventloop when renaming files

Using a nested eventloop (started by KJob::exec()) meant that in case of
file names conflict, the KIO::RenameDialog that is shown can't be accessed
at all, as the eventloop of the job blocks all user input events.

Instead make the code async.

Reported by Alexander Volkov:
frameworks/kio@fdb8e14e (comment 380644)
parent 98f1df7a
......@@ -14,6 +14,7 @@
#include <KIO/CopyJob>
#include <KIO/DeleteJob>
#include <KIO/OpenFileManagerWindowJob>
#include <KJobWidgets>
#include <KLocalizedString>
#include <KMessageBox>
#include <KPropertiesDialog>
......@@ -85,18 +86,24 @@ void KateFileActions::renameDocumentFile(QWidget *parent, KTextEditor::Document
doc->waitSaveComplete();
KIO::CopyJob *job = KIO::move(oldFileUrl, newFileUrl);
QSharedPointer<QMetaObject::Connection> sc(new QMetaObject::Connection());
auto success = [doc, sc](KIO::Job *, const QUrl &, const QUrl &realNewFileUrl, const QDateTime &, bool, bool) {
doc->openUrl(realNewFileUrl);
doc->documentSavedOrUploaded(doc, true);
QObject::disconnect(*sc);
};
*sc = parent->connect(job, &KIO::CopyJob::copyingDone, doc, success);
if (!job->exec()) {
KMessageBox::sorry(parent, i18n("File \"%1\" could not be moved to \"%2\"", oldFileUrl.toDisplayString(), newFileUrl.toDisplayString()));
doc->openUrl(oldFileUrl);
}
parent->connect(parent, &QObject::destroyed, job, [job]() {
job->kill();
});
// Associate the job with the parent widget, in case of renaming conflicts the ask-user-dialog
// is window-modal by default
KJobWidgets::setWindow(job, parent);
parent->connect(job, &KJob::result, parent, [parent, doc, oldFileUrl](KJob *job) {
auto *copyJob = static_cast<KIO::CopyJob *>(job);
if (!copyJob->error()) {
doc->openUrl(copyJob->destUrl());
doc->documentSavedOrUploaded(doc, true);
} else {
KMessageBox::sorry(parent, i18n("File \"%1\" could not be moved to \"%2\"", oldFileUrl.toDisplayString(), copyJob->destUrl().toDisplayString()));
doc->openUrl(oldFileUrl);
}
});
}
void KateFileActions::deleteDocumentFile(QWidget *parent, KTextEditor::Document *doc)
......
Supports Markdown
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