public void SetAreaSelection(TreeViewSelection selection)
 {
     m_AreaSelection = selection;
     RefreshDisplay();
 }
 public void SetAssemblySelection(TreeViewSelection selection)
 {
     m_AssemblySelection = selection;
     RefreshDisplay();
 }
        private void UpdateAssemblySelection()
        {
            if (m_AssemblyNames == null)
            {
                return;
            }

            if (m_AssemblySelection == null)
            {
                m_AssemblySelection = new TreeViewSelection();
            }

            m_AssemblySelection.selection.Clear();
            if (!string.IsNullOrEmpty(m_AssemblySelectionSummary))
            {
                if (m_AssemblySelectionSummary == "All")
                {
                    m_AssemblySelection.SetAll(m_AssemblyNames);
                }
                else if (m_AssemblySelectionSummary != "None")
                {
                    var assemblies = m_AssemblySelectionSummary.Split(new[] { ", " }, StringSplitOptions.None)
                                     .Where(assemblyName => m_AssemblyNames.Contains(assemblyName));
                    if (assemblies.Count() > 0)
                    {
                        foreach (var assembly in assemblies)
                        {
                            m_AssemblySelection.selection.Add(assembly);
                        }
                    }
                }
            }

            if (!m_AssemblySelection.selection.Any())
            {
                // initial selection setup:
                // - assemblies from user scripts or editable packages, or
                // - default assembly, or,
                // - all generated assemblies

                var compiledAssemblies = m_AssemblyNames.Where(a => !AssemblyHelper.IsModuleAssembly(a));
                if (AssemblyHelper.IsPackageInfoAvailable())
                {
                    compiledAssemblies = compiledAssemblies.Where(a =>
                                                                  !AssemblyHelper.GetAssemblyInfoFromAssemblyPath(a).readOnly);
                }
                m_AssemblySelection.selection.AddRange(compiledAssemblies);

                if (!m_AssemblySelection.selection.Any())
                {
                    if (m_AssemblyNames.Contains(AssemblyHelper.DefaultAssemblyName))
                    {
                        m_AssemblySelection.Set(AssemblyHelper.DefaultAssemblyName);
                    }
                    else
                    {
                        m_AssemblySelection.SetAll(m_AssemblyNames);
                    }
                }
            }

            // update assembly selection summary
            m_AssemblySelectionSummary = GetSelectedAssembliesSummary();
        }
        // SteveM TODO - This seems wildly more complex than it needs to be... UNLESS assemblies can have sub-assemblies?
        // If that's the case, we need to test for that. Otherwise we need to strip a bunch of this complexity out.
        private string GetSelectedSummary(TreeViewSelection selection, string[] names)
        {
            if (selection.selection == null || selection.selection.Count == 0)
            {
                return("None");
            }

            // Count all items in a group
            var dict          = new Dictionary <string, int>();
            var selectionDict = new Dictionary <string, int>();

            foreach (var nameWithIndex in names)
            {
                var identifier = new TreeItemIdentifier(nameWithIndex);
                if (identifier.index == TreeItemIdentifier.kAll)
                {
                    continue;
                }

                int count;
                if (dict.TryGetValue(identifier.name, out count))
                {
                    dict[identifier.name] = count + 1;
                }
                else
                {
                    dict[identifier.name] = 1;
                }

                selectionDict[identifier.name] = 0;
            }

            // Count all the items we have 'selected' in a group
            foreach (var nameWithIndex in selection.selection)
            {
                var identifier = new TreeItemIdentifier(nameWithIndex);

                if (dict.ContainsKey(identifier.name) &&
                    selectionDict.ContainsKey(identifier.name) &&
                    identifier.index <= dict[identifier.name])
                {
                    // Selected assembly valid and in the assembly list
                    // and also within the range of valid assemblies for this data set
                    selectionDict[identifier.name]++;
                }
            }

            // Count all groups where we have 'selected all the items'
            var selectedCount = 0;

            foreach (var name in dict.Keys)
            {
                if (selectionDict[name] != dict[name])
                {
                    continue;
                }

                selectedCount++;
            }

            // If we've just added all the item names we have everything selected
            // Note we don't compare against the names array directly as this contains the 'all' versions
            if (selectedCount == dict.Keys.Count)
            {
                return("All");
            }

            // Add all the individual items were we haven't already added the group
            var individualItems = new List <string>();

            foreach (var name in selectionDict.Keys)
            {
                var selectionCount = selectionDict[name];
                if (selectionCount <= 0)
                {
                    continue;
                }
                var itemCount = dict[name];
                if (itemCount == 1)
                {
                    individualItems.Add(name);
                }
                else if (selectionCount != itemCount)
                {
                    individualItems.Add(string.Format("{0} ({1} of {2})", name, selectionCount, itemCount));
                }
                else
                {
                    individualItems.Add(string.Format("{0} (All)", name));
                }
            }

            // Maintain alphabetical order
            individualItems.Sort(CompareUINames);

            if (individualItems.Count == 0)
            {
                return("None");
            }

            return(string.Join(", ", individualItems.ToArray()));
        }
 void SetData(ProjectAuditorWindow projectAuditorWindow, TreeViewSelection selection, string[] names)
 {
     m_ProjectAuditorWindow = projectAuditorWindow;
     CreateTable(projectAuditorWindow, selection, names);
 }
        static public AssemblySelectionWindow Open(float screenX, float screenY, ProjectAuditorWindow projectAuditorWindow, TreeViewSelection selection, string[] names)
        {
            AssemblySelectionWindow window = GetWindow <AssemblySelectionWindow>("Assemblies");

            window.position = new Rect(screenX, screenY, 400, 500);
            window.SetData(projectAuditorWindow, selection, names);
            window.Show();

            return(window);
        }
