<commit_before>﻿using Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace Launcher
{
    public partial class MainForm : Form
    {
        List<Form> activeForms = new List<Form>();

        public MainForm()
        {
            InitializeComponent();
            Type[] forms = GetAllMainForm();
            Add(forms);
        }

        private void Add(Type[] forms)
        {
            foreach (var type in forms)
            {
                var name = type.Name;
                var attributes = (MainFormAttribute[])type.GetCustomAttributes(typeof(MainFormAttribute), false);
                if (attributes.Length > 0)
                {
                    name = attributes?[0].Name;
                }
                Button button = CreateButton(name);
                button.Click += (sender, e) =>
                {
                    Form form = (Form)Activator.CreateInstance(type);
                    activeForms.Add(form);
                    form.Disposed += (sender2, e2) =>
                    {
                        activeForms.Remove(form);
                        if (activeForms.Count != 0)
                        {
                            activeForms.LastOrDefault().BringToFront();
                        }
                        else if (Visible)
                        {
                            BringToFront();
                        }
                        else
                        {
                            Application.Exit();
                        }
                    };
                    form.Show();
                };

                panel.Controls.Add(button);
            }
        }

        private Button CreateButton(string name)
        {
            Button button = new Button();
            button.FlatAppearance.BorderSize = 0;
            button.FlatStyle = FlatStyle.Popup;
            button.Location = new System.Drawing.Point(3, 3);
            button.Size = new System.Drawing.Size(250, 30);
            button.Text = name;
            button.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            button.TextImageRelation = TextImageRelation.ImageBeforeText;
            button.UseVisualStyleBackColor = true;
            return button;
        }

        private Type[] GetAllMainForm()
        {
            List<Type> forms = new List<Type>();
            Assembly[] assemblies = GetAllAssemblies();
            foreach (var assembly in assemblies)<commit_msg>keep buttons in sorted order as they are added<commit_after>﻿using Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace Launcher
{
    public partial class MainForm : Form
    {
        List<Form> activeForms = new List<Form>();

        public MainForm()
        {
            InitializeComponent();
            Type[] forms = GetAllMainForm();
            Add(forms);
        }

        private void Add(Type[] forms)
        {
            foreach (var type in forms)
            {
                var name = type.Name;
                var attributes = (MainFormAttribute[])type.GetCustomAttributes(typeof(MainFormAttribute), false);
                if (attributes.Length > 0)
                {
                    name = attributes?[0].Name;
                }
                Button button = CreateButton(name);
                button.Click += (sender, e) =>
                {
                    Form form = (Form)Activator.CreateInstance(type);
                    activeForms.Add(form);
                    form.Disposed += (sender2, e2) =>
                    {
                        activeForms.Remove(form);
                        if (activeForms.Count != 0)
                        {
                            activeForms.LastOrDefault().BringToFront();
                        }
                        else if (Visible)
                        {
                            BringToFront();
                        }
                        else
                        {
                            Application.Exit();
                        }
                    };
                    form.Show();
                };

                panel.Controls.Add(button);
                panel.Controls.SetChildIndex(button, panel.Controls.Count - 1);
            }
        }

        private Button CreateButton(string name)
        {
            Button button = new Button();
            button.FlatAppearance.BorderSize = 0;
            button.FlatStyle = FlatStyle.Popup;
            button.Location = new System.Drawing.Point(3, 3);
            button.Size = new System.Drawing.Size(250, 30);
            button.Text = name;
            button.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            button.TextImageRelation = TextImageRelation.ImageBeforeText;
            button.UseVisualStyleBackColor = true;
            return button;
        }

        private Type[] GetAllMainForm()
        {
            List<Type> forms = new List<Type>();
            Assembly[] assemblies = GetAllAssemblies();
            foreach (var assembly in assemblies)
{'fraction_non_alphanumeric': 0.08886774500475737, 'fraction_numerical': 0.005137963843958135, 'mean_word_length': 1.2065491183879093, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '5132343', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1165, 'n_words': 258}