// SPDX-FileCopyrightText: MailCraft contributors // SPDX-License-Identifier: MIT OR Apache-2.0 //! The ribbon: the tab strip and every tab's commands. Each control runs a command by id. //! //! A tab is described once ([`describe`]): its groups, and in each the controls with their //! command, icon, label and tooltip. Two layouts draw that description. The classic one sets it //! out in three rows, in named groups. The simplified one is a single row, in which what doesn't //! fit first loses its label and then goes behind `…` ([`plan`]). use std::collections::HashMap; use std::sync::Arc; use egui::{Align2, Rect, Sense, Shape, Stroke, Ui, pos2, vec2}; use mailcraft_engine::{CalView, Filter, Module, Pane, PeopleSort, SortBy, TaskFilter, TaskSort}; use mailcraft_model::{Account, Folder, FolderKind, Id, Importance}; use serde_json::{Value, json}; use crate::theme::{Tokens, medium, paint_clipped, regular, semibold}; use crate::widgets::{self, CONTENT_H, LABEL_H, bg, big_frame, command_tooltip, group, mi, mi_check, shortcut_text, small_frame, stack}; use crate::{MailApp, icons}; mod fit; use fit::{Cell, Stage}; mod view_menus; /// The height of the tab strip, and the size of the tabs' names (10 pt). const TAB_H: f32 = 30.0; const TAB_SIZE: f32 = 13.333; /// The gap between the ribbon and the panes under it. const SHEET_GAP: f32 = 7.0; /// The gap between the tabs and the ribbon. const TOP_GAP: f32 = 5.0; /// The simplified row: the band's height and a button's. const BAND_H: f32 = 48.0; const BUTTON_H: f32 = 32.0; /// In a button: the space at its ends, its icon, the gap before its label and the label's size /// (10 pt), the part that holds its `▾` and the gap before that part with a label and without. const PAD: f32 = 8.0; const ICON: f32 = 20.0; const LABEL_GAP: f32 = 8.0; const LABEL_SIZE: f32 = 13.333; pub(crate) const DROP_W: f32 = 22.0; const DROP_GAP_LABEL: f32 = 2.0; const DROP_GAP_ICON: f32 = 5.0; /// Between two buttons, and between two that a rule parts (the rule is in the middle). const BUTTON_GAP: f32 = 2.0; const RULE_GAP: f32 = 9.0; /// The `…` button, and the button at the right end that chooses the layout. const MORE_W: f32 = 36.0; const MODE_W: f32 = 24.0; /// A note after the buttons is drawn when this much room is left for it. const NOTE_MIN: f32 = 180.0; /// How the ribbon lays its commands out (the menu at its right end, View › Layout, /// `ui.ribbonMode`): `Simplified`, one row of commands with what doesn't fit behind `…`, which /// is what a new installation starts with; or `Classic`, three rows in groups with their names. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(from = "String", into = "String")] pub enum Mode { #[default] Simplified, Classic, } impl Mode { /// In menu order. pub const ALL: [Mode; 2] = [Mode::Classic, Mode::Simplified]; /// The value used in `ui.json` and by the `ui.ribbonMode` command. pub fn code(self) -> &'static str { match self { Mode::Simplified => "simplified", Mode::Classic => "classic", } } pub fn from_code(code: &str) -> Option { Mode::ALL.into_iter().find(|m| m.code().eq_ignore_ascii_case(code.trim())) } /// The English label (translated with `tl!` where shown). pub fn label(self) -> &'static str { match self { Mode::Simplified => "Simplified Ribbon", Mode::Classic => "Classic Ribbon", } } } /// An unknown saved value reads as the default rather than discarding the whole `ui.json`. impl From for Mode { fn from(s: String) -> Self { Mode::from_code(&s).unwrap_or_default() } } impl From for String { fn from(m: Mode) -> Self { m.code().to_string() } } /// The tabs in order. `File` opens Backstage; `Message`, `Insert`, `Format Text` and `Review` are /// there while a message is being written in the reading pane (a window of its own has them in /// its ribbon, [`show_window`]). pub fn tabs(app: &MailApp) -> Vec<&'static str> { let mut tabs = vec!["File", "Home", "Send / Receive", "Folder", "View", "Help"]; if crate::windows::compose_window::pane_compose(app).is_some() { tabs.splice(1..1, ["Message", "Insert", "Format Text", "Review"]); } if crate::attachment_preview::pane_target(app).is_some() { tabs.push("Attachments"); } tabs } /// The id a control of the ribbon goes by in the hit map, from its key (for most, the id of the /// command it runs). The kinds: `ribbon` for a control, `ribbonMenu` for the `▾` half of one that /// both runs a command and opens a menu, `ribbonMore` for `…` and `ribbonMode` for the layout /// button (both with id 0), `ribbonBand` (id 0) for the band they are all in. pub fn hit_id(key: &str) -> u64 { key.bytes().fold(0xCBF2_9CE4_8422_2325u64, |h, b| (h ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01B3)) } /// A menu a control of the ribbon opens. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum Menu { NewItems, MoveMessages, Rules, CategorizeMail, FollowUp, /// Follow Up in the message being written (#948). ComposeFollowUp, FilterMail, ShowAs, Reminder, CategorizeEvent, CategorizeContact, CategorizeTask, FilterTasks, Signature, MoveFolder, ReadingPane, GmailCategories, NavigationBar, Preview, ArrangeBy, Theme, RibbonLayout, TimeScale, ChangeView, Zoom, RecentSearches, FontSize, Font, FontColor, Highlight, Junk, RecentAttachments, OpenCalendar, } impl Menu { /// The command a menu stands for, when all it does is run it with a choice (the font menus): /// it is greyed when that command can't run, as a button would be. pub(crate) fn command(self) -> Option<&'static str> { match self { Menu::Font => Some("format.font"), Menu::FontSize => Some("format.size"), Menu::FontColor => Some("format.color"), Menu::Highlight => Some("format.highlight"), Menu::RecentAttachments => Some("ui.attach"), _ => None, } } } /// Whether a control can be used now: its command can run, or the command its menu stands for /// ([`Menu::command`]); a menu that stands for none always can. Every layout draws by it. pub(crate) fn usable(app: &MailApp, item: &Item) -> bool { match (&item.command, item.menu) { (Some((command, params)), _) => { let explicit_attachment = matches!(*command, "mail.openAttachment" | "mail.removeAttachment" | "mail.saveAttachment" | "mail.saveAllAttachments") && params .get("id") .and_then(Value::as_u64) .is_some_and(|id| crate::attachment_preview::target(app, app.hit.window(), id).is_some()); explicit_attachment || app.enabled(command) } (None, Some(menu)) => menu_usable(app, menu), (None, None) => true, } } /// Whether a menu can be opened now: the command it stands for can run, or it stands for none. fn menu_usable(app: &MailApp, menu: Menu) -> bool { (menu != Menu::RecentAttachments || crate::recent_attachments::available(app)) && menu.command().is_none_or(|command| app.enabled(command)) } /// Whether a menu holds a text field the owner clicks in and types into: a colour typed by hand, /// a folder search. Such a menu keeps a click made inside it — that click is for the field, and /// not a way out of the menu. Every item of these menus shuts it itself /// ([`crate::widgets::mi`], [`crate::widgets::mi_check], the colour squares, a chosen folder), and /// a click outside it still shuts it. The font menu joins them when it gets its search field /// (#1494). fn holds_a_field(menu: Menu) -> bool { matches!(menu, Menu::FontColor | Menu::Highlight | Menu::MoveMessages | Menu::Rules | Menu::MoveFolder) } /// The menus a button of the simplified row opens: its own, and those of what hangs under it. fn button_menus(b: &Button<'_>) -> Vec { b.item.menu.into_iter().chain(b.drops.iter().filter_map(|under| under.menu)).collect() } /// A menu's popup: one that holds a text field keeps a click made inside it (#1493). Only menus /// whose every item shuts the menu themselves get this; a `…` of folded groups or of what didn't /// fit holds plain buttons, which count on the popup shutting for them, so those stay as they are. fn menu_popup<'a>(resp: &egui::Response, menus: impl IntoIterator) -> egui::Popup<'a> { let popup = egui::Popup::menu(resp); if menus.into_iter().any(holds_a_field) { popup.close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside) } else { popup } } /// A menu as an entry of another (a `▾`, a `…`): it opens while it can ([`menu_usable`]), and is /// greyed otherwise, saying why when hovered. pub(crate) fn submenu(ui: &mut Ui, app: &mut MailApp, name: String, menu: Menu) { if menu_usable(app, menu) { ui.menu_button(name, |ui| menu_contents(ui, app, menu)); return; } let reason = menu.command().and_then(|c| app.session.registry.get(c)).and_then(|spec| (spec.enabled)(&app.session)); let entry = ui.add_enabled(false, egui::Button::new(name).min_size(vec2(190.0, 0.0))); if let Some(reason) = reason { entry.on_disabled_hover_text(crate::i18n::fmt(tl!("Not available: {reason}"), &[("reason", tl!(reason))])); } } /// A menu button's tooltip: its name, and when its menu stands for a command that can't run now /// ([`usable`]), why, as a greyed button's says. fn menu_tooltip(app: &MailApp, resp: egui::Response, item: &Item, on: bool) -> egui::Response { match item.menu.and_then(Menu::command) { Some(command) if !on => command_tooltip(app, resp, &item.tip_text(), command), _ => resp.on_hover_text(item.tip_text()), } } /// How a control is drawn in the classic layout. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum Size { /// A large button: the icon over its label. Big, /// A small button: the icon beside its label, three to a column. Small, /// Not drawn there: it gathers commands into one menu for the simplified row. Hidden, } /// One control of the ribbon, as both layouts need it. #[derive(Clone, Debug, PartialEq)] pub(crate) struct Item { /// What the hit map and the tests call it, unique in its tab: the id of its command unless /// several controls run that command. pub key: &'static str, pub icon: &'static str, /// Its label (English; shown through `tl!`). A `\n` breaks it in two under a large button; /// everywhere else it reads as a space. pub label: &'static str, /// What its tooltip calls it when that is more than the label. pub tip: &'static str, /// The command it runs, with its parameters. pub command: Option<(&'static str, Value)>, /// The menu it opens. pub menu: Option, pub size: Size, /// It is something that stays on, and it is on. pub checked: bool, /// Simplified row: which stretch of the row it is in. The stretches follow one another with a /// rule between them, and in each the controls keep the order they are described in. pub section: u8, /// Simplified row: how much it matters, 1 the most. What matters least gives way first. pub rank: u8, /// Simplified row: its icon says what it is, so its label is among the first to go. pub plain: bool, /// Simplified row: it is not a button of its own but an entry under the `▾` of the button /// with this key. pub under: Option<&'static str>, /// One of classic Outlook's controls with no feature behind it yet: shown greyed, with /// "Pending development", and runs nothing. pub pending: bool, } impl Item { fn new(key: &'static str, icon: &'static str, label: &'static str, size: Size) -> Item { Item { key, icon, label, tip: "", command: None, menu: None, size, checked: false, section: 9, rank: 5, plain: false, under: None, pending: false, } } /// A small button for a control of classic Outlook's that is still to be built (`key`: its /// id in the catalog): greyed, "Pending development", and the first to give way in the row. fn pending(key: &'static str, label: &'static str, section: u8) -> Item { Item { pending: true, ..Item::new(key, "pending", label, Size::Small) }.at(section, 5) } /// A large button that runs `id`. fn big(icon: &'static str, label: &'static str, id: &'static str, params: Value) -> Item { Item { command: Some((id, params)), ..Item::new(id, icon, label, Size::Big) } } /// A small button that runs `id`; `tip` is what its tooltip calls it. fn small(icon: &'static str, label: &'static str, tip: &'static str, id: &'static str, params: Value) -> Item { Item { command: Some((id, params)), tip, ..Item::new(id, icon, label, Size::Small) } } /// A large button that opens `menu`. fn big_menu(key: &'static str, icon: &'static str, label: &'static str, tip: &'static str, menu: Menu) -> Item { Item { menu: Some(menu), tip, ..Item::new(key, icon, label, Size::Big) } } /// A small button that opens `menu`. fn small_menu(key: &'static str, icon: &'static str, label: &'static str, tip: &'static str, menu: Menu) -> Item { Item { menu: Some(menu), tip, ..Item::new(key, icon, label, Size::Small) } } /// A button of the simplified row alone, whose `▾` lists the controls that are `under` it. fn gather(key: &'static str, icon: &'static str, label: &'static str) -> Item { Item { tip: label, ..Item::new(key, icon, label, Size::Hidden) } } fn key(self, key: &'static str) -> Item { Item { key, ..self } } fn checked(self, checked: bool) -> Item { Item { checked, ..self } } /// Its place in the simplified row, and how much it matters there. fn at(self, section: u8, rank: u8) -> Item { Item { section, rank, ..self } } fn plain(self) -> Item { Item { plain: true, ..self } } fn under(self, key: &'static str) -> Item { Item { under: Some(key), ..self } } /// The label on one line, in the interface language. fn name(&self) -> String { tl!(self.label).replace("-\n", "-").replace("/\n", "/").replace('\n', " ") } /// What the tooltip calls it. fn tip_text(&self) -> String { if self.tip.is_empty() { self.name() } else { tl!(self.tip).to_string() } } } /// A named group of the classic layout. #[derive(Clone, Debug, PartialEq)] pub(crate) struct Group { pub title: &'static str, pub items: Vec, /// Classic layout: how long it keeps its form as the window narrows, the higher the longer /// (set per tab in [`fit::prioritise`]). pub priority: u8, } fn g(title: &'static str, items: Vec) -> Group { Group { title, items, priority: 5 } } /// A tab: its groups, and a line of explanation after them where there is something to explain. #[derive(Clone, Debug, PartialEq)] pub(crate) struct Tab { pub groups: Vec, pub note: &'static str, /// How wide the note is set in the classic layout. pub note_width: f32, } impl Tab { fn of(groups: Vec) -> Tab { Tab { groups, note: "", note_width: 0.0 } } /// Every control, in the order it is described. pub(crate) fn items(&self) -> impl Iterator { self.groups.iter().flat_map(|g| g.items.iter()) } } /// The tab in view, as the window stands. pub(crate) fn describe(app: &MailApp) -> Tab { describe_tab(app, &app.ui.tab) } /// The tab `name`, as the window stands. pub(crate) fn describe_tab(app: &MailApp, name: &str) -> Tab { let (mut tab, which) = match name { "Message" => (message(app), "Message"), "Insert" => (insert(), "Insert"), "Format Text" => (format_text(app), "Format Text"), "Review" => (review(), "Review"), "Attachments" => { (crate::attachment_preview::pane_target(app).map_or_else(|| Tab::of(Vec::new()), |(id, index)| attachments(id, index)), "Attachments") } "Send / Receive" => (send_receive(app), "Send / Receive"), "Folder" => (folder(app), "Folder"), "View" => (view(app), "View"), "Help" => (help(), "Help"), _ => match app.session.view.module { Module::Mail => (home_mail(app), "Home mail"), Module::Calendar => (home_calendar(app), "Home calendar"), Module::People => (home_people(app), "Home people"), Module::Tasks => (home_tasks(app), "Home tasks"), }, }; if app.services.recent_attachments.is_some() { for item in tab.groups.iter_mut().flat_map(|group| &mut group.items) { if item.command.as_ref().is_some_and(|(command, _)| *command == "ui.attach") { item.menu = Some(Menu::RecentAttachments); } } } fit::prioritise(&mut tab, which); tab } fn no() -> Value { json!({}) } fn attachments(id: mailcraft_model::Id, index: usize) -> Tab { let file = json!({"id": id, "index": index}); Tab::of(vec![ g( "Actions", vec![ Item::big("open", "Open", "mail.openAttachment", file.clone()).at(0, 1), Item::big("delete", "Remove\nAttachment", "mail.removeAttachment", file.clone()).at(0, 4), ], ), g( "Save to Computer", vec![ Item::big("save", "Save As", "mail.saveAttachment", file).at(1, 1), Item::big("save", "Save All\nAttachments", "mail.saveAllAttachments", json!({"id": id})).at(1, 3), ], ), g("Message", vec![Item::big("mail", "Show\nMessage", "ui.showAttachmentMessage", no()).at(2, 1)]), ]) } /// What the owner pressed: with Shift held and nothing else, Delete runs as Delete Permanently, /// as in Outlook, whose permanent delete key is Shift+Delete (#1438). fn pressed(ui: &Ui, command: &'static str) -> &'static str { if command == "mail.delete" && ui.ctx().input(|i| i.modifiers.shift && !i.modifiers.ctrl && !i.modifiers.command && !i.modifiers.alt) { "mail.deletePermanently" } else { command } } fn home_mail(app: &MailApp) -> Tab { // Junk ▾: Block Sender, Never Block…, Not Junk and Junk E-mail Options (#504). let junk = Item::small_menu("junk", "junk", "Junk", "Junk", Menu::Junk); let pinned = app.session.focused_message().is_some_and(|m| m.pinned); Tab::of(vec![ g( "New", vec![ Item::big("newMail", "New\nEmail", "mail.new", no()).at(0, 1), Item::big_menu("newItems", "plus", "New\nItems", "New Items", Menu::NewItems).under("mail.new"), ], ), g( "Delete", vec![ Item::big("delete", "Delete", "mail.delete", no()).at(1, 1).plain(), Item::big("archive", "Archive", "mail.archive", no()).at(1, 2).plain(), junk.under("mail.delete"), Item::small("deletePermanently", "Delete Permanently", "Delete Permanently", "mail.deletePermanently", no()).under("mail.delete"), ], ), g( "Respond", vec![ Item::big("reply", "Reply", "mail.reply", no()).at(2, 1).plain(), Item::big("replyAll", "Reply\nAll", "mail.replyAll", no()).at(2, 2).plain(), Item::big("forward", "Forward", "mail.forward", no()).at(2, 2).plain(), Item::small("forwardAsAttachment", "Forward as Attachment", "", "mail.forwardAsAttachment", no()).under("mail.forward"), Item::small("delete", "Reply and Delete", "", "mail.replyAndDelete", no()).under("mail.reply"), Item::small("open", "View Source", "", "mail.viewSource", no()).under("mail.forward"), Item::small("meeting", "Meeting", "Reply with Meeting", "calendar.fromMessage", no()).at(5, 6), Item::small("newContact", "Add Sender", "Add to Contacts", "people.fromMessage", no()).at(5, 7), ], ), g( "Move", vec![ Item::big_menu("moveMessages", "move", "Move", "Move to Folder", Menu::MoveMessages).at(1, 2).plain(), Item::big_menu("rules", "rules", "Rules", "Rules", Menu::Rules).at(4, 4), Item::small("send", "Resend Message", "Open a message you sent as a new one", "mail.resend", no()).at(5, 7), ], ), g( "Tags", vec![ Item::big("toggleRead", "Unread/\nRead", "mail.toggleRead", no()).at(3, 3), Item::big_menu("categorize", "categorize", "Categorize", "Categorize", Menu::CategorizeMail).at(3, 3).plain(), Item::big_menu("followUp", "flag", "Follow\nUp", "Follow Up", Menu::FollowUp).at(3, 3).plain(), Item::small("pin", "Pin", "Pin to the top of the list", "mail.pin", no()).checked(pinned).at(5, 5), ], ), g( "Find", vec![ Item::big_menu("filter", "filter", "Filter\nEmail", "Filter Email", Menu::FilterMail).at(4, 4), Item::small("findRelated", "Related", "Find Related Messages", "mail.findRelated", no()).at(5, 7), Item::small("findFromSender", "From Sender", "Messages from Sender", "mail.findFromSender", no()).at(5, 7), ], ), g("Send/Receive", vec![Item::big("sync", "Send/Receive\nAll Folders", "ui.sync", no()).at(5, 5)]), ]) } /// The calendar's four views, the one in use marked, in `section` of the simplified row: Home has /// them, and View while the calendar is in front. fn calendar_views(cur: CalView, section: u8) -> Vec { vec![ Item::big("day", "Day", "view.day", no()).checked(cur == CalView::Day).at(section, 2), Item::big("workWeek", "Work\nWeek", "view.workWeek", no()).checked(cur == CalView::WorkWeek).at(section, 2), Item::big("week", "Week", "view.week", no()).checked(cur == CalView::Week).at(section, 2), Item::big("month", "Month", "view.month", no()).checked(cur == CalView::Month).at(section, 2), ] } fn home_calendar(app: &MailApp) -> Tab { let cur = app.session.view.calendar; let selected = app.session.sel.event.and_then(|id| app.session.mailbox.event(id)); let private = selected.is_some_and(|e| e.private); let respond = |icon, label, key, answer: &str| Item::small(icon, label, label, "calendar.respond", json!({"response": answer})).key(key).at(4, 4); // The simplified row reads: the new items | today and the next seven days | the four views, // with their names (which keep them longest: their icons alone don't tell them apart), the // one in use marked | and, while an event is selected, what is done with it and the answers // to somebody else's meeting | the rest. let mut groups = vec![ g( "New", vec![ Item::big("newAppointment", "New\nAppointment", "calendar.new", no()).at(0, 1), Item::big("newMeeting", "New\nMeeting", "calendar.newMeeting", no()).at(0, 3), Item::big_menu("newItems", "plus", "New\nItems", "New Items", Menu::NewItems).under("calendar.new"), ], ), g( "Go To", vec![ Item::big("today", "Today", "view.today", no()).at(1, 3), Item::big("week", "Next 7\nDays", "view.next7Days", no()).at(1, 4), // (Back and Forward are in the calendar's own header: in the row they are under Today.) Item::small("previous", "Back", "Back", "view.previous", no()).under("view.today"), Item::small("next", "Forward", "Forward", "view.next", no()).under("view.today"), Item::small("calendar", "Go to Date", "Go to Date", "view.goToDate", no()).under("view.today"), ], ), g("Arrange", calendar_views(cur, 2)), ]; // What is done with an appointment is there while one is selected (in Outlook, a tab of its // own comes up for it), and the answers to a meeting while it is somebody else's. if let Some(event) = selected { // High and Low Importance are each on or off: pressing the one that is on turns it off. let (high, low) = (event.importance == Importance::High, event.importance == Importance::Low); let matters = |on: bool, value: &str| json!({"value": if on { "normal" } else { value }}); let mut items = vec![ Item::big("edit", "Open", "calendar.edit", no()).at(3, 5), Item::big("delete", "Delete", "calendar.delete", no()).at(3, 5).plain(), Item::small("forward", "Forward", "Forward", "calendar.forward", no()).at(3, 7).plain(), Item::small_menu("showAs", "showAs", "Show As", "Show As", Menu::ShowAs).at(3, 6), Item::small_menu("reminder", "reminder", "Reminder", "Reminder", Menu::Reminder).at(3, 6), Item::small("private", "Private", "Private", "calendar.private", no()).checked(private).at(3, 6), Item::small("importanceHigh", "High Importance", "High Importance", "calendar.importance", matters(high, "high")) .key("calendar.importanceHigh") .checked(high) .at(3, 7) .plain(), Item::small("importanceLow", "Low Importance", "Low Importance", "calendar.importance", matters(low, "low")) .key("calendar.importanceLow") .checked(low) .at(3, 7) .plain(), Item::big_menu("categorize", "categorize", "Categorize", "Categorize", Menu::CategorizeEvent).at(3, 5).plain(), ]; // An online meeting that has a link to join by. if event.join_link().is_some() { items.insert(2, Item::small("joinMeeting", "Join", "Join Online Meeting", "ui.joinMeeting", no()).at(3, 4)); } // A meeting: a message to its people, and how they have answered. if !event.attendees.is_empty() { items.push(Item::small("people", "Contact Attendees", "Email the people of this meeting", "calendar.contactAttendees", no()).at(3, 7)); items.push(Item::small("list", "Tracking", "Who has answered, and how", "calendar.tracking", no()).at(3, 7)); } groups.push(g("Appointment", items)); if crate::calendar_view::invitation(app, event).0 { let mut answers = vec![ respond("accept", "Accept", "calendar.accept", "accepted"), respond("tentative", "Tentative", "calendar.tentative", "tentative"), respond("decline", "Decline", "calendar.decline", "declined"), ]; // Another time can be proposed for a meeting that an account's server keeps, when // its organizer takes proposals. let kept = mailcraft_engine::cmd::remote::keeper(&app.session.mailbox, &event.origin).is_some(); if kept && event.origin.guest && event.response_options.allow_proposals { answers.push(Item::small("proposeTime", "Propose New Time", "Propose New Time", "calendar.propose", no()).at(4, 5)); } answers.push(Item::small("reply", "Reply by Email", "Write to the organizer without answering", "calendar.respondEmail", no()).at(4, 6)); groups.push(g("Respond", answers)); } } // Somebody else's calendar, by their address (#70), or one on the web (#209). groups.push(g("Manage Calendars", vec![Item::big_menu("calendar", "calendar", "Open\nCalendar", "Open Calendar", Menu::OpenCalendar).at(4, 9)])); groups.push(g( "Share", vec![ Item::big("email", "Email\nCalendar", "calendar.email", no()).at(5, 5), Item::big("export", "Save\nCalendar", "file.exportCalendar", no()).at(5, 6), ], )); groups.push(g("Find", vec![Item::big("search", "Search\nCalendar", "calendar.search", no()).at(4, 6)])); Tab::of(groups) } fn home_people(app: &MailApp) -> Tab { let favorite = app.session.sel.contact.and_then(|id| app.session.mailbox.contact(id)).is_some_and(|c| c.favorite); let new = g( "New", vec![ Item::big("newContact", "New\nContact", "people.new", no()).at(0, 1), Item::big_menu("newItems", "plus", "New\nItems", "New Items", Menu::NewItems).under("people.new"), ], ); // An organisation's address list, beside the contacts (#1262): where there is one. let find = (!mailcraft_engine::cmd::people::address_lists(&app.session.mailbox).is_empty()) .then(|| g("Find", vec![Item::big("people", "Address\nBook", "people.addressBook", no()).at(5, 4)])); // In the address list, what acts on a contact has nothing to act on: its card has its own. if app.address_book_shown().is_some() { return Tab::of(std::iter::once(new).chain(find).collect()); } let mut groups = vec![ new, g("Delete", vec![Item::big("delete", "Delete", "people.delete", no()).at(1, 2).plain()]), g( "Communicate", vec![Item::big("mail", "Email", "people.email", no()).at(2, 2), Item::big("meeting", "Meeting", "people.meeting", no()).at(2, 3)], ), g( "Actions", vec![ Item::big("edit", "Edit\nContact", "people.edit", no()).at(3, 2), Item::big(if favorite { "starOn" } else { "star" }, "Favorite", "people.favorite", no()).checked(favorite).at(3, 3), Item::big_menu("categorize", "categorize", "Categorize", "Categorize", Menu::CategorizeContact).at(3, 3).plain(), // The contacts picked together, else every group that shares an address or a // number (#506). Item::big("mergeContacts", "Merge\nDuplicates", "people.merge", merge_params(app)).at(3, 4), ], ), g( "Share", vec![ Item::big("forward", "Forward\nContact", "people.forward", no()).at(4, 4), Item::big("export", "Export\nContacts", "file.exportContacts", no()).at(4, 5), Item::big("import", "Import", "ui.import", no()).at(4, 5), ], ), ]; groups.extend(find); Tab::of(groups) } /// What Merge Duplicates opens its dialog with: the contacts picked together in the list, when /// there are two or more. pub(crate) fn merge_params(app: &MailApp) -> Value { if app.people_picked.len() >= 2 { json!({"ids": app.people_picked}) } else { json!({}) } } fn home_tasks(app: &MailApp) -> Tab { let task = app.session.sel.task.and_then(|id| app.session.mailbox.task(id)); let done = task.is_some_and(|x| x.is_complete()); let importance = task.map(|x| x.importance); let today = app.session.today(); let to_friday = (4 - i64::from(today.weekday().index())).max(0); let due = |icon, label, tip, key, date: Value| Item::small(icon, label, tip, "tasks.edit", json!({"due": date})).key(key).under("followUp"); let weight = |icon, label, key, which: Importance, code: &str| { let on = importance == Some(which); Item::small(icon, label, label, "tasks.edit", json!({"importance": if on { "normal" } else { code }})).key(key).checked(on).at(3, 5) }; Tab::of(vec![ g( "New", vec![ Item::big("newTask", "New\nTask", "tasks.new", no()).at(0, 1), Item::big_menu("newItems", "plus", "New\nItems", "New Items", Menu::NewItems).under("tasks.new"), ], ), g("Delete", vec![Item::big("delete", "Delete", "tasks.delete", no()).at(1, 2).plain()]), g( "Manage Task", vec![ Item::big("complete", "Mark\nComplete", "tasks.complete", no()).checked(done).at(2, 2), Item::big("edit", "Edit\nTask", "tasks.edit", no()).at(2, 3), Item::big("mail", "Send Status\nReport", "tasks.statusReport", no()).at(2, 4), ], ), g( "Follow Up", vec![ Item::gather("followUp", "flag", "Follow Up").at(3, 3).plain(), due("flag", "Today", "Due today", "tasks.due.today", json!(today.iso())), due("flag", "Tomorrow", "Due tomorrow", "tasks.due.tomorrow", json!(today.add_days(1).iso())), due("flag", "This Week", "Due this week", "tasks.due.thisWeek", json!(today.add_days(to_friday).iso())), due("flag", "Next Week", "Due next week", "tasks.due.nextWeek", json!(today.add_days(to_friday + 7).iso())), due("clearFlag", "No Date", "No due date", "tasks.due.none", Value::Null), ], ), g( "Tags", vec![ Item::big_menu("categorize", "categorize", "Categorize", "Categorize", Menu::CategorizeTask).at(3, 4).plain(), weight("highImportance", "High Importance", "tasks.importance.high", Importance::High, "high"), weight("lowImportance", "Low Importance", "tasks.importance.low", Importance::Low, "low"), ], ), g("Current View", vec![Item::big_menu("filter", "filter", "Filter", "Filter Tasks", Menu::FilterTasks).at(4, 4)]), ]) } /// How the text the selection covers looks (with nothing selected, how the next character typed /// will), for the buttons that say so. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub(crate) struct Look { pub bold: bool, pub italic: bool, pub underline: bool, /// The size all of it has: `Some(None)` the message's own. pub size: Option>, /// The font and the colour all of it has, the same way. pub font: Option>, pub color: Option>, pub highlight: Option>, pub bullets: bool, pub numbering: bool, pub link: bool, pub plain: bool, } /// How the selection of the text being edited looks ([`mailcraft_engine::Session::doc`]). pub(crate) fn look_now(app: &MailApp) -> Look { app.session.doc().map(|(body, plain)| look(body, plain)).unwrap_or_default() } pub(crate) fn look(body: &mailcraft_model::RichBody, plain: bool) -> Look { use mailcraft_model::rich::ListKind; let sel = body.selection(); let text = body.text(); let (from, to) = (sel.start(), sel.end()); let all = |f: &dyn Fn(&mailcraft_model::rich::Style) -> bool| { if sel.is_empty() { f(&body.typing_style()) } else { text.all(from, to, f).unwrap_or(false) } }; let first = if sel.is_empty() { body.typing_style() } else { text.style_at(from + 1) }; Look { bold: all(&|s| s.bold), italic: all(&|s| s.italic), underline: all(&|s| s.underline), size: all(&|s| s.size == first.size).then_some(first.size), font: all(&|s| s.font == first.font).then_some(first.font), color: all(&|s| s.color == first.color).then(|| first.color.clone()), highlight: all(&|s| s.highlight == first.highlight).then(|| first.highlight.clone()), bullets: text.all_lists(from, to, ListKind::Bullet).unwrap_or(false), numbering: text.all_lists(from, to, ListKind::Numbered).unwrap_or(false), link: if sel.is_empty() { text.link_span(sel.head).is_some() } else { text.all(from, to, |s| s.link.is_some()).unwrap_or(false) }, plain, } } /// The font sizes offered, in points. pub(crate) const FONT_SIZES: [u8; 12] = [8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 28, 36]; fn message(app: &MailApp) -> Tab { let importance = app.session.compose.as_ref().map(|c| c.importance); let read_receipt = app.session.compose.as_ref().is_some_and(|c| c.read_receipt); let delayed = crate::send_later::delay_is_on(app); let look = look_now(app); let painting = app.session.doc().is_some_and(|(b, _)| b.painter().is_some()); Tab::of(vec![ g("Send", vec![Item::big("send", "Send", "compose.send", no()).at(0, 1)]), g( "Clipboard", vec![Item::small("formatPainter", "Format Painter", "Format Painter", "edit.formatPainter", no()).checked(painting).at(1, 5).plain()], ), g( "Basic Text", vec![ Item::small_menu("font", "font", "Font", "Font", Menu::Font).at(1, 4).plain(), Item::small_menu("fontSize", "fontSize", "Font Size", "Font Size", Menu::FontSize).at(1, 4).plain(), Item::small_menu("fontColor", "fontColor", "Font Color", "Font Color", Menu::FontColor).at(1, 3).plain(), Item::small_menu("highlight", "highlight", "Text Highlight Color", "Text Highlight Color", Menu::Highlight).at(1, 4).plain(), Item::small("bold", "Bold", "Bold", "format.bold", no()).checked(look.bold && !look.plain).at(1, 2).plain(), Item::small("italic", "Italic", "Italic", "format.italic", no()).checked(look.italic && !look.plain).at(1, 2).plain(), Item::small("underline", "Underline", "Underline", "format.underline", no()).checked(look.underline && !look.plain).at(1, 2).plain(), Item::small("bullets", "Bullets", "Bullets", "format.bullets", no()).checked(look.bullets).at(1, 3).plain(), Item::small("numbering", "Numbering", "Numbering", "format.numbering", no()).checked(look.numbering).at(1, 3).plain(), Item::small("decreaseIndent", "Decrease Indent", "Decrease Indent", "format.outdent", no()).at(1, 4).plain(), Item::small("increaseIndent", "Increase Indent", "Increase Indent", "format.indent", no()).at(1, 4).plain(), Item::small("clearFormatting", "Clear Formatting", "Clear All Formatting", "format.clear", no()).at(1, 5).plain(), ], ), g("Names", vec![Item::big("checkNames", "Check\nNames", "compose.checkNames", no()).at(3, 4)]), g( "Include", vec![ Item::big("attach", "Attach\nFile", "ui.attach", no()).at(2, 2), Item::big("insertLink", "Link", "compose.link", no()).checked(look.link && !look.plain).at(2, 3), Item::big_menu("signature", "signature", "Signature", "Signature", Menu::Signature).at(2, 3), ], ), g( "Tags", vec![ Item::big_menu("composeFollowUp", "flag", "Follow\nUp", "Follow Up", Menu::ComposeFollowUp).at(3, 3).plain(), Item::small("highImportance", "High Importance", "High Importance", "compose.highImportance", no()) .checked(importance == Some(Importance::High)) .at(4, 4), Item::small("lowImportance", "Low Importance", "Low Importance", "compose.lowImportance", no()) .checked(importance == Some(Importance::Low)) .at(4, 4), Item::small("reply", "Direct Replies To", "Have replies sent to other addresses", "compose.replyTo", no()).at(4, 6), Item::small("read", "Request a Read Receipt", "Ask to be told when the message is read", "compose.readReceipt", no()) .checked(read_receipt) .at(4, 6), Item::small("clock", "Delay Delivery", "Do not deliver before a date and time", "compose.delay", no()).checked(delayed).at(4, 6), ], ), g( "Format", vec![ Item::small("formatHtml", "HTML", "Format as HTML", "compose.formatHtml", no()).checked(!look.plain).at(5, 5), Item::small("formatPlain", "Plain Text", "Format as Plain Text", "compose.formatPlain", no()).checked(look.plain).at(5, 5), ], ), g( "Editing", vec![ Item::small("find", "Find", "Find", "edit.find", no()).at(5, 4).plain(), Item::small("replace", "Replace", "Replace", "edit.replace", no()).at(5, 5).plain(), ], ), g( "Draft", vec![ Item::big("saveDraft", "Save\nDraft", "compose.saveDraft", no()).at(6, 2), Item::big("discard", "Discard", "compose.discard", no()).at(6, 3).plain(), Item::big("close", "Close", "compose.close", no()).at(6, 3), ], ), // The reading pane's message into a window of its own (#286; a window's ribbon leaves it out). g("Window", vec![Item::big("popOut", "Pop\nOut", "compose.popOut", no()).at(6, 4)]), ]) } /// Format Text, in a window of a message being written (#286): the message's format, and the /// text's font and paragraphs, in classic Outlook's groups. fn format_text(app: &MailApp) -> Tab { let look = look_now(app); let painting = app.session.doc().is_some_and(|(b, _)| b.painter().is_some()); let rich = !look.plain; Tab::of(vec![ g( "Clipboard", vec![ Item::big("paste", "Paste", "edit.paste", no()).at(0, 1), Item::small("formatPainter", "Format Painter", "Format Painter", "edit.formatPainter", no()).checked(painting).at(0, 5).plain(), ], ), g( "Format", vec![ Item::big("formatHtml", "HTML", "compose.formatHtml", no()).checked(rich).at(1, 2), Item::big("formatPlain", "Plain\nText", "compose.formatPlain", no()).checked(look.plain).at(1, 2), Item::pending("compose.formatRich", "Rich Text", 1), ], ), g( "Font", vec![ Item::small_menu("font", "font", "Font", "Font", Menu::Font).at(2, 4).plain(), Item::small_menu("fontSize", "fontSize", "Font Size", "Font Size", Menu::FontSize).at(2, 4).plain(), Item::small_menu("fontColor", "fontColor", "Font Color", "Font Color", Menu::FontColor).at(2, 3).plain(), Item::small_menu("highlight", "highlight", "Text Highlight Color", "Text Highlight Color", Menu::Highlight).at(2, 4).plain(), Item::small("bold", "Bold", "Bold", "format.bold", no()).checked(look.bold && rich).at(2, 2).plain(), Item::small("italic", "Italic", "Italic", "format.italic", no()).checked(look.italic && rich).at(2, 2).plain(), Item::small("underline", "Underline", "Underline", "format.underline", no()).checked(look.underline && rich).at(2, 2).plain(), Item::small("clearFormatting", "Clear Formatting", "Clear All Formatting", "format.clear", no()).at(2, 5).plain(), ], ), g( "Paragraph", vec![ Item::small("bullets", "Bullets", "Bullets", "format.bullets", no()).checked(look.bullets).at(3, 3).plain(), Item::small("numbering", "Numbering", "Numbering", "format.numbering", no()).checked(look.numbering).at(3, 3).plain(), Item::small("decreaseIndent", "Decrease Indent", "Decrease Indent", "format.outdent", no()).at(3, 4).plain(), Item::small("increaseIndent", "Increase Indent", "Increase Indent", "format.indent", no()).at(3, 4).plain(), Item::pending("format.lineSpacing", "Line Spacing", 3), ], ), g("Styles", vec![Item::pending("format.styles", "Styles", 4)]), g( "Editing", vec![ Item::small("find", "Find", "Find", "edit.find", no()).at(5, 4).plain(), Item::small("replace", "Replace", "Replace", "edit.replace", no()).at(5, 5).plain(), ], ), ]) } /// Insert, while a message is being written, in classic Outlook's groups: what Message › Include /// has, the date or the time, and the rest still to be built. fn insert() -> Tab { Tab::of(vec![ g( "Include", vec![ Item::big("attach", "Attach\nFile", "ui.attach", no()).at(0, 2), Item::big("open", "Item", "compose.attachItem", no()).at(0, 3), Item::big("people", "Contact\nCard", "insert.businessCard", no()).at(0, 4), Item::small("calendar", "Calendar", "Insert Calendar", "insert.calendar", no()).at(0, 4), Item::big_menu("signature", "signature", "Signature", "Signature", Menu::Signature).at(0, 3), ], ), g("Tables", vec![Item::pending("insert.table", "Table", 1)]), g( "Illustrations", vec![ Item::small("picture", "Pictures", "Insert Picture", "insert.picture", no()).at(2, 5), Item::pending("insert.shape", "Shapes", 2), Item::pending("insert.icon", "Icons", 2), Item::pending("insert.models3d", "3D Models", 2), Item::pending("insert.diagram", "Diagram", 2), Item::pending("insert.chart", "Chart", 2), Item::pending("insert.screenshot", "Screenshot", 2), ], ), g("Links", vec![Item::big("insertLink", "Link", "compose.link", no()).at(3, 3), Item::pending("insert.bookmark", "Bookmark", 3)]), g( "Text", vec![ Item::pending("insert.textBox", "Text Box", 4), Item::pending("insert.quickParts", "Saved Text", 4), Item::pending("insert.textEffects", "Text Effects", 4), Item::pending("insert.dropCap", "Drop Cap", 4), Item::big("dateTime", "Date &\nTime", "insert.dateTime", no()).at(4, 3), Item::pending("insert.object", "Object", 4), ], ), g( "Symbols", vec![ Item::pending("insert.equation", "Equation", 5), Item::big("symbol", "Symbol", "insert.symbol", no()).at(5, 4), Item::pending("insert.rule", "Horizontal Line", 5), Item::pending("insert.emoji", "Emoji", 5), ], ), ]) } /// Review, while a message is being written, in classic Outlook's groups: Word Count, and the /// rest still to be built. fn review() -> Tab { Tab::of(vec![ g( "Proofing", vec![ Item::pending("review.spelling", "Spelling & Grammar", 0), Item::pending("review.thesaurus", "Thesaurus", 0), Item::big("wordCount", "Word\nCount", "review.wordCount", no()).at(0, 3), ], ), g("Accessibility", vec![Item::pending("review.accessibility", "Check Accessibility", 1)]), g("Language", vec![Item::pending("review.translate", "Translate", 2), Item::pending("review.language", "Language", 2)]), ]) } /// What a control still to be built says when the pointer is on it; a screen reader has it as a /// button that can't be used, ", pending development". (The other controls of the ribbon /// have no name for it yet: tests that look for a menu's or a dialog's items by name count on that.) fn pending_tip(resp: egui::Response, item: &Item) -> egui::Response { let name = crate::i18n::fmt(tl!("{name}, pending development"), &[("name", &item.name())]); resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, false, name.clone())); resp.on_hover_ui(|ui| { ui.label(egui::RichText::new(item.name()).font(semibold(12.0))); ui.label(egui::RichText::new(tl!("Pending development")).small().weak()); }) } fn send_receive(app: &MailApp) -> Tab { let note = if !app.services.can_sync() { tl_later!("This build can't connect to mail servers. Use the desktop app, or bring mail in with File › Import.") } else if !app.session.enabled("sync.request") { tl_later!("No account is connected to a mail server yet.") } else { "" }; Tab { groups: vec![ g( "Send & Receive", vec![ Item::big("sync", "Send/Receive\nAll Folders", "ui.sync", no()).at(0, 1), Item::big("syncProgress", "Show\nProgress", "ui.dialog", json!({"name": "syncProgress"})).key("sync.progress").at(0, 3), Item::big("close", "Cancel\nAll", "sync.cancel", no()).at(0, 4), ], ), g( "Accounts", vec![ Item::big("account", "Add\nAccount", "ui.dialog", json!({"name": "account"})).key("account.add").at(1, 2), Item::big("info", "Account\nSettings", "ui.backstage", json!({"value": true, "page": "info"})).key("account.settings").at(1, 2), ], ), g("Preferences", vec![Item::big("device", "Work\nOffline", "sync.offline", no()).checked(app.offline()).at(2, 2)]), ], note, note_width: 360.0, } } fn folder(app: &MailApp) -> Tab { // (As the folder pane lists it: by Outlook's own list where an account has one.) let favorite = mailcraft_engine::cmd::folder::favorites(&app.session).contains(&app.session.view.folder); Tab::of(vec![ g("New", vec![Item::big("folderNew", "New\nFolder", "folder.new", no()).at(0, 1)]), g( "Actions", vec![ Item::big("rename", "Rename\nFolder", "folder.rename", no()).at(1, 2), Item::big_menu("moveFolder", "move", "Move\nFolder", "Move Folder", Menu::MoveFolder).at(1, 2), Item::big("delete", "Delete\nFolder", "folder.delete", no()).at(1, 2), ], ), g( "Clean Up", vec![ Item::big("markAllRead", "Mark All\nas Read", "mail.markAllRead", no()).at(2, 3), Item::big("rules", "Run Rules\nNow", "rules.run", no()).at(2, 4), Item::big("empty", "Empty\nFolder", "folder.empty", no()).at(2, 4), // (Copies earlier imports left beside the server's mail, #1401.) Item::big("copy", "Remove Imported\nDuplicates", "mail.removeImportedDuplicates", no()).at(2, 5), ], ), g( "Favorites", vec![ Item::big( if favorite { "starOn" } else { "star" }, if favorite { "Remove from\nFavorites" } else { "Add to\nFavorites" }, "folder.favorite", no(), ) .checked(favorite) .at(3, 3), ], ), g( "Export", vec![ Item::big("export", "Export\nFolder", "file.exportFolder", no()).at(4, 5), Item::big("import", "Import", "ui.import", no()).at(4, 5), ], ), g("Properties", vec![Item::big("info", "Folder\nProperties", "folder.properties", no()).at(5, 5)]), ]) } fn view(app: &MailApp) -> Tab { let v = &app.session.view; let mut tab = view_of_any(app); if v.module == Module::Calendar { // The calendar's own, in place of the messages' preview and sorting, which mean nothing // here: its four views, as Home has them (Outlook's View tab has them too, and that is // where people look); what a row of its hours stands for; and whether the calendars that // are shown lie over one another or stand side by side. let scale = Item::big_menu("timeScale", "clock", "Time\nScale", "Time Scale", Menu::TimeScale).at(2, 3); let over = mailcraft_engine::cmd::calendar_settings::overlaid(&app.session); let overlay = Item::big("copy", "Overlay", "view.overlay", no()).checked(over).at(2, 3); let beside = Item::big("readingPane", "Side-by-\nSide", "view.sideBySide", no()).at(2, 3); tab.groups.retain(|group| !["Current View", "Messages", "Arrangement", "Search"].contains(&group.title)); let after_layout = tab.groups.len().min(1); tab.groups.splice(after_layout..after_layout, [g("Arrangement", calendar_views(v.calendar, 1)), g("Calendar", vec![scale, overlay, beside])]); } tab } /// The View tab as every module has it: the list's ready-made views, Layout, then the messages' /// two groups (which the calendar replaces with its own, by their titles), the recent searches, /// then Window. The calendar drops the ready-made views and the recent searches, which are the /// mail's. fn view_of_any(app: &MailApp) -> Tab { let v = &app.session.view; let tight = app.session.prefs.tight_spacing; let mut layout = vec![ Item::big("folderPane", "Folder\nPane", "view.folderPane", no()).checked(v.folder_pane).at(0, 1), Item::big_menu("readingPane", "readingPane", "Reading\nPane", "Reading Pane", Menu::ReadingPane).at(0, 2), Item::big_menu("navigationBar", "navigationBar", "Navigation\nBar", "Navigation Bar", Menu::NavigationBar).at(0, 3), ]; // Gmail's categories as folders or as tabs (#911): only with a Gmail account that shows them. if mailcraft_engine::gmail::offered(&app.session).is_none() { layout.push(Item::big_menu("gmailCategories", "inbox", "Gmail\nCategories", "Gmail Categories", Menu::GmailCategories).at(0, 3)); } layout.push(Item::big_menu("ribbonLayout", "ribbon", "Ribbon\nLayout", "Ribbon Layout", Menu::RibbonLayout).at(3, 4)); Tab::of(vec![ g("Current View", vec![Item::big_menu("changeView", "changeView", "Change\nView", "Change View", Menu::ChangeView).at(0, 1)]), g("Layout", layout), g( "Messages", vec![ Item::big("conversations", "Show as\nConversations", "view.conversations", no()).checked(v.conversations).at(1, 2), Item::big_menu("preview", "previewLines", "Message\nPreview", "Message Preview", Menu::Preview).at(1, 3), Item::big("density", "Tighter\nSpacing", "view.density", no()).checked(tight).at(1, 4), ], ), g( "Arrangement", vec![ Item::big_menu("arrangeBy", "sort", "Arrange\nBy", "Arrange By", Menu::ArrangeBy).at(2, 2), Item::big("reverseSort", "Reverse\nSort", "view.reverseSort", no()).at(2, 3), ], ), g("Search", vec![Item::big_menu("recentSearches", "recentSearches", "Recent\nSearches", "Recent Searches", Menu::RecentSearches).at(2, 4)]), g( "Window", vec![ Item::big_menu("theme", "theme", "Theme", "Interface Theme", Menu::Theme).at(3, 3), Item::big_menu("zoom", "zoom", "Zoom", "Zoom the Message", Menu::Zoom).at(3, 4), Item::big("bell", "Reminders\nWindow", "view.reminders", no()).at(3, 4), Item::big("reset", "Reset\nView", "view.reset", no()).at(3, 5), ], ), ]) } fn help() -> Tab { Tab { groups: vec![g( "Help", vec![ Item::big("help", "Help", "help.help", no()).at(0, 1), Item::big("info", "Show\nTraining", "help.training", no()).at(0, 3), Item::big("web", "Get\nSupport", "help.support", no()).at(0, 3), Item::big("notes", "Feedback", "help.feedback", no()).at(0, 4), Item::big("favorite", "What's\nNew", "help.whatsNew", no()).at(0, 3), Item::big("search", "Search\nCommands", "ui.dialog", json!({"name": "commands"})).key("help.commands").at(0, 1), Item::big("about", "About\nMailCraft", "ui.dialog", json!({"name": "about"})).key("help.about").at(0, 2), Item::big("copy", "Copy\nDiagnostics", "ui.copyDiagnostics", no()).at(0, 3), Item::big("report", "Report a\nProblem", "ui.reportProblem", no()).at(0, 4), ], )], note: tl!( "MailCraft is open source (MIT or Apache-2.0). Every button here runs a command that scripts and agents can run too: see Search Commands." ), note_width: 420.0, } } // ---- menus ---- /// Longest search read (the rest is ignored), so that a pasted wall of text costs nothing. const FOLDER_SEARCH_MAX: usize = 200; /// What the search box of a folder menu remembers while the menu is open (#74). #[derive(Clone, Default)] struct FolderSearch { text: String, /// The row the arrow keys are on, among the rows they can choose. at: usize, /// The frame the menu was last drawn in: a popup's sizing pass draws it twice in one frame, /// and the second must keep the first's state. seen: Option, } /// A folder as Move to Folder, Copy to Folder and the Move Items and Copy Items dialogs list it. /// Built in one pass over the mailbox when the list opens, not on every frame (#1176). pub(crate) struct FolderRow { pub(crate) id: Id, /// Its name, shown indented under its account's heading. pub(crate) name: String, /// Its place in its account (`Inbox/Projects`), shown for a search's matches. pub(crate) path: String, pub(crate) depth: usize, /// What a search reads: its place and its mailbox, folded once. pub(crate) fold: String, /// The account it is in, as a search's match names it (`Name (address)`). pub(crate) account: String, /// The account's name, on the first of its folders: the heading above its tree. pub(crate) heading: Option, } impl FolderRow { /// Whether a search for `wanted` (folded, never empty) finds this folder: its text holds it /// as typed, or every word typed starts a word of its place or mailbox, in any order /// (`Sum 2025` finds `Summer 2025`, #1655). pub(crate) fn matches(&self, wanted: &str, words: &[String]) -> bool { if self.fold.contains(wanted) { return true; } if words.len() < 2 { return false; } let have = mailcraft_model::words::words(&format!("{} {}", self.path, self.account)); words.iter().all(|q| have.iter().any(|h| h.starts_with(q.as_str()))) } } /// The folders whose place (or mailbox) holds `query` (any part, ignoring case and accents), or /// whose words each start with a word of it, as indexes into `list`. Nothing typed (or nothing but marks) is all of them. fn folder_matches(list: &[FolderRow], query: &str) -> Vec { let query: String = query.chars().take(FOLDER_SEARCH_MAX).collect(); let wanted = mailcraft_model::words::fold(&query); let words = mailcraft_model::words::words(&query); list.iter().enumerate().filter(|(_, row)| wanted.is_empty() || row.matches(&wanted, &words)).map(|(i, _)| i).collect() } /// What a folder menu offers. #[derive(Clone, Copy, PartialEq, Eq)] pub(crate) enum FolderScope { /// The account in view's folders, as rules, Move Folder and a message file's menu take them. ThisAccount, /// Every account's folders, for Move to Folder and Copy to Folder: mail reaches another /// account's server too (#451). EveryAccount, } /// The account in view, else the default one. fn account_in_view(app: &MailApp) -> Option { let mb = &app.session.mailbox; mb.folder(app.session.view.folder).map(|f| f.account).or_else(|| mb.default_account().map(|a| a.id)) } /// Most folders a menu lists, and how deep a tree is walked, however a mailbox is tangled. const FOLDER_ROWS_MAX: usize = 100_000; const FOLDER_DEPTH_MAX: usize = 32; /// `account`'s folders, and those under `parent`, appended to `out` as a tree, each with its place /// built as the tree is walked. fn walk_folders( under: &HashMap<(Id, Option), Vec<&Folder>>, account: &Account, parent: Option, above: &str, depth: usize, out: &mut Vec, ) { if depth > FOLDER_DEPTH_MAX { return; } let account_name = crate::nav::account_name(account); let label = crate::nav::account_label(account); let email = account.email.trim(); for f in under.get(&(account.id, parent)).into_iter().flatten() { if out.len() >= FOLDER_ROWS_MAX { return; } let name = crate::nav::folder_name(f).to_string(); let path = if above.is_empty() { name.clone() } else { format!("{above}/{name}") }; // (A search finds a folder by its place, by the mailbox it is in, or by its address.) let fold = mailcraft_model::words::fold(&format!("{path} - {label} - {email}")); out.push(FolderRow { id: f.id, name, path: path.clone(), depth, fold, account: account_name.clone(), heading: None }); walk_folders(under, account, Some(f.id), &path, depth + 1, out); } } /// The folders `scope` offers, in the folder pane's order: the account in view's first, then the /// others' as the pane has them, each as a tree. `bool` is whether more than one mailbox is /// listed: then each tree has its account's name above it and a search's matches name theirs. /// /// The trees are found in one pass over the mailbox's folders, as Move Items builds them, so that /// a mailbox of several accounts with thousands of folders opens the menu without a wait (#1176). pub(crate) fn folder_rows(app: &MailApp, scope: FolderScope) -> (Vec, bool) { let mb = &app.session.mailbox; let in_view = account_in_view(app); let mut accounts: Vec<&Account> = match scope { FolderScope::ThisAccount => in_view.and_then(|id| mb.account(id)).into_iter().collect(), FolderScope::EveryAccount => { let mut all = mb.accounts_in_order(); if let Some(at) = all.iter().position(|a| Some(a.id) == in_view) { let a = all.remove(at); all.insert(0, a); } all } }; let many = accounts.len() > 1; // (Each account's folders under their parent, sorted as `Mailbox::children` sorts them.) let rank = |f: &Folder| FolderKind::STANDARD.iter().position(|k| *k == f.kind).unwrap_or(usize::MAX); let listed: std::collections::HashSet = accounts.iter().map(|a| a.id).collect(); let mut under: HashMap<(Id, Option), Vec<&Folder>> = HashMap::new(); for f in &mb.folders { if listed.contains(&f.account) { under.entry((f.account, f.parent)).or_default().push(f); } } for v in under.values_mut() { v.sort_by(|a, b| rank(a).cmp(&rank(b)).then_with(|| a.name.to_lowercase().cmp(&b.name.to_lowercase()))); } let mut out = Vec::new(); for a in accounts.drain(..) { let first = out.len(); walk_folders(&under, a, None, "", 0, &mut out); // (The account's name above the first of its folders, none for an account that has none.) if many && let Some(row) = out.get_mut(first) { row.heading = Some(crate::nav::account_label(a)); } } (out, many) } /// A menu's folder list, kept while the menu is open: built once when it opens rather than on /// every frame, since every account's folders can be thousands (#1176). struct FolderList { rows: Vec, many: bool, } /// A search box and then the folders of `scope` as menu items; `pick` runs with the chosen one. /// Typing narrows the list to the folders whose place (or mailbox) matches, each shown with its /// place in the tree; the arrow keys and Enter choose, and Escape clears the search before it /// closes the menu (#74). fn folder_menu_scope(ui: &mut Ui, app: &mut MailApp, scope: FolderScope, mut pick: impl FnMut(&mut MailApp, Id)) { let key = ui.scope_id().with("folder-search"); let list_key = ui.scope_id().with("folder-list"); let frame = ui.ctx().cumulative_frame_nr(); let mut st: FolderSearch = ui.data(|d| d.get_temp(key)).unwrap_or_default(); // (The menu opens afresh when its layer wasn't on screen in the pass before, which egui knows // itself: no frame count guesses at it, and a menu that stayed open through a pass with no // repaint keeps its list. The frame keeps a popup's sizing pass, which draws the menu twice // in one frame, from reading the folders twice.) let was_open = ui.ctx().memory(|m| m.areas().visible_last_frame(&ui.layer_id())); let fresh = st.seen != Some(frame) && !was_open; if fresh { st = FolderSearch::default(); } st.seen = Some(frame); // (The folders are read once, when the menu opens, and kept while it is drawn: reading every // account's tree on every frame made the menu stutter with thousands of folders (#1176).) let list: Arc = match (fresh, ui.data(|d| d.get_temp::>(list_key))) { (false, Some(list)) => list, _ => { let (rows, many) = folder_rows(app, scope); let list = Arc::new(FolderList { rows, many }); ui.data_mut(|d| d.insert_temp(list_key, Arc::clone(&list))); list } }; let many = list.many; let list = &list.rows; let edit = ui.add(egui::TextEdit::singleline(&mut st.text).hint_text(tl!("Search folders")).desired_width(200.0).char_limit(FOLDER_SEARCH_MAX)); let edit = crate::text_menu::field(edit); if fresh { edit.request_focus(); } let searching = !mailcraft_model::words::fold(&st.text).is_empty(); let shown = folder_matches(list, &st.text); // The rows the keys can choose: not the folder in view, which can't be moved to. let current = app.session.view.folder; let choosable: Vec = shown.iter().copied().filter(|i| list.get(*i).is_some_and(|row| row.id != current)).collect(); st.at = st.at.min(choosable.len().saturating_sub(1)); let (down, up, enter, escape) = ui.input_mut(|i| { ( i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown), i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp), i.consume_key(egui::Modifiers::NONE, egui::Key::Enter), // Escape clears a search first; with none typed the menu takes it and closes. searching && i.consume_key(egui::Modifiers::NONE, egui::Key::Escape), ) }); if escape { st.text.clear(); st.at = 0; } if !choosable.is_empty() { if down { st.at = (st.at + 1) % choosable.len(); } if up { st.at = if st.at == 0 { choosable.len() - 1 } else { st.at - 1 }; } } let marked = if searching { choosable.get(st.at).copied() } else { None }; let mut chosen = if enter { marked.and_then(|i| list.get(i)).map(|row| row.id) } else { None }; ui.add_space(2.0); egui::ScrollArea::vertical().max_height(360.0).show(ui, |ui| { if shown.is_empty() { ui.label(egui::RichText::new(tl!("No folders match")).color(Tokens::get(ui.ctx()).text_dim)); } for i in shown { let Some(row) = list.get(i) else { continue }; // (Above each account's tree: its name, which a search's matches show instead.) if !searching && let Some(heading) = &row.heading { ui.add_space(2.0); ui.label(egui::RichText::new(heading).small().color(Tokens::get(ui.ctx()).text_dim)); } let label = if searching { // (A search's matches name their mailbox: the same place exists in each.) if many { format!("{} - {}", row.path, row.account) } else { row.path.clone() } } else { format!("{}{name}", " ".repeat(row.depth), name = row.name) }; let button = egui::Button::new(label).selected(marked == Some(i)).min_size(vec2(200.0, 0.0)); let response = ui.add_enabled(row.id != current, button); if marked == Some(i) && (down || up) { response.scroll_to_me(None); } if response.clicked() { chosen = Some(row.id); } } }); ui.data_mut(|d| d.insert_temp(key, st)); if let Some(id) = chosen { pick(app, id); ui.data_mut(|d| d.insert_temp(key, FolderSearch::default())); ui.close(); } } /// A search box and then every folder of the account in view, as menu items. pub fn folder_menu(ui: &mut Ui, app: &mut MailApp, pick: impl FnMut(&mut MailApp, Id)) { folder_menu_scope(ui, app, FolderScope::ThisAccount, pick); } /// The same for Move to Folder and Copy to Folder, whose folders are every account's: a message /// moved from one mailbox into another is what the target accepts (#451). pub fn folder_menu_all(ui: &mut Ui, app: &mut MailApp, pick: impl FnMut(&mut MailApp, Id)) { folder_menu_scope(ui, app, FolderScope::EveryAccount, pick); } /// The accounts of the selected messages, each once. pub(crate) fn selected_accounts(app: &MailApp) -> Vec { let mut accounts: Vec = app.session.sel.messages.iter().filter_map(|id| app.session.mailbox.message(*id)).map(|m| m.account).collect(); accounts.sort_unstable(); accounts.dedup(); accounts } /// The categories the selected messages carry, each once. pub(crate) fn selected_categories(app: &MailApp) -> Vec { let messages = app.session.sel.messages.iter().filter_map(|id| app.session.mailbox.message(*id)); let mut names: Vec = messages.flat_map(|m| m.categories.iter().cloned()).collect(); names.sort_unstable(); names.dedup(); names } /// Most names off the list that the Categorize menu shows. const MAX_OFF_LIST: usize = 32; /// The rows of [`category_menu`]: the categories of `accounts`, then the names of `carried` that /// none of them lists (at most [`MAX_OFF_LIST`]), each once as the lists compare names (any /// alphabet's capitals, #790), in grey unless a list gives it a colour. pub(crate) fn category_rows(mailbox: &mailcraft_model::Mailbox, accounts: &[Id], carried: &[String]) -> Vec { let mut cats = mailbox.categories_for(accounts); let listed = cats.len(); for name in carried { if cats.len() < listed + MAX_OFF_LIST && !cats.iter().any(|c| mailcraft_model::sync::same_category(&c.name, name)) { let color = accounts.iter().find_map(|a| mailbox.category_of(*a, name)).map_or(mailcraft_model::GREY_CATEGORY, |c| c.color); cats.push(mailcraft_model::Category { name: name.clone(), color }); } } cats } /// The categories of `accounts`, those of the selection's items (#633), and the names of `carried` /// (what the items have) that aren't on those lists, as menu items that toggle one on the /// selection through `command`: an item moved from another account, or a name its server stopped /// listing, can still have it taken off. pub fn category_menu( ui: &mut Ui, app: &mut MailApp, accounts: &[Id], carried: &[String], command: &str, has: impl Fn(&MailApp, &str) -> bool, clear: Option<&str>, ) { let cats: Vec<(String, egui::Color32)> = category_rows(&app.session.mailbox, accounts, carried).into_iter().map(|c| (c.name, crate::theme::c32(c.color))).collect(); for (name, color) in cats { let on = has(app, &name); ui.horizontal(|ui| { let (r, _) = ui.allocate_exact_size(vec2(14.0, 14.0), Sense::hover()); ui.painter().rect_filled(r.shrink(1.0), 3.0, color); if on { ui.painter().text(r.center(), Align2::CENTER_CENTER, "✓", medium(10.0), Tokens::get(ui.ctx()).on_swatch); } if ui.add(egui::Button::new(name.as_str()).selected(on).min_size(vec2(170.0, 0.0))).clicked() { let _ = app.run(command, json!({"category": name})); ui.close(); } }); } if let Some(clear) = clear { ui.separator(); mi(ui, app, "Clear All Categories", clear, json!({})); } ui.separator(); if ui.add(egui::Button::new(tl!("All Categories…")).min_size(vec2(190.0, 0.0))).clicked() { let _ = app.run("ui.dialog", json!({"name": "categories", "account": accounts.first()})); ui.close(); } } fn new_items(ui: &mut Ui, app: &mut MailApp) { mi(ui, app, "Email Message", "mail.new", json!({})); mi(ui, app, "Appointment", "calendar.new", json!({})); mi(ui, app, "Meeting", "calendar.newMeeting", json!({})); mi(ui, app, "Contact", "people.new", json!({})); mi(ui, app, "Task", "tasks.new", json!({})); ui.separator(); mi(ui, app, "Folder…", "folder.new", json!({})); } /// A menu item that isn't a command of its own: `true` when it is chosen. fn plain_item(ui: &mut Ui, label: &str) -> bool { let chosen = ui.add(egui::Button::new(label).min_size(vec2(190.0, 0.0))).clicked(); if chosen { ui.close(); } chosen } /// Add Reminder… and Remove Reminder of the selected messages (#948): Home › Tags › Follow Up and the /// message's context menu. pub(crate) fn follow_up_items(ui: &mut Ui, app: &mut MailApp) { let selected = !app.session.sel.messages.is_empty(); if ui.add_enabled(selected, egui::Button::new(tl!("Add Reminder…")).min_size(vec2(190.0, 0.0))).clicked() { let _ = app.run("ui.dialog", json!({"name": "addReminder"})); ui.close(); } let any = app.session.sel.messages.iter().any(|id| app.session.mailbox.message(*id).is_some_and(|m| m.follow_up.is_some())); if any { mi(ui, app, "Remove Reminder", "mail.clearReminder", json!({})); } } /// Home › Delete › Junk ▾ (and the message's context menu): the lists and what is in Junk E-mail. pub(crate) fn junk_menu(ui: &mut Ui, app: &mut MailApp) { mi(ui, app, "Block Sender", "junk.blockSender", json!({})); mi(ui, app, "Never Block Sender", "junk.neverBlockSender", json!({})); mi(ui, app, "Never Block Sender's Domain", "junk.neverBlockDomain", json!({})); ui.separator(); // Where the message is (a search's result may be elsewhere than the folder in view). let folder = app.session.focused_message().map_or(app.session.view.folder, |m| m.folder); let in_junk = app.session.mailbox.folder(folder).is_some_and(|f| f.kind == FolderKind::Junk); if in_junk { mi(ui, app, "Not Junk", "mail.notJunk", json!({})); } else { mi(ui, app, "Move to Junk", "mail.junk", json!({})); } ui.separator(); if plain_item(ui, tl!("Junk E-mail Options…")) { let _ = app.run("ui.dialog", json!({"name": "junkOptions"})); } } /// What `menu` lists. fn menu_contents(ui: &mut Ui, app: &mut MailApp, menu: Menu) { match menu { Menu::RecentAttachments => crate::recent_attachments::contents(ui, app), Menu::NewItems => new_items(ui, app), Menu::MoveMessages => { if app.session.sel.messages.is_empty() { ui.label(tl!("Select a message first")); return; } // (Not mail a JMAP account's server has, which stays where it is for now: why, instead.) let refused = app.session.registry.get("mail.move").and_then(|c| (c.enabled)(&app.session)); match refused { Some(why) => { ui.label(tl!(why)); } None => folder_menu_all(ui, app, |app, folder| { let _ = app.run("mail.move", json!({"folder": folder})); }), } ui.separator(); ui.menu_button(tl!("Copy to Folder"), |ui| { folder_menu_all(ui, app, |app, folder| { let _ = app.run("mail.copy", json!({"folder": folder})); }); }); } Menu::Rules => { if !app.session.sel.messages.is_empty() { // A shared mailbox's rules are its own, which this version doesn't make: one for // the owner's account would move the owner's own mail into the shared mailbox. let mb = &app.session.mailbox; let shared = app.session.sel.focus().and_then(|m| mb.message(m)).and_then(|m| mb.account(m.account)).is_some_and(|a| a.is_shared()); if shared { ui.add_enabled(false, egui::Button::new(tl!("Always Move Messages From This Sender")).min_size(vec2(190.0, 0.0))) .on_disabled_hover_text(tl!("A shared mailbox's rules are its own: this version doesn't make them")); } else { ui.menu_button(tl!("Always Move Messages From This Sender"), |ui| { folder_menu(ui, app, |app, folder| { // The New rule filled in, for the owner to see and add, where it is kept too. let _ = app.run("ui.dialog", json!({"name": "rules", "folder": folder})); }); }); } ui.separator(); } mi(ui, app, "Run Rules Now", "rules.run", json!({})); if plain_item(ui, tl!("Manage Rules…")) { let _ = app.run("ui.dialog", json!({"name": "rules"})); } } Menu::Junk => junk_menu(ui, app), Menu::OpenCalendar => { mi(ui, app, "Open Shared Calendar…", "calendar.openShared", json!({})); mi(ui, app, "From Internet…", "calendar.subscribe", json!({})); } Menu::CategorizeMail => { let ids = app.session.sel.messages.clone(); let accounts = selected_accounts(app); let carried = selected_categories(app); category_menu( ui, app, &accounts, &carried, "mail.categorize", |app, name| !ids.is_empty() && ids.iter().all(|id| app.session.mailbox.message(*id).is_some_and(|m| m.has_category(name))), Some("mail.clearCategories"), ); } Menu::FollowUp => { let today = app.session.today(); let weekday = i64::from(today.weekday().index()); for (label, days) in [("Today", 0), ("Tomorrow", 1), ("This Week", 4 - weekday), ("Next Week", 11 - weekday)] { mi(ui, app, label, "mail.flag", json!({"due": today.add_days(days.max(0)).iso()})); } mi(ui, app, "No Date", "mail.flag", json!({})); ui.separator(); follow_up_items(ui, app); ui.separator(); mi(ui, app, "Mark Complete", "mail.complete", json!({})); mi(ui, app, "Clear Flag", "mail.clearFlag", json!({})); ui.separator(); mi(ui, app, "Add to Tasks", "tasks.fromMessage", json!({})); } Menu::ComposeFollowUp => { let plan = app.session.compose.as_ref().and_then(|c| c.follow_up); ui.label(egui::RichText::new(tl!("Remind me if nobody replies")).weak()); for d in crate::reminder_dialog::DAYS { let label = tln!(d, "{n} day", "{n} days"); mi_check( ui, app, &label, plan == Some(mailcraft_engine::cmd::followup::FollowUpPlan::Days(d)), "compose.followUp", json!({"days": d}), ); } if plain_item(ui, tl!("Choose a date…")) { let _ = app.run("ui.dialog", json!({"name": "followUpDate"})); } if plan.is_some() { ui.separator(); mi(ui, app, "No Reminder", "compose.followUp", json!({"clear": true})); } } Menu::FilterMail => { let filter = app.session.view.filter; for f in Filter::ALL { mi_check(ui, app, f.label(), f == filter, "view.filter", json!({"value": f})); } } Menu::ShowAs => { let shown = app.session.sel.event.and_then(|id| app.session.mailbox.event(id)).map(|e| e.show_as); for s in mailcraft_model::ShowAs::ALL { mi_check(ui, app, s.label(), shown == Some(s), "calendar.showAs", json!({"value": s.code()})); } } Menu::Reminder => { let cur = app.session.sel.event.and_then(|id| app.session.mailbox.event(id)).and_then(|e| e.reminder_minutes); mi_check(ui, app, "None", cur.is_none(), "calendar.reminder", json!({"minutes": null})); for m in [0u32, 5, 10, 15, 30, 60, 120, 1440] { let label = if m == 0 { tl!("At start time").to_string() } else { crate::dates::duration(i64::from(m)) }; mi_check(ui, app, &label, cur == Some(m), "calendar.reminder", json!({"minutes": m})); } } Menu::CategorizeEvent => { let id = app.session.sel.event; let has = |app: &MailApp, name: &str| { id.and_then(|id| app.session.mailbox.event(id)) .is_some_and(|e| e.categories.iter().any(|c| mailcraft_model::sync::same_category(c, name))) }; let event = id.and_then(|id| app.session.mailbox.event(id)); let account = event.map(|e| app.session.mailbox.event_account(e)); let carried = event.map(|e| e.categories.clone()).unwrap_or_default(); category_menu(ui, app, account.as_slice(), &carried, "calendar.categorize", has, None); } Menu::CategorizeContact => { let id = app.session.sel.contact; let has = |app: &MailApp, name: &str| { id.and_then(|id| app.session.mailbox.contact(id)) .is_some_and(|c| c.categories.iter().any(|x| mailcraft_model::sync::same_category(x, name))) }; let contact = id.and_then(|id| app.session.mailbox.contact(id)); let (account, carried) = (contact.map(|c| c.origin.account), contact.map(|c| c.categories.clone()).unwrap_or_default()); category_menu(ui, app, account.as_slice(), &carried, "people.categorize", has, None); } Menu::CategorizeTask => { let id = app.session.sel.task; let has = |app: &MailApp, name: &str| { id.and_then(|id| app.session.mailbox.task(id)) .is_some_and(|x| x.categories.iter().any(|c| mailcraft_model::sync::same_category(c, name))) }; let task = id.and_then(|id| app.session.mailbox.task(id)); let (account, carried) = (task.map(|t| t.origin.account), task.map(|t| t.categories.clone()).unwrap_or_default()); category_menu(ui, app, account.as_slice(), &carried, "tasks.categorize", has, None); } Menu::FilterTasks => { let cur = app.session.view.task_filter; for f in TaskFilter::ALL { mi_check(ui, app, f.label(), f == cur, "view.taskFilter", json!({"value": f})); } } Menu::Signature => { let names: Vec = app.session.mailbox.signatures.iter().map(|s| s.name.clone()).collect(); if names.is_empty() { ui.label(tl!("No signatures yet")); } for name in &names { if plain_item(ui, name) { let _ = app.run("compose.signature", json!({"name": name})); } } ui.separator(); if plain_item(ui, tl!("Signatures…")) { let _ = app.run("ui.backstage", json!({"value": true, "page": "signatures"})); } } Menu::MoveFolder => { if ui.add(egui::Button::new(tl!("Top Level")).min_size(vec2(200.0, 0.0))).clicked() { let _ = app.run("folder.move", json!({"parent": null})); ui.close(); } ui.separator(); folder_menu(ui, app, |app, parent| { let _ = app.run("folder.move", json!({"parent": parent})); }); } Menu::ReadingPane => { let cur = app.session.view.reading_pane; for (label, code, pane) in [("Right", "right", Pane::Right), ("Bottom", "bottom", Pane::Bottom), ("Off", "off", Pane::Off)] { mi_check(ui, app, label, cur == pane, "view.readingPane", json!({"value": code})); } } Menu::NavigationBar => { let foot = app.session.view.nav_foot; mi_check(ui, app, "Bar on the Left", !foot, "view.navigationBar", json!({"value": "bar"})); mi_check(ui, app, "At the Foot of the Pane", foot, "view.navigationBar", json!({"value": "foot"})); } Menu::GmailCategories => { let tabs = app.session.view.gmail_tabs; mi_check(ui, app, "As Folders", !tabs, "view.gmailCategories", json!({"value": "folders"})); mi_check(ui, app, "As Tabs above the Inbox", tabs, "view.gmailCategories", json!({"value": "tabs"})); } Menu::Preview => { let lines = app.session.prefs.preview_lines; for (label, n) in [("Off", 0u8), ("1 Line", 1), ("2 Lines", 2), ("3 Lines", 3)] { mi_check(ui, app, label, lines == n, "view.previewLines", json!({"value": n})); } ui.separator(); let one = app.session.prefs.one_line; mi_check(ui, app, "Single Line", one, "view.oneLine", json!({"value": !one})); } // Tasks and People have their own arrangements. Menu::ArrangeBy if app.session.view.module == Module::Tasks => { let sort = app.session.view.task_sort; for s in TaskSort::ALL { mi_check(ui, app, s.label(), sort == s, "tasks.arrange", json!({"by": s})); } } Menu::ArrangeBy if app.session.view.module == Module::People => { let sort = app.session.view.people_sort; for s in PeopleSort::ALL { mi_check(ui, app, s.label(), sort == s, "people.arrange", json!({"by": s})); } } Menu::ArrangeBy => { let sort = app.session.view.sort; for s in SortBy::ALL { mi_check(ui, app, s.label(), sort == s, "view.sort", json!({"by": s})); } ui.separator(); let groups = app.session.prefs.show_groups; mi_check(ui, app, "Show in Groups", groups, "view.groups", json!({"value": !groups})); } Menu::Theme => { let theme = app.ui.theme; for a in crate::theme::Appearance::ALL { mi_check(ui, app, a.label(), a == theme, "ui.theme", json!({"value": a.code()})); } } Menu::RibbonLayout => { let mode = app.ui.ribbon_mode; for m in Mode::ALL { mi_check(ui, app, m.label(), m == mode, "ui.ribbonMode", json!({"value": m.code()})); } } Menu::TimeScale => crate::calendar_view::time_scale_menu(ui, app), Menu::ChangeView | Menu::Zoom | Menu::RecentSearches => view_menus::show(ui, app, menu), Menu::Font => font_menu(ui, app), Menu::FontColor => color_menu(ui, app), Menu::Highlight => highlight_menu(ui, app), Menu::FontSize => size_menu(ui, app), } } /// The font sizes (`format.size`), each in a menu entry. pub(crate) fn size_menu(ui: &mut Ui, app: &mut MailApp) { let now = look_now(app).size; mi_check(ui, app, "Default", now == Some(None), "format.size", json!({"size": null})); let enabled = app.enabled("format.size"); for size in FONT_SIZES { let checked = now == Some(Some(size)); // A number reads the same in every language. let mark = egui::RichText::new("✓"); let mark = if checked { mark } else { mark.color(egui::Color32::TRANSPARENT) }; if ui.add_enabled(enabled, egui::Button::new((mark, size.to_string())).selected(checked).min_size(vec2(190.0, 0.0))).clicked() { let _ = app.run("format.size", json!({"size": size})); ui.close(); } } } /// The fonts a message may ask for (`format.font`), each in a menu entry. pub(crate) fn font_menu(ui: &mut Ui, app: &mut MailApp) { use mailcraft_model::rich::Font; let now = look_now(app).font; mi_check(ui, app, "Default", now == Some(None), "format.font", json!({"value": null})); for f in Font::ALL { mi_check(ui, app, f.label(), now == Some(Some(f)), "format.font", json!({"value": f.label()})); } } /// Text colours offered: an original palette, readable on white. pub(crate) const COLORS: [(&str, &str); 10] = [ (tl_later!("Black"), "#000000"), (tl_later!("Grey"), "#595959"), (tl_later!("Dark Red"), "#c00000"), (tl_later!("Orange"), "#c55a11"), (tl_later!("Gold"), "#bf8f00"), (tl_later!("Green"), "#2e7d32"), (tl_later!("Teal"), "#00796b"), (tl_later!("Navy"), "#1f4e79"), (tl_later!("Blue"), "#0563c1"), (tl_later!("Purple"), "#7030a0"), ]; /// The text colours (`format.color`): Automatic, the palette as swatches, and a value of the /// owner's own (`#rrggbb`). pub(crate) fn color_menu(ui: &mut Ui, app: &mut MailApp) { let now = look_now(app).color; let enabled = app.enabled("format.color"); mi_check(ui, app, "Automatic", now == Some(None), "format.color", json!({"value": null})); ui.horizontal_wrapped(|ui| { ui.set_max_width(190.0); for (name, hex) in COLORS { let Ok(c) = egui::Color32::from_hex(hex) else { continue }; let chosen = now.as_ref().is_some_and(|n| n.as_deref() == Some(hex)); let (r, resp) = ui.allocate_exact_size(vec2(16.0, 16.0), egui::Sense::click()); ui.painter().rect_filled(r, 2.0, c); if chosen || resp.hovered() { ui.painter().rect_stroke(r.expand(1.5), 2.0, egui::Stroke::new(1.5, ui.visuals().text_color()), egui::StrokeKind::Outside); } if resp.on_hover_text(tl!(name)).clicked() && enabled { let _ = app.run("format.color", json!({"value": hex})); ui.close(); } } }); ui.horizontal(|ui| { let key = egui::Id::unique("mailcraft-custom-color"); let mut typed: String = ui.data(|d| d.get_temp(key)).unwrap_or_else(|| now.clone().flatten().unwrap_or_default()); crate::text_menu::field(ui.add(egui::TextEdit::singleline(&mut typed).hint_text("#rrggbb").desired_width(90.0).char_limit(7))); let valid = mailcraft_model::rich::safe_color(&typed); if ui.add_enabled(enabled && valid.is_some(), egui::Button::new(tl!("Apply"))).clicked() && let Some(hex) = valid { let _ = app.run("format.color", json!({"value": hex})); ui.close(); } ui.data_mut(|d| d.insert_temp(key, typed)); }); } /// Highlights offered behind text: an original palette of light colours, which dark text reads on. pub(crate) const HIGHLIGHTS: [(&str, &str); 8] = [ (tl_later!("Yellow"), "#fff176"), (tl_later!("Lime"), "#c5e1a5"), (tl_later!("Aqua"), "#80deea"), (tl_later!("Sky"), "#90caf9"), (tl_later!("Pink"), "#f8bbd0"), (tl_later!("Lavender"), "#d1c4e9"), (tl_later!("Peach"), "#ffcc80"), (tl_later!("Grey"), "#d9d9d9"), ]; /// The highlights (`format.highlight`): No Color, and the palette as swatches. pub(crate) fn highlight_menu(ui: &mut Ui, app: &mut MailApp) { let now = look_now(app).highlight; let enabled = app.enabled("format.highlight"); mi_check(ui, app, "No Color", now == Some(None), "format.highlight", json!({"value": null})); ui.horizontal_wrapped(|ui| { ui.set_max_width(190.0); for (name, hex) in HIGHLIGHTS { let Ok(c) = egui::Color32::from_hex(hex) else { continue }; let chosen = now.as_ref().is_some_and(|n| n.as_deref() == Some(hex)); let (r, resp) = ui.allocate_exact_size(vec2(16.0, 16.0), egui::Sense::click()); ui.painter().rect_filled(r, 2.0, c); if chosen || resp.hovered() { ui.painter().rect_stroke(r.expand(1.5), 2.0, egui::Stroke::new(1.5, ui.visuals().text_color()), egui::StrokeKind::Outside); } app.hit.add("highlightSwatch", hit_id(hex), r); if resp.on_hover_text(tl!(name)).clicked() && enabled { let _ = app.run("format.highlight", json!({"value": hex})); ui.close(); } } }); } /// A control that runs a command, as an entry of a menu: its name on one line, its key, a mark /// when it is on. fn entry(ui: &mut Ui, app: &mut MailApp, item: &Item) { let Some((id, params)) = &item.command else { return }; let (key, enabled) = (shortcut_text(app, id), usable(app, item)); let mut button = egui::Button::new(item.name()).selected(item.checked).min_size(vec2(190.0, 0.0)); if !key.is_empty() { button = button.shortcut_text(key); } if ui.add_enabled(enabled, button).clicked() { let _ = app.run(pressed(ui, id), params.clone()); ui.close(); } } // ---- the simplified row ---- /// A button of the simplified row: a control, and the controls listed under its `▾`. #[derive(Clone, Debug, PartialEq)] pub(crate) struct Button<'a> { pub item: &'a Item, pub drops: Vec<&'a Item>, } impl Button<'_> { /// It has a `▾`: it opens a menu of its own, or has controls under it. fn has_drop(&self) -> bool { self.item.menu.is_some() || !self.drops.is_empty() } /// Its main part runs a command and its `▾` opens a menu. fn is_split(&self) -> bool { self.item.command.is_some() && self.has_drop() } } /// The buttons of a tab's simplified row, in the row's order: the stretches one after another, /// and in each the controls as they are described. pub(crate) fn row(tab: &Tab) -> Vec> { let mut buttons: Vec> = tab .items() .filter(|item| item.under.is_none()) .map(|item| Button { item, drops: tab.items().filter(|under| under.under == Some(item.key)).collect() }) .collect(); buttons.sort_by_key(|b| b.item.section); buttons } /// What the simplified row shows at a width. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub(crate) struct Plan { /// The buttons in the row, in order, by their place in [`row`]: each with whether its label shows. pub shown: Vec<(usize, bool)>, /// The buttons behind `…`, in the row's order. pub more: Vec, } /// The width of a row of buttons: `state` says of each whether it is in the row, and with its /// label; `width` how wide the button at a place in the row is, with its label and without. fn row_width(buttons: &[Button<'_>], state: &[(bool, bool)], width: &dyn Fn(usize, bool) -> f32) -> f32 { let mut total = 0.0; let mut before: Option = None; for (i, (b, (shown, labelled))) in buttons.iter().zip(state).enumerate() { if !shown { continue; } if let Some(section) = before { total += if section == b.item.section { BUTTON_GAP } else { RULE_GAP }; } total += width(i, *labelled); before = Some(b.item.section); } if state.iter().any(|(shown, _)| !shown) { total += BUTTON_GAP + MORE_W; } total } /// Fit `buttons` into `available`: labels go first and then buttons, what matters least before /// what matters more, until the row fits. /// /// The order: the labels of the buttons whose icon says what they are; the other labels, all but /// the first-rank buttons'; then buttons go behind `…`, all but the first rank; then the /// first-rank labels and last those buttons themselves. In each step the higher rank number goes /// first, and of two the one further along the row. pub(crate) fn plan(buttons: &[Button<'_>], width: &dyn Fn(usize, bool) -> f32, available: f32) -> Plan { let mut state = vec![(true, true); buttons.len()]; // (step, rank, place in the row, whether the step takes the button out of the row) let mut steps: Vec<(u8, u8, usize, bool)> = Vec::with_capacity(buttons.len() * 2); for (i, b) in buttons.iter().enumerate() { let (rank, first) = (b.item.rank, b.item.rank <= 1); // What is still to be built goes behind `…` before anything else gives way. if b.item.pending { steps.push((0, rank, i, true)); continue; } steps.push(( if b.item.plain { 0 } else if first { 3 } else { 1 }, rank, i, false, )); steps.push((if first { 4 } else { 2 }, rank, i, true)); } steps.sort_by_key(|(step, rank, place, _)| (*step, std::cmp::Reverse(*rank), std::cmp::Reverse(*place))); for (_, _, i, out) in steps { if row_width(buttons, &state, width) <= available { break; } if let Some(s) = state.get_mut(i) { *s = if out { (false, false) } else { (s.0, false) }; } } Plan { shown: state.iter().enumerate().filter(|(_, (shown, _))| *shown).map(|(i, (_, labelled))| (i, *labelled)).collect(), more: state.iter().enumerate().filter(|(_, (shown, _))| !shown).map(|(i, _)| i).collect(), } } /// The width of a button of the simplified row whose name is `text` wide. fn button_width(b: &Button<'_>, labelled: bool, text: f32) -> f32 { let label = if labelled { LABEL_GAP + text } else { 0.0 }; let end = match (b.has_drop(), labelled) { (true, true) => DROP_GAP_LABEL + DROP_W, (true, false) => DROP_GAP_ICON + DROP_W, (false, _) => PAD, }; PAD + ICON + label + end } /// What is under a button's `▾`: its own menu, then the controls under it. fn drop_menu(ui: &mut Ui, app: &mut MailApp, b: &Button<'_>) { ui.set_min_width(200.0); if let Some(menu) = b.item.menu { menu_contents(ui, app, menu); } // A single menu under a button that has none of its own is that button's menu. let alone = b.item.menu.is_none() && b.drops.len() == 1; for under in &b.drops { match under.menu { Some(menu) if alone => menu_contents(ui, app, menu), Some(menu) => submenu(ui, app, under.name(), menu), None => entry(ui, app, under), } } } /// A button that is behind `…`, as entries of that menu. fn more_entries(ui: &mut Ui, app: &mut MailApp, b: &Button<'_>) { if b.item.pending { let entry = ui.add_enabled(false, egui::Button::new(b.item.name()).min_size(vec2(190.0, 0.0))); entry.on_disabled_hover_text(tl!("Pending development")); return; } if b.item.command.is_none() { match b.item.menu { Some(menu) if b.drops.is_empty() => submenu(ui, app, b.item.name(), menu), _ => { ui.menu_button(b.item.name(), |ui| drop_menu(ui, app, b)); } } return; } entry(ui, app, b.item); if let Some(menu) = b.item.menu { submenu(ui, app, b.item.tip_text(), menu); } for under in &b.drops { match under.menu { Some(menu) => submenu(ui, app, under.name(), menu), None => entry(ui, app, under), } } } /// A small `▾`, centred on `c` (also the one at an attachment chip's right end, #785). pub(crate) fn drop_mark(ui: &Ui, c: egui::Pos2, color: egui::Color32) { ui.painter().add(Shape::line(vec![pos2(c.x - 2.75, c.y - 1.0), pos2(c.x, c.y + 1.25), pos2(c.x + 2.75, c.y - 1.0)], Stroke::new(1.1, color))); } /// One button of the simplified row, in `rect`. fn simple_button(app: &mut MailApp, ui: &mut Ui, t: &Tokens, b: &Button<'_>, labelled: bool, rect: Rect) { let item = b.item; let id = ui.scope_id().with(("ribbon", item.key)); let on = usable(app, item); let drop_rect = Rect::from_min_max(pos2(rect.max.x - DROP_W, rect.min.y), rect.max); let main_rect = if b.is_split() { Rect::from_min_max(rect.min, pos2(drop_rect.min.x, rect.max.y)) } else { rect }; // (A control still to be built takes no clicks and no keyboard.) let main = ui.interact(main_rect, id, if item.pending { Sense::hover() } else { Sense::click() }); app.hit.add("ribbon", hit_id(item.key), main_rect); if item.pending { let icon = Rect::from_center_size(pos2(rect.min.x + PAD + ICON / 2.0, rect.center().y), vec2(ICON, ICON)); icons::paint(ui.painter(), icon, item.icon, t.text_disabled, t.text_disabled); if labelled { ui.painter().text(pos2(icon.max.x + LABEL_GAP, rect.center().y), Align2::LEFT_CENTER, item.name(), regular(LABEL_SIZE), t.text_disabled); } pending_tip(main, item); return; } if on { bg(ui, main_rect, &main, item.checked, t); } let (ink, accent, text) = if on { (t.icon, t.accent, t.text) } else { (t.text_disabled, t.text_disabled, t.text_disabled) }; let icon = Rect::from_center_size(pos2(rect.min.x + PAD + ICON / 2.0, rect.center().y), vec2(ICON, ICON)); icons::paint(ui.painter(), icon, item.icon, ink, accent); if labelled { ui.painter().text(pos2(icon.max.x + LABEL_GAP, rect.center().y), Align2::LEFT_CENTER, item.name(), regular(LABEL_SIZE), text); } let Some((command, params)) = &item.command else { // The whole button opens its menu. drop_mark(ui, drop_rect.center(), ink); let main = menu_tooltip(app, main, item, on); if on { menu_popup(&main, button_menus(b)).show(|ui| drop_menu(ui, app, b)); } return; }; let main = command_tooltip(app, main, &item.tip_text(), command); if main.clicked() && on { let _ = app.run(pressed(ui, command), params.clone()); } if !b.has_drop() { return; } // Its other half: the `▾` opens the menu, whether or not the command can run now. let drop = ui.interact(drop_rect, id.with("menu"), Sense::click()); if item.menu != Some(Menu::RecentAttachments) { app.hit.add("ribbonMenu", hit_id(item.key), drop_rect); } bg(ui, drop_rect, &drop, false, t); drop_mark(ui, drop_rect.center(), t.icon); let tip = b.drops.first().map_or_else(|| item.tip_text(), |under| under.tip_text()); let drop = drop.on_hover_text(tip); if item.menu != Some(Menu::RecentAttachments) || menu_usable(app, Menu::RecentAttachments) { menu_popup(&drop, button_menus(b)).show(|ui| drop_menu(ui, app, b)); } } /// The keys of the buttons that were behind `…` in the frame just laid out. #[cfg(test)] pub(crate) fn behind_more(ctx: &egui::Context) -> Vec<&'static str> { ctx.data(|d| d.get_temp::>(egui::Id::unique("ribbon_more"))).unwrap_or_default() } /// The simplified layout: one row of `tab` in `area`, with `…` at its end for what doesn't fit. fn simplified(app: &mut MailApp, ui: &mut Ui, t: &Tokens, tab: &Tab, area: Rect) { let buttons = row(tab); let names: Vec = buttons.iter().map(|b| ui.ctx().fonts_mut(|f| f.layout_no_wrap(b.item.name(), regular(LABEL_SIZE), t.text).size().x)).collect(); let width = |i: usize, labelled: bool| match (buttons.get(i), names.get(i)) { (Some(b), Some(text)) => button_width(b, labelled, *text), _ => 0.0, }; let plan = plan(&buttons, &width, area.width()); let mut x = area.min.x; let mut before: Option = None; for (i, labelled) in &plan.shown { let Some(b) = buttons.get(*i) else { continue }; if let Some(section) = before { if section == b.item.section { x += BUTTON_GAP; } else { // A rule between two stretches of the row. let rule = (x + RULE_GAP / 2.0).floor() + 0.5; ui.painter().line_segment([pos2(rule, area.min.y), pos2(rule, area.max.y)], Stroke::new(1.0, t.border_strong)); x += RULE_GAP; } } let w = width(*i, *labelled); simple_button(app, ui, t, b, *labelled, Rect::from_min_size(pos2(x, area.min.y), vec2(w, area.height()))); x += w; before = Some(b.item.section); } let more: Vec<&Button<'_>> = plan.more.iter().filter_map(|i| buttons.get(*i)).collect(); ui.data_mut(|d| d.insert_temp(egui::Id::unique("ribbon_more"), more.iter().map(|b| b.item.key).collect::>())); if !more.is_empty() { // What didn't fit, behind `…` at the end of the row. let rect = Rect::from_min_size(pos2(area.max.x - MORE_W, area.min.y), vec2(MORE_W, area.height())); let resp = ui.interact(rect, ui.scope_id().with("ribbon_more"), Sense::click()); app.hit.add("ribbonMore", 0, rect); bg(ui, rect, &resp, false, t); icons::paint(ui.painter(), Rect::from_center_size(rect.center(), vec2(ICON, ICON)), "more", t.icon, t.accent); let resp = resp.on_hover_text(tl!("More commands")); egui::Popup::menu(&resp).show(|ui| { ui.set_min_width(200.0); let mut before: Option = None; for b in &more { if before.is_some_and(|section| section != b.item.section) { ui.separator(); } more_entries(ui, app, b); before = Some(b.item.section); } }); } else if !tab.note.is_empty() && area.max.x - x - 16.0 >= NOTE_MIN { // Room is left: the tab's line of explanation, as much of it as fits (all of it in the tooltip). let rect = Rect::from_min_max(pos2(x + 16.0, area.min.y), area.max); paint_clipped(ui.painter(), pos2(rect.min.x, rect.center().y), rect.width(), tl!(tab.note), regular(12.0), t.text_dim); ui.interact(rect, ui.scope_id().with("ribbon_note"), Sense::hover()).on_hover_text(tl!(tab.note)); } } // ---- the classic layout ---- fn classic_recent_attachments(app: &mut MailApp, response: &egui::Response, enabled: bool) { if !enabled { return; } if crate::recent_attachments::available(app) { egui::Popup::menu(response).show(|ui| crate::recent_attachments::contents(ui, app)); } else if response.clicked() { let _ = app.run("ui.attach", json!({})); } } /// A large button of the classic layout. fn classic_big(app: &mut MailApp, ui: &mut Ui, item: &Item) { let label = tl!(item.label); match (&item.command, item.menu) { (_, Some(Menu::RecentAttachments)) => { let on = usable(app, item); let (resp, text) = big_frame(ui, item.icon, label, on, false, true); app.hit.add("ribbon", hit_id(item.key), resp.rect); app.hit.add("ribbonLabel", hit_id(item.key), text); classic_recent_attachments(app, &resp, on); } (Some((command, params)), _) => { let on = usable(app, item); let (resp, text) = big_frame(ui, item.icon, label, on, item.checked, false); app.hit.add("ribbon", hit_id(item.key), resp.rect); app.hit.add("ribbonLabel", hit_id(item.key), text); let resp = command_tooltip(app, resp, &item.tip_text(), command); if resp.clicked() && on { let _ = app.run(pressed(ui, command), params.clone()); } } (None, Some(menu)) => { let on = usable(app, item); let (resp, text) = big_frame(ui, item.icon, label, on, false, true); let resp = menu_tooltip(app, resp, item, on); app.hit.add("ribbon", hit_id(item.key), resp.rect); app.hit.add("ribbonLabel", hit_id(item.key), text); if on { menu_popup(&resp, [menu]).show(|ui| { ui.set_min_width(200.0); menu_contents(ui, app, menu); }); } } (None, None) if item.pending => { let (resp, _) = big_frame(ui, item.icon, label, false, false, false); app.hit.add("ribbon", hit_id(item.key), resp.rect); pending_tip(resp, item); } (None, None) => {} } } /// A column of small buttons of the classic layout (up to three), with their labels or without /// (then each is named in its tooltip). fn classic_column(app: &mut MailApp, ui: &mut Ui, items: &[&Item], labelled: bool) { if items.is_empty() { return; } stack(ui, |ui| { for item in items { let name = item.name(); let label = labelled.then_some(name.as_str()); match (&item.command, item.menu) { (_, Some(Menu::RecentAttachments)) => { let on = usable(app, item); let resp = menu_tooltip(app, small_frame(ui, item.icon, label, on, false, true), item, on); app.hit.add("ribbon", hit_id(item.key), resp.rect); classic_recent_attachments(app, &resp, on); } (Some((command, params)), _) => { let on = usable(app, item); let resp = small_frame(ui, item.icon, label, on, item.checked, false); app.hit.add("ribbon", hit_id(item.key), resp.rect); let resp = command_tooltip(app, resp, &item.tip_text(), command); if resp.clicked() && on { let _ = app.run(pressed(ui, command), params.clone()); } } (None, Some(menu)) => { let on = usable(app, item); let resp = menu_tooltip(app, small_frame(ui, item.icon, label, on, false, true), item, on); app.hit.add("ribbon", hit_id(item.key), resp.rect); if on { menu_popup(&resp, [menu]).show(|ui| { ui.set_min_width(200.0); menu_contents(ui, app, menu); }); } } (None, None) if item.pending => { let resp = small_frame(ui, item.icon, label, false, false, false); app.hit.add("ribbon", hit_id(item.key), resp.rect); pending_tip(resp, item); } (None, None) => {} } } }); } /// A group's controls laid out at `stage`: large buttons side by side and small ones three to a column. fn classic_cells(app: &mut MailApp, ui: &mut Ui, items: &[&Item], stage: Stage) { for cell in fit::cells(items, stage) { match cell { Cell::Big(item) => classic_big(app, ui, item), Cell::Column(column) => classic_column(app, ui, &column, stage != Stage::Icons), } } } /// A group that is behind `…`, as entries of a menu. fn group_entries(ui: &mut Ui, app: &mut MailApp, group: &Group) { ui.set_min_width(200.0); for item in fit::shown(group) { if item.pending { let entry = ui.add_enabled(false, egui::Button::new(item.name()).min_size(vec2(190.0, 0.0))); entry.on_disabled_hover_text(tl!("Pending development")); } else if item.menu == Some(Menu::RecentAttachments) && crate::recent_attachments::available(app) { submenu(ui, app, item.name(), Menu::RecentAttachments); } else if item.command.is_some() { entry(ui, app, item); } else if let Some(menu) = item.menu { submenu(ui, app, item.name(), menu); } } } /// Each group of the classic layout in the frame just laid out: its title, its stage, and whether it is behind `…`. #[cfg(test)] pub(crate) fn last_fit(ctx: &egui::Context) -> Vec<(&'static str, Stage, bool)> { ctx.data(|d| d.get_temp::>(egui::Id::NULL.with("ribbon_fit"))).unwrap_or_default() } /// The classic layout: `tab` in its groups, large buttons side by side and small ones three to a /// column. In less than `available` wide, groups shrink, fold and go behind `…` ([`fit::fit`]). fn classic(app: &mut MailApp, ui: &mut Ui, t: &Tokens, tab: &Tab, available: f32) { let groups: Vec<&Group> = tab.groups.iter().filter(|group| !fit::shown(group).is_empty()).collect(); let widths: Vec<[f32; 4]> = groups.iter().map(|group| fit::group_widths(group, &|text, size| widgets::label_width(ui, text, size))).collect(); let priority: Vec = groups.iter().map(|group| group.priority).collect(); let note = if tab.note.is_empty() { 0.0 } else { tab.note_width }; let plan = fit::fit(&widths, &priority, note, available); #[cfg(test)] { let shown: Vec<(&'static str, Stage, bool)> = groups.iter().zip(&plan.stages).enumerate().map(|(i, (group, stage))| (group.title, *stage, plan.behind.contains(&i))).collect(); ui.data_mut(|d| d.insert_temp(egui::Id::NULL.with("ribbon_fit"), shown)); } for (i, group_of) in groups.iter().enumerate() { let items = fit::shown(group_of); let stage = plan.stages.get(i).copied().unwrap_or(Stage::Full); if plan.behind.contains(&i) { continue; } if stage != Stage::Folded { group(ui, group_of.title, app, |ui, app| classic_cells(app, ui, &items, stage)); continue; } let top = ui.cursor().min.y; let icon = items.first().map_or("more", |item| item.icon); let resp = widgets::fold_frame(ui, icon, tl!(group_of.title)); app.hit.add("ribbonFold", hit_id(group_of.title), resp.rect); // The group as it normally looks; as small buttons when even that is wider than the window. let room = ui.ctx().content_rect().width() - 24.0; let open = if widths.get(i).is_some_and(|w| w[0] - fit::GROUP_TAIL <= room) { Stage::Full } else { Stage::Small }; egui::Popup::menu(&resp).show(|ui| { ui.horizontal_top(|ui| { ui.spacing_mut().item_spacing = vec2(1.0, 1.0); classic_cells(app, ui, &items, open); }); }); widgets::group_end(ui, top); } if !plan.behind.is_empty() { ui.add_space(2.0); let (rect, resp) = ui.allocate_exact_size(vec2(MORE_W, CONTENT_H + LABEL_H), Sense::click()); app.hit.add("ribbonMore", 0, rect); bg(ui, rect, &resp, false, t); icons::paint(ui.painter(), Rect::from_center_size(rect.center(), vec2(ICON, ICON)), "more", t.icon, t.accent); let resp = resp.on_hover_text(tl!("More commands")); egui::Popup::menu(&resp).show(|ui| { ui.set_min_width(200.0); for i in &plan.behind { if let Some(group_of) = groups.get(*i) { ui.menu_button(tl!(group_of.title), |ui| group_entries(ui, app, group_of)); } } }); } if plan.note { ui.add_space(fit::NOTE_GAP); ui.allocate_ui(vec2(tab.note_width, CONTENT_H), |ui| { ui.add(egui::Label::new(egui::RichText::new(tl!(tab.note)).color(t.text_dim).size(11.5)).wrap()); }); } } // ---- the ribbon ---- pub fn show(app: &mut MailApp, ui: &mut Ui) { crate::attachment_preview::follow_message(app, 0, crate::attachment_preview::pane_message(app)); let tabs = tabs(app); if !tabs.contains(&app.ui.tab.as_str()) { app.ui.tab = "Home".into(); } let current = if app.ui.backstage { String::new() } else { app.ui.tab.clone() }; // The tabs and the ribbon start beside the module bar, in line with the panes under them. if let Some((tab, double)) = strip(app, ui, &tabs, ¤t, egui::Id::unique("tabs")) { let _ = app.run("ui.tab", json!({"tab": tab})); if double && tab != "File" { let _ = app.run("ui.collapseRibbon", json!({})); } } if app.ui.ribbon_collapsed { return; } let tab = describe(app); band(app, ui, &tab, egui::Id::unique("ribbon")); } pub(crate) fn show_attachment_window(app: &mut MailApp, ui: &mut Ui, window: u64, message: mailcraft_model::Id) -> bool { let Some(index) = crate::attachment_preview::target(app, window, message) else { return false }; if strip(app, ui, &["Message", "Attachments"], "Attachments", egui::Id::unique(("attachment-tabs", window))) .is_some_and(|(tab, _)| tab == "Message") { let _ = app.run("ui.showAttachmentMessage", no()); return true; } band(app, ui, &attachments(message, index), egui::Id::unique(("attachment-ribbon", window))); true } /// The ribbon of a window of its own with a message being written (#286), numbered `window`: /// its tabs Message, Insert, Format Text and Review, of which `tab` is in view, and Search /// commands, in the main ribbon's layout (classic or simplified). What it runs acts on the /// window's message, which is the current one while the window is laid out. pub(crate) fn show_window(app: &mut MailApp, ui: &mut Ui, window: u64, tab: &mut &'static str) { let tabs = crate::windows::compose_window::TABS; if !tabs.contains(tab) { *tab = "Message"; } if let Some((chosen, _)) = strip(app, ui, &tabs, tab, egui::Id::unique(("tabs", window))) && let Some(chosen) = tabs.iter().find(|t| **t == chosen) { *tab = chosen; } let mut described = describe_tab(app, tab); // (It is in a window of its own already; and Send is beside its lines, as a message's window // has it in classic Outlook, not in its ribbon too.) for group in &mut described.groups { group.items.retain(|item| item.command.as_ref().is_none_or(|(id, _)| !matches!(*id, "compose.popOut" | "compose.send"))); } described.groups.retain(|group| !group.items.is_empty()); band(app, ui, &described, egui::Id::unique(("ribbon", window))); } /// The row of tabs, `current` the one in view, with Search commands at its right end; `id` names /// its panel. The tab clicked, and whether it was a double click. fn strip(app: &mut MailApp, ui: &mut Ui, tabs: &[&'static str], current: &str, id: egui::Id) -> Option<(&'static str, bool)> { let t = Tokens::get(ui.ctx()); let mut clicked = None; egui::Panel::top(id) .exact_size(TAB_H) .show_separator_line(false) .frame(egui::Frame::NONE.fill(t.tab_strip).inner_margin(egui::Margin { left: 3, right: 10, top: 0, bottom: 0 })) .show(ui, |ui| { ui.horizontal_centered(|ui| { ui.spacing_mut().item_spacing = vec2(0.0, 0.0); for tab in tabs { let shown = tl!(tab); let active = current == *tab; // As wide as its name in the heavier weight, so a tab keeps its place when chosen. let text_w = ui.ctx().fonts_mut(|f| f.layout_no_wrap(shown.to_string(), semibold(TAB_SIZE), t.text).size().x); let w = text_w + 24.0; let (r, resp) = ui.allocate_exact_size(vec2(w, TAB_H), Sense::click()); app.hit.add("ribbonTab", hit_id(tab), r); if resp.hovered() && !active { ui.painter().rect_filled(r.shrink2(vec2(2.0, 4.0)), 4.0, t.hover); } // The tab that came up for the message being written stands out. let color = if matches!(*tab, "Message" | "Attachments") && !active { t.accent_text } else { t.text }; ui.painter().text(r.center(), Align2::CENTER_CENTER, shown, if active { semibold(TAB_SIZE) } else { regular(TAB_SIZE) }, color); if active { // The tab in view: its name in the heavier weight, underlined in the accent. let u = Rect::from_min_size(pos2(r.center().x - text_w / 2.0, r.min.y + 25.0), vec2(text_w, 2.0)); ui.painter().rect_filled(u, 1.0, t.accent_text); } if resp.clicked() { clicked = Some((*tab, false)); } if resp.double_clicked() { clicked = Some((*tab, true)); } } // Search every command by name ("Tell me"), in what the tabs leave of the row: it // gives way before it would cover them, to the magnifier alone and then to nothing // (the Help tab has it too, #712). let label = tl!("Search commands"); let shown = fit::search(ui.available_width(), widgets::icon_text_width(ui, label)); if shown != fit::Search::Hidden { ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { let resp = match shown { fit::Search::Named => widgets::icon_text_button(ui, "search", label, true), _ => widgets::icon_button(ui, "search", label, 16.0, true), }; app.hit.add("ribbonSearch", 0, resp.rect); if resp.clicked() { let _ = app.run("ui.dialog", json!({"name": "commands"})); } }); } }); }); clicked } /// The commands of `tab` under the row of tabs, in the layout chosen; `id` names its panel. fn band(app: &mut MailApp, ui: &mut Ui, tab: &Tab, id: egui::Id) { let t = Tokens::get(ui.ctx()); let mode = app.ui.ribbon_mode; // The ribbon is a sheet on the window's own colour, with a gap under it before the panes. The // commands have the sheet less its edges and the layout button at its right end. let (height, edge) = match mode { Mode::Classic => (CONTENT_H + LABEL_H + 10.0, 4.0), Mode::Simplified => (BAND_H, (BAND_H - BUTTON_H) / 2.0), }; let margin = egui::Margin { left: 8, right: (16.0 + MODE_W) as i8, top: (edge + TOP_GAP) as i8, bottom: (edge + SHEET_GAP) as i8 }; egui::Panel::top(id) .exact_size(height + TOP_GAP + SHEET_GAP) .show_separator_line(false) .frame(egui::Frame::NONE.fill(t.tab_strip).inner_margin(margin)) .show(ui, |ui| { let area = ui.max_rect(); let sheet = Rect::from_min_max(pos2(area.min.x - 8.0, area.min.y - edge), pos2(area.max.x + 8.0 + MODE_W, area.max.y + edge)); // In the dark the sheet stands out by itself; on a light window it needs its edge. let line = t.ribbon_edge; ui.painter().rect(sheet, 8.0, t.ribbon, line, egui::StrokeKind::Inside); app.hit.add("ribbonBand", 0, sheet); match mode { Mode::Classic => { egui::ScrollArea::horizontal().scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden).show(ui, |ui| { ui.horizontal_top(|ui| { ui.spacing_mut().item_spacing = vec2(2.0, 2.0); classic(app, ui, &t, tab, area.width()); }); }); } Mode::Simplified => { simplified(app, ui, &t, tab, area); ui.allocate_rect(area, Sense::hover()); } } // The layout button, at the right end of the sheet (at its foot in the classic layout). let side = MODE_W - 4.0; let centre = match mode { Mode::Classic => pos2(sheet.max.x - 4.0 - side / 2.0, sheet.max.y - 4.0 - side / 2.0), Mode::Simplified => pos2(sheet.max.x - 4.0 - side / 2.0, sheet.center().y), }; let rect = Rect::from_center_size(centre, vec2(side, side)); let resp = ui.interact(rect, ui.scope_id().with("ribbon_mode"), Sense::click()); app.hit.add("ribbonMode", 0, rect); bg(ui, rect, &resp, false, &t); ui.painter().add(Shape::line( vec![pos2(centre.x - 4.0, centre.y - 2.0), pos2(centre.x, centre.y + 2.0), pos2(centre.x + 4.0, centre.y - 2.0)], Stroke::new(1.5, t.icon), )); let resp = resp.on_hover_text(tl!("Ribbon Layout")); egui::Popup::menu(&resp).show(|ui| { ui.set_min_width(200.0); menu_contents(ui, app, Menu::RibbonLayout); }); }); } #[cfg(test)] mod fit_tests; #[cfg(test)] mod move_menu_tests; #[cfg(test)] mod plain_tests; #[cfg(test)] mod category_rows_tests; #[cfg(test)] mod tests { use egui_kittest::kittest::Queryable as _; use mailcraft_engine::Session; use super::*; use crate::Services; /// Wednesday 2026-10-14 16:00 UTC. const NOW: i64 = 1_791_993_600; type Window = egui_kittest::Harness<'static, MailApp>; fn app() -> MailApp { let mut app = MailApp::new(Session::at(mailcraft_engine::sample::mailbox(NOW, 0), NOW, 0), Services::default()); app.autosave = false; app } /// A run starts on Home, and File opens on Info every time, as in Outlook: where the owner /// last was is neither kept in the preferences nor while File is closed (#119). #[test] fn the_ribbon_opens_on_home_and_file_on_info() { let mut a = app(); a.execute("ui.tab", json!({"tab": "View"})).unwrap(); a.execute("ui.backstage", json!({"value": true, "page": "options"})).unwrap(); let saved: crate::UiState = serde_json::from_value(serde_json::to_value(a.prefs()).unwrap()).unwrap(); let mut b = app(); b.apply_prefs(saved); assert_eq!((b.ui.tab.as_str(), b.ui.backstage_page.as_str(), b.ui.backstage), ("Home", "info", false)); // Within a run: a tab stays chosen, File's page doesn't once File is closed. b.execute("ui.tab", json!({"tab": "View"})).unwrap(); assert_eq!(b.ui.tab, "View"); b.execute("ui.backstage", json!({"value": true, "page": "options"})).unwrap(); assert_eq!(b.ui.backstage_page, "options"); // Another page while it is open is kept. b.execute("ui.backstage", json!({"value": true, "page": "signatures"})).unwrap(); assert_eq!(b.ui.backstage_page, "signatures"); for open in [json!({"value": true}), json!({})] { b.execute("ui.backstage", json!({"value": false})).unwrap(); assert_eq!(b.execute("ui.backstage", open).unwrap()["page"], "info"); } b.execute("ui.backstage", json!({"value": true, "page": "options"})).unwrap(); b.execute("ui.tab", json!({"tab": "Home"})).unwrap(); b.execute("ui.tab", json!({"tab": "File"})).unwrap(); assert_eq!((b.ui.backstage, b.ui.backstage_page.as_str()), (true, "info")); } fn window(app: MailApp, width: f32) -> Window { let mut harness = egui_kittest::Harness::builder().with_accessibility_check(false).allow_missing_glyphs().with_size(vec2(width, 700.0)).build_ui_state( |ui, app: &mut MailApp| { let ctx = ui.ctx().clone(); app.logic(&ctx); app.ui(ui); }, app, ); harness.run_steps(4); // The sample has reminders due, and their window would lie over the ribbon. let _ = harness.state_mut().execute("ui.dismissReminder", json!({"all": true})); harness.run_steps(3); harness } fn click(harness: &mut Window, pos: egui::Pos2) { harness.event(egui::Event::PointerMoved(pos)); harness.step(); for pressed in [true, false] { harness.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }); harness.step(); } harness.run_steps(3); } /// What brings up every tab of every module, and the tab a message being written has. fn every_tab() -> Vec<(String, Vec<(&'static str, Value)>)> { let mut out = Vec::new(); for module in ["view.mail", "view.calendar", "view.people", "view.tasks"] { for tab in ["Home", "Send / Receive", "Folder", "View", "Help"] { out.push((format!("{module} › {tab}"), vec![(module, json!({})), ("ui.tab", json!({"tab": tab}))])); } } for tab in ["Message", "Insert", "Format Text", "Review"] { out.push(( tab.to_string(), vec![("view.mail", json!({})), ("mail.first", json!({})), ("mail.reply", json!({})), ("ui.tab", json!({"tab": tab}))], )); } out } /// Every label, tooltip name and group title of every tab is in the template the catalogues /// are made from (`cargo xtask i18n`), as written, a large button's line break and all: a /// control the extraction missed would stay English in every language. #[test] fn every_ribbon_text_is_in_the_template() { let template = mailcraft_i18n::po::parse(include_str!("../../i18n/po/messages.pot")); let known: std::collections::BTreeSet = template.entries.iter().filter(|e| e.context.is_none()).map(|e| e.id.clone()).collect(); let mut a = app(); let mut missing = std::collections::BTreeSet::new(); for (_, commands) in every_tab() { for (command, params) in commands { a.run(command, params).unwrap(); } let tab = describe(&a); for group in &tab.groups { let texts = std::iter::once(group.title).chain(group.items.iter().flat_map(|i| [i.label, i.tip])); missing.extend(texts.filter(|s| !s.is_empty() && !known.contains(*s))); } } assert!(missing.is_empty(), "not in messages.pot (run `cargo xtask i18n`): {missing:?}"); } /// One description feeds both layouts: every control has a key of its own, an icon that is /// drawn and a command the program knows, and a place in the classic groups and in the row. #[test] fn every_control_has_its_place_in_both_layouts() { let mut a = app(); let mut seen = 0; for (name, commands) in every_tab() { for (command, params) in commands { a.run(command, params).unwrap(); } let tab = describe(&a); let items: Vec<&Item> = tab.items().collect(); assert!(!items.is_empty(), "{name}"); for item in &items { let key = item.key; assert_eq!(items.iter().filter(|other| other.key == key).count(), 1, "{name}: two controls are called {key}"); assert!(icons::NAMES.contains(&item.icon), "{name}: {key} has no drawing for \"{}\"", item.icon); assert!(!item.label.is_empty() && item.rank >= 1, "{name}: {key}"); if let Some((command, _)) = &item.command { let known = a.session.registry.get(command).is_some() || crate::UI_COMMANDS.iter().any(|c| c.0 == *command); assert!(known, "{name}: {key} runs {command}, which is no command"); } match item.size { // Only there to gather others in the simplified row: nothing of its own to do. Size::Hidden => { assert!(item.command.is_none() && item.menu.is_none(), "{name}: {key}"); assert!(items.iter().any(|other| other.under == Some(key)), "{name}: nothing is under {key}"); } Size::Big | Size::Small if item.pending => { assert!(item.command.is_none() && item.menu.is_none(), "{name}: {key} is pending and does nothing") } Size::Big | Size::Small => assert!(item.command.is_some() != item.menu.is_some(), "{name}: {key} runs a command or opens a menu"), } if let Some(host) = item.under { let host = items.iter().find(|other| other.key == host).unwrap_or_else(|| panic!("{name}: {key} is under {host}, which isn't there")); assert!(host.under.is_none(), "{name}: {key} is under {}, which is under something itself", host.key); } } // The simplified row has every control: as a button, or under one. let buttons = row(&tab); assert_eq!(buttons.len() + buttons.iter().map(|b| b.drops.len()).sum::(), items.len(), "{name}"); assert!(buttons.windows(2).all(|pair| pair[0].item.section <= pair[1].item.section), "{name}: the row is in its stretches' order"); assert!(buttons.iter().all(|b| b.item.command.is_some() || b.has_drop() || b.item.pending), "{name}: a button does something"); // The classic layout has all but what is only there for the row. assert!(tab.groups.iter().all(|group| !group.title.is_empty() && !group.items.is_empty()), "{name}"); seen += 1; } assert_eq!(seen, 24); } /// Mail › Home in the order the simplified row has it, with its split buttons. #[test] fn the_mail_row_is_in_order() { let a = app(); let tab = describe(&a); let buttons = row(&tab); let keys: Vec<&str> = buttons.iter().map(|b| b.item.key).collect(); assert_eq!( keys.iter().take(12).copied().collect::>(), [ "mail.new", "mail.delete", "mail.archive", "moveMessages", "mail.reply", "mail.replyAll", "mail.forward", "mail.toggleRead", "categorize", "followUp", "rules", "filter" ] ); let sections: Vec = buttons.iter().take(12).map(|b| b.item.section).collect(); assert_eq!(sections, [0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4]); let button = |key: &str| buttons.iter().find(|b| b.item.key == key).unwrap(); // New Email and Delete run their command and open a menu; Move only opens one; Archive only runs. assert!(button("mail.new").is_split() && button("mail.new").drops.iter().map(|d| d.key).eq(["newItems"])); assert!(button("mail.delete").is_split() && button("mail.delete").drops.iter().map(|d| d.key).eq(["junk", "mail.deletePermanently"])); assert!(!button("moveMessages").is_split() && button("moveMessages").has_drop()); assert!(!button("mail.archive").has_drop()); assert_eq!(button("mail.replyAll").item.name(), "Reply All"); // Calendar › Home: the new items, then today and the views. let mut a = app(); a.execute("view.calendar", json!({})).unwrap(); let tab = describe(&a); let buttons = row(&tab); let keys: Vec<&str> = buttons.iter().map(|b| b.item.key).take(8).collect(); assert_eq!( keys, ["calendar.new", "calendar.newMeeting", "view.today", "view.next7Days", "view.day", "view.workWeek", "view.week", "view.month"] ); assert_eq!(buttons.iter().take(8).map(|b| b.item.section).collect::>(), [0, 0, 1, 1, 2, 2, 2, 2]); // New Appointment has the other new items under its ▾; the four views keep their // names as long as there is room (they aren't told from one another by their icons // alone), and the one in use is marked. let button = |key: &str| buttons.iter().find(|b| b.item.key == key).unwrap(); assert!(button("calendar.new").is_split() && !button("calendar.newMeeting").has_drop()); for view in ["view.day", "view.workWeek", "view.week", "view.month"] { assert!(!button(view).item.plain && button(view).item.checked == (view == "view.week"), "{view}"); } assert_eq!((button("view.workWeek").item.name(), button("view.next7Days").item.name()), ("Work Week".to_string(), "Next 7 Days".to_string())); assert!(button("view.day").item.rank < button("view.today").item.rank && button("view.today").item.rank < button("view.next7Days").item.rank); // Back, Forward and Go to Date are under Today's ▾ (the calendar's own header has them too). assert!( button("view.today").is_split() && button("view.today").drops.iter().map(|d| d.key).eq(["view.previous", "view.next", "view.goToDate"]) ); // What is done with an appointment is in the row while one is selected, and the // answers to a meeting while it is somebody else's. let has = |a: &MailApp, key: &str| describe(a).items().any(|item| item.key == key); assert!(!has(&a, "calendar.edit") && !has(&a, "calendar.delete") && !has(&a, "calendar.accept") && has(&a, "file.exportCalendar")); let event = |a: &MailApp, title: &str| a.session.mailbox.events.values().find(|e| e.title.starts_with(title)).map(|e| e.id).unwrap(); a.execute("calendar.select", json!({"id": event(&a, "Lunch with Dev")})).unwrap(); assert!(has(&a, "calendar.edit") && has(&a, "calendar.delete") && has(&a, "showAs") && has(&a, "categorize") && !has(&a, "calendar.decline")); a.execute("calendar.select", json!({"id": event(&a, "Q4 roadmap")})).unwrap(); assert!(has(&a, "calendar.edit") && has(&a, "calendar.accept") && has(&a, "calendar.tentative") && has(&a, "calendar.decline")); let tab = describe(&a); let sections: Vec<(&str, u8)> = row(&tab).iter().map(|b| (b.item.key, b.item.section)).filter(|(_, section)| *section >= 3).collect(); assert_eq!(sections.first().copied(), Some(("calendar.edit", 3))); assert_eq!(sections.last().copied(), Some(("file.exportCalendar", 5))); a.execute("calendar.select", json!({"id": null})).unwrap(); // The View tab has the calendar's time scale while the calendar is in front. a.execute("ui.tab", json!({"tab": "View"})).unwrap(); assert!(describe(&a).items().any(|item| item.key == "timeScale" && item.menu == Some(Menu::TimeScale))); a.execute("view.mail", json!({})).unwrap(); assert!(!describe(&a).items().any(|item| item.key == "timeScale")); a.execute("ui.tab", json!({"tab": "Home"})).unwrap(); // Tasks › Home gathers the five due dates under one button. a.execute("view.tasks", json!({})).unwrap(); let tab = describe(&a); let buttons = row(&tab); let follow_up = buttons.iter().find(|b| b.item.key == "followUp").unwrap(); assert_eq!(follow_up.drops.len(), 5); assert!(follow_up.item.command.is_none() && !follow_up.is_split()); } /// Calendar › View has the four views, the one in use marked, in place of the messages' /// sorting and preview, which mean nothing there; Mail › View keeps those and has no views. #[test] fn the_calendar_view_tab_has_its_views() { let mail_only = ["view.conversations", "preview", "arrangeBy", "view.reverseSort"]; let views = ["view.day", "view.workWeek", "view.week", "view.month"]; let checked_view = |a: &MailApp| -> Vec<&str> { describe(a).items().filter(|item| views.contains(&item.key) && item.checked).map(|item| item.key).collect() }; let mut a = app(); a.execute("view.calendar", json!({})).unwrap(); a.execute("ui.tab", json!({"tab": "View"})).unwrap(); let tab = describe(&a); assert_eq!(tab.groups.iter().map(|g| g.title).collect::>(), ["Layout", "Arrangement", "Calendar", "Window"]); let arrangement: Vec<(&str, bool, u8, u8)> = tab.groups[1].items.iter().map(|item| (item.key, item.checked, item.section, item.rank)).collect(); assert_eq!(arrangement, [("view.day", false, 1, 2), ("view.workWeek", false, 1, 2), ("view.week", true, 1, 2), ("view.month", false, 1, 2)]); // The calendar's own group is as it was. let calendar: Vec<&str> = tab.groups[2].items.iter().map(|item| item.key).collect(); assert_eq!(calendar, ["timeScale", "view.overlay", "view.sideBySide"]); assert!(!tab.items().any(|item| mail_only.contains(&item.key))); // Each view, pressed, is the one marked. for view in views { a.execute(view, json!({})).unwrap(); assert_eq!(checked_view(&a), [view]); } a.execute("view.mail", json!({})).unwrap(); let tab = describe(&a); assert!(!tab.items().any(|item| views.contains(&item.key))); assert!(mail_only.iter().all(|key| tab.items().any(|item| item.key == *key))); } /// Labels go before buttons, the plain before the others, the least important first; the /// first-rank button keeps its label until all the rest is behind `…`. #[test] fn the_row_gives_way_in_order() { let item = |key: &'static str, section: u8, rank: u8, plain: bool| { let item = Item::big("mail", key, key, json!({})).at(section, rank); if plain { item.plain() } else { item } }; let tab = Tab::of(vec![g("All", vec![item("a", 0, 1, false), item("b", 1, 1, true), item("c", 1, 3, false), item("d", 2, 5, false)])]); let buttons = row(&tab); let width = |_: usize, labelled: bool| if labelled { 100.0 } else { 40.0 }; let at = |available: f32| plan(&buttons, &width, available); let all = |labels: [bool; 4]| labels.iter().copied().enumerate().collect::>(); // 100 + rule + 100 + gap + 100 + rule + 100. let full = 400.0 + 2.0 * RULE_GAP + BUTTON_GAP; assert_eq!(at(full), Plan { shown: all([true, true, true, true]), more: vec![] }); assert_eq!(at(10_000.0).shown, at(full).shown); // The plain one's label first, then the others' from the least important. assert_eq!(at(full - 1.0).shown, all([true, false, true, true])); assert_eq!(at(full - 61.0).shown, all([true, false, true, false])); assert_eq!(at(full - 121.0).shown, all([true, false, false, false])); // Then buttons go behind `…`, the least important first; the first one keeps its label. assert_eq!(at(full - 181.0), Plan { shown: vec![(0, true), (1, false), (2, false)], more: vec![3] }); let three = 100.0 + RULE_GAP + 40.0 + BUTTON_GAP + 40.0 + BUTTON_GAP + MORE_W; assert_eq!(at(three - 1.0), Plan { shown: vec![(0, true), (1, false)], more: vec![2, 3] }); // Then the first-rank label, and last the first-rank buttons, from the end of the row. let two = 100.0 + RULE_GAP + 40.0 + BUTTON_GAP + MORE_W; assert_eq!(at(two - 1.0), Plan { shown: vec![(0, false), (1, false)], more: vec![2, 3] }); assert_eq!(at(two - 61.0), Plan { shown: vec![(0, false)], more: vec![1, 2, 3] }); assert_eq!(at(40.0), Plan { shown: vec![], more: vec![0, 1, 2, 3] }); assert_eq!(at(-5.0).more.len(), 4); assert_eq!(plan(&[], &width, 100.0), Plan::default()); // At any width: every button is in the row or behind `…`, the row fits, and a narrower // window never shows a button or a label that a wider one doesn't. let mut wider: Option = None; for available in (0..=450).rev().map(|w| w as f32) { let p = at(available); let mut places: Vec = p.shown.iter().map(|(i, _)| *i).chain(p.more.iter().copied()).collect(); places.sort_unstable(); assert_eq!(places, [0, 1, 2, 3], "{available}"); let state: Vec<(bool, bool)> = (0..4).map(|i| p.shown.iter().find(|(place, _)| *place == i).map_or((false, false), |(_, labelled)| (true, *labelled))).collect(); assert!(p.shown.is_empty() || row_width(&buttons, &state, &width) <= available, "{available}: {p:?}"); if let Some(wider) = &wider { for (i, labelled) in &p.shown { let before = wider.shown.iter().find(|(place, _)| place == i); assert!(before.is_some_and(|(_, was)| *was || !*labelled), "{available}: {p:?} after {wider:?}"); } } wider = Some(p); } } /// What is on screen of a tab's row: checks that it is all inside the band, in order and not /// over one another, and that what isn't on screen is behind `…`. Returns the keys behind `…`. fn check_row(harness: &Window, name: &str) -> Vec<&'static str> { let app = harness.state(); let tab = describe(app); let buttons = row(&tab); let band = app.hit.rect("ribbonBand", 0).unwrap_or_else(|| panic!("{name}: no band")); let more = behind_more(&harness.ctx); let inside = |r: Rect| r.min.x >= band.min.x - 0.5 && r.max.x <= band.max.x + 0.5 && r.min.y >= band.min.y - 0.5 && r.max.y <= band.max.y + 0.5; let mut end = band.min.x; for b in &buttons { let key = b.item.key; let Some(r) = app.hit.rect("ribbon", hit_id(key)) else { assert!(more.contains(&key), "{name}: {key} is neither in the row nor behind …"); continue; }; assert!(!more.contains(&key), "{name}: {key} is in the row and behind …"); assert!(inside(r), "{name}: {key} at {r:?} is outside the band {band:?}"); assert!(r.min.x >= end - 0.5 && r.width() >= ICON, "{name}: {key} at {r:?} is over the button before it (which ends at {end})"); end = r.max.x; // Its `▾` half is beside it when it has one of its own. match app.hit.rect("ribbonMenu", hit_id(key)) { Some(drop) => { assert!(b.is_split() && inside(drop) && (drop.min.x - end).abs() < 0.5, "{name}: {key} ▾ at {drop:?}"); end = drop.max.x; } None => assert!(!b.is_split(), "{name}: {key} has no ▾"), } } let mode = app.hit.rect("ribbonMode", 0).unwrap_or_else(|| panic!("{name}: no layout button")); assert!(inside(mode) && mode.min.x >= end - 0.5, "{name}: the layout button at {mode:?}"); match app.hit.rect("ribbonMore", 0) { Some(r) => assert!(!more.is_empty() && inside(r) && r.min.x >= end - 0.5 && r.max.x <= mode.min.x + 0.5, "{name}: … at {r:?}"), None => assert!(more.is_empty(), "{name}: {more:?} are behind a … that isn't there"), } more } /// Every tab of every module in one row at 1200, 1000 and 800 wide: nothing is cut off and /// nothing scrolls; what doesn't fit is behind `…`. #[test] fn the_simplified_row_fits_at_every_width() { assert_eq!(crate::UiState::default().ribbon_mode, Mode::Simplified); for width in [1200.0, 1000.0, 800.0] { let mut harness = window(app(), width); let mut most = 0; for (name, commands) in every_tab() { for (command, params) in commands { harness.state_mut().run(command, params).unwrap(); } harness.run_steps(3); let name = format!("{name} at {width}"); let more = check_row(&harness, &name); most = most.max(more.len()); // What a tab is for stays in the row, with its label (what is still to be built // gives way first). let first = row(&describe(harness.state())).iter().find(|b| !b.item.pending).map(|b| b.item.key).unwrap(); assert!(harness.state().hit.rect("ribbon", hit_id(first)).is_some_and(|r| r.width() > 60.0), "{name}: {first}"); // The band is one row high, and the panes start right under it. let band = harness.state().hit.rect("ribbonBand", 0).unwrap(); assert!((band.height() - BAND_H).abs() < 0.5, "{name}: {band:?}"); } // Mail › Home has the most to show: all of it at 1200, some of it behind … at 800. harness.state_mut().run("compose.discard", json!({})).ok(); harness.state_mut().run("ui.tab", json!({"tab": "Home"})).unwrap(); harness.run_steps(3); let more = check_row(&harness, "mail home"); match width as u32 { 1200 => assert!(more.is_empty(), "{more:?}"), 800 => assert!( more.contains(&"mail.findRelated") && more.contains(&"mail.findFromSender") && !more.contains(&"mail.delete") && most >= more.len(), "{more:?}" ), _ => {} } } } /// The buttons of the row do what they say: the main part runs the command, a `▾` opens its /// menu, and what is behind `…` runs from there. #[test] fn the_row_runs_its_commands_and_so_does_what_is_behind_more() { let mut harness = window(app(), 800.0); harness.state_mut().run("mail.next", json!({})).unwrap(); harness.run_steps(3); let focus = harness.state().session.sel.focus().unwrap(); let message = |h: &Window| h.state().session.mailbox.message(focus).cloned().unwrap(); let at = |h: &Window, kind: &str, key: &str| h.state().hit.rect(kind, hit_id(key)).unwrap_or_else(|| panic!("no {kind} {key}")).center(); // The main part: Unread/Read on the message in view. let read = message(&harness).read; let pos = at(&harness, "ribbon", "mail.toggleRead"); click(&mut harness, pos); assert_eq!(message(&harness).read, !read); // Behind `…`: Pin, Related and From Sender are there, and run. let more = check_row(&harness, "mail home at 800"); assert!(more.contains(&"mail.pin") && more.contains(&"mail.findRelated") && more.contains(&"mail.findFromSender"), "{more:?}"); assert!(harness.query_by_label("Pin").is_none(), "the menu is shut"); let dots = harness.state().hit.rect("ribbonMore", 0).unwrap().center(); click(&mut harness, dots); for key in &more { let item = describe(harness.state()).items().find(|item| item.key == *key).cloned().unwrap(); assert!(harness.query_all_by_label_contains(&item.name()).next().is_some(), "{key} isn't in the menu behind …"); } let pinned = message(&harness).pinned; harness.get_by_label("Pin").click(); harness.run_steps(3); assert_eq!(message(&harness).pinned, !pinned); assert!(harness.query_by_label("Pin").is_none(), "the menu shuts when something is chosen"); click(&mut harness, dots); harness.get_by_label("Related").click(); harness.run_steps(3); assert!(harness.state().session.view.search.starts_with("subject:"), "{:?}", harness.state().session.view.search); harness.state_mut().execute("view.clearSearch", json!({})).unwrap(); harness.state_mut().execute("mail.select", json!({"id": focus})).unwrap(); harness.run_steps(3); let sender = mailcraft_model::search::keyword_value(message(&harness).from.email.trim()); click(&mut harness, dots); harness.get_by_label("From Sender").click(); harness.run_steps(3); assert_eq!(harness.state().session.view.search, format!("from:{sender}")); harness.state_mut().execute("view.clearSearch", json!({})).unwrap(); harness.state_mut().execute("mail.select", json!({"id": focus})).unwrap(); harness.run_steps(3); // A `▾`: New Email's lists the other new things; Delete's, what else gets rid of a message. let pos = at(&harness, "ribbonMenu", "mail.new"); click(&mut harness, pos); assert!(harness.state().session.compose.is_none(), "the ▾ doesn't start a message"); harness.get_by_label_contains("Folder…").click(); harness.run_steps(3); assert_eq!(harness.state().dialog.as_ref().map(|d| d.name()), Some("folder")); harness.state_mut().execute("ui.closeDialog", json!({})).unwrap(); harness.run_steps(2); let junk = harness.state().session.mailbox.folders.iter().find(|f| f.kind == FolderKind::Junk).map(|f| f.id).unwrap(); assert_ne!(message(&harness).folder, junk); let pos = at(&harness, "ribbonMenu", "mail.delete"); click(&mut harness, pos); // Its Junk is a menu of its own (#504): Move to Junk is in it. harness.get_by_role_and_label(egui::accesskit::Role::Button, "Junk").click(); harness.run_steps(3); harness.get_by_label_contains("Move to Junk").click(); harness.run_steps(3); assert_eq!(message(&harness).folder, junk); // And the main part of that button: New Email starts a message, in the reading pane, as a // reply does (#286). let pos = at(&harness, "ribbon", "mail.new"); click(&mut harness, pos); let compose = harness.state().session.compose_id().expect("a message"); assert!(harness.state().windows.of_compose(compose).is_none()); assert_eq!(crate::windows::compose_window::pane_compose(harness.state()), Some(compose)); assert_eq!(harness.state().ui.tab, "Message"); } /// The layout is chosen at the right end of the band, in View and by command; it is kept with /// the settings, and settings that say nothing of it (or nonsense) mean the simplified one. #[test] fn the_layout_is_chosen_and_kept() { let mut harness = window(app(), 1200.0); assert_eq!(harness.state().ui.ribbon_mode, Mode::Simplified); let simple = harness.state().hit.rect("ribbonBand", 0).unwrap(); let button = harness.state().hit.rect("ribbonMode", 0).unwrap().center(); click(&mut harness, button); assert!(harness.query_all_by_label_contains("Simplified Ribbon").next().is_some()); harness.get_by_label_contains("Classic Ribbon").click(); harness.run_steps(3); assert_eq!(harness.state().ui.ribbon_mode, Mode::Classic); let classic = harness.state().hit.rect("ribbonBand", 0).unwrap(); assert!(classic.height() > simple.height() + 30.0, "{simple:?} -> {classic:?}"); // Kept with the settings. let saved = serde_json::to_value(harness.state().prefs()).unwrap(); assert_eq!(saved["ribbonMode"], "classic"); let restored: crate::UiState = serde_json::from_value(saved).unwrap(); assert_eq!(restored.ribbon_mode, Mode::Classic); let old: crate::UiState = serde_json::from_value(json!({"tab": "Home"})).unwrap(); assert_eq!(old.ribbon_mode, Mode::Simplified); let odd: crate::UiState = serde_json::from_value(json!({"ribbonMode": "sideways", "tab": "View"})).unwrap(); assert_eq!((odd.ribbon_mode, odd.tab.as_str()), (Mode::Simplified, "View")); // By command, and from the button again. let a = harness.state_mut(); assert!(a.enabled("ui.ribbonMode")); assert!(a.execute("ui.ribbonMode", json!({"value": "sideways"})).is_err() && a.execute("ui.ribbonMode", json!({})).is_err()); assert_eq!(a.ui.ribbon_mode, Mode::Classic); assert_eq!(a.execute("ui.ribbonMode", json!({"value": "Simplified"})).unwrap()["value"], "simplified"); assert_eq!(a.execute("ui.ribbonMode", json!({"value": "classic"})).unwrap()["value"], "classic"); harness.run_steps(3); let button = harness.state().hit.rect("ribbonMode", 0).unwrap().center(); click(&mut harness, button); harness.get_by_label_contains("Simplified Ribbon").click(); harness.run_steps(3); assert_eq!(harness.state().ui.ribbon_mode, Mode::Simplified); // View lists it too. harness.state_mut().run("ui.tab", json!({"tab": "View"})).unwrap(); assert!(describe(harness.state()).items().any(|item| item.menu == Some(Menu::RibbonLayout))); } /// #123: there is room between the tabs and the ribbon in both layouts, and in the classic one /// between the lowest line of a large button's label and the group's name under it. #[test] fn the_ribbon_has_room_under_the_tabs_and_over_the_group_names() { let mut harness = window(app(), 2400.0); for mode in ["classic", "simplified"] { harness.state_mut().execute("ui.ribbonMode", json!({"value": mode})).unwrap(); for (name, commands) in every_tab() { for (command, params) in commands { harness.state_mut().run(command, params).unwrap(); } harness.run_steps(3); let name = format!("{name} ({mode})"); let app = harness.state(); let band = app.hit.rect("ribbonBand", 0).unwrap(); let strip = app.hit.rect("ribbonTab", hit_id("Home")).unwrap(); assert!(band.min.y - strip.max.y >= 4.0, "{name}: tabs end at {}, the ribbon starts at {}", strip.max.y, band.min.y); if mode != "classic" { continue; } let mut checked = 0; for group in &describe(app).groups { let Some(title) = app.hit.rect("ribbonGroup", hit_id(group.title)) else { continue }; assert!(title.max.y <= band.max.y - 2.0, "{name}: {} at {title:?} in {band:?}", group.title); for item in group.items.iter().filter(|item| item.size == Size::Big) { let label = app.hit.rect("ribbonLabel", hit_id(item.key)).unwrap_or_else(|| panic!("{name}: {} has no label", item.key)); let gap = title.min.y - label.max.y; // 2 pt, not 4: Windows draws the label half a point taller than Linux does. assert!(gap >= 2.0, "{name}: {}'s label ends {gap} over {}", item.key, group.title); checked += 1; } } assert!(checked > 0 || name.contains("Help"), "{name}: no large buttons were measured"); } } } /// The classic layout is what it was: every control in its group, large buttons the height of /// the band's content side by side, small ones three to a column, in the order described. #[test] fn the_classic_layout_sets_every_control_in_its_group() { let mut harness = window(app(), 2400.0); harness.state_mut().execute("ui.ribbonMode", json!({"value": "classic"})).unwrap(); for (name, commands) in every_tab() { for (command, params) in commands { harness.state_mut().run(command, params).unwrap(); } harness.run_steps(3); let app = harness.state(); let tab = describe(app); let band = app.hit.rect("ribbonBand", 0).unwrap(); assert!((band.height() - (CONTENT_H + LABEL_H + 10.0)).abs() < 0.5, "{name}: {band:?}"); assert!(app.hit.rect("ribbonMore", 0).is_none() && app.hit.rect("ribbonMode", 0).is_some(), "{name}"); let mut end = band.min.x; for group in &tab.groups { let mut column: Vec = Vec::new(); for item in &group.items { let at = app.hit.rect("ribbon", hit_id(item.key)); match item.size { Size::Hidden => assert!(at.is_none(), "{name}: {} is drawn", item.key), Size::Big => { let r = at.unwrap_or_else(|| panic!("{name}: {} isn't drawn", item.key)); assert!((r.height() - CONTENT_H).abs() < 0.5 && r.width() >= 46.0, "{name}: {} at {r:?}", item.key); assert!(r.min.x >= end - 0.5 && r.max.x <= band.max.x, "{name}: {} at {r:?} after {end}", item.key); end = r.max.x; column.clear(); } Size::Small => { let r = at.unwrap_or_else(|| panic!("{name}: {} isn't drawn", item.key)); assert!((r.height() - 22.0).abs() < 0.5, "{name}: {} at {r:?}", item.key); if column.len() == 3 { column.clear(); } match column.last() { // Under the one before it, in the same column. Some(above) => { assert!((r.min.x - above.min.x).abs() < 0.5 && r.min.y >= above.max.y - 0.5, "{name}: {} at {r:?}", item.key) } // A new column, after what came before. None => { assert!(r.min.x >= end - 0.5, "{name}: {} at {r:?} after {end}", item.key); } } column.push(r); end = end.max(r.max.x); } } } } } // Mail › Home, group by group, as the classic ribbon has always had it. let a = app(); let tab = describe(&a); let groups: Vec<(&str, Vec<&str>)> = tab.groups.iter().map(|g| (g.title, g.items.iter().filter(|i| i.size != Size::Hidden).map(|i| i.label).collect())).collect(); assert_eq!( groups, [ ("New", vec!["New\nEmail", "New\nItems"]), ("Delete", vec!["Delete", "Archive", "Junk", "Delete Permanently"]), ( "Respond", vec!["Reply", "Reply\nAll", "Forward", "Forward as Attachment", "Reply and Delete", "View Source", "Meeting", "Add Sender"] ), ("Move", vec!["Move", "Rules", "Resend Message"]), ("Tags", vec!["Unread/\nRead", "Categorize", "Follow\nUp", "Pin"]), ("Find", vec!["Filter\nEmail", "Related", "From Sender"]), ("Send/Receive", vec!["Send/Receive\nAll Folders"]), ] ); } /// The folder menu with a search box, drawn on its own: the app, and the folder chosen. type Picker = egui_kittest::Harness<'static, (MailApp, Option)>; fn picker(app: MailApp) -> Picker { let mut h = egui_kittest::Harness::builder().with_accessibility_check(false).allow_missing_glyphs().with_size(vec2(400.0, 500.0)).build_ui_state( |ui, (app, picked): &mut (MailApp, Option)| { folder_menu(ui, app, |_, id| *picked = Some(id)); }, (app, None), ); h.run_steps(3); h } fn type_into(h: &mut Picker, text: &str) { h.event(egui::Event::Text(text.to_string())); h.run_steps(3); } fn press(h: &mut Picker, key: egui::Key) { h.key_press(key); h.run_steps(3); } fn folder_row(name: &str) -> FolderRow { FolderRow { id: 1, name: name.to_string(), path: name.to_string(), depth: 0, fold: mailcraft_model::words::fold(name), account: String::new(), heading: None, } } /// Typing narrows the list to the folders whose name holds it, any part, whatever the case /// and accents; nothing typed shows all (#74). #[test] fn folder_search_matches_any_part_ignoring_case_and_accents() { let list = [folder_row("Inbox"), folder_row("Café Receipts"), folder_row("Projects"), folder_row("Archive 2026")]; assert_eq!(folder_matches(&list, ""), [0, 1, 2, 3]); assert_eq!(folder_matches(&list, " "), [0, 1, 2, 3]); assert_eq!(folder_matches(&list, "BOX"), [0]); assert_eq!(folder_matches(&list, "cafe"), [1]); assert_eq!(folder_matches(&list, "é rec"), [1]); assert_eq!(folder_matches(&list, "202"), [3]); assert!(folder_matches(&list, "zzz").is_empty()); } /// Hostile or enormous text asks for nothing and never panics. #[test] fn folder_search_survives_hostile_text() { let list = [folder_row("Inbox"), folder_row("Ünï")]; let long = "é".repeat(100_000); for q in [long.as_str(), "\u{0}\u{7f}\u{202e}", "\u{1F600}\u{200d}\u{1F600}", "%s{}[]\\", "\n\r\t", "ß", "\u{301}"] { let _ = folder_matches(&list, q); } assert!(folder_matches(&list, &long).is_empty()); assert!(folder_matches(&[], "x").is_empty()); // Through the window as well: typed, then keys, with nothing to choose. let mut h = picker(app()); type_into(&mut h, &"\u{1F600}x".repeat(500)); for key in [egui::Key::ArrowDown, egui::Key::ArrowUp, egui::Key::Enter, egui::Key::Escape] { press(&mut h, key); } assert_eq!(h.state().1, None); } /// The box has the keyboard when the menu opens: typing filters, Enter chooses. #[test] fn folder_search_is_typed_into_and_chosen_by_keyboard() { let a = app(); let sent = { let mb = &a.session.mailbox; let account = mb.default_account().map(|x| x.id).unwrap(); mb.folder_of_kind(account, mailcraft_model::FolderKind::Sent).unwrap() }; let mut h = picker(a); assert!(h.query_by_label_contains("Drafts").is_some()); type_into(&mut h, "SENT"); assert!(h.query_by_label_contains("Drafts").is_none()); press(&mut h, egui::Key::Enter); assert_eq!(h.state().1, Some(sent)); } /// Nothing matching says so, and Enter chooses nothing. #[test] fn folder_search_with_no_match_says_so() { let mut h = picker(app()); type_into(&mut h, "qqqqzz"); assert!(h.query_by_label_contains("No folders match").is_some()); press(&mut h, egui::Key::Enter); assert_eq!(h.state().1, None); } /// Down moves to the next match, and Escape clears the search (so the full list is back). #[test] fn folder_search_arrows_move_and_escape_clears() { let mut probe = picker(app()); type_into(&mut probe, "e"); press(&mut probe, egui::Key::Enter); let first = probe.state().1; let mut h = picker(app()); type_into(&mut h, "e"); press(&mut h, egui::Key::ArrowDown); press(&mut h, egui::Key::Enter); assert!(h.state().1.is_some()); assert_ne!(h.state().1, first); let mut h = picker(app()); type_into(&mut h, "sent"); assert!(h.query_by_label_contains("Drafts").is_none()); press(&mut h, egui::Key::Escape); assert!(h.query_by_label_contains("Drafts").is_some()); } }