Exemplo n.º 7
0
        public MultiSelectionTable(TreeViewState state, MultiColumnHeader multicolumnHeader, string[] names, TreeViewSelection selection) : base(state, multicolumnHeader)
        {
            m_AllIdentifier = new TreeItemIdentifier();
            m_AllIdentifier.SetName("All");
            m_AllIdentifier.SetAll();

            Assert.AreEqual(m_SortOptions.Length, Enum.GetValues(typeof(MyColumns)).Length, "Ensure number of sort options are in sync with number of MyColumns enum values");

            // Custom setup
            rowHeight = kRowHeights;
            showAlternatingRowBackgrounds = true;
            showBorder           = true;
            customFoldoutYOffset = (kRowHeights - EditorGUIUtility.singleLineHeight) * 0.5f; // center foldout in the row since we also center content. See RowGUI
            // extraSpaceBeforeIconAndLabel = 0;
            multicolumnHeader.sortingChanged += OnSortingChanged;

            m_Names     = names;
            m_Selection = new TreeViewSelection(selection);
            Reload();
        }
Exemplo n.º 8
0
        private void OnEnable()
        {
            m_ProjectAuditor = new ProjectAuditor();

            var assemblyNames = m_ProjectAuditor.GetAuditor <ScriptAuditor>().assemblyNames.ToList();

            assemblyNames.Sort();
            m_AssemblyNames = assemblyNames.ToArray();

            if (m_AssemblySelection == null)
            {
                m_AssemblySelection = new TreeViewSelection();

                if (!string.IsNullOrEmpty(m_AssemblySelectionSummary))
                {
                    if (m_AssemblySelectionSummary == "All")
                    {
                        m_AssemblySelection.SetAll(m_AssemblyNames);
                    }
                    else if (m_AssemblySelectionSummary != "None")
                    {
                        string[] assemblies = m_AssemblySelectionSummary.Split(new string[] { ", " }, StringSplitOptions.None);
                        foreach (string assembly in assemblies)
                        {
                            m_AssemblySelection.selection.Add(assembly);
                        }
                    }
                }
                else if (m_AssemblyNames.Contains(m_DefaultAssemblyName))
                {
                    m_AssemblySelection.Set(m_DefaultAssemblyName);
                }
                else
                {
                    m_AssemblySelection.SetAll(m_AssemblyNames);
                }
            }

            if (m_AreaSelection == null)
            {
                m_AreaSelection = new TreeViewSelection();
                if (!string.IsNullOrEmpty(m_AreaSelectionSummary))
                {
                    if (m_AreaSelectionSummary == "All")
                    {
                        m_AreaSelection.SetAll(m_AreaNames);
                    }
                    else if (m_AreaSelectionSummary != "None")
                    {
                        string[] areas = m_AreaSelectionSummary.Split(new string[] { ", " }, StringSplitOptions.None);
                        foreach (string area in areas)
                        {
                            m_AreaSelection.selection.Add(area);
                        }
                    }
                }
                else
                {
                    m_AreaSelection.SetAll(m_AreaNames);
                }
            }

            m_CallHierarchyView = new CallHierarchyView(new TreeViewState());

            RefreshDisplay();
        }