Lines
97.44 %
Functions
66.67 %
Branches
100 %
//! The windows listed at the end of the Window menu.
use super::App;
use crate::event::Intent;
use crate::window::{Win, WindowId};
impl App {
/// The Window menu's list: the windows by number, the unnumbered ones last in opening order.
pub(super) fn window_entries(&self) -> Vec<(Intent, String)> {
let mut listed: Vec<&Win> = self.windows.iter().collect();
listed.sort_by_key(|win| win.number.unwrap_or(u8::MAX));
listed
.into_iter()
.map(|win| (Intent::RaiseWindow(win.id), self.window_label(win)))
.collect()
}
/// `n Title` for a numbered window, the title alone otherwise.
fn window_label(&self, win: &Win) -> String {
let title = win.view.title(&self.suffix_of(win));
match win.number {
Some(number) => format!("{number} {title}"),
None => title,
/// What the frame of window `id` appends to its title.
pub(crate) fn window_suffix(&self, id: WindowId) -> String {
self.win_by(id)
.map(|win| self.suffix_of(win))
.unwrap_or_default()
/// The ordinal of a later window of its view, when another window is titled the same.
fn suffix_of(&self, win: &Win) -> String {
let title = win.view.title("");
let clash = win.ordinal > 1
&& self
.windows
.iter()
.any(|other| other.id != win.id && other.view.title("") == title);
match clash {
true => format!(" ({})", win.ordinal),
false => String::new(),
/// Raises window `id` and loads it; a window that has closed since the list was drawn is left.
pub(crate) fn raise_listed(&mut self, id: WindowId) {
if self.win_by(id).is_some() {
self.activate_window(id);
/// Raises the window numbered `number`; says so when there is none.
pub(crate) fn select_window_number(&mut self, number: u8) {
let found = self.windows.iter().find(|win| win.number == Some(number));
match found.map(|win| win.id) {
Some(id) => self.activate_window(id),
None => self.set_status(format!("no window {number}")),