From 5a2dcf36199d3b94eb1b682c73232b0ef4bd5210 Mon Sep 17 00:00:00 2001 From: Anders Ejlersen Date: Mon, 27 Mar 2023 22:02:44 +0200 Subject: [PATCH] 1.8.4: History received a fix for startup issue, increased entry size, and context menu options - Set selection active in history is now a toggleable feature in the context menu - Increased number of entries in history from 32 to 64 - Clear entries moved to context menu in history - Fixed issue, where history didn't work on first startup --- CHANGELOG.md | 13 +++++++ ...IUtility.cs => EditorHistoryGUIUtility.cs} | 8 ++-- ...s.meta => EditorHistoryGUIUtility.cs.meta} | 0 .../{HistoryList.cs => EditorHistoryList.cs} | 12 +++--- ...List.cs.meta => EditorHistoryList.cs.meta} | 0 ...ess.cs => EditorHistoryListPostProcess.cs} | 26 +++++++------ ...a => EditorHistoryListPostProcess.cs.meta} | 0 .../History/Utilities/EditorHistoryPrefs.cs | 15 ++++++++ .../Utilities/EditorHistoryPrefs.cs.meta | 3 ++ .../History/Utilities/EditorHistoryUtility.cs | 37 +++++++++++++++++++ ...y.cs.meta => EditorHistoryUtility.cs.meta} | 0 Editor/History/Utilities/HistoryUtility.cs | 37 ------------------- Editor/History/Window/EditorHistoryWindow.cs | 36 +++++++++++++----- Editor/History/Window/Styles/Styles.cs | 7 +++- .../Views/EditorHistoryViewSearchList.cs | 12 +++--- .../Window/Views/EditorHistoryViewTools.cs | 19 +++++----- package.json | 2 +- 17 files changed, 141 insertions(+), 86 deletions(-) rename Editor/History/Utilities/{HistoryGUIUtility.cs => EditorHistoryGUIUtility.cs} (91%) rename Editor/History/Utilities/{HistoryGUIUtility.cs.meta => EditorHistoryGUIUtility.cs.meta} (100%) rename Editor/History/Utilities/{HistoryList.cs => EditorHistoryList.cs} (89%) rename Editor/History/Utilities/{HistoryList.cs.meta => EditorHistoryList.cs.meta} (100%) rename Editor/History/Utilities/{HistoryListPostProcess.cs => EditorHistoryListPostProcess.cs} (65%) rename Editor/History/Utilities/{HistoryListPostProcess.cs.meta => EditorHistoryListPostProcess.cs.meta} (100%) create mode 100644 Editor/History/Utilities/EditorHistoryPrefs.cs create mode 100644 Editor/History/Utilities/EditorHistoryPrefs.cs.meta create mode 100644 Editor/History/Utilities/EditorHistoryUtility.cs rename Editor/History/Utilities/{HistoryUtility.cs.meta => EditorHistoryUtility.cs.meta} (100%) delete mode 100644 Editor/History/Utilities/HistoryUtility.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 87af46b..5ff8713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,19 @@ # Change Log All notable changes to this project will be documented in this file. +## [1.8.4] - 2023-03-27 + +### Added +- Set selection active in history is now a toggleable feature in the context menu + +### Changed +- Increased number of entries in history from 32 to 64 +- Clear entries moved to context menu in history + +### Fixed +- Fixed issue, where history didn't work on first startup + + ## [1.8.3] - 2023-03-16 ### Changed diff --git a/Editor/History/Utilities/HistoryGUIUtility.cs b/Editor/History/Utilities/EditorHistoryGUIUtility.cs similarity index 91% rename from Editor/History/Utilities/HistoryGUIUtility.cs rename to Editor/History/Utilities/EditorHistoryGUIUtility.cs index a7c1e20..f4bd5ad 100644 --- a/Editor/History/Utilities/HistoryGUIUtility.cs +++ b/Editor/History/Utilities/EditorHistoryGUIUtility.cs @@ -4,19 +4,19 @@ using UnityEngine; namespace Module.NavigationTool.Editor.History { - internal static class HistoryGUIUtility + internal static class EditorHistoryGUIUtility { private static readonly int ENTRY_HASH = "DrawHistoryEntry".GetHashCode(); public static bool isClicked; public static bool isDoubleClick; - public static HistoryList.Entry currentEntry; + public static EditorHistoryList.Entry currentEntry; - private static HistoryList.Entry LAST_CLICK_ENTRY; + private static EditorHistoryList.Entry LAST_CLICK_ENTRY; private static double LAST_CLICK_TIME; private static int CLICK_COUNT; - public static void DrawEntry(Rect rect, HistoryList.Entry entry, Styles styles, bool ignoreIndentLevel = false) + public static void DrawEntry(Rect rect, EditorHistoryList.Entry entry, Styles styles, bool ignoreIndentLevel = false) { int id = GUIUtility.GetControlID(ENTRY_HASH, FocusType.Passive, rect); bool on = currentEntry == entry; diff --git a/Editor/History/Utilities/HistoryGUIUtility.cs.meta b/Editor/History/Utilities/EditorHistoryGUIUtility.cs.meta similarity index 100% rename from Editor/History/Utilities/HistoryGUIUtility.cs.meta rename to Editor/History/Utilities/EditorHistoryGUIUtility.cs.meta diff --git a/Editor/History/Utilities/HistoryList.cs b/Editor/History/Utilities/EditorHistoryList.cs similarity index 89% rename from Editor/History/Utilities/HistoryList.cs rename to Editor/History/Utilities/EditorHistoryList.cs index 2719d96..dbc4f8f 100644 --- a/Editor/History/Utilities/HistoryList.cs +++ b/Editor/History/Utilities/EditorHistoryList.cs @@ -9,14 +9,14 @@ using Object = UnityEngine.Object; namespace Module.NavigationTool.Editor.History { [Serializable] - internal sealed class HistoryList + internal sealed class EditorHistoryList { public static readonly string PREF_ID = "PREF_HISTORY_LIST"; - public const int MAX_LENGTH = 32; + public const int MAX_LENGTH = 64; public List entries; - public HistoryList() + public EditorHistoryList() { entries = new List(); string json = EditorProjectPrefs.GetString(PREF_ID); @@ -134,10 +134,10 @@ namespace Module.NavigationTool.Editor.History public void Refresh() { string path = AssetDatabase.GUIDToAssetPath(guid); - name = Path.GetFileNameWithoutExtension(path); - lowerName = name.ToLower(); + name = AssetDatabase.IsValidFolder(path) ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path); + lowerName = !string.IsNullOrEmpty(name) ? name.ToLower() : string.Empty; valid = AssetDatabase.LoadMainAssetAtPath(path) != null; - content = new GUIContent(name, HistoryGUIUtility.GetIcon(path), path); + content = new GUIContent(name, EditorHistoryGUIUtility.GetIcon(path), path); } } } diff --git a/Editor/History/Utilities/HistoryList.cs.meta b/Editor/History/Utilities/EditorHistoryList.cs.meta similarity index 100% rename from Editor/History/Utilities/HistoryList.cs.meta rename to Editor/History/Utilities/EditorHistoryList.cs.meta diff --git a/Editor/History/Utilities/HistoryListPostProcess.cs b/Editor/History/Utilities/EditorHistoryListPostProcess.cs similarity index 65% rename from Editor/History/Utilities/HistoryListPostProcess.cs rename to Editor/History/Utilities/EditorHistoryListPostProcess.cs index c88cda1..83d52ca 100644 --- a/Editor/History/Utilities/HistoryListPostProcess.cs +++ b/Editor/History/Utilities/EditorHistoryListPostProcess.cs @@ -2,12 +2,14 @@ namespace Module.NavigationTool.Editor.History { - internal sealed class HistoryListPostProcess : AssetPostprocessor + [InitializeOnLoad] + internal sealed class EditorHistoryListPostProcess : AssetPostprocessor { private static bool IGNORE_NEXT_SELECTION_CHANGE; - static HistoryListPostProcess() + static EditorHistoryListPostProcess() { + Selection.selectionChanged -= OnSelectionChanged; Selection.selectionChanged += OnSelectionChanged; } @@ -17,8 +19,13 @@ namespace Module.NavigationTool.Editor.History movedAssets.Length != 0 || movedFromAssetPaths.Length != 0; - if (isDirty && HistoryUtility.IsLoaded()) - HistoryUtility.RefreshAll(); + if (isDirty && EditorHistoryUtility.IsLoaded()) + EditorHistoryUtility.RefreshAll(); + } + + public static void IgnoreNextSelectionChange() + { + IGNORE_NEXT_SELECTION_CHANGE = true; } private static void OnSelectionChanged() @@ -32,15 +39,10 @@ namespace Module.NavigationTool.Editor.History } else { - HistoryList historyList = HistoryUtility.GetHistoryList(); - historyList.AddRange(Selection.assetGUIDs); - HistoryGUIUtility.Repaint(); + EditorHistoryList editorHistoryList = EditorHistoryUtility.GetHistoryList(); + editorHistoryList.AddRange(Selection.assetGUIDs); + EditorHistoryGUIUtility.Repaint(); } } - - public static void IgnoreNextSelectionChange() - { - IGNORE_NEXT_SELECTION_CHANGE = true; - } } } \ No newline at end of file diff --git a/Editor/History/Utilities/HistoryListPostProcess.cs.meta b/Editor/History/Utilities/EditorHistoryListPostProcess.cs.meta similarity index 100% rename from Editor/History/Utilities/HistoryListPostProcess.cs.meta rename to Editor/History/Utilities/EditorHistoryListPostProcess.cs.meta diff --git a/Editor/History/Utilities/EditorHistoryPrefs.cs b/Editor/History/Utilities/EditorHistoryPrefs.cs new file mode 100644 index 0000000..a4f0af2 --- /dev/null +++ b/Editor/History/Utilities/EditorHistoryPrefs.cs @@ -0,0 +1,15 @@ +using UnityEditor; + +namespace Module.NavigationTool.Editor.History +{ + internal static class EditorHistoryPrefs + { + private const string PREF_IS_SET_AS_ACTIVE_OBJECT_ENABLED = "EditorHistoryWindow.IsSetAsActiveObjectEnabled"; + + public static bool IsSetAsActiveObjectEnabled + { + get => EditorPrefs.GetBool(PREF_IS_SET_AS_ACTIVE_OBJECT_ENABLED, true); + set => EditorPrefs.SetBool(PREF_IS_SET_AS_ACTIVE_OBJECT_ENABLED, value); + } + } +} \ No newline at end of file diff --git a/Editor/History/Utilities/EditorHistoryPrefs.cs.meta b/Editor/History/Utilities/EditorHistoryPrefs.cs.meta new file mode 100644 index 0000000..1920c60 --- /dev/null +++ b/Editor/History/Utilities/EditorHistoryPrefs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8673b42e45bc489988f66cbd2ebd1eb5 +timeCreated: 1679940554 \ No newline at end of file diff --git a/Editor/History/Utilities/EditorHistoryUtility.cs b/Editor/History/Utilities/EditorHistoryUtility.cs new file mode 100644 index 0000000..4ae95a3 --- /dev/null +++ b/Editor/History/Utilities/EditorHistoryUtility.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; + +namespace Module.NavigationTool.Editor.History +{ + internal static class EditorHistoryUtility + { + private static EditorHistoryList EDITOR_HISTORY_LIST; + + static EditorHistoryUtility() + { + EDITOR_HISTORY_LIST = null; + } + + public static EditorHistoryList GetHistoryList() + { + return EDITOR_HISTORY_LIST ?? (EDITOR_HISTORY_LIST = new EditorHistoryList()); + } + + public static bool IsLoaded() + { + return EDITOR_HISTORY_LIST != null; + } + + public static void RefreshAll() + { + if (EDITOR_HISTORY_LIST == null) + return; + + List entries = EDITOR_HISTORY_LIST.entries; + + for (var i = 0; i < entries.Count; i++) + { + entries[i].Refresh(); + } + } + } +} \ No newline at end of file diff --git a/Editor/History/Utilities/HistoryUtility.cs.meta b/Editor/History/Utilities/EditorHistoryUtility.cs.meta similarity index 100% rename from Editor/History/Utilities/HistoryUtility.cs.meta rename to Editor/History/Utilities/EditorHistoryUtility.cs.meta diff --git a/Editor/History/Utilities/HistoryUtility.cs b/Editor/History/Utilities/HistoryUtility.cs deleted file mode 100644 index aebd41c..0000000 --- a/Editor/History/Utilities/HistoryUtility.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; - -namespace Module.NavigationTool.Editor.History -{ - internal static class HistoryUtility - { - private static HistoryList HISTORY_LIST; - - static HistoryUtility() - { - HISTORY_LIST = null; - } - - public static HistoryList GetHistoryList() - { - return HISTORY_LIST ?? (HISTORY_LIST = new HistoryList()); - } - - public static bool IsLoaded() - { - return HISTORY_LIST != null; - } - - public static void RefreshAll() - { - if (HISTORY_LIST == null) - return; - - List entries = HISTORY_LIST.entries; - - for (var i = 0; i < entries.Count; i++) - { - entries[i].Refresh(); - } - } - } -} \ No newline at end of file diff --git a/Editor/History/Window/EditorHistoryWindow.cs b/Editor/History/Window/EditorHistoryWindow.cs index deb45dd..d27600f 100644 --- a/Editor/History/Window/EditorHistoryWindow.cs +++ b/Editor/History/Window/EditorHistoryWindow.cs @@ -5,7 +5,7 @@ using Object = UnityEngine.Object; namespace Module.NavigationTool.Editor.History { - internal sealed class EditorHistoryWindow : EditorWindow + internal sealed class EditorHistoryWindow : EditorWindow, IHasCustomMenu { [NonSerialized] private Styles styles; @@ -38,8 +38,8 @@ namespace Module.NavigationTool.Editor.History return; styles.Initialize(GUI.skin); - var rectTools = new Rect(0.0f, 0.0f, position.width, EditorGUIUtility.singleLineHeight); - var rectList = new Rect(0.0f, rectTools.yMax, position.width, position.height - rectTools.height); + var rectTools = new Rect(0.0f, 4.0f, position.width, EditorGUIUtility.singleLineHeight); + var rectList = new Rect(0.0f, rectTools.yMax + 4.0f, position.width, position.height - rectTools.height - 8.0f); viewTools.Initialize(); viewTools.Draw(this, rectTools, styles); @@ -52,27 +52,43 @@ namespace Module.NavigationTool.Editor.History private void HandleClickEvent() { - if (!HistoryGUIUtility.isClicked) + if (!EditorHistoryGUIUtility.isClicked) return; - HistoryList historyList = HistoryUtility.GetHistoryList(); - Object obj = historyList.GetObject(HistoryGUIUtility.currentEntry); + EditorHistoryList editorHistoryList = EditorHistoryUtility.GetHistoryList(); + Object obj = editorHistoryList.GetObject(EditorHistoryGUIUtility.currentEntry); if (obj != null) { - if (HistoryGUIUtility.isDoubleClick) + if (EditorHistoryGUIUtility.isDoubleClick) { AssetDatabase.OpenAsset(obj); } else { - HistoryListPostProcess.IgnoreNextSelectionChange(); - Selection.activeObject = obj; + EditorHistoryListPostProcess.IgnoreNextSelectionChange(); + + if (EditorHistoryPrefs.IsSetAsActiveObjectEnabled) + Selection.activeObject = obj; + EditorGUIUtility.PingObject(obj); } } - HistoryGUIUtility.Used(); + EditorHistoryGUIUtility.Used(); + } + + void IHasCustomMenu.AddItemsToMenu(GenericMenu menu) + { + menu.AddItem(new GUIContent("Clear"), + false, + () => EditorHistoryUtility.GetHistoryList()?.Clear()); + + menu.AddSeparator(""); + + menu.AddItem(new GUIContent("Active object in selection"), + EditorHistoryPrefs.IsSetAsActiveObjectEnabled, + () => EditorHistoryPrefs.IsSetAsActiveObjectEnabled = !EditorHistoryPrefs.IsSetAsActiveObjectEnabled); } } } \ No newline at end of file diff --git a/Editor/History/Window/Styles/Styles.cs b/Editor/History/Window/Styles/Styles.cs index f5711ad..39be7db 100644 --- a/Editor/History/Window/Styles/Styles.cs +++ b/Editor/History/Window/Styles/Styles.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using UnityEditor; +using UnityEngine; namespace Module.NavigationTool.Editor.History { @@ -8,6 +9,8 @@ namespace Module.NavigationTool.Editor.History public GUIStyle entry; public GUIStyle invalidEntry; + + public GUIContent iconSearch; private GUISkin skin; @@ -27,6 +30,8 @@ namespace Module.NavigationTool.Editor.History invalidEntry.normal.textColor = Color.red; invalidEntry.hover.textColor = invalidEntry.onHover.textColor = new Color(1.0f, 0.3f, 0.3f); invalidEntry.active.textColor = invalidEntry.onActive.textColor = new Color(1.0f, 0.0f, 0.5f); + + iconSearch = EditorGUIUtility.IconContent("d_Search Icon"); } } } \ No newline at end of file diff --git a/Editor/History/Window/Views/EditorHistoryViewSearchList.cs b/Editor/History/Window/Views/EditorHistoryViewSearchList.cs index e71e521..1086aac 100644 --- a/Editor/History/Window/Views/EditorHistoryViewSearchList.cs +++ b/Editor/History/Window/Views/EditorHistoryViewSearchList.cs @@ -11,17 +11,17 @@ namespace Module.NavigationTool.Editor.History private Vector2 scrollPosition; [NonSerialized] - private HistoryList historyList; + private EditorHistoryList editorHistoryList; public override void Initialize() { - historyList = HistoryUtility.GetHistoryList(); + editorHistoryList = EditorHistoryUtility.GetHistoryList(); } public override void Draw(EditorHistoryWindow window, Rect rect, Styles styles) { float entryHeight = EditorGUIUtility.singleLineHeight; - float height = entryHeight * historyList.entries.Count; + float height = entryHeight * editorHistoryList.entries.Count; bool isSearching = !string.IsNullOrEmpty(window.viewTools.searchStr); string lowerSearchStr = window.viewTools.searchStr.ToLower(); @@ -34,14 +34,14 @@ namespace Module.NavigationTool.Editor.History scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect); { - for (int i = historyList.entries.Count - 1; i >= 0; i--) + for (int i = editorHistoryList.entries.Count - 1; i >= 0; i--) { - HistoryList.Entry e = historyList.entries[i]; + EditorHistoryList.Entry e = editorHistoryList.entries[i]; if (isSearching && !e.lowerName.Contains(lowerSearchStr)) continue; - HistoryGUIUtility.DrawEntry(entryRect, historyList.entries[i], styles, true); + EditorHistoryGUIUtility.DrawEntry(entryRect, editorHistoryList.entries[i], styles, true); entryRect.y += entryHeight; } } diff --git a/Editor/History/Window/Views/EditorHistoryViewTools.cs b/Editor/History/Window/Views/EditorHistoryViewTools.cs index 746e26d..8bf120c 100644 --- a/Editor/History/Window/Views/EditorHistoryViewTools.cs +++ b/Editor/History/Window/Views/EditorHistoryViewTools.cs @@ -8,27 +8,28 @@ namespace Module.NavigationTool.Editor.History internal sealed class EditorHistoryViewTools : AbstractEditorHistoryView { public string searchStr = string.Empty; - - [NonSerialized] - private HistoryList historyList; public override void Initialize() { - historyList = HistoryUtility.GetHistoryList(); } public override void Draw(EditorHistoryWindow window, Rect rect, Styles styles) { + const float PADDING = 4.0f; + const float ICON_SIZE = 20.0f; const float BUTTON_SIZE = 50.0f; GUI.BeginGroup(rect, styles.toolbox); { - var r0 = new Rect(0.0f, 0.0f, rect.width - BUTTON_SIZE, rect.height); - var r1 = new Rect(r0.xMax, 0.0f, BUTTON_SIZE, rect.height); - searchStr = EditorGUI.TextField(r0, searchStr); + var r0 = new Rect(PADDING, 0.0f, ICON_SIZE, rect.height); + var r1 = new Rect(r0.xMax, 0.0f, rect.width - BUTTON_SIZE - ICON_SIZE - PADDING * 2.0f, rect.height); + var r2 = new Rect(r1.xMax, 0.0f, BUTTON_SIZE, rect.height); + + GUI.Label(r0, styles.iconSearch); + searchStr = EditorGUI.TextField(r1, searchStr); - if (GUI.Button(r1, "Clear")) - historyList.Clear(); + if (GUI.Button(r2, "Clear")) + searchStr = string.Empty; } GUI.EndGroup(); } diff --git a/package.json b/package.json index 70a3408..567731c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "1.8.3", + "version": "1.8.4", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",