-
Notifications
You must be signed in to change notification settings - Fork 38
fix(frame): ensure default filename has correct extension #186
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
When saving files with the default filename, the code now automatically appends the appropriate file extension based on the selected file filter. This prevents saving files without extensions and ensures proper file association. log: ensure default filename has correct extension bug: https://pms.uniontech.com/bug-view-331447.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures the default filename used in the file save dialog has the correct extension derived from the active file filter, and exposes the suffix-extraction helper on FileSelectDialog for this purpose. Sequence diagram for default filename extension handling in file save dialogsequenceDiagram
actor User
participant DrawBoard
participant DrawBoard_private
participant FileSelectDialog
participant DrawApp
User->>DrawBoard: triggerSave()
DrawBoard->>DrawBoard_private: execFileSelectDialog(defaultFileName, toddf, file)
alt toddf is true
DrawBoard_private->>FileSelectDialog: construct with _borad as parent
DrawBoard_private->>FileSelectDialog: setAcceptMode(Save)
DrawBoard_private->>FileSelectDialog: setNameFilters(...)
alt file is not empty
DrawBoard_private->>FileSelectDialog: selectFile(file)
DrawBoard_private->>FileSelectDialog: setDirectory(dir of file)
else file is empty
DrawBoard_private->>FileSelectDialog: fullFileName = defaultFileName
DrawBoard_private->>FileSelectDialog: fileInfo = QFileInfo(fullFileName)
alt fileInfo.suffix is empty
DrawBoard_private->>DrawApp: defaultFileDialogNameFilter()
DrawApp-->>DrawBoard_private: filter
DrawBoard_private->>FileSelectDialog: extractSuffix(filter)
FileSelectDialog-->>DrawBoard_private: suffix
alt suffix not empty
DrawBoard_private->>DrawBoard_private: normalize suffix with leading dot
DrawBoard_private->>DrawBoard_private: append suffix if missing
end
end
DrawBoard_private->>FileSelectDialog: selectFile(fullFileName)
DrawBoard_private->>FileSelectDialog: setDirectory(drawApp.defaultFileDialogPath())
end
DrawBoard_private->>FileSelectDialog: exec()
FileSelectDialog-->>DrawBoard_private: dialog result
DrawBoard_private-->>DrawBoard: selected file path
else toddf is false
DrawBoard_private-->>DrawBoard: use alternative path selection
end
DrawBoard-->>User: file saved with correct extension
Updated class diagram for FileSelectDialog and DrawBoard_privateclassDiagram
class FileSelectDialog {
+FileSelectDialog(QWidget parent)
+int exec()
+QString resultFile() const
+QString extractSuffix(QString filter)
-void saveSetting()
-QString checkAndBuildPath(QString path)
-QString _resultFile
}
class DrawBoard_private {
+QString execFileSelectDialog(QString defaultFileName, bool toddf, QString file)
-QWidget _borad
}
class DrawBoard {
-DrawBoard_private* d
+void triggerSave()
}
DrawBoard --> DrawBoard_private : uses
DrawBoard_private --> FileSelectDialog : creates
DrawBoard_private --> DrawBoard : enclosing_class_relationship
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码的修改主要是为了在文件对话框打开时,自动为没有后缀名的默认文件名添加后缀。以下是对这段代码的详细审查和改进建议: 1. 语法与逻辑审查
2. 代码质量
3. 代码性能
4. 代码安全
5. 改进后的代码示例结合以上建议,优化后的代码片段如下: // src/frame/ccentralwidget.cpp
// ...
// 建议参数使用 const 引用
QString execFileSelectDialog(const QString &defaultFileName, bool toddf = true, const QString &file = QString())
{
if (toddf) {
FileSelectDialog dialog(_borad);
// ... (其他初始化代码)
if (!file.isEmpty()) {
dialog.selectFile(file);
dialog.setDirectory(QFileInfo(file).dir().absolutePath());
} else {
// Add a format suffix to the default filename
QString fullFileName = defaultFileName;
QFileInfo fileInfo(fullFileName);
if (fileInfo.suffix().isEmpty()) {
// 建议确保 drawApp 有效
if (drawApp) {
QString nameFilter = drawApp->defaultFileDialogNameFilter();
QString suffix = dialog.extractSuffix(nameFilter);
if (!suffix.isEmpty()) {
if (!suffix.startsWith("."))
suffix.prepend(".");
// 使用 += 替代 +
if (!fullFileName.endsWith(suffix))
fullFileName += suffix;
}
}
}
dialog.selectFile(fullFileName);
dialog.setDirectory(drawApp ? drawApp->defaultFileDialogPath() : QString());
}
dialog.exec();
// ...
}
// ...
}总结这段修改解决了默认文件名缺少后缀的问题,逻辑正确。主要的改进点在于:
|
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 - I've left some high level feedback:
- The logic that normalizes and appends the suffix to
defaultFileNamewould be clearer and more reusable if it were encapsulated insideFileSelectDialog(e.g., a helper likebuildDefaultFileNameWithSuffix(...)) instead of reimplementing the suffix handling inexecFileSelectDialog. - When appending the suffix, consider normalizing against the filter pattern rather than simple string checks (
startsWith('.'),endsWith(suffix)), as this can behave unexpectedly with multi-part extensions or filters containing multiple patterns (e.g.,"*.jpg *.jpeg").
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The logic that normalizes and appends the suffix to `defaultFileName` would be clearer and more reusable if it were encapsulated inside `FileSelectDialog` (e.g., a helper like `buildDefaultFileNameWithSuffix(...)`) instead of reimplementing the suffix handling in `execFileSelectDialog`.
- When appending the suffix, consider normalizing against the filter pattern rather than simple string checks (`startsWith('.')`, `endsWith(suffix)`), as this can behave unexpectedly with multi-part extensions or filters containing multiple patterns (e.g., `"*.jpg *.jpeg"`).Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind 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 |
|
/merge |
When saving files with the default filename, the code now automatically appends the appropriate file extension based on the selected file filter. This prevents saving files without extensions and ensures proper file association.
log: ensure default filename has correct extension
bug: https://pms.uniontech.com/bug-view-331447.html
Summary by Sourcery
Ensure the file save dialog applies a proper extension to the default filename based on the selected file filter.
Bug Fixes:
Enhancements: