diff --git a/dodo/app.py b/dodo/app.py index 857d9fd..032751c 100644 --- a/dodo/app.py +++ b/dodo/app.py @@ -194,7 +194,7 @@ def open_search(self, query: str, keep_open: bool=False) -> None: p = search.SearchPanel(self, query, keep_open=keep_open) self.add_panel(p) - def open_thread(self, thread_id: str, query: str) -> None: + def open_thread(self, thread_id: str, query: str, default_message: thread.MessageSelector|None=None) -> None: """Open a thread panel with the given thread_id If a panel with this thread_id is already open, switch to it rather than @@ -206,7 +206,7 @@ def open_thread(self, thread_id: str, query: str) -> None: self.tabs.setCurrentIndex(i) return - p = thread.ThreadPanel(self, thread_id, query) + p = thread.ThreadPanel(self, thread_id, query, default_message=default_message) self.add_panel(p) def open_compose(self, mode: str='', msg: Optional[dict]=None) -> None: diff --git a/dodo/search.py b/dodo/search.py index bc69842..0970cde 100644 --- a/dodo/search.py +++ b/dodo/search.py @@ -391,12 +391,12 @@ def next_page(self) -> None: pos = self.tree.rect().topLeft() self.tree.setCurrentIndex(self.tree.indexAt(pos)) - def open_current_thread(self) -> None: + def open_current_thread(self, *, default_message: thread.MessageSelector|None=None) -> None: """Open the selected thread""" thread_id = self.model.thread_id(self.tree.currentIndex()) if thread_id: - self.app.open_thread(thread_id, self.model.q) + self.app.open_thread(thread_id, self.model.q, default_message=default_message) def toggle_thread_tag(self, tag: str) -> None: """Toggle the given thread tag""" diff --git a/dodo/thread.py b/dodo/thread.py index ab9c50a..2ecf7a7 100644 --- a/dodo/thread.py +++ b/dodo/thread.py @@ -17,8 +17,8 @@ # along with Dodo. If not, see . from __future__ import annotations -from typing import List, Optional, Any, Union, Literal -from collections.abc import Generator, Iterable +from typing import List, Optional, Any, Union, Literal, TypeAlias +from collections.abc import Generator, Iterable, Callable from PyQt6.QtCore import * from PyQt6.QtGui import QFont, QColor, QDesktopServices @@ -450,7 +450,7 @@ def next_unread(self, current: QModelIndex) -> QModelIndex: msg = self.message_at(idx) if msg['id'] in self.matches and 'unread' in msg['tags']: return idx - return QModelIndex() + return current def data(self, index: QModelIndex, role: int=Qt.ItemDataRole.DisplayRole) -> Any: """Overrides `QAbstractItemModel.data` to populate a list view with short descriptions of @@ -502,6 +502,7 @@ def rowCount(self, parent: QModelIndex=QModelIndex()) -> int: """The number of rows (for a given parent)""" return len(self._children_at(parent)) +MessageSelector: TypeAlias = Callable[[ThreadModel], QModelIndex] class ThreadPanel(panel.Panel): """A panel showing an email thread @@ -512,7 +513,7 @@ class ThreadPanel(panel.Panel): :param thread_id: the unique ID notmuch uses to identify this thread """ - def __init__(self, a: app.Dodo, thread_id: str, search_query: str, parent: Optional[QWidget]=None): + def __init__(self, a: app.Dodo, thread_id: str, search_query: str, parent: Optional[QWidget]=None, default_message: MessageSelector|None=None): super().__init__(a, parent=parent) self.set_keymap(keymap.thread_keymap) self.model = ThreadModel(thread_id, search_query, settings.default_thread_list_mode) @@ -521,6 +522,7 @@ def __init__(self, a: app.Dodo, thread_id: str, search_query: str, parent: Optio self.html_mode = settings.default_to_html self._saved_msg = None self._saved_collapsed = None + self._default_message = default_message or (lambda m: m.default_message()) self.subject = '(no subject)' @@ -595,7 +597,7 @@ def _do_reset(self): if idx.isValid(): self._select_index(idx) else: - self._select_index(self.model.default_message()) + self._select_index(self._default_message(self.model)) def toggle_list_mode(self): self.model.toggle_mode()