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
This commit is contained in:
Anders Ejlersen 2023-03-27 22:02:44 +02:00
parent 305aa13317
commit 5a2dcf3619
17 changed files with 141 additions and 86 deletions

View file

@ -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);
}
}
}

View file

@ -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");
}
}
}

View file

@ -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;
}
}

View file

@ -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();
}