- fix: Can't save new file using filename with custom suffix.

This commit is contained in:
Roy Qu 2023-01-07 20:29:57 +08:00
parent 2ab5efc6fe
commit d75ffef9bb
3 changed files with 46 additions and 18 deletions

View File

@ -19,6 +19,7 @@ Red Panda C++ Version 2.8
- enhancement: Correctly handle tab in the exported RTF.
- change: Disable undo limit by default.
- fix: "Goto declaration" / "Goto definition" / "Find occurences" not correctly disabled for non-c/c++ files.
- fix: Can't save new file using filename with custom suffix.
Red Panda C++ Version 2.7

View File

@ -312,32 +312,55 @@ bool Editor::saveAs(const QString &name, bool fromProject){
QFileDialog dialog(this,tr("Save As"),extractFilePath(mFilename),
pSystemConsts->defaultFileFilters().join(";;"));
dialog.selectNameFilter(selectedFileFilter);
dialog.setDefaultSuffix(defaultExt);
//dialog.setDefaultSuffix(defaultExt);
dialog.selectFile(mFilename);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setAcceptMode(QFileDialog::AcceptSave);
connect(&dialog, &QFileDialog::filterSelected,
[&dialog](const QString &filter){
int pos = filter.indexOf("*.");
if (pos>=0) {
QString suffix;
pos+=2;
while (pos<filter.length()) {
if (filter[pos] == ';' || filter[pos] ==' ' || filter[pos] == ')')
break;
suffix+=filter[pos];
pos++;
}
dialog.setDefaultSuffix(suffix);
} else {
dialog.setDefaultSuffix("");
}
});
// connect(&dialog, &QFileDialog::filterSelected,
// [&dialog](const QString &filter){
// if (filter.indexOf("*.*")) {
// dialog.setDefaultSuffix("");
// qDebug()<<"lllll";
// return;
// }
// int pos = filter.indexOf("*.");
// if (pos>=0) {
// QString suffix;
// pos+=2;
// while (pos<filter.length()) {
// if (filter[pos] == ';' || filter[pos] ==' ' || filter[pos] == ')')
// break;
// suffix+=filter[pos];
// pos++;
// }
// //dialog.setDefaultSuffix(suffix);
// } else {
// dialog.setDefaultSuffix("");
// }
// });
if (dialog.exec()!=QFileDialog::Accepted) {
return false;
}
newName = dialog.selectedFiles()[0];
QFileInfo fileInfo(newName);
if (fileInfo.suffix().isEmpty()) {
QString filter = dialog.selectedNameFilter();
if (!filter.contains("*.*")) {
int pos = filter.indexOf("*.");
if (pos>=0) {
QString suffix;
pos+=2;
while (pos<filter.length()) {
if (filter[pos] == ';' || filter[pos] ==' ' || filter[pos] == ')')
break;
suffix+=filter[pos];
pos++;
}
newName += "." + suffix;
}
}
}
QDir::setCurrent(extractFileDir(newName));
}

View File

@ -26,7 +26,11 @@ SystemConsts* pSystemConsts;
SystemConsts::SystemConsts(): mDefaultFileFilters()
{
#ifdef Q_OS_WIN
addDefaultFileFilter(QObject::tr("All files"),"*.*");
#else
addDefaultFileFilter(QObject::tr("All files"),"*");
#endif
addDefaultFileFilter(QObject::tr("Dev C++ Project files"),"*.dev");
addDefaultFileFilter(QObject::tr("C files"),"*.c");
addDefaultFileFilter(QObject::tr("C++ files"),"*.cpp *.cc *.cxx");