diff --git a/kate/kateconfigdialog.h b/kate/kateconfigdialog.h --- a/kate/kateconfigdialog.h +++ b/kate/kateconfigdialog.h @@ -80,6 +80,7 @@ bool m_dataChanged; QCheckBox *m_modNotifications; + QCheckBox *m_modCloseAfterLast; QCheckBox *m_saveMetaInfos; KPluralHandlingSpinBox *m_daysMetaInfos; diff --git a/kate/kateconfigdialog.cpp b/kate/kateconfigdialog.cpp --- a/kate/kateconfigdialog.cpp +++ b/kate/kateconfigdialog.cpp @@ -96,6 +96,17 @@ connect(m_modNotifications, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged); vbox->addWidget(m_modNotifications); + + // Closing last file closes Kate + m_modCloseAfterLast = new QCheckBox( + i18n("Close Kate entirely when the last file is closed"), buttonGroup); + m_modCloseAfterLast->setChecked(parent->modCloseAfterLast()); + m_modCloseAfterLast->setWhatsThis(i18n( + "If enabled, Kate will shutdown when the last file being edited is closed, " + "otherwise a blank page will open so that you can start a new file.")); + connect(m_modCloseAfterLast, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged); + + vbox->addWidget(m_modCloseAfterLast); buttonGroup->setLayout(vbox); // GROUP with the one below: "Meta-information" @@ -320,6 +331,9 @@ cg.writeEntry("Modified Notification", m_modNotifications->isChecked()); m_mainWindow->setModNotificationEnabled(m_modNotifications->isChecked()); + cg.writeEntry("Close After Last", m_modCloseAfterLast->isChecked()); + m_mainWindow->setModCloseAfterLast(m_modCloseAfterLast->isChecked()); + // patch document modified warn state const QList &docs = KateApp::self()->documentManager()->documentList(); foreach(KTextEditor::Document * doc, docs) diff --git a/kate/katemainwindow.h b/kate/katemainwindow.h --- a/kate/katemainwindow.h +++ b/kate/katemainwindow.h @@ -283,6 +283,14 @@ m_modNotification = e; } + bool modCloseAfterLast() const { + return m_modCloseAfterLast; + } + + void setModCloseAfterLast(bool e) { + m_modCloseAfterLast = e; + } + KRecentFilesAction *fileOpenRecent() const { return m_fileOpenRecent; } @@ -490,6 +498,11 @@ */ bool m_modNotification; + /** + * Shutdown Kate after last file is closed + */ + bool m_modCloseAfterLast; + /** * stacked widget containing the central area, aka view manager, quickopen, ... */ diff --git a/kate/katemainwindow.cpp b/kate/katemainwindow.cpp --- a/kate/katemainwindow.cpp +++ b/kate/katemainwindow.cpp @@ -564,6 +564,7 @@ const KConfigGroup generalGroup(config, "General"); m_modNotification = generalGroup.readEntry("Modified Notification", false); + m_modCloseAfterLast = generalGroup.readEntry("Close After Last", false); KateApp::self()->documentManager()->setSaveMetaInfos(generalGroup.readEntry("Save Meta Infos", true)); KateApp::self()->documentManager()->setDaysMetaInfos(generalGroup.readEntry("Days Meta Infos", 30)); diff --git a/kate/kateviewmanager.cpp b/kate/kateviewmanager.cpp --- a/kate/kateviewmanager.cpp +++ b/kate/kateviewmanager.cpp @@ -264,18 +264,12 @@ void KateViewManager::slotDocumentClose(KTextEditor::Document *document) { -// prevent close document if only one view alive and the document of - // it is not modified and empty !!! - if ((KateApp::self()->documentManager()->documentList().size() == 1) - && !document->isModified() - && document->url().isEmpty() - && document->documentEnd() == KTextEditor::Cursor::start()) { - document->closeUrl(); - return; - } + bool shutdownKate = m_mainWindow->modCloseAfterLast() && KateApp::self()->documentManager()->documentList().size() == 1; // close document - KateApp::self()->documentManager()->closeDocument(document); + if (KateApp::self()->documentManager()->closeDocument(document) && shutdownKate) { + KateApp::self()->shutdownKate(m_mainWindow); + } } void KateViewManager::slotDocumentClose() diff --git a/kate/kateviewspace.cpp b/kate/kateviewspace.cpp --- a/kate/kateviewspace.cpp +++ b/kate/kateviewspace.cpp @@ -525,7 +525,7 @@ { KTextEditor::Document *doc = m_docToTabId.key(id); Q_ASSERT(doc); - KateApp::self()->documentManager()->closeDocument(doc); + m_viewManager->slotDocumentClose(doc); } void KateViewSpace::createNewDocument()