(ctx: &mut ScriptContext<'_, API>)
| 1048 | reveal_file_path_in_tree(state, &path); |
| 1049 | state.log = format!("new {kind}\n{path}"); |
| 1050 | }); |
| 1051 | if kind == "scene" { |
| 1052 | open_scene_path(ctx, &path); |
| 1053 | } else if kind == "anim" { |
| 1054 | attach_animation_to_selected_player(ctx, &path); |
| 1055 | } else if kind == "script" { |
| 1056 | attach_script_to_selected_node(ctx, &path); |
| 1057 | } else if kind == "mat" { |
| 1058 | attach_material_to_selected_node(ctx, &path); |
| 1059 | } else { |
| 1060 | refresh_all(ctx); |
| 1061 | } |
| 1062 | } |
| 1063 | Err(err) => set_log(ctx, &format!("new asset fail\n{path}\n{err}")), |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | pub fn create_quick_folder<API: ScriptAPI + ?Sized>(ctx: &mut ScriptContext<'_, API>) { |
| 1068 | let request = with_state!(ctx.run, EditorState, ctx.id, |state| { |
| 1069 | if state.project_root.is_empty() { |
| 1070 | return None; |
| 1071 | } |
| 1072 | let dir = quick_asset_dir(state, "folder"); |
| 1073 | let path = unique_res_folder_path(&state.project_root, &dir, "new_folder"); |
| 1074 | Some((state.project_root.clone(), path)) |
| 1075 | }).unwrap_or_default(); |
| 1076 | let Some((root, path)) = request else { |
| 1077 | set_log(ctx, "new folder fail\nopen project first"); |
| 1078 | return; |
| 1079 | }; |
| 1080 | let abs = res_to_abs(&root, &path); |
| 1081 | match fs::create_dir_all(&abs) { |
| 1082 | Ok(()) => { |
| 1083 | let _ = with_state_mut!(ctx.run, EditorState, ctx.id, |state| { |
| 1084 | if let Ok(paths) = scan_res_paths(Path::new(&state.project_root)) { |
| 1085 | state.file_paths = paths; |
| 1086 | } |
| 1087 | state.sidebar_mode = "files".to_string(); |
| 1088 | state.activity_mode = "scene".to_string(); |
| 1089 | state.active_asset_path = path.clone(); |
| 1090 | state.file_scope = parent_res_folder(&path); |
| 1091 | reveal_file_path_in_tree(state, &path); |
| 1092 | state.log = format!("new folder\n{path}"); |
| 1093 | }); |
| 1094 | refresh_all(ctx); |
| 1095 | } |
| 1096 | Err(err) => set_log(ctx, &format!("new folder fail\n{path}\n{err}")), |
| 1097 | } |
nothing calls this directly
no test coverage detected