Skip to content

Commit

Permalink
fix: The application name on the dde-desktop cannot be renamed
Browse files Browse the repository at this point in the history
Desktop files on the desktop are hard linked and can be renamed based on whether the file is writable

Log: The application name on the dde-desktop cannot be renamed
Bug: https://pms.uniontech.com/bug-view-256967.html
  • Loading branch information
liyigang1 committed Sep 20, 2024
1 parent 7a4dce4 commit 2d3f80a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/dfm-base/file/local/desktopfileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ bool DesktopFileInfo::canAttributes(const CanableInfoType type) const
return false;

return ProxyFileInfo::canAttributes(type);
case FileCanType::kCanRename:
if (!isAttributes(OptInfoType::kIsWritable))
return false;
return ProxyFileInfo::canAttributes(type);
default:
return ProxyFileInfo::canAttributes(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ bool FileOperatorMenuScene::initialize(const QVariantHash &params)

if (!d->isEmptyArea) {
QString errString;
d->focusFileInfo = DFMBASE_NAMESPACE::InfoFactory::create<FileInfo>(d->focusFile, Global::CreateFileInfoType::kCreateFileInfoAuto, &errString);
d->focusFileInfo = DFMBASE_NAMESPACE::InfoFactory::create<FileInfo>(d->focusFile,
Global::CreateFileInfoType::kCreateFileInfoAuto, &errString);
if (d->focusFileInfo.isNull()) {
fmDebug() << errString;
return false;
Expand Down Expand Up @@ -175,6 +176,10 @@ void FileOperatorMenuScene::updateState(QMenu *parent)
|| !d->focusFileInfo->canAttributes(CanableInfoType::kCanRename)
|| !d->indexFlags.testFlag(Qt::ItemIsEditable))
rename->setDisabled(true);

if (d->focusFileInfo && FileUtils::isDesktopFileInfo(d->focusFileInfo)
&& !d->focusFileInfo->canAttributes(CanableInfoType::kCanRename))
rename->setDisabled(true);
}

// set as wallpaper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <dfm-base/dfm_menu_defines.h>
#include <dfm-base/base/configs/dconfig/dconfigmanager.h>
#include <dfm-base/utils/fileutils.h>
#include <dfm-base/base/schemefactory.h>

#include <dfm-framework/dpf.h>

Expand Down Expand Up @@ -78,6 +80,11 @@ void CanvasMenuScenePrivate::filterDisableAction(QMenu *menu)
else
disableActions = &normalDisableActions;

bool renameAbled = true;
if (focusFileInfo && FileUtils::isDesktopFileInfo(focusFileInfo)
&& !focusFileInfo->canAttributes(CanableInfoType::kCanRename))
renameAbled = false;

if (!disableActions->isEmpty()) {
for (auto action : actions) {
if (action->isSeparator())
Expand All @@ -94,6 +101,8 @@ void CanvasMenuScenePrivate::filterDisableAction(QMenu *menu)
// disable,remove it.
menu->removeAction(action);
}
if (actionId == dfmplugin_menu::ActionID::kRename)
action->setEnabled(renameAbled);
}
}
}
Expand Down Expand Up @@ -144,8 +153,10 @@ bool CanvasMenuScene::initialize(const QVariantHash &params)
{
d->currentDir = params.value(MenuParamKey::kCurrentDir).toUrl();
d->selectFiles = params.value(MenuParamKey::kSelectFiles).value<QList<QUrl>>();
if (!d->selectFiles.isEmpty())
if (!d->selectFiles.isEmpty()) {
d->focusFile = d->selectFiles.first();
d->focusFileInfo = InfoFactory::create<FileInfo>(d->focusFile);
}
d->onDesktop = params.value(MenuParamKey::kOnDesktop).toBool();
d->isEmptyArea = params.value(MenuParamKey::kIsEmptyArea).toBool();
d->indexFlags = params.value(MenuParamKey::kIndexFlags).value<Qt::ItemFlags>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,19 @@ bool WorkspaceMenuScene::create(DMenu *parent)
void WorkspaceMenuScene::updateState(DMenu *parent)
{
auto currentWidget = WorkspaceHelper::instance()->findWorkspaceByWindowId(d->windowId);
bool renameAbled = true;
if (d->focusFileInfo && FileUtils::isDesktopFileInfo(d->focusFileInfo)
&& !d->focusFileInfo->canAttributes(CanableInfoType::kCanRename))
renameAbled = false;
if (currentWidget && !currentWidget->canAddNewTab()) {
auto actions = parent->actions();
for (auto act : actions) {
const auto &actId = act->property(ActionPropertyKey::kActionID);
if (dfmplugin_menu::ActionID::kOpenInNewTab == actId)
if (dfmplugin_menu::ActionID::kOpenInNewTab == actId) {
act->setEnabled(false);
} else if (!renameAbled && dfmplugin_menu::ActionID::kRename == actId){
act->setEnabled(renameAbled);
}
}
}

Expand Down

0 comments on commit 2d3f80a

Please sign in to comment.