teksilo_widgets/notification/log_dialog.rs
1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! `NotificationLogDialog` — one-line modal preset wrapping
5//! [`NotificationLog`] inside a
6//! [`ModalContainer`].
7//!
8//! ```ignore
9//! NotificationLogDialog::show(archive.clone(), ctx);
10//! ```
11//!
12//! Presented through `ctx.present_modal(ModalRequest::deferred(…))`
13//! — the modal layer picks Auto presentation (in-tree centered or
14//! native window per platform conventions). The user can dismiss
15//! via Escape or click-outside.
16
17use std::rc::Rc;
18
19use teksilo_core::modal::{ModalCloseBehavior, ModalPresentation, ModalRequest};
20use teksilo_core::widget::EventContext;
21
22use crate::dialog::ModalContainer;
23use crate::notification::NotificationArchiveModel;
24use crate::notification::log::NotificationLog;
25
26/// One-liner modal preset around `NotificationLog`. Apps usually
27/// wire this to a menu item or shortcut (e.g. "Window → Notification
28/// Log…").
29pub struct NotificationLogDialog;
30
31impl NotificationLogDialog {
32 /// Present the dialog with the standard chrome (title +
33 /// 720x520 default size, escape-or-click-outside dismissal).
34 pub fn show(archive: Rc<NotificationArchiveModel>, ctx: &mut EventContext) {
35 Self::show_with(archive, ctx, |log| log);
36 }
37
38 /// Same as `show`, but lets the caller configure the embedded
39 /// `NotificationLog` (e.g. attach an `on_action_invoked` hook
40 /// for archive replay).
41 pub fn show_with(
42 archive: Rc<NotificationArchiveModel>,
43 ctx: &mut EventContext,
44 configure: impl FnOnce(NotificationLog) -> NotificationLog + 'static,
45 ) {
46 ctx.present_modal(
47 ModalRequest::deferred(move |tree| {
48 let log = configure(NotificationLog::new(archive));
49 tree.add(
50 ModalContainer::new(log)
51 .title(teksilo_i18n::tr_widget!(notifications_title()))
52 .min_width(640.0),
53 )
54 })
55 .presentation(ModalPresentation::Auto)
56 .close_behavior(ModalCloseBehavior::EscapeOrClickOutside)
57 .size(720, 520),
58 );
59 }
60}