bool DocumentWindow::closeDocument() { if (!m_document.isCharged()) { emit documentClosed(m_path); return true; } if (!m_synchronized) { const int buttonPressed = showClosingDialog(); if (buttonPressed == QMessageBox::Cancel) { return false; } else if (buttonPressed == QMessageBox::Save && !saveDocumentToLastPath()) { return false; } } emit documentClosed(m_path); m_document.close(); m_documentView->setModel(nullptr); m_synchronized = false; m_path = ""; setWindowTitle(m_path); return true; }
bool DocumentWindow::saveDocument(const QString& path) { const bool samePath = m_path == path; const QString oldPath = m_path; if (m_synchronized && samePath) { return true; } const QFile::FileError saving = m_document.saveToFile(path); if (saving != QFile::NoError) { showPopup(tr("Error"), tr("Failed to save to file: %1").arg(path)); return false; } if (!samePath) { m_path = path; } m_synchronized = true; setWindowTitle(separateName(m_path)); emit documentSaved(path); if (!samePath) { emit documentClosed(oldPath); } return true; }
void KateAppAdaptor::emitDocumentClosed(const QString& token) { documentClosed(token); }