Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/startmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ void StartManager::autoBackupFile()
QFileInfo fileInfo;
m_qlistTemFile.clear();
listBackupInfo = Settings::instance()->settings->option("advance.editor.browsing_history_temfile")->value().toStringList();
if (m_windows.isEmpty()) {
return;
}

//记录所有的文件信息
for (int var = 0; var < m_windows.count(); ++var) {
Expand Down
65 changes: 64 additions & 1 deletion src/widgets/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,65 @@ bool Window::closeAllFiles()
return true;
}

bool Window::saveAllFiles()
{
qInfo() << "begin saveAllFiles()";
QMap<QString, EditWrapper *> wrappers = m_wrappers;
for (int i = wrappers.count() - 1; i > 0; i--) {
const QString &filePath = m_tabbar->fileAt(i);
// 避免异常情况重入时当前已无标签页的情况
if (filePath.isEmpty()) {
return false;
}
EditWrapper *wrapper = m_wrappers.value(filePath);
if (!wrapper) {
return false;
}
bool isDraftFile = wrapper->isDraftFile();
bool isModified = wrapper->isModified();
bool bIsBackupFile = false;

if (wrapper->isTemFile()) {
bIsBackupFile = true;
}

if (isModified) {
DDialog *dialog = createDialog(tr("Do you want to save this file?"), "");
int res = dialog->exec();

//取消或关闭弹窗不做任务操作
if (res == 0 || res == -1) {
return false;
}

//不保存
if (res == 1) {
continue;
}

//保存
if (res == 2) {
m_tabbar->setCurrentIndex(i);
QFileInfo fileInfo(filePath);
QString newFilePath;
if (isDraftFile) {
wrapper->saveDraftFile(newFilePath);
} else if(bIsBackupFile) {
if (!wrapper->saveFile()) {
saveAsFile();
}
} else {
if (!wrapper->saveFile()) {
saveAsFile();
}
}
}
}
}
qInfo() << "end saveAllFiles()";
return true;
}

/**
* @brief addTemFileTab 恢复备份文件标签页
* @param qstrPath 打开文件路径
Expand Down Expand Up @@ -3394,7 +3453,11 @@ void Window::closeEvent(QCloseEvent *e)
QString filePath = itr.value()->textEditor()->getFilePath();
Utils::recordCloseFile(filePath);
}

if (!saveAllFiles()) {
backupFile();
e->ignore();
return;
}
backupFile();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class Window : public DMainWindow
void backupFile();
// 关闭当前窗口所有文件
bool closeAllFiles();
// 保存窗口所有文件
bool saveAllFiles();
// 恢复备份文件标签页
void addTemFileTab(const QString &qstrPath, const QString &qstrName, const QString &qstrTruePath, const QString &lastModifiedTime, bool bIsTemFile = false);

Expand Down
Loading