Skip to content

Commit 9ce896a

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

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
@@ -142,6 +142,9 @@ void StartManager::autoBackupFile()
142142
QFileInfo fileInfo;
143143
m_qlistTemFile.clear();
144144
listBackupInfo = Settings::instance()->settings->option("advance.editor.browsing_history_temfile")->value().toStringList();
145+
if (m_windows.isEmpty()) {
146+
return;
147+
}
145148

146149
//记录所有的文件信息
147150
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
@@ -2606,6 +2606,65 @@ bool Window::closeAllFiles()
26062606
return true;
26072607
}
26082608

2609+
bool Window::saveAllFiles()
2610+
{
2611+
qInfo() << "begin saveAllFiles()";
2612+
QMap<QString, EditWrapper *> wrappers = m_wrappers;
2613+
for (int i = wrappers.count() - 1; i > 0; i--) {
2614+
const QString &filePath = m_tabbar->fileAt(i);
2615+
// 避免异常情况重入时当前已无标签页的情况
2616+
if (filePath.isEmpty()) {
2617+
return false;
2618+
}
2619+
EditWrapper *wrapper = m_wrappers.value(filePath);
2620+
if (!wrapper) {
2621+
return false;
2622+
}
2623+
bool isDraftFile = wrapper->isDraftFile();
2624+
bool isModified = wrapper->isModified();
2625+
bool bIsBackupFile = false;
2626+
2627+
if (wrapper->isTemFile()) {
2628+
bIsBackupFile = true;
2629+
}
2630+
2631+
if (isModified) {
2632+
DDialog *dialog = createDialog(tr("Do you want to save this file?"), "");
2633+
int res = dialog->exec();
2634+
2635+
//取消或关闭弹窗不做任务操作
2636+
if (res == 0 || res == -1) {
2637+
return false;
2638+
}
2639+
2640+
//不保存
2641+
if (res == 1) {
2642+
continue;
2643+
}
2644+
2645+
//保存
2646+
if (res == 2) {
2647+
m_tabbar->setCurrentIndex(i);
2648+
QFileInfo fileInfo(filePath);
2649+
QString newFilePath;
2650+
if (isDraftFile) {
2651+
wrapper->saveDraftFile(newFilePath);
2652+
} else if(bIsBackupFile) {
2653+
if (!wrapper->saveFile()) {
2654+
saveAsFile();
2655+
}
2656+
} else {
2657+
if (!wrapper->saveFile()) {
2658+
saveAsFile();
2659+
}
2660+
}
2661+
}
2662+
}
2663+
}
2664+
qInfo() << "end saveAllFiles()";
2665+
return true;
2666+
}
2667+
26092668
/**
26102669
* @brief addTemFileTab 恢复备份文件标签页
26112670
* @param qstrPath 打开文件路径
@@ -3412,7 +3471,11 @@ void Window::closeEvent(QCloseEvent *e)
34123471
QString filePath = itr.value()->textEditor()->getFilePath();
34133472
Utils::recordCloseFile(filePath);
34143473
}
3415-
3474+
if (!saveAllFiles()) {
3475+
backupFile();
3476+
e->ignore();
3477+
return;
3478+
}
34163479
backupFile();
34173480
}
34183481
}

src/widgets/window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class Window : public DMainWindow
124124
void backupFile();
125125
// 关闭当前窗口所有文件
126126
bool closeAllFiles();
127+
// 保存窗口所有文件
128+
bool saveAllFiles();
127129
// 恢复备份文件标签页
128130
void addTemFileTab(const QString &qstrPath, const QString &qstrName, const QString &qstrTruePath, const QString &lastModifiedTime, bool bIsTemFile = false);
129131

0 commit comments

Comments
 (0)