<commit_before>﻿using System.Diagnostics.CodeAnalysis;
using System.Windows;
using Rees.UserInteraction.Contracts;

namespace Rees.Wpf
{
    /// <summary>
    /// Used to abstract away from instantiating and interacting with real windows within Controller and ViewModel code.
    /// </summary>
    /// <typeparam name="T">The view load.</typeparam>
    public class WpfViewLoader<T> : IViewLoader where T : Window, new()
    {
        private T window;

        public virtual void Close()
        {
            if (this.window != null)
            {
                this.window.Close();
                this.window = null;
            }
        }

        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
            Justification = "Clean up code. The window is orphaned or has been instructed to close.")]
        public virtual void Show(object context)
        {
            if (this.window != null)
            {
                try
                {
                    this.window.Close();
                }
// ReSharper disable EmptyGeneralCatchClause
                catch 
// ReSharper restore EmptyGeneralCatchClause
                {
                    // Swallow any exception trying to close the orphaned window.
                }
            }

            this.window = new T {DataContext = context};
            this.window.Show();
        }

        public virtual bool? ShowDialog(object context)
        {
            this.window = new T {DataContext = context, Owner = Application.Current.MainWindow};
            bool? result = this.window.ShowDialog();
            this.window = null;
            return result;
        }
    }
}<commit_msg>Allowed subclasses to set Window<commit_after>﻿using System.Diagnostics.CodeAnalysis;
using System.Windows;
using Rees.UserInteraction.Contracts;

namespace Rees.Wpf
{
    /// <summary>
    ///     Used to abstract away from instantiating and interacting with real windows within Controller and ViewModel code.
    /// </summary>
    /// <typeparam name="T">The view load.</typeparam>
    public class WpfViewLoader<T> : IViewLoader where T : Window, new()
    {
        protected T TargetWindow { get; set; }

        public virtual void Close()
        {
            if (TargetWindow != null)
            {
                TargetWindow.Close();
                TargetWindow = null;
            }
        }

        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
            Justification = "Clean up code. The window is orphaned or has been instructed to close.")]
        public virtual void Show(object context)
        {
            if (TargetWindow != null)
            {
                try
                {
                    TargetWindow.Close();
                }
// ReSharper disable EmptyGeneralCatchClause
                catch 
// ReSharper restore EmptyGeneralCatchClause
                {
                    // Swallow any exception trying to close the orphaned window.
                }
            }

            TargetWindow = new T {DataContext = context};
            TargetWindow.Show();
        }

        public virtual bool? ShowDialog(object context)
        {
            TargetWindow = new T {DataContext = context, Owner = Application.Current.MainWindow};
            bool? result = TargetWindow.ShowDialog();
            TargetWindow = null;
            return result;
        }
    }
}
{'fraction_non_alphanumeric': 0.08613689095127611, 'fraction_numerical': 0.002320185614849188, 'mean_word_length': 1.6510376633358954, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5204350', 'n_tokens_mistral': 871, 'n_tokens_neox': 830, 'n_words': 242}