解决另存为和导出对话框,按下回车键未做同文件是否替换提醒;BUG-807

This commit is contained in:
yangjiaxuan 2023-12-11 12:46:59 +08:00
parent 6e3db40cd0
commit f13792d25e
6 changed files with 470 additions and 426 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -190,18 +190,20 @@ void Dialog_Export::on_dialog_accepted()
assert(!extName.isEmpty()); assert(!extName.isEmpty());
bool warning = true;
QString selectedFile = ui->fileDialog->selectedFiles()[0]; QString selectedFile = ui->fileDialog->selectedFiles()[0];
int pos = selectedFile.lastIndexOf('/'); int pos = selectedFile.lastIndexOf('/');
if (-1 != pos) if (-1 != pos)
{ {
QString path = selectedFile.left(pos + 1); QString path = selectedFile.left(pos + 1);
QString name = selectedFile.right(selectedFile.count() - pos - 1); QString name = selectedFile.right(selectedFile.count() - pos - 1);
pos = name.lastIndexOf('.');
if (-1 != pos #if defined (HG_CMP_MSC)
&& is_support_file_type(name.right(name.length() - pos))) if (name.endsWith(extName, Qt::CaseInsensitive))
#else
if (name.endsWith(extName, Qt::CaseSensitive))
#endif
{ {
warning = false; // 带扩展名,系统已经警告同名文件 pos = name.lastIndexOf('.');
name = name.left(pos); name = name.left(pos);
} }
@ -215,8 +217,11 @@ void Dialog_Export::on_dialog_accepted()
QFile file(m_savePath + m_saveName + m_saveExt); QFile file(m_savePath + m_saveName + m_saveExt);
if (file.exists()) if (file.exists())
{ {
int ret = QMessageBox::question(this, tr("Question"), tr("The file already exists. Do you want to overwrite it?")); QMessageBox msg(QMessageBox::Question, tr("Question"),
if (ret != QMessageBox::Yes) tr("The file already exists. Do you want to overwrite it?"),
QMessageBox::Yes | QMessageBox::No, this);
msg.exec();
if (msg.clickedButton() != msg.button(QMessageBox::Yes))
{ {
return; return;
} }

View File

@ -198,7 +198,7 @@ void Dialog_SaveAs::on_dialog_accepted()
if(checked) if(checked)
{ {
QString dirName = NULL; QString dirName = NULL;
dirName = path + QDateTime::currentDateTime().toString("yy-MM-dd hh.mm.ss"); dirName = path + QDateTime::currentDateTime().toString("yy-MM-dd hh.mm.ss") + "/";
QDir dir(dirName); QDir dir(dirName);
if(!dir.exists()) if(!dir.exists())
{ {
@ -207,7 +207,11 @@ void Dialog_SaveAs::on_dialog_accepted()
path = dirName; path = dirName;
} }
if(name.endsWith(extName)) #if defined (HG_CMP_MSC)
if (name.endsWith(extName, Qt::CaseInsensitive))
#else
if (name.endsWith(extName, Qt::CaseSensitive))
#endif
m_savePath = getStdFileName(path + name); m_savePath = getStdFileName(path + name);
else else
m_savePath = getStdFileName(path + name + extName); m_savePath = getStdFileName(path + name + extName);
@ -216,8 +220,11 @@ void Dialog_SaveAs::on_dialog_accepted()
QFile file(m_savePath); QFile file(m_savePath);
if (file.exists()) if (file.exists())
{ {
int ret = QMessageBox::question(this, tr("Question"), tr("The file already exists. Do you want to overwrite it?")); QMessageBox msg(QMessageBox::Question, tr("Question"),
if (ret != QMessageBox::Yes) tr("The file already exists. Do you want to overwrite it?"),
QMessageBox::Yes | QMessageBox::No, this);
msg.exec();
if (msg.clickedButton() != msg.button(QMessageBox::Yes))
{ {
return; return;
} }