File size: 2,578 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | using UnityEngine;
using UnityEditor.TestTools.CodeCoverage.Utils;
namespace UnityEditor.TestTools.CodeCoverage
{
internal class FolderDropDownMenu
{
GenericMenu m_Menu;
string m_Path;
string m_Message;
readonly CodeCoverageWindow m_Parent;
readonly FolderType m_FolderType;
static class Styles
{
public static readonly GUIContent ShowInExplorerLabel = EditorGUIUtility.TrTextContent("Open Containing Folder");
public static readonly GUIContent ChangeLocationLabel = EditorGUIUtility.TrTextContent("Change Location");
public static readonly GUIContent ResetToDefaultLabel = EditorGUIUtility.TrTextContent("Reset to Default Location");
}
public FolderDropDownMenu(CodeCoverageWindow parent, FolderType type)
{
m_Parent = parent;
m_FolderType = type;
}
private void PopulateMenu()
{
m_Menu = new GenericMenu();
m_Menu.AddItem(Styles.ShowInExplorerLabel, false, () => ShowInExplorer());
m_Menu.AddItem(Styles.ChangeLocationLabel, false, () => ChangeLocation());
if (m_Path.Equals(CoverageUtils.GetProjectPath()))
m_Menu.AddDisabledItem(Styles.ResetToDefaultLabel);
else
m_Menu.AddItem(Styles.ResetToDefaultLabel, false, () => ResetToDefault());
}
public void Show(Rect position, string folderPath, string message)
{
m_Path = folderPath;
m_Message = message;
PopulateMenu();
m_Menu.DropDown(position);
}
private void ShowInExplorer()
{
string path = m_FolderType == FolderType.Results ?
m_Parent.GetResultsRootFolder() :
m_Parent.GetReportHistoryFolder();
EditorUtility.RevealInFinder(path);
}
private void ChangeLocation()
{
string candidate = CoverageUtils.BrowseForDir(m_Path, m_Message);
if (m_FolderType == FolderType.Results)
m_Parent.SetCoverageLocation(candidate);
else
m_Parent.SetCoverageHistoryLocation(candidate);
m_Parent.LoseFocus();
}
private void ResetToDefault()
{
if (m_FolderType == FolderType.Results)
m_Parent.SetDefaultCoverageLocation();
else
m_Parent.SetDefaultCoverageHistoryLocation();
m_Parent.LoseFocus();
}
}
}
|