/// <summary> /// Copies a File / Directory at a given path to the Trash folder if eligible /// </summary> public static void DeleteAndCopyToRecycleBin(FileInfo file) { //The input parameter is relative to the project folder e.g.: /Assets/MyScript.cs string assetPath = Path.Combine(projectFolder, file.FullName); DirectoryInfo recycleBinDirectory = new DirectoryInfo(recycleBinPath); if (FileFunctions.IsDirectory(assetPath)) { FileFunctions.CopyFileOrDirectory(assetPath, recycleBinDirectory); } else { if (recycleBinPreferences.IsEligibleToSave(file)) { FileFunctions.CopyFileOrDirectory(assetPath, recycleBinDirectory); } } FileUtil.DeleteFileOrDirectory(assetPath); RefreshSearch(""); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.LabelField("Recycle Bin", EditorStyles.centeredGreyMiniLabel); settings = EditorGUILayout.Foldout(settings, "Settings"); if (settings) { EditorGUI.indentLevel++; EditorGUILayout.Space(); EditorGUILayout.PropertyField(name_, new GUIContent("Folder Name")); EditorGUILayout.Space(); EditorGUILayout.LabelField("Path:"); EditorGUILayout.LabelField(recycleBin); EditorGUILayout.Space(); //Draw everything besides script name and deleted file list. This way there's no need to reimplement arrays of strings for the extensions. DrawPropertiesExcluding(serializedObject, new string[] { "m_Script", "trash" }); EditorGUILayout.Space(); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.PropertyField(all, new GUIContent("Save All")); EditorGUILayout.PropertyField(none, new GUIContent("Discard All")); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUI.indentLevel--; } EditorGUILayout.Space(); List <TrashFile> list = pref.trash; EditorGUILayout.Space(); EditorGUILayout.LabelField("Trash", skin); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); //Search field EditorGUILayout.PropertyField(search, new GUIContent("Search")); EditorGUILayout.Space(); //View folder content/data fields showSubfolders = EditorGUILayout.Toggle(new GUIContent("View Folder Content"), showSubfolders); showDate = EditorGUILayout.Toggle(new GUIContent("View Date"), showDate); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); RecycleBinFunctions.RefreshSearch(pref.search); } EditorGUILayout.Space(); EditorGUILayout.Space(); //Draws files and directories. for (int i = 0; i < list.Count; i++) { if (!FileFunctions.IsDirectory(list[i].path)) { DrawFile(list[i].path, true, true); } else { DrawFolderRecursive(new DirectoryInfo(list[i].path), true); } EditorGUILayout.Space(); } EditorGUILayout.Space(); //Draws Delete / Restore All DrawButtons(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorPrefs.SetBool("show", showSubfolders); EditorPrefs.SetBool("date", showDate); serializedObject.ApplyModifiedProperties(); }