feat: stash composes closed by sidebar trips as drafts

This commit is contained in:
randogoth 2026-10-03 09:44:19 +03:00
parent f55821213d
commit 84650e50bd
5 changed files with 310 additions and 13 deletions

View file

@ -183,6 +183,8 @@ pub struct CarrierWidgets {
// sidebar top: actions and destinations
folders: gtk::ListBox,
folder_counts: Vec<gtk::Label>,
/// The Drafts row, hidden until the folder holds one.
drafts_nav: gtk::ListBoxRow,
settings_nav: gtk::ListBox,
fetch_button: gtk::Button,
write_button: gtk::Button,
@ -303,12 +305,21 @@ impl CarrierWidgets {
nav_row("folder-download-symbolic", "Inbox"),
nav_row("contact-new-symbolic", "Requests"),
nav_row("mail-send-symbolic", "Sent"),
nav_row("document-edit-symbolic", "Drafts"),
];
let mut folder_counts = Vec::new();
for (row, count) in folder_rows {
let mut drafts_nav = None;
for (index, (row, count)) in folder_rows.into_iter().enumerate() {
// The drafts folder is carrier's own: it stays out of the
// sidebar until a compose has been set aside into it.
if index == 3 {
row.set_visible(false);
drafts_nav = Some(row.clone());
}
folders.append(&row);
folder_counts.push(count);
}
let drafts_nav = drafts_nav.expect("four folder rows");
sidebar_top.append(&folders);
// Settings closes the top panel, pinned to its bottom. It is its
@ -782,6 +793,7 @@ impl CarrierWidgets {
0 => Folder::Inbox,
1 => Folder::Requests,
2 => Folder::Sent,
3 => Folder::Drafts,
_ => return,
};
folder_sender.input(Message::GotoMail(folder));
@ -804,6 +816,7 @@ impl CarrierWidgets {
"0" => Folder::Inbox,
"1" => Folder::Requests,
"2" => Folder::Sent,
"3" => Folder::Drafts,
_ => return,
};
mail_sender.input(Message::MessageSelected(folder, id.to_string()));
@ -902,6 +915,7 @@ impl CarrierWidgets {
toolbar,
folders,
folder_counts,
drafts_nav,
settings_nav,
fetch_button,
write_button,
@ -1158,7 +1172,13 @@ fn render(model: &Carrier, w: &mut CarrierWidgets, sender: &ComponentSender<Carr
.map(|rows| rows.iter().filter(|r| r.unread).count())
.unwrap_or(0)
};
for (count, value) in w.folder_counts.iter().zip([unread(0), unread(1), 0]) {
let draft_count = model.drafts.len();
w.drafts_nav.set_visible(draft_count > 0);
for (count, value) in w
.folder_counts
.iter()
.zip([unread(0), unread(1), 0, draft_count])
{
count.set_text(&value.to_string());
count.set_visible(value > 0);
}
@ -1198,11 +1218,7 @@ fn render(model: &Carrier, w: &mut CarrierWidgets, sender: &ComponentSender<Carr
// Mail list.
clear_list(&w.mail_list);
let rows = model
.lists
.get(model.folder as usize)
.cloned()
.unwrap_or_default();
let rows = model.rows();
let (icon, title, description) = match model.folder {
Folder::Inbox => (
"mail-read-symbolic",
@ -1219,6 +1235,11 @@ fn render(model: &Carrier, w: &mut CarrierWidgets, sender: &ComponentSender<Carr
"Nothing sent yet",
"Messages you send keep a sealed copy here.",
),
Folder::Drafts => (
"document-edit-symbolic",
"No drafts",
"A compose closed from the sidebar is kept here.",
),
};
w.list_empty.set_icon_name(Some(icon));
w.list_empty.set_title(title);