Git commit 517788147e18ddb724e30eb9b18a1878faa3c4b5 by Christoph Cullmann, on behalf of Ben Gooding. Committed on 18/02/2024 at 14:54. Pushed by cullmann into branch 'master'.
Cleanup before merge request M +40 -48 apps/lib/autotests/kate_doc_manager_tests.cpp M +4 -4 apps/lib/autotests/kate_doc_manager_tests.h M +11 -9 apps/lib/katedocmanager.cpp M +3 -3 apps/lib/katedocmanager.h M +2 -2 apps/lib/katemainwindow.cpp M +5 -3 apps/lib/kateviewmanager.cpp M +1 -1 doc/kate/fundamentals.docbook M +1 -1 doc/kate/menus.docbook https://invent.kde.org/utilities/kate/-/commit/517788147e18ddb724e30eb9b18a1878faa3c4b5 diff --git a/apps/lib/autotests/kate_doc_manager_tests.cpp b/apps/lib/autotests/kate_doc_manager_tests.cpp index a7d37f7eb2..59322b7072 100644 --- a/apps/lib/autotests/kate_doc_manager_tests.cpp +++ b/apps/lib/autotests/kate_doc_manager_tests.cpp @@ -13,18 +13,37 @@ QTEST_MAIN(KateDocManagerTests) namespace { -QCommandLineParser &GetParser() +constexpr auto FirstTestUrl = "Test Url 1"; +constexpr auto SecondTestUrl = "Test Url 2"; + +QCommandLineParser &getParser() { static QCommandLineParser parser; return parser; } -KateDocumentInfo CreateMockDocument(QUrl url = {}) +KateDocumentInfo createMockDocument(QUrl url = {}) { KateDocumentInfo mockDocumentInfo; mockDocumentInfo.normalizedUrl = url; return mockDocumentInfo; } + +QList<KTextEditor::Document *> createTestDocumentsWithUrls(KateDocManager *documentManager) +{ + QList<KTextEditor::Document *> createdDocuments; + createdDocuments.push_back(documentManager->createDoc(createMockDocument(QUrl(i18n(FirstTestUrl))))); + createdDocuments.push_back(documentManager->createDoc(createMockDocument(QUrl(i18n(SecondTestUrl))))); + return createdDocuments; +} + +QList<KTextEditor::Document *> createTestDocumentsWithoutUrls(KateDocManager *documentManager) +{ + QList<KTextEditor::Document *> createdDocuments; + createdDocuments.push_back(documentManager->createDoc(createMockDocument())); + createdDocuments.push_back(documentManager->createDoc(createMockDocument())); + return createdDocuments; +} } KateDocManagerTests::KateDocManagerTests(QObject *) @@ -42,7 +61,7 @@ void KateDocManagerTests::setUp() // ensure we use some dummy config KConfig::setMainConfigName(tempdir->path() + QStringLiteral("/testconfigfilerc")); - app = std::make_unique<KateApp>(GetParser(), KateApp::ApplicationKWrite, tempdir->path()); + app = std::make_unique<KateApp>(getParser(), KateApp::ApplicationKWrite, tempdir->path()); } void KateDocManagerTests::tearDown() @@ -57,102 +76,75 @@ void KateDocManagerTests::canCreateDocument() auto documentManager = app->documentManager(); QSignalSpy documentCreatedSpy(documentManager, &KateDocManager::documentCreated); - const auto document = documentManager->createDoc(CreateMockDocument()); + const auto document = documentManager->createDoc(createMockDocument()); Q_ASSERT(document != nullptr); Q_ASSERT(documentCreatedSpy.count() == 1); tearDown(); } -void KateDocManagerTests::popRecentlyClosedURLsClearsRecentlyClosedURLs() +void KateDocManagerTests::popRecentlyClosedUrlsClearsRecentlyClosedUrls() { setUp(); - constexpr auto FirstTestURL = "Test URL 1"; - constexpr auto SecondTestURL = "Test URL 2"; - auto documentManager = app->documentManager(); - documentManager->closeAllDocuments(); - - const auto createdDocuments = [&documentManager] { - QList<KTextEditor::Document *> createdDocuments; - createdDocuments.push_back(documentManager->createDoc(CreateMockDocument(QUrl(i18n(FirstTestURL))))); - createdDocuments.push_back(documentManager->createDoc(CreateMockDocument(QUrl(i18n(SecondTestURL))))); - return createdDocuments; - }(); + const auto createdDocuments = createTestDocumentsWithUrls(documentManager); documentManager->closeDocuments(createdDocuments, false); { - const auto recentlyClosedURLs = documentManager->popRecentlyClosedURLs(); - Q_ASSERT(recentlyClosedURLs.size() == 2); + const auto recentlyClosedUrls = documentManager->popRecentlyClosedUrls(); + Q_ASSERT(recentlyClosedUrls.size() == 2); } { - const auto recentlyClosedURLs = documentManager->popRecentlyClosedURLs(); - Q_ASSERT(recentlyClosedURLs.size() == 0); + const auto recentlyClosedUrls = documentManager->popRecentlyClosedUrls(); + Q_ASSERT(recentlyClosedUrls.size() == 0); } tearDown(); } -void KateDocManagerTests::popRecentlyClosedURLsReturnsNoneIfNoTabsClosedDuringSession() +void KateDocManagerTests::popRecentlyClosedUrlsReturnsNoneIfNoTabsClosedDuringSession() { setUp(); auto documentManager = app->documentManager(); - Q_ASSERT(documentManager->popRecentlyClosedURLs().empty()); + Q_ASSERT(documentManager->popRecentlyClosedUrls().empty()); tearDown(); } -void KateDocManagerTests::popRecentlyClosedURLsReturnsURLIfTabClosedDuringSession() +void KateDocManagerTests::popRecentlyClosedUrlsReturnsUrlIfTabClosedDuringSession() { setUp(); - constexpr auto FirstTestURL = "Test URL 1"; - constexpr auto SecondTestURL = "Test URL 2"; - auto documentManager = app->documentManager(); - documentManager->closeAllDocuments(); - - const auto createdDocuments = [&documentManager] { - QList<KTextEditor::Document *> createdDocuments; - createdDocuments.push_back(documentManager->createDoc(CreateMockDocument(QUrl(i18n(FirstTestURL))))); - createdDocuments.push_back(documentManager->createDoc(CreateMockDocument(QUrl(i18n(SecondTestURL))))); - return createdDocuments; - }(); + const auto createdDocuments = createTestDocumentsWithUrls(documentManager); const bool documentClosed = documentManager->closeDocuments({createdDocuments[0]}, false); Q_ASSERT(documentClosed); - const auto recentlyClosedURLs = documentManager->popRecentlyClosedURLs(); - Q_ASSERT(recentlyClosedURLs.contains(QUrl(i18n(FirstTestURL)))); - Q_ASSERT(!recentlyClosedURLs.contains(QUrl(i18n(SecondTestURL)))); + const auto recentlyClosedUrls = documentManager->popRecentlyClosedUrls(); + Q_ASSERT(recentlyClosedUrls.contains(QUrl(i18n(FirstTestUrl)))); + Q_ASSERT(!recentlyClosedUrls.contains(QUrl(i18n(SecondTestUrl)))); tearDown(); } -void KateDocManagerTests::closeDocumentsWithEmptyURLsAreNotRestorable() +void KateDocManagerTests::closedDocumentsWithEmptyUrlsAreNotRestorable() { setUp(); auto documentManager = app->documentManager(); - documentManager->closeAllDocuments(); - - const auto createdDocuments = [&documentManager] { - QList<KTextEditor::Document *> createdDocuments; - createdDocuments.push_back(documentManager->createDoc(CreateMockDocument())); - createdDocuments.push_back(documentManager->createDoc(CreateMockDocument())); - return createdDocuments; - }(); + const auto createdDocuments = createTestDocumentsWithoutUrls(documentManager); const bool documentsClosed = documentManager->closeDocuments(createdDocuments, false); Q_ASSERT(documentsClosed); - const auto recentlyClosedURLs = documentManager->popRecentlyClosedURLs(); - Q_ASSERT(recentlyClosedURLs.isEmpty()); + const auto recentlyClosedUrls = documentManager->popRecentlyClosedUrls(); + Q_ASSERT(recentlyClosedUrls.isEmpty()); tearDown(); } diff --git a/apps/lib/autotests/kate_doc_manager_tests.h b/apps/lib/autotests/kate_doc_manager_tests.h index 385d86bc9a..fea73242b6 100644 --- a/apps/lib/autotests/kate_doc_manager_tests.h +++ b/apps/lib/autotests/kate_doc_manager_tests.h @@ -17,10 +17,10 @@ private: private Q_SLOTS: void canCreateDocument(); - void popRecentlyClosedURLsClearsRecentlyClosedURLs(); - void popRecentlyClosedURLsReturnsNoneIfNoTabsClosedDuringSession(); - void popRecentlyClosedURLsReturnsURLIfTabClosedDuringSession(); - void closeDocumentsWithEmptyURLsAreNotRestorable(); + void popRecentlyClosedUrlsClearsRecentlyClosedUrls(); + void popRecentlyClosedUrlsReturnsNoneIfNoTabsClosedDuringSession(); + void popRecentlyClosedUrlsReturnsUrlIfTabClosedDuringSession(); + void closedDocumentsWithEmptyUrlsAreNotRestorable(); private: std::unique_ptr<KateApp> app; diff --git a/apps/lib/katedocmanager.cpp b/apps/lib/katedocmanager.cpp index 000a8ca4db..f0d7fc22e9 100644 --- a/apps/lib/katedocmanager.cpp +++ b/apps/lib/katedocmanager.cpp @@ -171,11 +171,11 @@ KTextEditor::Document *KateDocManager::openUrl(const QUrl &url, const QString &e return doc; } -QList<QUrl> KateDocManager::popRecentlyClosedURLs() +QList<QUrl> KateDocManager::popRecentlyClosedUrls() { - const auto recentlyClosedURLs = m_recentlyClosedURLs; - m_recentlyClosedURLs.clear(); - return recentlyClosedURLs; + const auto recentlyClosedUrls = m_recentlyClosedUrls; + m_recentlyClosedUrls.clear(); + return recentlyClosedUrls; } bool KateDocManager::closeDocuments(const QList<KTextEditor::Document *> documents, bool closeUrl) @@ -184,12 +184,14 @@ bool KateDocManager::closeDocuments(const QList<KTextEditor::Document *> documen return false; } - m_recentlyClosedURLs.clear(); + m_recentlyClosedUrls.clear(); for (const auto &document : documents) { - const auto &docInfo = m_docInfos.at(document); + if (const auto &docInfoItr = m_docInfos.find(document); docInfoItr != m_docInfos.end()) { + const auto &docInfo = docInfoItr->second; - if (!docInfo.normalizedUrl.isEmpty()) { - m_recentlyClosedURLs.push_back(docInfo.normalizedUrl); + if (!docInfo.normalizedUrl.isEmpty()) { + m_recentlyClosedUrls.push_back(docInfo.normalizedUrl); + } } } @@ -506,7 +508,7 @@ void KateDocManager::saveMetaInfos(const QList<KTextEditor::Document *> &documen */ doc->writeSessionConfig(urlGroup, flags); if (!urlGroup.keyList().isEmpty()) { - urlGroup.writeEntry("URL", url); + urlGroup.writeEntry("Url", url); urlGroup.writeEntry("Checksum", QString::fromLatin1(checksum)); urlGroup.writeEntry("Time", now); } else { diff --git a/apps/lib/katedocmanager.h b/apps/lib/katedocmanager.h index 56c75a61eb..f84d3e4487 100644 --- a/apps/lib/katedocmanager.h +++ b/apps/lib/katedocmanager.h @@ -53,7 +53,7 @@ public: KateDocumentInfo *documentInfo(KTextEditor::Document *doc); - /** Returns the documentNumber of the doc with url URL or -1 if no such doc is found */ + /** Returns the documentNumber of the doc with url Url or -1 if no such doc is found */ KTextEditor::Document *findDocument(const QUrl &url) const; const QList<KTextEditor::Document *> &documentList() const @@ -66,7 +66,7 @@ public: std::vector<KTextEditor::Document *> openUrls(const QList<QUrl> &, const QString &encoding = QString(), const KateDocumentInfo &docInfo = KateDocumentInfo()); - QList<QUrl> popRecentlyClosedURLs(); + QList<QUrl> popRecentlyClosedUrls(); bool closeDocument(KTextEditor::Document *, bool closeUrl = true); bool closeDocuments(const QList<KTextEditor::Document *> documents, bool closeUrl = true); @@ -177,7 +177,7 @@ private: bool m_saveMetaInfos; int m_daysMetaInfos; - QList<QUrl> m_recentlyClosedURLs; + QList<QUrl> m_recentlyClosedUrls; private Q_SLOTS: void documentOpened(); diff --git a/apps/lib/katemainwindow.cpp b/apps/lib/katemainwindow.cpp index 53771fc9cd..aa9dfac37d 100644 --- a/apps/lib/katemainwindow.cpp +++ b/apps/lib/katemainwindow.cpp @@ -419,10 +419,10 @@ void KateMainWindow::setupActions() a = actionCollection()->addAction(QStringLiteral("reopen_latest_closed_tab")); a->setIcon(QIcon::fromTheme(QStringLiteral("reopentab"))); - a->setText(i18n("&Reopen latest closed tab.")); + a->setText(i18n("&Reopen latest closed tab(s).")); actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_T)); connect(a, &QAction::triggered, m_viewManager, &KateViewManager::slotRestoreLastClosedDocument); - a->setWhatsThis(i18n("Reopen the tab that was most recently closed")); + a->setWhatsThis(i18n("Reopen the tab or tabs that were most recently closed")); a = actionCollection()->addAction(KStandardAction::Quit, QStringLiteral("file_quit")); // Qt::QueuedConnection: delay real shutdown, as we are inside menu action handling (bug #185708) diff --git a/apps/lib/kateviewmanager.cpp b/apps/lib/kateviewmanager.cpp index bb3a3d3b2d..8c57cc2b59 100644 --- a/apps/lib/kateviewmanager.cpp +++ b/apps/lib/kateviewmanager.cpp @@ -403,9 +403,11 @@ void KateViewManager::slotDocumentClose() void KateViewManager::slotRestoreLastClosedDocument() { const auto &documentManager = KateApp::self()->documentManager(); - const auto recentlyClosedUrls = documentManager->popRecentlyClosedURLs(); - - openUrls(recentlyClosedUrls, QString()); + if (const auto recentlyClosedUrls = documentManager->popRecentlyClosedUrls(); !recentlyClosedUrls.isEmpty()) { + if (const auto restoredDoc = openUrls(recentlyClosedUrls, QString())) { + activateView(restoredDoc); + } + } } KTextEditor::Document * diff --git a/doc/kate/fundamentals.docbook b/doc/kate/fundamentals.docbook index 5b562cfc84..eb26149661 100644 --- a/doc/kate/fundamentals.docbook +++ b/doc/kate/fundamentals.docbook @@ -373,7 +373,7 @@ action="simul">&Ctrl;<keycap>W</keycap></keycombo> / </row> <row> <entry><para><keycombo action="simul">&Ctrl;&Shift;<keycap>T</keycap></keycombo></para></entry> -<entry><para>Reopen Latest Closed Tab</para></entry> +<entry><para>Reopen Latest Closed Tab(s)</para></entry> </row> </tbody> diff --git a/doc/kate/menus.docbook b/doc/kate/menus.docbook index d810c61fa4..0a504e0b7f 100644 --- a/doc/kate/menus.docbook +++ b/doc/kate/menus.docbook @@ -757,7 +757,7 @@ The new instance will be identical to your previous instance. <guimenuitem>Reopen Latest Closed Tab</guimenuitem> </menuchoice></term> <listitem> -<para>Reopens the latest closed tab.</para> +<para>Reopens the latest closed tab or tabs.</para> </listitem> </varlistentry>