Lines
93.88 %
Functions
66.67 %
Branches
100 %
//! Loading and refreshing windows: each window of a kind is treated alike.
use super::App;
use crate::view::ViewId;
use crate::window::WindowId;
impl App {
/// Fetches what window `window` shows, if it has not been fetched.
pub(super) fn load_window(&mut self, window: WindowId) {
let Some(view) = self.win_by(window).map(|win| &win.view) else {
return;
};
if !view.idle() {
}
match view.kind() {
ViewId::Accounts | ViewId::Transactions | ViewId::Commodities => {
self.ensure_list_loaded(window);
ViewId::Config => self.fetch_config(window),
ViewId::SshKeys => self.fetch_ssh_keys(window),
ViewId::Tags => self.fetch_tags(window),
ViewId::Templates => self.fetch_templates(window),
ViewId::Scripts => self.fetch_scripts(window),
ViewId::Reports | ViewId::Console | ViewId::Viewer => {}
/// Fetches again what every window of `kind` shows, whether or not its dialog's window is
/// still there.
pub fn refresh_windows(&mut self, kind: ViewId) {
if kind == ViewId::Transactions {
self.refetch_account_balances();
self.refresh_details();
let windows = self.window_ids(kind);
if kind == ViewId::Reports {
return self.rerun_reports(windows);
for window in windows {
self.refresh_window(window);
/// Reruns the reports of the windows that have one; says so once when none has.
fn rerun_reports(&mut self, windows: Vec<WindowId>) {
let ran: Vec<WindowId> = windows
.into_iter()
.filter(|window| self.last_report(*window).is_some())
.collect();
if ran.is_empty() {
self.set_status("no report run yet");
for window in ran {
fn refresh_window(&mut self, window: WindowId) {
let Some(view) = self.view_mut(window) else {
if view.loading() {
if view.kind() == ViewId::Reports {
return self.rerun_report(window);
view.invalidate();
self.load_window(window);