Skip to content

Commit c56b1c3

Browse files
myk1343deepin-bot[bot]
authored andcommitted
fix: 修复关闭窗口保存提示
修复关闭窗口保存提示 Bug: https://pms.uniontech.com/bug-view-315439.html Log: 修复关闭窗口保存提示
1 parent 98dd63d commit c56b1c3

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

src/startmanager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ void StartManager::autoBackupFile()
174174
QFileInfo fileInfo;
175175
m_qlistTemFile.clear();
176176
listBackupInfo = Settings::instance()->settings->option("advance.editor.browsing_history_temfile")->value().toStringList();
177+
if (m_windows.isEmpty()) {
178+
return;
179+
}
177180

178181
//记录所有的文件信息
179182
for (int var = 0; var < m_windows.count(); ++var) {

src/widgets/window.cpp

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,65 @@ bool Window::closeAllFiles()
29392939
return true;
29402940
}
29412941

2942+
bool Window::saveAllFiles()
2943+
{
2944+
qInfo() << "begin saveAllFiles()";
2945+
QMap<QString, EditWrapper *> wrappers = m_wrappers;
2946+
for (int i = wrappers.count() - 1; i > 0; i--) {
2947+
const QString &filePath = m_tabbar->fileAt(i);
2948+
// 避免异常情况重入时当前已无标签页的情况
2949+
if (filePath.isEmpty()) {
2950+
return false;
2951+
}
2952+
EditWrapper *wrapper = m_wrappers.value(filePath);
2953+
if (!wrapper) {
2954+
return false;
2955+
}
2956+
bool isDraftFile = wrapper->isDraftFile();
2957+
bool isModified = wrapper->isModified();
2958+
bool bIsBackupFile = false;
2959+
2960+
if (wrapper->isTemFile()) {
2961+
bIsBackupFile = true;
2962+
}
2963+
2964+
if (isModified) {
2965+
DDialog *dialog = createDialog(tr("Do you want to save this file?"), "");
2966+
int res = dialog->exec();
2967+
2968+
//取消或关闭弹窗不做任务操作
2969+
if (res == 0 || res == -1) {
2970+
return false;
2971+
}
2972+
2973+
//不保存
2974+
if (res == 1) {
2975+
continue;
2976+
}
2977+
2978+
//保存
2979+
if (res == 2) {
2980+
m_tabbar->setCurrentIndex(i);
2981+
QFileInfo fileInfo(filePath);
2982+
QString newFilePath;
2983+
if (isDraftFile) {
2984+
wrapper->saveDraftFile(newFilePath);
2985+
} else if(bIsBackupFile) {
2986+
if (!wrapper->saveFile()) {
2987+
saveAsFile();
2988+
}
2989+
} else {
2990+
if (!wrapper->saveFile()) {
2991+
saveAsFile();
2992+
}
2993+
}
2994+
}
2995+
}
2996+
}
2997+
qInfo() << "end saveAllFiles()";
2998+
return true;
2999+
}
3000+
29423001
/**
29433002
* @brief addTemFileTab 恢复备份文件标签页
29443003
* @param qstrPath 打开文件路径
@@ -3952,7 +4011,11 @@ void Window::closeEvent(QCloseEvent *e)
39524011
QString filePath = itr.value()->textEditor()->getFilePath();
39534012
Utils::recordCloseFile(filePath);
39544013
}
3955-
4014+
if (!saveAllFiles()) {
4015+
backupFile();
4016+
e->ignore();
4017+
return;
4018+
}
39564019
backupFile();
39574020
}
39584021
}

src/widgets/window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class Window : public DMainWindow
118118
void backupFile();
119119
// 关闭当前窗口所有文件
120120
bool closeAllFiles();
121+
// 保存窗口所有文件
122+
bool saveAllFiles();
121123
// 恢复备份文件标签页
122124
void addTemFileTab(const QString &qstrPath, const QString &qstrName, const QString &qstrTruePath, const QString &lastModifiedTime, bool bIsTemFile = false);
123125

0 commit comments

Comments
 (0)