private static void BuildSelectedAssetsFromResults(List <ReferencesTreeElement> results) { var resultsCount = results.Count; var showProgress = resultsCount > 500000; if (showProgress) { EditorUtility.DisplayProgressBar(ModuleName, "Parsing results...", 0); } var rootItems = new List <FilterItem>(resultsCount); var updateStep = Math.Max(resultsCount / MaintainerSettings.UpdateProgressStep, 1); for (var i = 0; i < resultsCount; i++) { if (showProgress && i % updateStep == 0) { EditorUtility.DisplayProgressBar(ModuleName, "Parsing results...", (float)i / resultsCount); } var result = results[i]; if (result.depth != 0) { continue; } rootItems.Add(FilterItem.Create(result.assetPath, FilterKind.Path)); } SearchResultsStorage.ReferencesFinderLastSearched = rootItems.ToArray(); }
public static FilterItem[] GetDefaultFilters() { return(new[] { FilterItem.Create("/Plugins/", FilterKind.Path, true), FilterItem.Create(".preset", FilterKind.Extension, true), }); }
private static void MigrateFromPre_1_4_1_0(ProjectSettings settings) { if (!CSFilterTools.IsValueMatchesAnyFilterOfKind("dummy.asmdef", settings.projectCleanerSettings.pathIgnoresFilters, FilterKind.Extension)) { ArrayUtility.Add(ref settings.projectCleanerSettings.pathIgnoresFilters, FilterItem.Create(".asmdef", FilterKind.Extension)); } }
/// <summary> /// Finds references for specific assets. /// </summary> /// <param name="assets">Specific assets.</param> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of ReferencesTreeElement for the TreeView buildup or manual parsing.</returns> public static ReferencesTreeElement[] FindAssetsReferences(string[] assets, bool showResults = true) { var assetsFilters = new FilterItem[assets.Length]; for (var i = 0; i < assets.Length; i++) { assetsFilters[i] = FilterItem.Create(assets[i], FilterKind.Path); } return(FindAssetsReferences(assetsFilters, false, showResults)); }
/// <summary> /// Adds new assets to the last selection if it existed and calls a GetReferences() with extended selection; /// </summary> /// <param name="selectedAssets">Additionally selected assets.</param> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of ReferencesTreeElement for the TreeView buildup or manual parsing.</returns> public static ReferencesTreeElement[] AddToSelectionAndRun(string[] selectedAssets, bool showResults = true) { var additiveSelection = new FilterItem[selectedAssets.Length]; for (var i = 0; i < selectedAssets.Length; i++) { additiveSelection[i] = FilterItem.Create(selectedAssets[i], FilterKind.Path); } return(AddToSelectionAndRun(additiveSelection, showResults)); }
/// <summary> /// Finds references for specific assets. /// </summary> /// <param name="assets">Specific assets.</param> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of ProjectReferenceItem for the TreeView buildup or manual parsing.</returns> public static ProjectReferenceItem[] FindAssetsReferences(string[] assets, bool showResults = true) { var assetsFilters = new FilterItem[assets.Length]; for (var i = 0; i < assets.Length; i++) { assetsFilters[i] = FilterItem.Create(assets[i], FilterKind.Path); } return(ProjectScopeReferencesFinder.FindAssetsReferences(assetsFilters, false, showResults)); }
public static List <FilterItem> SelectCategories(SqlConnector sql) { List <FilterItem> items = new List <FilterItem>(); var ds = sql.SelectDataSet("SELECT id,name FROM category"); foreach (var row in ds) { items.Add(FilterItem.Create(row)); } return(items); }
private static FilterItem[] GetMandatoryFilters() { return(new[] { FilterItem.Create("/Gizmos/", FilterKind.Path, true), FilterItem.Create("/Editor/", FilterKind.Path, true), FilterItem.Create("/Resources/", FilterKind.Path, true), FilterItem.Create("/Editor Resources/", FilterKind.Path, true), // example: Amplify FilterItem.Create("/EditorResources/", FilterKind.Path, true), // example: TextMeshPro FilterItem.Create("/StreamingAssets/", FilterKind.Path, true), FilterItem.Create("/Editor Default Resources/", FilterKind.Path, true), }); }
private static void MigrateAllIgnores(ICollection <string> oldFilters, ref FilterItem[] newFilters, FilterKind filterKind) { if (oldFilters == null || oldFilters.Count == 0) { return; } var newFiltersList = new List <FilterItem>(oldFilters.Count); foreach (var oldFilter in oldFilters) { if (CSFilterTools.IsValueMatchesAnyFilter(oldFilter, newFilters)) { continue; } newFiltersList.Add(FilterItem.Create(oldFilter, filterKind)); } ArrayUtility.AddRange(ref newFilters, newFiltersList.ToArray()); }
private static bool MigrateAllIgnores(string[] oldFilters, ref FilterItem[] newFilters, FilterKind filterKind) { if (oldFilters == null || oldFilters.Length == 0) { return(false); } var newFiltersList = new List <FilterItem>(oldFilters.Length); foreach (var oldFilter in oldFilters) { if (CSFilterTools.IsValueMatchesAnyFilter(oldFilter, newFilters)) { continue; } newFiltersList.Add(FilterItem.Create(oldFilter, filterKind)); } ArrayUtility.AddRange(ref newFilters, newFiltersList.ToArray()); return(true); }
private static void SaveLastSearched(List <ProjectReferenceItem> results) { var resultsCount = results.Count; var showProgress = resultsCount > 500000; if (showProgress) { EditorUtility.DisplayProgressBar(ReferencesFinder.ModuleName, "Parsing results...", 0); } var rootItems = new List <FilterItem>(resultsCount); #if !UNITY_2020_1_OR_NEWER var updateStep = Math.Max(resultsCount / ProjectSettings.UpdateProgressStep, 1); #endif for (var i = 0; i < resultsCount; i++) { if (showProgress #if !UNITY_2020_1_OR_NEWER && i % updateStep == 0 #endif ) { EditorUtility.DisplayProgressBar(ReferencesFinder.ModuleName, "Parsing results...", (float)i / resultsCount); } var result = results[i]; if (result.depth != 0) { continue; } rootItems.Add(FilterItem.Create(result.assetPath, FilterKind.Path)); } SearchResultsStorage.ProjectReferencesLastSearched = rootItems.ToArray(); }
protected virtual void DrawAddItemSection() { EditorGUILayout.LabelField(GetAddNewLabel()); using (new GUILayout.HorizontalScope()) { GUILayout.Space(6); GUI.SetNextControlName("AddButton"); var flag = currentEvent.isKey && Event.current.type == EventType.KeyDown && (currentEvent.keyCode == KeyCode.Return || currentEvent.keyCode == KeyCode.KeypadEnter); if (UIHelpers.IconButton(CSIcons.Plus, "Adds custom filter to the list.") || flag) { if (string.IsNullOrEmpty(newItemText)) { window.ShowNotification(new GUIContent("You can't add an empty filter!")); } else if (newItemText.IndexOf('*') != -1) { window.ShowNotification(new GUIContent("Masks are not supported!")); } else { if (newItemKind == FilterKind.Extension && !newItemText.StartsWith(".")) { newItemText = "." + newItemText; } if (CheckNewItem(ref newItemText)) { if (CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(newItemText, newItemKind, newItemIgnoreCase))) { SaveChanges(); newItemText = ""; GUI.FocusControl("AddButton"); didFocus = false; } else { window.ShowNotification(new GUIContent("This filter already exists in the list!")); } } } } if (flag) { currentEvent.Use(); currentEvent.Use(); } newItemKind = DrawFilterKindDropdown(newItemKind); newItemIgnoreCase = DrawFilterIgnoreCaseToggle(newItemIgnoreCase); GUILayout.Space(5); GUI.SetNextControlName("filtersTxt"); newItemText = EditorGUILayout.TextField(newItemText); if (!didFocus) { didFocus = true; EditorGUI.FocusTextInControl("filtersTxt"); } } }
internal override void ProcessDrags() { if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform) { return; } var paths = DragAndDrop.paths; var objectReferences = DragAndDrop.objectReferences; if (paths != null && objectReferences != null && paths.Length > 0 && paths.Length == objectReferences.Length) { var atLeastOneFileAsset = objectReferences.Any(AssetDatabase.Contains); if (!atLeastOneFileAsset) { return; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (currentEventType == EventType.DragPerform) { for (var i = 0; i < objectReferences.Length; i++) { paths[i] = CSPathTools.EnforceSlashes(AssetDatabase.GetAssetPath(objectReferences[i])); } var needToSave = false; var needToShowWarning = false; foreach (var path in paths) { var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(path, FilterKind.Path)); needToSave |= added; needToShowWarning |= !added; } if (needToSave) { SaveChanges(); } if (needToShowWarning) { window.ShowNotification(new GUIContent("One or more of the dragged items already present in the list!")); } DragAndDrop.AcceptDrag(); } } Event.current.Use(); }
internal override void ProcessDrags() { if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform) { return; } var objects = DragAndDrop.objectReferences; if (objects != null && objects.Length > 0) { var canDrop = false; for (var i = 0; i < objects.Length; i++) { if (objects[i] is Component) { canDrop = true; break; } var monoScript = objects[i] as MonoScript; if (monoScript != null) { var type = monoScript.GetClass(); if (type.IsSubclassOf(CSReflectionTools.componentType)) { canDrop = true; break; } } } if (canDrop) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (currentEventType == EventType.DragPerform) { var needToSave = false; var needToShowWarning = false; var noComponent = false; var invalidComponent = false; for (var i = 0; i < objects.Length; i++) { var component = objects[i] as Component; var monoScript = objects[i] as MonoScript; string componentName = null; if (component != null) { componentName = component.GetType().Name; } else if (monoScript != null) { var type = monoScript.GetClass(); if (type.IsSubclassOf(CSReflectionTools.componentType)) { componentName = type.Name; } else { noComponent = true; } } else { noComponent = true; } if (noComponent) { continue; } if (!string.IsNullOrEmpty(componentName) && componentName != "Object" && componentName != "Component" && componentName != "Behaviour") { var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(componentName, FilterKind.Type)); needToSave |= added; needToShowWarning |= !added; } else { invalidComponent = true; } } if (needToSave) { SaveChanges(); } var warningText = ""; if (needToShowWarning) { warningText = "One or more of the dragged items already present in the list!"; } if (noComponent) { if (!string.IsNullOrEmpty(warningText)) { warningText += "\n"; } warningText += "One or more of the dragged items are not the Components!"; } if (invalidComponent) { if (!string.IsNullOrEmpty(warningText)) { warningText += "\n"; } warningText += "Can't detect valid name for one or more of the dragged items!"; } if (!string.IsNullOrEmpty(warningText)) { window.ShowNotification(new GUIContent(warningText)); } DragAndDrop.AcceptDrag(); } } } Event.current.Use(); }
internal override void ProcessDrags() { if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform) { return; } var paths = DragAndDrop.paths; if (paths != null && paths.Length > 0) { var canDrop = false; for (var i = 0; i < paths.Length; i++) { paths[i] = CSPathTools.EnforceSlashes(paths[i]); if (LooksLikeSceneFile(paths[i])) { canDrop = true; break; } } if (canDrop) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (currentEventType == EventType.DragPerform) { var needToSave = false; var needToShowWarning = false; foreach (var path in paths) { if (LooksLikeSceneFile(path)) { var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(path, FilterKind.Path)); needToSave |= added; needToShowWarning |= !added; } } if (needToSave) { SaveChanges(); } if (needToShowWarning) { window.ShowNotification(new GUIContent("One or more of the dragged items already present in the list!")); } DragAndDrop.AcceptDrag(); } } } Event.current.Use(); }
public static ProjectReferenceItem[] FindAssetReferencesFromResults(string asset) { return(FindAssetsReferences(new [] { FilterItem.Create(asset, FilterKind.Path) }, true, true)); }
internal static ReferencesTreeElement[] FindAssetReferencesFromResults(string asset) { return(FindAssetsReferences(new [] { FilterItem.Create(asset, FilterKind.Path) }, true, true)); }
private void DrawMoreButton(AssetRecord assetRecord) { if (UIHelpers.RecordButton(assetRecord, "Shows menu with additional actions for this record.", CSIcons.More)) { var menu = new GenericMenu(); if (!string.IsNullOrEmpty(assetRecord.path)) { menu.AddItem(new GUIContent("Ignore/Full Path"), false, () => { if (!CSFilterTools.IsValueMatchesAnyFilter(assetRecord.assetDatabasePath, MaintainerSettings.Cleaner.pathIgnoresFilters)) { var newFilter = FilterItem.Create(assetRecord.assetDatabasePath, FilterKind.Path); ArrayUtility.Add(ref MaintainerSettings.Cleaner.pathIgnoresFilters, newFilter); MaintainerWindow.ShowNotification("Ignore added: " + assetRecord.assetDatabasePath); CleanerFiltersWindow.Refresh(); if (MaintainerSettings.Cleaner.rescanAfterContextIgnore) { StartSearch(); } } else { MaintainerWindow.ShowNotification("Already added to the ignores!"); } }); var dir = Directory.GetParent(assetRecord.assetDatabasePath); if (!CSPathTools.IsAssetsRootPath(dir.FullName)) { menu.AddItem(new GUIContent("Ignore/Parent Folder"), false, () => { var dirPath = CSPathTools.EnforceSlashes(dir.ToString()); if (!CSFilterTools.IsValueMatchesAnyFilter(dirPath, MaintainerSettings.Cleaner.pathIgnoresFilters)) { var newFilter = FilterItem.Create(dirPath, FilterKind.Directory); ArrayUtility.Add(ref MaintainerSettings.Cleaner.pathIgnoresFilters, newFilter); MaintainerWindow.ShowNotification("Ignore added: " + dirPath); CleanerFiltersWindow.Refresh(); if (MaintainerSettings.Cleaner.rescanAfterContextIgnore) { StartSearch(); } } else { MaintainerWindow.ShowNotification("Already added to the ignores!"); } }); } var extension = Path.GetExtension(assetRecord.path); if (!string.IsNullOrEmpty(extension)) { menu.AddItem(new GUIContent("Ignore/\"" + extension + "\" Extension"), false, () => { if (!CSFilterTools.IsValueMatchesAnyFilterOfKind(extension, MaintainerSettings.Cleaner.pathIgnoresFilters, FilterKind.Extension)) { var newFilter = FilterItem.Create(extension, FilterKind.Extension, true); ArrayUtility.Add(ref MaintainerSettings.Cleaner.pathIgnoresFilters, newFilter); MaintainerWindow.ShowNotification("Ignore added: " + extension); CleanerFiltersWindow.Refresh(); if (MaintainerSettings.Cleaner.rescanAfterContextIgnore) { StartSearch(); } } else { MaintainerWindow.ShowNotification("Already added to the ignores!"); } }); } } menu.ShowAsContext(); } }
private void DrawMoreButton(AssetIssueRecord record) { if (!UIHelpers.RecordButton(record, "Shows menu with additional actions for this record.", CSIcons.More)) { return; } var menu = new GenericMenu(); if (!string.IsNullOrEmpty(record.Path)) { menu.AddItem(new GUIContent("Ignore/Full Path"), false, () => { if (!CSFilterTools.IsValueMatchesAnyFilter(record.Path, ProjectSettings.Issues.pathIgnoresFilters)) { var newFilter = FilterItem.Create(record.Path, FilterKind.Path); ArrayUtility.Add(ref ProjectSettings.Issues.pathIgnoresFilters, newFilter); ApplyNewIgnoreFilter(newFilter); MaintainerWindow.ShowNotification("Ignore added: " + record.Path); CleanerFiltersWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Already added to the ignores!"); } }); var dir = Directory.GetParent(record.Path); if (!CSPathTools.IsAssetsRootPath(dir.FullName)) { menu.AddItem(new GUIContent("Ignore/Parent Folder"), false, () => { var dirPath = CSPathTools.EnforceSlashes(dir.ToString()); if (!CSFilterTools.IsValueMatchesAnyFilter(dirPath, ProjectSettings.Issues.pathIgnoresFilters)) { var newFilter = FilterItem.Create(dirPath, FilterKind.Directory); ArrayUtility.Add(ref ProjectSettings.Issues.pathIgnoresFilters, newFilter); ApplyNewIgnoreFilter(newFilter); MaintainerWindow.ShowNotification("Ignore added: " + dirPath); CleanerFiltersWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Already added to the ignores!"); } }); } } var objectIssue = record as GameObjectIssueRecord; if (objectIssue != null) { if (!string.IsNullOrEmpty(objectIssue.componentName)) { menu.AddItem(new GUIContent("Ignore/\"" + objectIssue.componentName + "\" Component"), false, () => { if (!CSFilterTools.IsValueMatchesAnyFilter(objectIssue.componentName, ProjectSettings.Issues.componentIgnoresFilters)) { var newFilter = FilterItem.Create(objectIssue.componentName, FilterKind.Type); ArrayUtility.Add(ref ProjectSettings.Issues.componentIgnoresFilters, newFilter); ApplyNewIgnoreFilter(newFilter); MaintainerWindow.ShowNotification("Ignore added: " + objectIssue.componentName); CleanerFiltersWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Already added to the ignores!"); } }); } } menu.ShowAsContext(); }
private static MaintainerSettings LoadOrCreate() { MaintainerSettings settings; if (!File.Exists(Path)) { settings = CreateNewSettingsFile(); } else { settings = LoadInstance(); if (settings == null) { CSFileTools.DeleteFile(Path); settings = CreateNewSettingsFile(); } if (settings.version != Maintainer.Version) { if (string.IsNullOrEmpty(settings.version)) { MigrateAllIgnores(settings.issuesFinderSettings.pathIgnores, ref settings.issuesFinderSettings.pathIgnoresFilters, FilterKind.Path); settings.issuesFinderSettings.pathIgnores = null; MigrateAllIgnores(settings.issuesFinderSettings.componentIgnores, ref settings.issuesFinderSettings.componentIgnoresFilters, FilterKind.Type); settings.issuesFinderSettings.componentIgnores = null; MigrateAllIgnores(settings.issuesFinderSettings.pathIncludes, ref settings.issuesFinderSettings.pathIncludesFilters, FilterKind.Path); settings.issuesFinderSettings.pathIncludes = null; MigrateAllIgnores(settings.issuesFinderSettings.sceneIncludes, ref settings.issuesFinderSettings.sceneIncludesFilters, FilterKind.Path); settings.issuesFinderSettings.sceneIncludes = null; MigrateAllIgnores(settings.projectCleanerSettings.pathIgnores, ref settings.projectCleanerSettings.pathIgnoresFilters, FilterKind.Path); settings.projectCleanerSettings.pathIgnores = null; MigrateAllIgnores(settings.projectCleanerSettings.sceneIgnores, ref settings.projectCleanerSettings.sceneIgnoresFilters, FilterKind.Path); settings.projectCleanerSettings.sceneIgnores = null; settings.projectCleanerSettings.AddDefaultFilters(); } if (new Version(settings.version) < new Version("1.4.1.0")) { if (!CSFilterTools.IsValueMatchesAnyFilterOfKind("dummy.asmdef", settings.projectCleanerSettings.pathIgnoresFilters, FilterKind.Extension)) { ArrayUtility.Add(ref settings.projectCleanerSettings.pathIgnoresFilters, FilterItem.Create(".asmdef", FilterKind.Extension)); } } if (new Version(settings.version) < new Version("1.5.1")) { if (settings.projectCleanerSettings.pathIgnoresFilters != null && settings.projectCleanerSettings.pathIgnoresFilters.Length > 0) { var defaultFilters = settings.projectCleanerSettings.GetDefaultFilters(); var mandatoryFilters = settings.projectCleanerSettings.MandatoryFilters; var modificationsLog = new StringBuilder(); for (var i = settings.projectCleanerSettings.pathIgnoresFilters.Length - 1; i >= 0; i--) { var pathIgnoresFilter = settings.projectCleanerSettings.pathIgnoresFilters[i]; if (pathIgnoresFilter.ignoreCase) { continue; } var isMandatory = false; if (CSFilterTools.IsValueMatchesAnyFilterOfKind(pathIgnoresFilter.value, mandatoryFilters, pathIgnoresFilter.kind)) { isMandatory = true; } else { switch (pathIgnoresFilter.kind) { case FilterKind.Extension: var extension = pathIgnoresFilter.value.ToLowerInvariant(); if (extension == ".dll" || extension == ".asmdef" || extension == ".mdb" || extension == ".xml" || extension == ".rsp") { isMandatory = true; } break; case FilterKind.FileName: var value = pathIgnoresFilter.value.ToLowerInvariant(); if (value == "readme" || value == "manual") { isMandatory = true; } break; } } if (isMandatory) { modificationsLog.Append("Removing Project Cleaner filter '") .Append(pathIgnoresFilter.value) .AppendLine("': built-in mandatory filter covers it now."); ArrayUtility.RemoveAt(ref settings.projectCleanerSettings.pathIgnoresFilters, i); continue; } if (CSFilterTools.IsValueMatchesAnyFilterOfKind(pathIgnoresFilter.value, defaultFilters, pathIgnoresFilter.kind)) { modificationsLog.Append("Changing default Project Cleaner filter '") .Append(pathIgnoresFilter.value) .AppendLine("': ignore case setting to 'true' for better accuracy."); pathIgnoresFilter.ignoreCase = true; } } if (modificationsLog.Length > 0) { modificationsLog.Insert(0, "Maintainer settings updated, read below for details\n"); Debug.Log(Maintainer.LogPrefix + modificationsLog); } } } SearchResultsStorage.Clear(); //AssetsMap.Delete(); } } settings.hideFlags = HideFlags.HideAndDontSave; settings.version = Maintainer.Version; return(settings); }