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
7 changed files with 148 additions and 29 deletions
|
|
@ -10,27 +10,41 @@ namespace Module.NavigationTool.Editor.History
|
|||
|
||||
public static bool isClicked;
|
||||
public static bool isDoubleClick;
|
||||
public static bool isPinClicked;
|
||||
public static EditorHistoryList.Entry currentEntry;
|
||||
|
||||
public static bool isCurrentEntryPinned;
|
||||
|
||||
private static EditorHistoryList.Entry LAST_CLICK_ENTRY;
|
||||
private static double LAST_CLICK_TIME;
|
||||
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);
|
||||
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)
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
if (intersects)
|
||||
{
|
||||
isPinClicked = intersectsPin;
|
||||
currentEntry = entry;
|
||||
isCurrentEntryPinned = isPinned;
|
||||
Event.current.Use();
|
||||
}
|
||||
break;
|
||||
case EventType.MouseMove:
|
||||
Event.current.Use();
|
||||
break;
|
||||
case EventType.MouseUp:
|
||||
if (currentEntry == entry)
|
||||
{
|
||||
|
|
@ -38,16 +52,19 @@ namespace Module.NavigationTool.Editor.History
|
|||
|
||||
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)
|
||||
CLICK_COUNT++;
|
||||
else
|
||||
CLICK_COUNT = 1;
|
||||
if (dt < 0.3 && CLICK_COUNT == 1 && LAST_CLICK_ENTRY == entry)
|
||||
CLICK_COUNT++;
|
||||
else
|
||||
CLICK_COUNT = 1;
|
||||
|
||||
LAST_CLICK_ENTRY = entry;
|
||||
LAST_CLICK_TIME = EditorApplication.timeSinceStartup;
|
||||
isDoubleClick = CLICK_COUNT == 2;
|
||||
LAST_CLICK_ENTRY = entry;
|
||||
LAST_CLICK_TIME = EditorApplication.timeSinceStartup;
|
||||
isDoubleClick = CLICK_COUNT == 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -61,10 +78,23 @@ namespace Module.NavigationTool.Editor.History
|
|||
}
|
||||
break;
|
||||
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();
|
||||
EditorGUIUtility.SetIconSize(new Vector2(rect.height, rect.height));
|
||||
EditorGUIUtility.SetIconSize(new Vector2(r1.height, r1.height));
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,12 @@ namespace Module.NavigationTool.Editor.History
|
|||
public static readonly string PREF_ID = "PREF_HISTORY_LIST";
|
||||
public const int MAX_LENGTH = 64;
|
||||
|
||||
public List<Entry> pinnedEntries;
|
||||
public List<Entry> entries;
|
||||
|
||||
public EditorHistoryList()
|
||||
{
|
||||
pinnedEntries = new List<Entry>();
|
||||
entries = new List<Entry>();
|
||||
string json = EditorProjectPrefs.GetString(PREF_ID);
|
||||
|
||||
|
|
@ -88,6 +90,42 @@ namespace Module.NavigationTool.Editor.History
|
|||
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)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(entry.guid);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue