From 5a4d8f5f021dc98b2a7cc471125aa3040c02675c Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 7 Aug 2026 12:03:14 +0200 Subject: feat(tags): mark every thread in the view read, in one undoable step An action removing "unread" from every thread in the current view, on the toolbar, the Message menu and Ctrl+Shift+U. It deliberately ignores the selection, which makes it the one action in the window that does, and it routes through the same funnel as every other tag change, so it is one write rather than one per thread. Disabled until the query reports its total. Threads arrive in batches, so before then the model holds only what has landed, and an action saying "all" must not silently skip the rest. A greyed control says "not yet" without needing a dialog or a stall the user cannot see. The state is also set at registration, since QAction starts enabled and a window that has not run a query has nothing to act on. Two things came out differently from the plan, both forced by existing code. It carries a default binding, because everyActionHasAShortcut requires every registered action to have one: an unbound action is unreachable from the keyboard, and that invariant is deliberate, so the action was given Ctrl+Shift+U rather than the invariant relaxed. And only the threads that are actually unread are sent, because sending the rest would inflate the pending-edit count with writes that change nothing, and the quit prompt reads that count. A view with nothing unread does nothing, pushes no command and says so: an undo entry that restores nothing is worse than none, since it absorbs a Ctrl+Z meant for the previous action. undoDepthForTesting() is new and exists for a reason worth recording: undo->isEnabled() cannot answer "was a command pushed", because the undo QAction is always enabled and tests canUndo() when triggered. The first version of the no-op test asserted on it and passed against a mutant with the unread filter removed. Closes item 43. Co-Authored-By: Claude Opus 5 --- src/mainwindow.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a3b5496..bb11261 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -677,6 +677,11 @@ void MainWindow::registerActions() else tagSelected({ QStringLiteral("unread") }, {}, tr("Mark unread")); }); + addAction(QStringLiteral("mark_all_read"), tr("Mark all &read"), + tr("Remove the unread tag from every thread in this view"), + [this]() { + markAllRead(); + }); addAction(QStringLiteral("edit_tags"), tr("Edit &tags..."), tr("Add or remove any tag on the selected threads"), [this]() { editTagsOnSelection(); @@ -768,6 +773,13 @@ void MainWindow::registerActions() // silently dead. KeyMap warns about unknown names, but only a check here // catches the reverse: a known action nothing implements. Q_ASSERT(m_actions.size() == KeyMap::knownActions().size()); + + // QAction starts enabled, so the view-wide actions have to be put into + // their real state here rather than waiting for the first query: a window + // that has not run one yet has an empty model and no complete result set, + // and offering "Mark all read" against nothing is a live control that does + // nothing. + updateViewWideActions(); } void MainWindow::buildMenus() @@ -791,6 +803,7 @@ void MainWindow::buildMenus() messageMenu->addAction(m_actions.value(QStringLiteral("spam"))); messageMenu->addSeparator(); messageMenu->addAction(m_actions.value(QStringLiteral("toggle_unread"))); + messageMenu->addAction(m_actions.value(QStringLiteral("mark_all_read"))); messageMenu->addAction(m_actions.value(QStringLiteral("edit_tags"))); messageMenu->addAction(m_actions.value(QStringLiteral("flag"))); @@ -876,6 +889,7 @@ void MainWindow::buildMenus() toolBar->addSeparator(); toolBar->addAction(m_actions.value(QStringLiteral("archive"))); toolBar->addAction(m_actions.value(QStringLiteral("delete"))); + toolBar->addAction(m_actions.value(QStringLiteral("mark_all_read"))); toolBar->addSeparator(); toolBar->addAction(m_actions.value(QStringLiteral("undo"))); } @@ -1102,6 +1116,11 @@ void MainWindow::runCurrentQuery() m_statusLabel->setText(tr("Searching...")); + // The result set is incomplete from here until queryFinished arrives, so + // anything claiming to act on the whole view must wait. + m_queryComplete = false; + updateViewWideActions(); + QMetaObject::invokeMethod(m_worker, "runQuery", Qt::QueuedConnection, Q_ARG(QString, query), Q_ARG(quint64, m_generation)); @@ -1124,6 +1143,61 @@ void MainWindow::onQueryFinished(int total, quint64 generation) // nothing. m_defaultStatus = tr("%n thread(s)", "", total); m_statusLabel->setText(m_defaultStatus); + + // The model now holds every row the query matched, so "the whole view" is + // a thing that can honestly be acted on. + m_queryComplete = true; + updateViewWideActions(); +} + +void MainWindow::updateViewWideActions() +{ + // Threads arrive in batches of kBatchSize, so before the query reports its + // total the model holds only what has landed. An action that says "all" + // must not run against a partial set and silently skip the rest, and a + // disabled control says so without a dialog. + if (QAction *action = m_actions.value(QStringLiteral("mark_all_read"))) + action->setEnabled(m_queryComplete && m_model->rowCount() > 0); +} + +void MainWindow::markAllRead() +{ + // Every row, not the selection: this is the one action in the window that + // deliberately ignores what is selected. + QStringList threadIds; + const int rows = m_model->rowCount(); + threadIds.reserve(rows); + for (int row = 0; row < rows; ++row) { + const ThreadSummary thread = m_model->threadAt(row); + // Only the threads that would actually change. Sending the rest would + // inflate the pending-edit count with writes that do nothing, and the + // quit prompt reads that count. + if (thread.isUnread()) + threadIds.append(thread.threadId); + } + + if (threadIds.isEmpty()) { + showTransientStatus(tr("Nothing unread in this view")); + return; + } + + // An automatic mark-read armed for the open thread would fire after this + // and push a second, redundant command onto the stack. + m_markReadTimer->stop(); + m_markReadThreadId.clear(); + + const QString description = tr("Mark all read"); + sendThreadTagChange(threadIds, {}, { QStringLiteral("unread") }, + description); + + // ONE command for the batch, exactly as tagSelected does: a user who marks + // 400 threads read expects a single Ctrl+Z to put them back. + m_undoStack.push(new ThreadTagCommand(this, threadIds, {}, + { QStringLiteral("unread") }, + description)); + + showTransientStatus( + tr("%1: %n thread(s)", "", threadIds.size()).arg(description)); } void MainWindow::showThreadContextMenu(const QPoint &pos) -- cgit v1.2.3