CorePlugin: Prevent double warnings for overwriting files

Task-number: QDS-6824
Change-Id: I935b2b1076a4e765230a7462c470d7c134063249
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Tapani Mattila
2022-06-10 12:30:42 +03:00
parent e49e0f87cd
commit 42ab928a27
2 changed files with 14 additions and 13 deletions

View File

@@ -830,8 +830,7 @@ FilePath DocumentManager::getSaveFileName(const QString &title, const FilePath &
bool repeat; bool repeat;
do { do {
repeat = false; repeat = false;
filePath = FileUtils::getSaveFilePath(nullptr, title, path, filter, selectedFilter, filePath = FileUtils::getSaveFilePath(nullptr, title, path, filter, selectedFilter);
QFileDialog::DontConfirmOverwrite);
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {
// If the selected filter is All Files (*) we leave the name exactly as the user // If the selected filter is All Files (*) we leave the name exactly as the user
// specified. Otherwise the suffix must be one available in the selected filter. If // specified. Otherwise the suffix must be one available in the selected filter. If
@@ -852,10 +851,8 @@ FilePath DocumentManager::getSaveFileName(const QString &title, const FilePath &
suffixOk = true; suffixOk = true;
break; break;
} }
if (!suffixOk && !suffixes.isEmpty()) if (!suffixOk && !suffixes.isEmpty()) {
filePath = filePath.stringAppended(suffixes.at(0)); filePath = filePath.stringAppended(suffixes.at(0));
}
}
if (filePath.exists()) { if (filePath.exists()) {
if (QMessageBox::warning(ICore::dialogParent(), tr("Overwrite?"), if (QMessageBox::warning(ICore::dialogParent(), tr("Overwrite?"),
tr("An item named \"%1\" already exists at this location. " tr("An item named \"%1\" already exists at this location. "
@@ -865,6 +862,10 @@ FilePath DocumentManager::getSaveFileName(const QString &title, const FilePath &
} }
} }
} }
}
}
}
} while (repeat); } while (repeat);
if (!filePath.isEmpty()) if (!filePath.isEmpty())
setFileDialogLastVisitedDirectory(filePath.absolutePath()); setFileDialogLastVisitedDirectory(filePath.absolutePath());

View File

@@ -217,7 +217,7 @@ void GenerateResource::generateMenuEntry()
QTC_ASSERT(currentProject, return); QTC_ASSERT(currentProject, return);
const FilePath projectPath = currentProject->projectFilePath().parentDir(); const FilePath projectPath = currentProject->projectFilePath().parentDir();
auto projectFileName = Core::DocumentManager::getSaveFileName( auto projectFileName = Core::DocumentManager::getSaveFileNameWithExtension(
QCoreApplication::translate("QmlDesigner::GenerateResource", "Save Project as QRC File"), QCoreApplication::translate("QmlDesigner::GenerateResource", "Save Project as QRC File"),
projectPath.pathAppended(currentProject->displayName() + ".qrc"), projectPath.pathAppended(currentProject->displayName() + ".qrc"),
QCoreApplication::translate("QmlDesigner::GenerateResource", QCoreApplication::translate("QmlDesigner::GenerateResource",
@@ -366,7 +366,7 @@ void GenerateResource::generateMenuEntry()
QTC_ASSERT(currentProject, return); QTC_ASSERT(currentProject, return);
const FilePath projectPath = currentProject->projectFilePath().parentDir(); const FilePath projectPath = currentProject->projectFilePath().parentDir();
const FilePath resourceFileName = Core::DocumentManager::getSaveFileName( const FilePath resourceFileName = Core::DocumentManager::getSaveFileNameWithExtension(
QCoreApplication::translate("QmlDesigner::GenerateResource", "Save Project as Resource"), QCoreApplication::translate("QmlDesigner::GenerateResource", "Save Project as Resource"),
projectPath.pathAppended(currentProject->displayName() + ".qmlrc"), projectPath.pathAppended(currentProject->displayName() + ".qmlrc"),
QCoreApplication::translate("QmlDesigner::GenerateResource", QCoreApplication::translate("QmlDesigner::GenerateResource",