1use crate::app::App;
4use crate::form::Form;
5use crate::modal::Modal;
6use crate::tabs::templates::TemplatesTab;
7use crate::view::Tab;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum TemplateKey {
12 Test,
14 Pick,
16}
17
18pub(super) fn apply_tab(app: &mut App, key: TemplateKey) {
19 match (app.front_kind(), key) {
20 (Some(Tab::Templates), TemplateKey::Test) => app.test_selected_template(),
21 (Some(Tab::Transactions), TemplateKey::Pick) => app.pick_template(),
22 _ => {}
23 }
24}
25
26pub(super) fn open_create(app: &mut App) {
27 app.open_dialog_for(Tab::Templates, Modal::Form(Form::template_create()));
28}
29
30pub(super) fn open_edit_for_selected(app: &mut App) {
32 match app
33 .front::<TemplatesTab>()
34 .and_then(|tab| tab.selected_key().map(str::to_string))
35 {
36 Some(id) => app.open_template_edit_async(&id),
37 None => app.set_status("no template selected"),
38 }
39}
40
41pub(super) fn confirm_delete_selected(app: &mut App) {
43 match app
44 .front::<TemplatesTab>()
45 .and_then(|tab| tab.selected_row().cloned())
46 {
47 Some(row) => app.confirm_delete_template(row),
48 None => app.set_status("no template selected"),
49 }
50}