1
//! What closing a window settles: the form and the bulk delete it started.
2

            
3
use super::App;
4
use crate::route::RouteCtx;
5
use crate::window::WindowId;
6

            
7
impl App {
8
    /// Releases the form and abandons the bulk delete whose replies belong to window `id`. The
9
    /// routes stay, so the replies are discarded as those of a gone window.
10
685
    pub(super) fn settle_window(&mut self, id: WindowId) {
11
685
        let notes = [self.release_form_of(id), self.abandon_bulk_of(id)];
12
685
        let notes: Vec<String> = notes.into_iter().flatten().collect();
13
685
        if !notes.is_empty() {
14
7
            self.set_status(notes.join("; "));
15
678
        }
16
685
        if self.status_owner == Some(id) {
17
            self.status_owner = None;
18
685
        }
19
685
    }
20

            
21
19
    fn targets(&self, request_id: i64, id: WindowId) -> bool {
22
19
        let route = self.pending_routes.get(&request_id);
23
19
        route.is_some_and(|route| route.target == Some(id))
24
19
    }
25

            
26
685
    fn release_form_of(&mut self, id: WindowId) -> Option<String> {
27
685
        let request_id = self.pending_form.as_ref()?.request_id;
28
12
        if !self.targets(request_id, id) {
29
10
            return None;
30
2
        }
31
2
        self.pending_form = None;
32
2
        Some("window closed; the outcome of its form is not shown".to_string())
33
685
    }
34

            
35
685
    fn abandon_bulk_of(&mut self, id: WindowId) -> Option<String> {
36
685
        let started_here = self.pending_routes.iter().any(|(request_id, route)| {
37
49
            matches!(route.ctx, RouteCtx::BulkDelete { .. }) && self.targets(*request_id, id)
38
49
        });
39
685
        if started_here {
40
5
            return self.bulk.abandon();
41
680
        }
42
680
        None
43
685
    }
44
}