fix: xdg folders rename

This commit is contained in:
kate 2022-01-17 03:08:30 +08:00
parent 3a062c3792
commit 5c450d527a
4 changed files with 27 additions and 3 deletions

View file

@ -19,6 +19,7 @@
#include "filepropertiesdialog.h"
#include "../desktopiconprovider.h"
#include "../helper/fm.h"
#include <QQmlContext>
#include <QQmlEngine>
@ -97,7 +98,7 @@ void FilePropertiesDialog::accept(const QString &text)
if (fileName() != newFileName) {
QUrl newUrl;
if (!location().isEmpty()) {
if (!location().isEmpty() && !Fm::isFixedFolder(m_items.first().url())) {
newUrl = location();
newUrl.setPath(concatPaths(newUrl.path(), newFileName));
newUrl.setScheme(item.url().scheme());

View file

@ -19,6 +19,9 @@
#include "fm.h"
#include <QDir>
#include <QUrl>
#include <QStandardPaths>
#include <KIO/EmptyTrashJob>
Fm::Fm(QObject *parent) : QObject(parent)
@ -36,3 +39,16 @@ void Fm::emptyTrash()
KIO::Job *job = KIO::emptyTrash();
job->start();
}
bool Fm::isFixedFolder(const QUrl &folderUrl)
{
const QString folder = folderUrl.toLocalFile();
return folder == QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first() ||
folder == QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first() ||
folder == QStandardPaths::standardLocations(QStandardPaths::MusicLocation).first() ||
folder == QStandardPaths::standardLocations(QStandardPaths::MoviesLocation).first() ||
folder == QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first() ||
folder == QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first() ||
folder == QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first();
}

View file

@ -31,6 +31,7 @@ public:
Q_INVOKABLE QString rootPath();
Q_INVOKABLE static void emptyTrash();
static bool isFixedFolder(const QUrl &folderUrl);
};
#endif // FM_H

View file

@ -33,6 +33,7 @@
#include "../helper/datehelper.h"
#include "../helper/filelauncher.h"
#include "../helper/fm.h"
#include "../cio/cfilesizejob.h"
@ -86,7 +87,6 @@ static bool isDropBetweenSharedViews(const QList<QUrl> &urls, const QUrl &folder
return true;
}
FolderModel::FolderModel(QObject *parent)
: QSortFilterProxyModel(parent)
, m_dirWatch(nullptr)
@ -1231,6 +1231,12 @@ void FolderModel::drop(QQuickItem *target, QObject *dropEvent, int row)
if (!isDropBetweenSharedViews(mimeData->urls(), dropTargetFolderUrl)) {
KIO::Job *job = KIO::move(mimeData->urls(), dropTargetUrl, KIO::HideProgressInfo);
job->start();
// Add select
for (QUrl url : mimeData->urls()) {
m_needSelectUrls.append(QUrl::fromLocalFile(QString("%1/%2").arg(rootItem().url().toLocalFile())
.arg(url.fileName())));
}
}
}
@ -1920,7 +1926,7 @@ void FolderModel::updateActions()
if (QAction *rename = m_actionCollection.action(QStringLiteral("rename"))) {
rename->setEnabled(itemProperties.supportsMoving());
rename->setVisible(!isTrash);
rename->setVisible(!isTrash && !Fm::isFixedFolder(items.first().url()));
}
if (QAction *trash = m_actionCollection.action("trash")) {