<commit_before>﻿using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace Radical.Windows.Presentation.Regions
{
    /// <summary>
    /// A switching elements region hosted by a TabControl.
    /// </summary>
    public class TabControlRegion : SwitchingElementsRegion<TabControl>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TabControlRegion"/> class.
        /// </summary>
        public TabControlRegion()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TabControlRegion"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public TabControlRegion( string name )
        {
            Name = name;
        }

        /// <summary>
        /// Called before the add operation.
        /// </summary>
        /// <param name="view">The view.</param>
        protected override void OnAdd( DependencyObject view )
        {
            var tabItem = new TabItem();
            tabItem.Content = view;

            var header = TryGetHeader( view );
            if( header != null )
            {
                tabItem.Header = header;
            }

            Element.Items.Add( tabItem );
        }

        /// <summary>
        /// Tries the get header.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        protected virtual object TryGetHeader( DependencyObject view )
        {
            return RegionHeaderedElement.GetHeader( view );
        }
<commit_msg>Check if incoming view is already a TabItem<commit_after>﻿using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace Radical.Windows.Presentation.Regions
{
    /// <summary>
    /// A switching elements region hosted by a TabControl.
    /// </summary>
    public class TabControlRegion : SwitchingElementsRegion<TabControl>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TabControlRegion"/> class.
        /// </summary>
        public TabControlRegion()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TabControlRegion"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public TabControlRegion( string name )
        {
            Name = name;
        }

        /// <summary>
        /// Called before the add operation.
        /// </summary>
        /// <param name="view">The view.</param>
        protected override void OnAdd( DependencyObject view )
        {
            var tabItem = view as TabItem;
            if (tabItem == null)
            {
                tabItem = new TabItem();
                tabItem.Content = view;
            }

            var header = TryGetHeader( view );
            if( header != null )
            {
                tabItem.Header = header;
            }

            Element.Items.Add( tabItem );
        }

        /// <summary>
        /// Tries the get header.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        protected virtual object TryGetHeader( DependencyObject view )
        {
            return RegionHeaderedElement.GetHeader( view );
        }

{'fraction_non_alphanumeric': 0.12159709618874773, 'fraction_numerical': 0.0, 'mean_word_length': 1.5379892555640828, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '6204408', 'n_tokens_mistral': 844, 'n_tokens_neox': 827, 'n_words': 228}