Repository: FlaxEngine/FlaxEngine
File: Source/Editor/Windows/ContentWindow.cs (C#)

Code before:
            {
                var filterButton = filters.ContextMenu.AddButton(_viewDropdown.Items[i], OnFilterClicked);
                filterButton.Tag = i;
            }
            filters.ContextMenu.VisibleChanged += control =>
            {
                if (!control.Visible)
                    return;
                foreach (var item in ((ContextMenu)control).Items)
                {
                    if (item is ContextMenuButton filterButton)
                        filterButton.Checked = _viewDropdown.IsSelected(filterButton.Text);
                }
            };
            
            var sortBy = menu.AddChildMenu("Sort by");
            sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked).Tag = SortType.AlphabeticOrder;
            sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked).Tag = SortType.AlphabeticReverse;
            sortBy.ContextMenu.VisibleChanged += control =>
            {
                if (!control.Visible)
                    return;
                foreach (var item in ((ContextMenu)control).Items)
                {
                    if (item is ContextMenuButton button)
                        button.Checked = _buttonNameChecked == button.Text;
                }
            };

            return menu;
        }

        private void OnViewTypeButtonClicked(ContextMenuButton button)
        {
            View.ViewType = (ContentViewType)button.Tag;
        }

        private void OnFilterClicked(ContextMenuButton filterButton)
        {
            var i = (int)filterButton.Tag;
            _viewDropdown.OnClicked(i);
        }

        private void OnSortByButtonClicked(ContextMenuButton button)
        {
            _buttonNameChecked = button.Text;
            switch (button.Text)
            {
                case "Alphabetic Order": _sortType = SortType.AlphabeticOrder;
                    break;
                case "Alphabetic Reverse": _sortType = SortType.AlphabeticReverse;

Review comment (suggestion):
This could use `(SortType)button.Tag == _sortType` instead of comparison based on button text.

Code after:
                var filterButton = filters.ContextMenu.AddButton(_viewDropdown.Items[i], OnFilterClicked);
                filterButton.Tag = i;
            }
            filters.ContextMenu.VisibleChanged += control =>
            {
                if (!control.Visible)
                    return;
                foreach (var item in ((ContextMenu)control).Items)
                {
                    if (item is ContextMenuButton filterButton)
                        filterButton.Checked = _viewDropdown.IsSelected(filterButton.Text);
                }
            };
            
            var sortBy = menu.AddChildMenu("Sort by");
            sortBy.ContextMenu.AddButton("Alphabetic Order", OnSortByButtonClicked).Tag = SortType.AlphabeticOrder;
            sortBy.ContextMenu.AddButton("Alphabetic Reverse", OnSortByButtonClicked).Tag = SortType.AlphabeticReverse;
            sortBy.ContextMenu.VisibleChanged += control =>
            {
                if (!control.Visible)
                    return;
                foreach (var item in ((ContextMenu)control).Items)
                {
                    if (item is ContextMenuButton button)
                        button.Checked = _sortType == (SortType)button.Tag;
                }
            };

            return menu;
        }

        private void OnViewTypeButtonClicked(ContextMenuButton button)
        {
            View.ViewType = (ContentViewType)button.Tag;
        }

        private void OnFilterClicked(ContextMenuButton filterButton)
        {
            var i = (int)filterButton.Tag;
            _viewDropdown.OnClicked(i);
        }

        private void OnSortByButtonClicked(ContextMenuButton button)
        {
            switch ((SortType)button.Tag)
            {
                case SortType.AlphabeticOrder: _sortType = SortType.AlphabeticOrder;
                    break;
                case SortType.AlphabeticReverse: _sortType = SortType.AlphabeticReverse;
                    break;
            }