-
Notifications
You must be signed in to change notification settings - Fork 55
fix: prevent dragging items to fixed plugin section #1277
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
Conversation
Reviewer's GuideAdds drag-and-drop validation in the tray UI to block moves onto fixed plugin sections by detecting forbidden targets in QML and marking the quick settings toggle as a fixed section in the sort order model. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Consider moving the linear search in isForbiddenDropTarget into the C++ model or caching a mapping from visual index to section type to avoid iterating the entire model on every drag event.
- Add the forbidden-target check in onDragMove (in addition to onEntered) to prevent users from dragging into fixed sections mid-drag.
- Define sectionType values as exported constants or enums in QML instead of using the hardcoded string literal 'fixed' to reduce brittleness.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider moving the linear search in isForbiddenDropTarget into the C++ model or caching a mapping from visual index to section type to avoid iterating the entire model on every drag event.
- Add the forbidden-target check in onDragMove (in addition to onEntered) to prevent users from dragging into fixed sections mid-drag.
- Define sectionType values as exported constants or enums in QML instead of using the hardcoded string literal 'fixed' to reduce brittleness.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
acfbd97 to
0e23b25
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR prevents users from dragging items to fixed plugin sections in the system tray by implementing validation logic to reject drop operations on protected areas. The changes prevent accidental reordering of critical system components like the quick settings toggle.
- Added validation to detect and reject drag operations targeting fixed plugin sections
- Implemented getSectionTypeByVisualIndex function to identify section types during drag operations
- Marked the quick settings toggle as a fixed section in the data model
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| traysortordermodel.h | Adds Q_INVOKABLE method declaration for getting section type by visual index |
| traysortordermodel.cpp | Implements section type lookup function and marks quick settings as fixed section |
| TrayContainer.qml | Adds drag validation logic to reject drops on fixed sections |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
| } | ||
|
|
||
| return QString(); // 未找到对应项目 |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is in Chinese. Consider using English for consistency with the rest of the codebase: '// Item not found'
| return QString(); // 未找到对应项目 | |
| return QString(); // Item not found |
| // 检查当前悬停位置是否是禁止拖拽的插件 | ||
| let dropIdx = DDT.TrayItemPositionManager.itemIndexByPoint(Qt.point(drag.x, drag.y)) | ||
| let visualIndex = dropIdx.index | ||
| let sectionType = DDT.TraySortOrderModel.getSectionTypeByVisualIndex(visualIndex) | ||
| if (sectionType === "fixed") { | ||
| dragEvent.accepted = false | ||
| return | ||
| } |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 171 is in Chinese. Consider using English for consistency: '// Check if current hover position is a forbidden drag target plugin'
| return | ||
| } | ||
|
|
||
| // 检查 ActionShowStashDelegate 是否显示 |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is in Chinese. Consider using English for consistency: '// Check if ActionShowStashDelegate is visible'
| // 检查 ActionShowStashDelegate 是否显示 | |
| // Check if ActionShowStashDelegate is visible |
0e23b25 to
97c2cbe
Compare
Added validation to prevent drag and drop operations from targeting fixed plugin sections in the system tray. The changes include: 1. Implemented isForbiddenDropTarget function to check if drop target is a fixed section 2. Added drag event rejection when attempting to drop on fixed sections 3. Marked quick settings toggle as fixed section in the model 4. This prevents users from accidentally moving or reordering critical system components fix: 防止拖拽项目到固定插件区域 添加验证以防止拖放操作目标为系统托盘中的固定插件区域。更改包括: 1. 实现 isForbiddenDropTarget 函数检查拖放目标是否为固定区域 2. 在尝试拖放到固定区域时添加拖放事件拒绝 3. 在模型中标记快速设置切换为固定区域 4. 防止用户意外移动或重新排列关键系统组件 Pms: BUG-289447 BUG-289445
97c2cbe to
03da045
Compare
deepin pr auto review我对这个代码审查如下:
改进建议:
QModelIndex TraySortOrderModel::getModelIndexByVisualIndex(int visualIndex) const
{
// 考虑添加一个缓存映射,避免每次都线性搜索
static QHash<int, QModelIndex> visualIndexToModelIndexCache;
// 如果缓存中没有,则进行查找并更新缓存
if (!visualIndexToModelIndexCache.contains(visualIndex)) {
for (int i = 0; i < rowCount(); i++) {
QModelIndex index = this->index(i, 0);
int itemVisualIndex = data(index, VisualIndexRole).toInt();
bool visibility = data(index, VisibilityRole).toBool();
if (visibility && itemVisualIndex == visualIndex) {
visualIndexToModelIndexCache[visualIndex] = index;
return index;
}
}
visualIndexToModelIndexCache[visualIndex] = QModelIndex();
}
return visualIndexToModelIndexCache.value(visualIndex);
}
总体而言,这段代码实现了拖放功能的基本需求,并且对固定类型插件进行了适当的保护。通过上述改进,可以进一步提高代码的性能、健壮性和可维护性。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, wjyrich The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Added validation to prevent drag and drop operations from targeting fixed plugin sections in the system tray. The changes include:
fix: 防止拖拽项目到固定插件区域
添加验证以防止拖放操作目标为系统托盘中的固定插件区域。更改包括:
Pms: BUG-289447 BUG-289445
Summary by Sourcery
Disallow dragging tray items onto fixed plugin sections to prevent accidental reordering of critical system components.
Bug Fixes:
Enhancements: