1.8.5: Marking history elements as favorites will move them to the top of the list
This commit is contained in:
parent
5a2dcf3619
commit
959f012d80
|
|
@ -1,6 +1,12 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [1.8.5] - 2023-03-28
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Marking history elements as favorites will move them to the top of the list
|
||||||
|
|
||||||
|
|
||||||
## [1.8.4] - 2023-03-27
|
## [1.8.4] - 2023-03-27
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -10,27 +10,41 @@ namespace Module.NavigationTool.Editor.History
|
||||||
|
|
||||||
public static bool isClicked;
|
public static bool isClicked;
|
||||||
public static bool isDoubleClick;
|
public static bool isDoubleClick;
|
||||||
|
public static bool isPinClicked;
|
||||||
public static EditorHistoryList.Entry currentEntry;
|
public static EditorHistoryList.Entry currentEntry;
|
||||||
|
public static bool isCurrentEntryPinned;
|
||||||
|
|
||||||
private static EditorHistoryList.Entry LAST_CLICK_ENTRY;
|
private static EditorHistoryList.Entry LAST_CLICK_ENTRY;
|
||||||
private static double LAST_CLICK_TIME;
|
private static double LAST_CLICK_TIME;
|
||||||
private static int CLICK_COUNT;
|
private static int CLICK_COUNT;
|
||||||
|
|
||||||
public static void DrawEntry(Rect rect, EditorHistoryList.Entry entry, Styles styles, bool ignoreIndentLevel = false)
|
public static void DrawEntry(Rect rect, EditorHistoryList.Entry entry, Styles styles, bool isPinned)
|
||||||
{
|
{
|
||||||
|
const float PIN_WIDTH = 20.0f;
|
||||||
|
var r0 = new Rect(rect.x, rect.y, PIN_WIDTH, rect.height);
|
||||||
|
var r1 = new Rect(r0.xMax, rect.y, rect.width - PIN_WIDTH, rect.height);
|
||||||
|
|
||||||
int id = GUIUtility.GetControlID(ENTRY_HASH, FocusType.Passive, rect);
|
int id = GUIUtility.GetControlID(ENTRY_HASH, FocusType.Passive, rect);
|
||||||
bool on = currentEntry == entry;
|
bool on = currentEntry == entry;
|
||||||
bool intersects = rect.Contains(Event.current.mousePosition);
|
|
||||||
|
bool intersectsPin = r0.Contains(Event.current.mousePosition);
|
||||||
|
bool intersectsEntry = r1.Contains(Event.current.mousePosition);
|
||||||
|
bool intersects = intersectsPin || intersectsEntry;
|
||||||
|
|
||||||
switch (Event.current.type)
|
switch (Event.current.type)
|
||||||
{
|
{
|
||||||
case EventType.MouseDown:
|
case EventType.MouseDown:
|
||||||
if (intersects)
|
if (intersects)
|
||||||
{
|
{
|
||||||
|
isPinClicked = intersectsPin;
|
||||||
currentEntry = entry;
|
currentEntry = entry;
|
||||||
|
isCurrentEntryPinned = isPinned;
|
||||||
Event.current.Use();
|
Event.current.Use();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case EventType.MouseMove:
|
||||||
|
Event.current.Use();
|
||||||
|
break;
|
||||||
case EventType.MouseUp:
|
case EventType.MouseUp:
|
||||||
if (currentEntry == entry)
|
if (currentEntry == entry)
|
||||||
{
|
{
|
||||||
|
|
@ -38,16 +52,19 @@ namespace Module.NavigationTool.Editor.History
|
||||||
|
|
||||||
if (isClicked)
|
if (isClicked)
|
||||||
{
|
{
|
||||||
double dt = EditorApplication.timeSinceStartup - LAST_CLICK_TIME;
|
if (!isPinClicked)
|
||||||
|
{
|
||||||
|
double dt = EditorApplication.timeSinceStartup - LAST_CLICK_TIME;
|
||||||
|
|
||||||
if (dt < 0.3 && CLICK_COUNT == 1 && LAST_CLICK_ENTRY == entry)
|
if (dt < 0.3 && CLICK_COUNT == 1 && LAST_CLICK_ENTRY == entry)
|
||||||
CLICK_COUNT++;
|
CLICK_COUNT++;
|
||||||
else
|
else
|
||||||
CLICK_COUNT = 1;
|
CLICK_COUNT = 1;
|
||||||
|
|
||||||
LAST_CLICK_ENTRY = entry;
|
LAST_CLICK_ENTRY = entry;
|
||||||
LAST_CLICK_TIME = EditorApplication.timeSinceStartup;
|
LAST_CLICK_TIME = EditorApplication.timeSinceStartup;
|
||||||
isDoubleClick = CLICK_COUNT == 2;
|
isDoubleClick = CLICK_COUNT == 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -61,10 +78,23 @@ namespace Module.NavigationTool.Editor.History
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EventType.Repaint:
|
case EventType.Repaint:
|
||||||
|
if (isPinned)
|
||||||
|
{
|
||||||
|
GUI.color = intersectsPin ? styles.colorToggleOff : styles.colorToggleOn;
|
||||||
|
styles.icon.Draw(r0, styles.iconPinned, id, on, intersectsPin);
|
||||||
|
GUI.color = Color.white;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUI.color = intersectsPin ? styles.colorToggleOff : styles.colorNone;
|
||||||
|
styles.icon.Draw(r0, styles.iconUnpinned, id, on, intersectsPin);
|
||||||
|
GUI.color = Color.white;
|
||||||
|
}
|
||||||
|
|
||||||
Vector2 oldSize = EditorGUIUtility.GetIconSize();
|
Vector2 oldSize = EditorGUIUtility.GetIconSize();
|
||||||
EditorGUIUtility.SetIconSize(new Vector2(rect.height, rect.height));
|
EditorGUIUtility.SetIconSize(new Vector2(r1.height, r1.height));
|
||||||
GUIStyle style = entry.valid ? styles.entry : styles.invalidEntry;
|
GUIStyle style = entry.valid ? styles.entry : styles.invalidEntry;
|
||||||
style.Draw(rect, entry.content, id, on, intersects);
|
style.Draw(r1, entry.content, id, on, intersectsEntry);
|
||||||
EditorGUIUtility.SetIconSize(oldSize);
|
EditorGUIUtility.SetIconSize(oldSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,12 @@ namespace Module.NavigationTool.Editor.History
|
||||||
public static readonly string PREF_ID = "PREF_HISTORY_LIST";
|
public static readonly string PREF_ID = "PREF_HISTORY_LIST";
|
||||||
public const int MAX_LENGTH = 64;
|
public const int MAX_LENGTH = 64;
|
||||||
|
|
||||||
|
public List<Entry> pinnedEntries;
|
||||||
public List<Entry> entries;
|
public List<Entry> entries;
|
||||||
|
|
||||||
public EditorHistoryList()
|
public EditorHistoryList()
|
||||||
{
|
{
|
||||||
|
pinnedEntries = new List<Entry>();
|
||||||
entries = new List<Entry>();
|
entries = new List<Entry>();
|
||||||
string json = EditorProjectPrefs.GetString(PREF_ID);
|
string json = EditorProjectPrefs.GetString(PREF_ID);
|
||||||
|
|
||||||
|
|
@ -88,6 +90,42 @@ namespace Module.NavigationTool.Editor.History
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Pin(Entry entry)
|
||||||
|
{
|
||||||
|
if (IsPinned(entry))
|
||||||
|
return;
|
||||||
|
|
||||||
|
pinnedEntries.Add(entry);
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unpin(Entry entry)
|
||||||
|
{
|
||||||
|
int index = IndexOfPinned(entry);
|
||||||
|
|
||||||
|
if (index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pinnedEntries.RemoveAt(index);
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsPinned(Entry entry)
|
||||||
|
{
|
||||||
|
return IndexOfPinned(entry) != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int IndexOfPinned(Entry entry)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < pinnedEntries.Count; i++)
|
||||||
|
{
|
||||||
|
if (pinnedEntries[i].guid.Equals(entry.guid))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public Object GetObject(Entry entry)
|
public Object GetObject(Entry entry)
|
||||||
{
|
{
|
||||||
string path = AssetDatabase.GUIDToAssetPath(entry.guid);
|
string path = AssetDatabase.GUIDToAssetPath(entry.guid);
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,9 @@ namespace Module.NavigationTool.Editor.History
|
||||||
viewSearchList.Draw(this, rectList, styles);
|
viewSearchList.Draw(this, rectList, styles);
|
||||||
|
|
||||||
HandleClickEvent();
|
HandleClickEvent();
|
||||||
|
|
||||||
|
if (Event.current.type == EventType.Repaint && position.Contains(Event.current.mousePosition))
|
||||||
|
Repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleClickEvent()
|
private void HandleClickEvent()
|
||||||
|
|
@ -56,22 +59,33 @@ namespace Module.NavigationTool.Editor.History
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EditorHistoryList editorHistoryList = EditorHistoryUtility.GetHistoryList();
|
EditorHistoryList editorHistoryList = EditorHistoryUtility.GetHistoryList();
|
||||||
Object obj = editorHistoryList.GetObject(EditorHistoryGUIUtility.currentEntry);
|
|
||||||
|
|
||||||
if (obj != null)
|
if (EditorHistoryGUIUtility.isPinClicked)
|
||||||
{
|
{
|
||||||
if (EditorHistoryGUIUtility.isDoubleClick)
|
if (EditorHistoryGUIUtility.isCurrentEntryPinned)
|
||||||
{
|
editorHistoryList.Unpin(EditorHistoryGUIUtility.currentEntry);
|
||||||
AssetDatabase.OpenAsset(obj);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
editorHistoryList.Pin(EditorHistoryGUIUtility.currentEntry);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Object obj = editorHistoryList.GetObject(EditorHistoryGUIUtility.currentEntry);
|
||||||
|
|
||||||
|
if (obj != null)
|
||||||
{
|
{
|
||||||
EditorHistoryListPostProcess.IgnoreNextSelectionChange();
|
if (EditorHistoryGUIUtility.isDoubleClick)
|
||||||
|
{
|
||||||
|
AssetDatabase.OpenAsset(obj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EditorHistoryListPostProcess.IgnoreNextSelectionChange();
|
||||||
|
|
||||||
if (EditorHistoryPrefs.IsSetAsActiveObjectEnabled)
|
if (EditorHistoryPrefs.IsSetAsActiveObjectEnabled)
|
||||||
Selection.activeObject = obj;
|
Selection.activeObject = obj;
|
||||||
|
|
||||||
EditorGUIUtility.PingObject(obj);
|
EditorGUIUtility.PingObject(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,17 @@ namespace Module.NavigationTool.Editor.History
|
||||||
{
|
{
|
||||||
public GUIStyle toolbox;
|
public GUIStyle toolbox;
|
||||||
|
|
||||||
|
public GUIStyle icon;
|
||||||
public GUIStyle entry;
|
public GUIStyle entry;
|
||||||
public GUIStyle invalidEntry;
|
public GUIStyle invalidEntry;
|
||||||
|
|
||||||
public GUIContent iconSearch;
|
public GUIContent iconSearch;
|
||||||
|
public GUIContent iconPinned;
|
||||||
|
public GUIContent iconUnpinned;
|
||||||
|
|
||||||
|
public Color colorNone;
|
||||||
|
public Color colorToggleOff;
|
||||||
|
public Color colorToggleOn;
|
||||||
|
|
||||||
private GUISkin skin;
|
private GUISkin skin;
|
||||||
|
|
||||||
|
|
@ -22,6 +29,12 @@ namespace Module.NavigationTool.Editor.History
|
||||||
this.skin = skin;
|
this.skin = skin;
|
||||||
toolbox = new GUIStyle(skin.box);
|
toolbox = new GUIStyle(skin.box);
|
||||||
|
|
||||||
|
icon = new GUIStyle
|
||||||
|
{
|
||||||
|
imagePosition = ImagePosition.ImageOnly,
|
||||||
|
padding = new RectOffset(4, 0, 1, 0)
|
||||||
|
};
|
||||||
|
|
||||||
entry = new GUIStyle(skin.label);
|
entry = new GUIStyle(skin.label);
|
||||||
entry.hover.textColor = entry.onHover.textColor = Color.white;
|
entry.hover.textColor = entry.onHover.textColor = Color.white;
|
||||||
entry.active.textColor = entry.onActive.textColor = Color.yellow;
|
entry.active.textColor = entry.onActive.textColor = Color.yellow;
|
||||||
|
|
@ -32,6 +45,12 @@ namespace Module.NavigationTool.Editor.History
|
||||||
invalidEntry.active.textColor = invalidEntry.onActive.textColor = new Color(1.0f, 0.0f, 0.5f);
|
invalidEntry.active.textColor = invalidEntry.onActive.textColor = new Color(1.0f, 0.0f, 0.5f);
|
||||||
|
|
||||||
iconSearch = EditorGUIUtility.IconContent("d_Search Icon");
|
iconSearch = EditorGUIUtility.IconContent("d_Search Icon");
|
||||||
|
iconPinned = EditorGUIUtility.IconContent("d_Favorite");
|
||||||
|
iconUnpinned = EditorGUIUtility.IconContent("Favorite");
|
||||||
|
|
||||||
|
colorNone = new Color(1.0f, 1.0f, 1.0f, 0.0f);
|
||||||
|
colorToggleOff = new Color(1.0f, 1.0f, 1.0f, 0.5f);
|
||||||
|
colorToggleOn = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
@ -34,6 +35,17 @@ namespace Module.NavigationTool.Editor.History
|
||||||
|
|
||||||
scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect);
|
scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect);
|
||||||
{
|
{
|
||||||
|
for (int i = editorHistoryList.pinnedEntries.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
EditorHistoryList.Entry e = editorHistoryList.pinnedEntries[i];
|
||||||
|
|
||||||
|
if (isSearching && !e.lowerName.Contains(lowerSearchStr))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
EditorHistoryGUIUtility.DrawEntry(entryRect, editorHistoryList.pinnedEntries[i], styles, true);
|
||||||
|
entryRect.y += entryHeight;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = editorHistoryList.entries.Count - 1; i >= 0; i--)
|
for (int i = editorHistoryList.entries.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
EditorHistoryList.Entry e = editorHistoryList.entries[i];
|
EditorHistoryList.Entry e = editorHistoryList.entries[i];
|
||||||
|
|
@ -41,7 +53,7 @@ namespace Module.NavigationTool.Editor.History
|
||||||
if (isSearching && !e.lowerName.Contains(lowerSearchStr))
|
if (isSearching && !e.lowerName.Contains(lowerSearchStr))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
EditorHistoryGUIUtility.DrawEntry(entryRect, editorHistoryList.entries[i], styles, true);
|
EditorHistoryGUIUtility.DrawEntry(entryRect, editorHistoryList.entries[i], styles, false);
|
||||||
entryRect.y += entryHeight;
|
entryRect.y += entryHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.module.navigationtool",
|
"name": "com.module.navigationtool",
|
||||||
"version": "1.8.4",
|
"version": "1.8.5",
|
||||||
"displayName": "Module.NavigationTool",
|
"displayName": "Module.NavigationTool",
|
||||||
"description": "Support for navigation tools, like favorites, history and toolbars",
|
"description": "Support for navigation tools, like favorites, history and toolbars",
|
||||||
"unity": "2019.2",
|
"unity": "2019.2",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue