Lines
95.65 %
Functions
50 %
Branches
100 %
//! The template keys of the Templates tab.
use crate::app::App;
use crate::form::Form;
use crate::modal::Modal;
use crate::tabs::templates::TemplatesTab;
use crate::view::Tab;
/// What a template key asks for.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TemplateKey {
/// Render the source (stored, or being edited) into a draft.
Test,
/// Start a new transaction from a template picked from a list.
Pick,
}
pub(super) fn apply_tab(app: &mut App, key: TemplateKey) {
match (app.front_kind(), key) {
(Some(Tab::Templates), TemplateKey::Test) => app.test_selected_template(),
(Some(Tab::Transactions), TemplateKey::Pick) => app.pick_template(),
_ => {}
pub(super) fn open_create(app: &mut App) {
app.open_dialog_for(Tab::Templates, Modal::Form(Form::template_create()));
/// Loads the selected template into the edit form; says why when none is selected.
pub(super) fn open_edit_for_selected(app: &mut App) {
match app
.front::<TemplatesTab>()
.and_then(|tab| tab.selected_key().map(str::to_string))
{
Some(id) => app.open_template_edit_async(&id),
None => app.set_status("no template selected"),
/// Confirms deleting the selected template; says why when none is selected.
pub(super) fn confirm_delete_selected(app: &mut App) {
.and_then(|tab| tab.selected_row().cloned())
Some(row) => app.confirm_delete_template(row),