<commit_before>using System;
using Selene.Backend;
using Qyoto;

namespace Selene.Qyoto.Frontend
{
    public abstract class QModalDialog<T> : ModalPresenterBase<QObject, T> where T : class
    {
        protected QDialog Dialog;
        protected QHBoxLayout InnerLayout;

        QVBoxLayout Layout;
        QPushButton OkButton, CancelButton;
        QHBoxLayout Buttons;

        public QModalDialog(string Title)
        {
            Dialog = new QDialog();
            OkButton = new QPushButton("OK");           // Localization?
            CancelButton = new QPushButton("Cancel");

            Layout = new QVBoxLayout(Dialog);
            Buttons = new QHBoxLayout();
            InnerLayout = new QHBoxLayout();

            Buttons.AddWidget(CancelButton);
            Buttons.AddStretch(1);
            Buttons.AddWidget(OkButton);
            Layout.AddLayout(InnerLayout);
            Layout.AddLayout(Buttons);
            Layout.sizeConstraint = QLayout.SizeConstraint.SetFixedSize;

            Dialog.SetWindowTitle(Title);

            QWidget.Connect(OkButton, Qt.SIGNAL("clicked()"), ClickOk);
            QWidget.Connect(CancelButton, Qt.SIGNAL("clicked()"), ClickCancel);

            OkButton.SetFocus();
        }

        void ClickCancel()
        {
            Dialog.Reject();
        }

        void ClickOk()
        {
            Dialog.Accept();
        }

        public override void Hide ()
        {
            Dialog.Hide();
        }

        public override bool Run (T Present)
        {
            base.Run (Present);

            if(Dialog.Exec() == 1)
            {
                Save();
                return true;
            }
            else return false;
        }

        public override void Show ()
        {
            Dialog.Show();
        }

        internal void AddCategory(CategoryLay Lay, ControlCategory Cat)
        {
            foreach(ControlSubcategory Subcat in Cat.Subcategories)
            {
                if(Cat.Subcategories.Length > 1) Lay.AddHeading(Subcat);

                foreach(Control Cont in Subcat.Controls)
                {
                    IConverter<QObject> Converter = ProcureState(Cont);

                    if(Converter != null)
                    {
                        Lay.AddWidget(Cont, Converter.Construct(Cont));
                        State.Add(Converter);
                    }
                }
            }
        }
    }
}<commit_msg>Further factored out repeating code<commit_after>using System;
using Selene.Backend;
using Qyoto;

namespace Selene.Qyoto.Frontend
{
    public abstract class QModalDialog<T> : ModalPresenterBase<QObject, T> where T : class
    {
        protected QDialog Dialog;
        protected QHBoxLayout InnerLayout;

        QVBoxLayout Layout;
        QPushButton OkButton, CancelButton;
        QHBoxLayout Buttons;

        public QModalDialog(string Title)
        {
            Dialog = new QDialog();
            OkButton = new QPushButton("OK");           // Localization?
            CancelButton = new QPushButton("Cancel");

            Layout = new QVBoxLayout(Dialog);
            Buttons = new QHBoxLayout();
            InnerLayout = new QHBoxLayout();

            Buttons.AddWidget(CancelButton);
            Buttons.AddStretch(1);
            Buttons.AddWidget(OkButton);
            Layout.AddLayout(InnerLayout);
            Layout.AddLayout(Buttons);
            Layout.sizeConstraint = QLayout.SizeConstraint.SetFixedSize;

            Dialog.SetWindowTitle(Title);

            QWidget.Connect(OkButton, Qt.SIGNAL("clicked()"), ClickOk);
            QWidget.Connect(CancelButton, Qt.SIGNAL("clicked()"), ClickCancel);

            OkButton.SetFocus();
        }

        void ClickCancel()
        {
            Dialog.Reject();
        }

        void ClickOk()
        {
            Dialog.Accept();
        }

        public override void Hide ()
        {
            Dialog.Hide();
        }

        public override bool Run (T Present)
        {
            base.Run (Present);

            if(Dialog.Exec() == 1)
            {
                Save();
                return true;
            }
            else return false;
        }

        public override void Show ()
        {
            Dialog.Show();
        }

        internal void AddCategory(CategoryLay Lay, ControlCategory Cat)
        {
            foreach(ControlSubcategory Subcat in Cat.Subcategories)
            {
                if(Cat.Subcategories.Length > 1) Lay.AddHeading(Subcat);

                AddSubcategory(Lay, Subcat, false);
            }

            Lay.AddStretch(1);
        }

        internal void AddSubcategory(CategoryLay Lay, ControlSubcategory Subcat)
        {
            AddSubcategory(Lay, Subcat, true);
        }

        void AddSubcategory(CategoryLay Lay, ControlSubcategory Subcat, bool Stretch)
        {
            foreach(Control Cont in Subcat.Controls)
            {
                IConverter<QObject> Converter = ProcureState(Cont);

                if(Converter != null)
                {
                    Lay.AddWidget(Cont, Converter.Construct(Cont));
                    State.Add(Converter);
                }
            }

            if(Stretch) Lay.AddStretch(1);
        }
    }
}
{'fraction_non_alphanumeric': 0.08982602118003026, 'fraction_numerical': 0.0015128593040847202, 'mean_word_length': 1.5054476551397442, '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': '3864753', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1329, 'n_words': 274}