When dismissing a message, it should be removed from the list and the tree view.

This commit is contained in:
2026-04-06 23:53:46 -04:00
parent 667c0babcb
commit e72cc79c6a
2 changed files with 195 additions and 0 deletions

View File

@@ -139,6 +139,32 @@ class NotificationPresenter:
self._notifications = []
self._current_index = -1
def remove_entry(self, entry: Optional[NotificationEntry]) -> bool:
"""Removes entry from the notification history."""
if entry is None:
return False
try:
index = self._notifications.index(entry)
except ValueError:
return False
del self._notifications[index]
if not self._notifications:
self._current_index = -1
return True
if self._current_index == -1:
return True
if index < self._current_index:
self._current_index -= 1
elif index == self._current_index and self._current_index >= len(self._notifications):
self._current_index = -1
return True
def refresh_live_notifications(self) -> bool:
"""Refreshes live mako state without announcing new notifications."""
@@ -207,6 +233,8 @@ class NotificationPresenter:
result = self._mako_monitor.dismiss_notification(entry.notification_id)
if result:
entry.live = False
self.remove_entry(entry)
script.presentMessage(messages.NOTIFICATION_DISMISSED)
return result
@@ -669,9 +697,50 @@ class NotificationListGUI:
if not self._presenter.dismiss_entry(self._script, entry):
self._script.presentMessage(messages.NOTIFICATION_UNAVAILABLE)
else:
self._remove_selected_row()
self._update_action_buttons()
def _remove_selected_row(self) -> None:
if self._selection is None or self._model is None:
return
model, paths = self._selection.get_selected_rows()
if not paths:
return
row_iter = model.get_iter(paths[0])
if row_iter is None:
return
model.remove(row_iter)
if self._model.iter_n_children(None) == 0:
return
row_index = self._path_to_index(paths[0])
if row_index is None:
self._selection.select_path(0)
return
next_index = min(row_index, self._model.iter_n_children(None) - 1)
self._selection.select_path(next_index)
def _path_to_index(self, path: Any) -> Optional[int]:
if isinstance(path, int):
return path
get_indices = getattr(path, "get_indices", None)
if callable(get_indices):
indices = get_indices()
if indices:
return indices[0]
try:
return path[0]
except (TypeError, IndexError, KeyError):
return None
_presenter = None