MCPcopy Create free account
hub / github.com/PerroEngine/Perro / close_scene_tab

Function close_scene_tab

perro_editor/res/scripts/assets/editor_assets.rs:822–876  ·  view source on GitHub ↗
(ctx: &mut ScriptContext<'_, API>, idx: usize)

Source from the content-addressed store, hash-verified

820 visible_tab_page_target(state.open_paths.len(), state.active_open, dir)
821 }).unwrap_or_default();
822 if let Some(idx) = idx {
823 set_active_tab(ctx, idx);
824 }
825}
826
827pub fn set_active_tab<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>, idx: usize) {
828 let switched = with_state_mut!(ctx.run, EditorState, ctx.id, |state| {
829 clear_destructive_confirmation(state);
830 if idx == state.active_open || idx >= state.open_paths.len() {
831 return false;
832 }
833 capture_active_scene_session(state);
834 if !restore_scene_session(state, idx) {
835 return false;
836 }
837 state.active_asset_path = state.open_paths[idx].clone();
838 state.log = format!("switch tab\n{}", state.active_asset_path);
839 true
840 })
841 .unwrap_or(false);
842 if !switched {
843 refresh_all(ctx);
844 return;
845 }
846 rebuild_preview(ctx);
847 refresh_all(ctx);
848}
849
850pub fn cycle_scene_tab<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>, dir: isize) {
851 let idx = with_state!(ctx.run, EditorState, ctx.id, |state| {
852 if state.open_paths.is_empty() {
853 return None;
854 }
855 Some(wrap_index(state.active_open, state.open_paths.len(), dir))
856 }).unwrap_or_default();
857 if let Some(idx) = idx {
858 set_active_tab(ctx, idx);
859 }
860}
861
862pub fn close_active_scene_tab<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>) {
863 let idx = with_state!(ctx.run, EditorState, ctx.id, |state| {
864 (!state.open_paths.is_empty()).then_some(state.active_open)
865 }).unwrap_or_default();
866 if let Some(idx) = idx {
867 close_scene_tab(ctx, idx);
868 }
869}
870
871pub fn close_all_scene_tabs<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>) {
872 if !save_all_scenes(ctx) {
873 set_log(ctx, "close all blocked\nsave failed");
874 refresh_all(ctx);
875 return;
876 }
877 let _ = with_state_mut!(ctx.run, EditorState, ctx.id, |state| {
878 let closed = state.open_paths.len();
879 state.open_paths.clear();

Callers 1

close_active_scene_tabFunction · 0.85

Calls 4

refresh_allFunction · 0.85
open_scene_pathFunction · 0.85
clear_previewFunction · 0.85

Tested by

no test coverage detected