private bool AddOrdering(IPage page, PageCapability.Ordering ordering) { var matchCurrentFilter = false; orderingMenu.menu.AppendAction($"{L10n.Tr(ordering.displayName)}", a => { orderingMenu.text = $"{L10n.Tr("Sort: ")} {a.name}"; var filters = page.filters.Clone(); filters.orderBy = ordering.orderBy; filters.isReverseOrder = ordering.order == PageCapability.Order.Descending; if (page.UpdateFilters(filters)) { PackageManagerFiltersAnalytics.SendEvent(filters); } }, a => { return(page.filters.orderBy == ordering.orderBy && (page.filters.isReverseOrder ? ordering.order == PageCapability.Order.Descending : ordering.order != PageCapability.Order.Descending) ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal); }); if (page.filters?.orderBy == ordering.orderBy && (page.filters?.isReverseOrder ?? false ? ordering.order == PageCapability.Order.Descending : ordering.order != PageCapability.Order.Descending) ) { matchCurrentFilter = true; orderingMenu.text = $"Sort: {L10n.Tr(ordering.displayName)}"; } return(matchCurrentFilter); }
private void SetupFilters() { filtersMenu.ShowTextTooltipOnSizeChange(-16); filtersMenu.clicked += () => { if (PackageManagerFiltersWindow.instance != null) { PackageManagerFiltersWindow.instance.Close(); } var page = m_PageManager.GetCurrentPage(); if (page != null && PackageManagerFiltersWindow.ShowAtPosition(GUIUtility.GUIToScreenRect(filtersMenu.worldBound), page)) { filtersMenu.pseudoStates |= PseudoStates.Active; PackageManagerFiltersWindow.instance.OnFiltersChanged += filters => { if (page.UpdateFilters(filters)) { PackageManagerFiltersAnalytics.SendEvent(filters); } }; PackageManagerFiltersWindow.instance.OnClose += () => { filtersMenu.pseudoStates &= ~PseudoStates.Active; }; } }; clearFiltersButton.clicked += () => { var page = m_PageManager.GetCurrentPage(); page.ClearFilters(); }; }
private void UpdateOrdering(IPage page) { orderingMenu.menu.MenuItems().Clear(); var shouldDisplayOrdering = page?.capability.orderingValues?.Any() ?? false; if (!shouldDisplayOrdering) { UIUtils.SetElementDisplay(orderingMenu, false); return; } UIUtils.SetElementDisplay(orderingMenu, true); var matchCurrentFilter = false; if (shouldDisplayOrdering) { foreach (var ordering in page.capability.orderingValues) { matchCurrentFilter |= AddOrdering(page, ordering); } } if (!matchCurrentFilter) { var filters = page.filters?.Clone(); var firstOrdering = page.capability?.orderingValues?.FirstOrDefault(); if (filters != null && firstOrdering != null) { orderingMenu.text = $"Sort: {L10n.Tr(firstOrdering.displayName)}"; filters.orderBy = firstOrdering.orderBy; filters.isReverseOrder = firstOrdering.order == PageCapability.Order.Descending; if (page.UpdateFilters(filters)) { PackageManagerFiltersAnalytics.SendEvent(filters); } } } }