- 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. - enhancement: Correctly handle tab in the exported RTF.
- change: Disable undo limit by default. - change: Disable undo limit by default.
- fix: "Goto declaration" / "Goto definition" / "Find occurences" not correctly disabled for non-c/c++ files. - 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 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), QFileDialog dialog(this,tr("Save As"),extractFilePath(mFilename),
pSystemConsts->defaultFileFilters().join(";;")); pSystemConsts->defaultFileFilters().join(";;"));
dialog.selectNameFilter(selectedFileFilter); dialog.selectNameFilter(selectedFileFilter);
dialog.setDefaultSuffix(defaultExt); //dialog.setDefaultSuffix(defaultExt);
dialog.selectFile(mFilename); dialog.selectFile(mFilename);
dialog.setFileMode(QFileDialog::AnyFile); dialog.setFileMode(QFileDialog::AnyFile);
dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setAcceptMode(QFileDialog::AcceptSave);
connect(&dialog, &QFileDialog::filterSelected, // connect(&dialog, &QFileDialog::filterSelected,
[&dialog](const QString &filter){ // [&dialog](const QString &filter){
int pos = filter.indexOf("*."); // if (filter.indexOf("*.*")) {
if (pos>=0) { // dialog.setDefaultSuffix("");
QString suffix; // qDebug()<<"lllll";
pos+=2; // return;
while (pos<filter.length()) { // }
if (filter[pos] == ';' || filter[pos] ==' ' || filter[pos] == ')') // int pos = filter.indexOf("*.");
break; // if (pos>=0) {
suffix+=filter[pos]; // QString suffix;
pos++; // pos+=2;
} // while (pos<filter.length()) {
dialog.setDefaultSuffix(suffix); // if (filter[pos] == ';' || filter[pos] ==' ' || filter[pos] == ')')
} else { // break;
dialog.setDefaultSuffix(""); // suffix+=filter[pos];
} // pos++;
}); // }
// //dialog.setDefaultSuffix(suffix);
// } else {
// dialog.setDefaultSuffix("");
// }
// });
if (dialog.exec()!=QFileDialog::Accepted) { if (dialog.exec()!=QFileDialog::Accepted) {
return false; return false;
} }
newName = dialog.selectedFiles()[0]; 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)); QDir::setCurrent(extractFileDir(newName));
} }

View File

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