-
Notifications
You must be signed in to change notification settings - Fork 180
refactor: optimize filename display logic #3350
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
Refactored the filename display logic to simplify the code and improve maintainability. The main changes include: 1. Removed complex text layout calculations for base name and suffix 2. Centralized ellipsis handling to ElideTextLayout::layout for consistent behavior 3. Simplified the logic for handling file suffixes based on application settings 4. Improved code readability by removing redundant text list operations The previous implementation had separate ellipsis handling for base names and suffixes, which could cause inconsistencies in text display. Now all ellipsis processing is handled by ElideTextLayout::layout, ensuring uniform behavior and better support for highlighting features. Influence: 1. Verify filename display in list view with various name lengths 2. Test filename display with and without suffix visibility setting 3. Check ellipsis behavior for long filenames 4. Verify highlighting functionality works correctly 5. Test desktop file display remains unaffected 重构:优化文件名显示逻辑 重构了文件名显示逻辑以简化代码并提高可维护性。主要变更包括: 1. 移除了对基础名称和后缀的复杂文本布局计算 2. 将省略处理集中到 ElideTextLayout::layout 以实现一致的行为 3. 简化了基于应用设置处理文件后缀的逻辑 4. 通过移除冗余的文本列表操作提高了代码可读性 之前的实现分别处理基础名称和后缀的省略,这可能导致文本显示不一致。现在所 有省略处理都由 ElideTextLayout::layout 处理,确保统一的行为并更好地支持 高亮功能。 影响: 1. 验证列表视图中不同长度文件名的显示 2. 测试开启和关闭后缀显示设置时的文件名显示 3. 检查长文件名的省略行为 4. 验证高亮功能正常工作 5. 测试桌面文件显示不受影响 BUG: https://pms.uniontech.com/bug-view-337877.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR refactors the filename display logic in ListItemDelegate to remove manual layout computations, centralize ellipsis handling within ElideTextLayout::layout, and streamline suffix visibility based on application settings, improving readability and maintainability. Sequence diagram for centralized ellipsis handling in filename displaysequenceDiagram
participant ListItemDelegate
participant ElideTextLayout
participant Application
ListItemDelegate->>Application: Query kShowedFileSuffix setting
ListItemDelegate->>ListItemDelegate: Build displayName (baseName [+ suffix])
ListItemDelegate->>ElideTextLayout: layout(rect, Qt::ElideRight, ...)
ElideTextLayout-->>ListItemDelegate: Return elided text for display
Class diagram for refactored filename display logic in ListItemDelegateclassDiagram
class ListItemDelegate {
+paintFileName(painter, option, index, url, role, textLineHeight, rect)
+getCorrectDisplayName(painter, index, option, url, role, textLineHeight, rect) : QString
}
class ElideTextLayout {
+layout(rect, elideMode, highlight, brush, textList)
}
class Application {
+instance()
+genericAttribute(key)
kShowedFileSuffix
}
ListItemDelegate --> ElideTextLayout : uses
ListItemDelegate --> Application : queries settings
Flow diagram for simplified filename display logicflowchart TD
A["Start: paintFileName()"] --> B["Get displayName (baseName [+ suffix])"]
B --> C["Check Application::kShowedFileSuffix"]
C --> D["Append suffix if setting is true"]
D --> E["Pass displayName to ElideTextLayout::layout"]
E --> F["Display filename with ellipsis and highlighting"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我来分析一下这段代码的修改:
建议:
总体来说,这次修改提高了代码的可维护性和性能,同时修复了高亮功能的问题,是一个良好的改进。 |
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 and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/plugins/filemanager/dfmplugin-workspace/views/listitemdelegate.cpp:686` </location>
<code_context>
+ displayName = index.data(kItemFileBaseNameRole).toString().remove('\n');
+ // 根据设置决定是否显示后缀
bool showSuffix { Application::instance()->genericAttribute(Application::kShowedFileSuffix).toBool() };
if (showSuffix)
displayName.append(suffix);
</code_context>
<issue_to_address>
**question:** Suffix display logic is now more direct, but may miss error handling for mismatched display names.
Consider whether removing the display name check could cause issues for files with unusual names or encodings, as the new logic may not always produce the intended display name.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| displayName = index.data(kItemFileBaseNameRole).toString().remove('\n'); | ||
|
|
||
| // 根据设置决定是否显示后缀 | ||
| bool showSuffix { Application::instance()->genericAttribute(Application::kShowedFileSuffix).toBool() }; |
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.
question: Suffix display logic is now more direct, but may miss error handling for mismatched display names.
Consider whether removing the display name check could cause issues for files with unusual names or encodings, as the new logic may not always produce the intended display name.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs, Kakueeen The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: behind) |
Refactored the filename display logic to simplify the code and improve
maintainability. The main changes include:
consistent behavior
settings
The previous implementation had separate ellipsis handling for base
names and suffixes, which could cause inconsistencies in text display.
Now all ellipsis processing is handled by ElideTextLayout::layout,
ensuring uniform behavior and better support for highlighting features.
Influence:
重构:优化文件名显示逻辑
重构了文件名显示逻辑以简化代码并提高可维护性。主要变更包括:
之前的实现分别处理基础名称和后缀的省略,这可能导致文本显示不一致。现在所
有省略处理都由 ElideTextLayout::layout 处理,确保统一的行为并更好地支持
高亮功能。
影响:
BUG: https://pms.uniontech.com/bug-view-337877.html
Summary by Sourcery
Refactor filename rendering by centralizing ellipsis processing in ElideTextLayout and streamlining suffix visibility logic to simplify code and ensure consistent behavior
Bug Fixes:
Enhancements: