<commit_before>﻿using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Controls.Platform;

#nullable enable

namespace Avalonia.Win32
{
    internal class Win32NativeToManagedMenuExporter : INativeMenuExporter
    {
        private NativeMenu? _nativeMenu;

        public void SetNativeMenu(NativeMenu nativeMenu)
        {
            _nativeMenu = nativeMenu;
        }

        private IEnumerable<MenuItem>? Populate (NativeMenu nativeMenu)
        {
            var items = new List<MenuItem>();

            foreach (var menuItem in nativeMenu.Items)
            {
                if (menuItem is NativeMenuItemSeparator separator)
                {
                    items.Add(new MenuItem { Header = "-" });   
                }
                else if (menuItem is NativeMenuItem item)
                {
                    var newItem = new MenuItem { Header = item.Header, Icon = item.Icon, Command = item.Command, CommandParameter = item.CommandParameter };

                    if(item.Menu != null)
                    {
                        newItem.ContextMenu = new ContextMenu() { Items = Populate(item.Menu) };
                    }
                    else if (item.HasClickHandlers && item is INativeMenuItemExporterEventsImplBridge bridge)
                    {
                        newItem.Click += (s, e) => bridge.RaiseClicked();
                    }

                    items.Add(newItem);
                }
            }

            return items;
        }

        public IEnumerable<MenuItem>? GetMenu ()
        {
            if(_nativeMenu != null)
            {
                return Populate(_nativeMenu);<commit_msg>fix sub-menus win32 trayicons<commit_after>﻿using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Controls.Platform;

#nullable enable

namespace Avalonia.Win32
{
    internal class Win32NativeToManagedMenuExporter : INativeMenuExporter
    {
        private NativeMenu? _nativeMenu;

        public void SetNativeMenu(NativeMenu nativeMenu)
        {
            _nativeMenu = nativeMenu;
        }

        private IEnumerable<MenuItem>? Populate (NativeMenu nativeMenu)
        {
            var items = new List<MenuItem>();

            foreach (var menuItem in nativeMenu.Items)
            {
                if (menuItem is NativeMenuItemSeparator separator)
                {
                    items.Add(new MenuItem { Header = "-" });   
                }
                else if (menuItem is NativeMenuItem item)
                {
                    var newItem = new MenuItem { Header = item.Header, Icon = item.Icon, Command = item.Command, CommandParameter = item.CommandParameter };

                    if(item.Menu != null)
                    {
                        newItem.Items = Populate(item.Menu);
                    }
                    else if (item.HasClickHandlers && item is INativeMenuItemExporterEventsImplBridge bridge)
                    {
                        newItem.Click += (s, e) => bridge.RaiseClicked();
                    }

                    items.Add(newItem);
                }
            }

            return items;
        }

        public IEnumerable<MenuItem>? GetMenu ()
        {
            if(_nativeMenu != null)
            {
                return Populate(_nativeMenu);
{'fraction_non_alphanumeric': 0.07779772591262717, 'fraction_numerical': 0.002992220227408737, 'mean_word_length': 1.459896983075791, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '980227', 'n_tokens_mistral': 832, 'n_tokens_neox': 779, 'n_words': 181}