1use crate::app::App;
4use crate::form::Form;
5use crate::modal::Modal;
6use crate::tabs::scripts::ScriptsTab;
7use crate::view::Tab;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum ScriptKey {
12 Toggle,
14}
15
16pub(super) fn apply_tab(app: &mut App, key: ScriptKey) {
17 if !app.front_is(Tab::Scripts) {
18 return;
19 }
20 match key {
21 ScriptKey::Toggle => toggle_selected(app),
22 }
23}
24
25pub(super) fn open_create(app: &mut App) {
26 app.open_dialog_for(Tab::Scripts, Modal::Form(Form::script_create()));
27}
28
29pub(super) fn open_edit_for_selected(app: &mut App) {
31 match app
32 .front::<ScriptsTab>()
33 .and_then(|tab| tab.selected_key().map(str::to_string))
34 {
35 Some(id) => app.open_script_edit_async(&id),
36 None => app.set_status("no script selected"),
37 }
38}
39
40pub(super) fn confirm_delete_selected(app: &mut App) {
42 match app
43 .front::<ScriptsTab>()
44 .and_then(|tab| tab.selected_row().cloned())
45 {
46 Some(row) => app.confirm_delete_script(row),
47 None => app.set_status("no script selected"),
48 }
49}
50
51fn toggle_selected(app: &mut App) {
52 match app
53 .front::<ScriptsTab>()
54 .and_then(|tab| tab.selected_row().cloned())
55 {
56 Some(row) => app.toggle_script(&row),
57 None => app.set_status("no script selected"),
58 }
59}