(ctx: &mut ScriptContext<'_, API>, kind: &str)
| 888 | }) |
| 889 | .unwrap_or(0); |
| 890 | clear_preview(ctx); |
| 891 | refresh_all(ctx); |
| 892 | } |
| 893 | |
| 894 | pub fn close_scene_tab<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>, idx: usize) { |
| 895 | let action = format!("scene_tab_close_{idx}"); |
| 896 | let request = with_state_mut!(ctx.run, EditorState, ctx.id, |state| { |
| 897 | cancel_destructive_confirmation_for_action(state, &action); |
| 898 | let target = state.open_paths.get(idx).cloned()?; |
| 899 | let dirty = state.dirty_scene_paths.iter().any(|path| path == &target); |
| 900 | if !dirty { |
| 901 | clear_destructive_confirmation(state); |
| 902 | return Some((target, false, idx == state.active_open)); |
| 903 | } |
| 904 | let confirmed = arm_or_confirm_destructive_action(state, &action, &target); |
| 905 | if !confirmed { |
| 906 | state.log = format!("close dirty?\nclick x again -> save + close\n{target}"); |
| 907 | } |
| 908 | Some((target, !confirmed, idx == state.active_open)) |
| 909 | }) |
| 910 | .flatten(); |
| 911 | let Some((target, armed, active)) = request else { |
| 912 | refresh_all(ctx); |
| 913 | return; |
| 914 | }; |
| 915 | if armed { |
| 916 | refresh_all(ctx); |
| 917 | return; |
| 918 | } |
| 919 | if with_state!(ctx.run, EditorState, ctx.id, |state| state |
| 920 | .dirty_scene_paths |
| 921 | .iter() |
| 922 | .any(|path| path == &target)).unwrap_or_default() |
| 923 | { |
| 924 | if !active { |
| 925 | set_log( |
| 926 | ctx, |
| 927 | &format!("close blocked\nselect + save first\n{target}"), |
| 928 | ); |
| 929 | refresh_all(ctx); |
| 930 | return; |
| 931 | } |
| 932 | if !save_active_scene_to_disk(ctx, true) { |
| 933 | refresh_all(ctx); |
| 934 | return; |
| 935 | } |
| 936 | } |
| 937 | let next = with_state_mut!(ctx.run, EditorState, ctx.id, |state| { |
| 938 | if idx >= state.open_paths.len() { |
| 939 | return None; |
| 940 | } |
| 941 | capture_active_scene_session(state); |
| 942 | let target = state.open_paths.get(idx).cloned()?; |
| 943 | if state.dirty_scene_paths.iter().any(|path| path == &target) { |
| 944 | state.log = format!("close blocked\nsave first\n{target}"); |
| 945 | return None; |
| 946 | } |
| 947 | let was_active = idx == state.active_open; |
nothing calls this directly
no test coverage detected