Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: The application name on the dde-desktop cannot be renamed #2302

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 renameEnabled = true;
if (focusFileInfo && FileUtils::isDesktopFileInfo(focusFileInfo)
&& !focusFileInfo->canAttributes(CanableInfoType::kCanRename))
renameEnabled = 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(renameEnabled);
}
}
}
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 renameEnabled = true;
if (d->focusFileInfo && FileUtils::isDesktopFileInfo(d->focusFileInfo)
&& !d->focusFileInfo->canAttributes(CanableInfoType::kCanRename))
renameEnabled = 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 (!renameEnabled && dfmplugin_menu::ActionID::kRename == actId){
act->setEnabled(renameEnabled);
}
}
}

Expand Down
Loading