File size: 2,657 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 | using System.Linq;
using System;
using UnityEngine;
using UnityEditor.TestTools.CodeCoverage.Utils;
namespace UnityEditor.TestTools.CodeCoverage
{
internal class PathToAddHandler
{
string m_PathsToFilter;
readonly CodeCoverageWindow m_Parent;
readonly PathFilterType m_PathFilterType;
private readonly string kSelectIncludedDirectoryMessage = L10n.Tr($"Select directory to include");
private readonly string kSelectIncludedFileMessage = L10n.Tr("Select file to include");
private readonly string kSelectExcludedDirectoryMessage = L10n.Tr($"Select directory to exclude");
private readonly string kSelectExcludedFileMessage = L10n.Tr("Select file to exclude");
public PathToAddHandler(CodeCoverageWindow parent, PathFilterType type)
{
m_Parent = parent;
m_PathFilterType = type;
}
public void BrowseForDir(string pathsToFilter)
{
m_PathsToFilter = pathsToFilter;
string candidate = CoverageUtils.BrowseForDir(Application.dataPath, m_PathFilterType == PathFilterType.Include ? kSelectIncludedDirectoryMessage : kSelectExcludedDirectoryMessage);
if (CoverageUtils.IsValidFolder(candidate))
{
candidate = string.Concat(candidate, "/**");
UpdatePathToFilter(candidate);
}
}
public void BrowseForFile(string pathsToFilter)
{
m_PathsToFilter = pathsToFilter;
string candidate = CoverageUtils.BrowseForFile(Application.dataPath, m_PathFilterType == PathFilterType.Include ? kSelectIncludedFileMessage : kSelectExcludedFileMessage);
if (CoverageUtils.IsValidFile(candidate))
{
UpdatePathToFilter(candidate);
}
}
private void UpdatePathToFilter(string candidate)
{
string[] pathFilters = m_PathsToFilter.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
candidate = CoverageUtils.NormaliseFolderSeparators(candidate);
if (!pathFilters.Contains(candidate))
{
if (m_PathsToFilter.Length > 0)
m_PathsToFilter += ",";
m_PathsToFilter += candidate;
if (m_PathFilterType == PathFilterType.Include)
{
m_Parent.PathsToInclude = m_PathsToFilter;
}
else
{
m_Parent.PathsToExclude = m_PathsToFilter;
}
m_Parent.LoseFocus();
}
}
}
}
|