Lines
98.21 %
Functions
50 %
Branches
100 %
//! Functions that construct and push overlay modals onto the app's overlay stack.
use crate::tabs::ssh_keys::SshKeysTab;
use crate::tabs::tags::TagsTab;
use forms::FormValues;
use crate::app::App;
use crate::form::Form;
use crate::modal::Modal;
use crate::tabs::config::ConfigTab;
use crate::tabs::list::ListTab;
use crate::view::{Tab, ViewId};
pub(super) fn open_config_set_modal(app: &mut App, args: &[(String, String)]) {
let mut form = Form::config_set();
for (arg, text) in args {
if let Some(field) = form.fields.iter_mut().find(|f| f.key == Some(arg.as_str())) {
field.widget.set_text(text);
}
app.open_dialog_for(ViewId::Config, Modal::Form(form));
/// Open config-set on the selected row; says why when there is none.
pub(super) fn open_config_edit_for_selected(app: &mut App) {
let Some((key, value)) = app.front::<ConfigTab>().and_then(ConfigTab::selected_edit) else {
let reason = if app.front::<ConfigTab>().is_some_and(ConfigTab::any_loading) {
"config is loading"
} else {
"no config key selected"
};
app.set_status(reason);
return;
open_config_set_modal(
app,
&[("key".to_string(), key), ("value".to_string(), value)],
);
/// Opens the add-key form, its key field filled from a palette `key=` arg.
pub(super) fn open_ssh_key_add_modal(app: &mut App, args: &[(String, String)]) {
let mut form = Form::ssh_key_add();
app.open_dialog_for(ViewId::SshKeys, Modal::Form(form));
/// Confirms removing the `fingerprint` key, or the selected one; says why when there is none.
pub(super) fn open_ssh_key_remove(app: &mut App, fingerprint: Option<String>) {
let selected = app
.front_is(Tab::SshKeys)
.then(|| {
app.front::<SshKeysTab>()
.and_then(|keys| keys.selected_key().map(str::to_string))
})
.flatten();
match fingerprint.or(selected) {
Some(fingerprint) => app.confirm_remove_ssh_key(fingerprint),
None => app.set_status("no SSH key selected"),
pub(super) fn open_tag_create_modal(app: &mut App) {
app.open_dialog_for(ViewId::Tags, Modal::Form(Form::tag_create()));
/// Load the selected tag into the edit form; sets a status when none is selected.
pub(super) fn open_tag_edit_for_selected(app: &mut App) {
match app
.front::<TagsTab>()
.and_then(|tab| tab.selected_key().map(str::to_string))
{
Some(id) => app.open_tag_edit_async(&id),
None => app.set_status("no tag selected"),
/// Confirms deleting the selected tag; sets a status when none is selected.
pub(super) fn confirm_delete_selected_tag(app: &mut App) {
.and_then(|tab| tab.selected_row().cloned())
Some(row) => app.confirm_delete_tag(row),
pub(super) fn open_commodity_create_modal(app: &mut App) {
app.open_dialog_for(ViewId::Commodities, Modal::Form(Form::commodity_create()));
pub(super) fn open_commodity_convert_modal(app: &mut App) {
app.open_dialog_for(ViewId::Commodities, Modal::Form(Form::commodity_convert()));
app.fetch_commodity_form_options();
pub(super) fn open_account_create_modal(app: &mut App) {
app.open_dialog_for(ViewId::Accounts, Modal::Form(Form::account_create()));
app.fetch_account_form_options();
/// Open account-merge from the selected account; sets a status when none is selected.
pub(super) fn open_account_merge_for_selected(app: &mut App) {
let Some(id) = app.selected_id(Tab::Accounts) else {
app.set_status("no account selected");
let mut values = FormValues::default();
values.set("from", &id);
app.open_account_merge(values);
pub(super) fn open_transaction_create_modal(app: &mut App) {
app.open_dialog_for(
ViewId::Transactions,
Modal::Form(Form::transaction_create()),
app.fetch_transaction_form_options();
/// Open transaction-create with the selected account as the first row's From.
pub(super) fn open_transaction_create_modal_for_selected(app: &mut App) {
let mut form = Form::transaction_create();
form.preselect_from_account(&id);
app.open_dialog_for(Tab::Accounts, Modal::Form(form));
pub(super) fn open_transaction_filter_modal(app: &mut App) {
let filter = app
.front_list(Tab::Transactions)
.map(ListTab::filter)
.unwrap_or_default();
Modal::Form(Form::transaction_filter(&filter)),
/// Load the selected account into the edit form; sets a status when none is selected.
pub(super) fn open_account_edit_for_selected(app: &mut App) {
match app.selected_id(Tab::Accounts) {
Some(id) => app.open_account_edit_async(&id),
None => app.set_status("no account selected"),
/// Load the selected commodity into the edit form; sets a status when none is selected.
pub(super) fn open_commodity_edit_for_selected(app: &mut App) {
match app.selected_id(Tab::Commodities) {
Some(id) => app.open_commodity_edit_async(&id),
None => app.set_status("no commodity selected"),