<commit_before>﻿using System.Collections.Generic;
using FairyGUI.Utils;
using System;

namespace FairyGUI
{
    /// <summary>
    /// Controller class.
    /// 控制器类。控制器的创建和设计需通过编辑器完成，不建议使用代码创建。
    /// 最常用的方法是通过selectedIndex获得或改变控制器的活动页面。如果要获得控制器页面改变的通知，使用onChanged事件。
    /// </summary>
    public class Controller : EventDispatcher
    {
        /// <summary>
        /// Name of the controller
        /// 控制器名称。
        /// </summary>
        public string name;

        internal GComponent parent;
        internal bool autoRadioGroupDepth;
        internal bool changing;

        int _selectedIndex;
        int _previousIndex;
        List<string> _pageIds;
        List<string> _pageNames;
        List<ControllerAction> _actions;

        EventListener _onChanged;

        static uint _nextPageId;

        public Controller()
        {
            _pageIds = new List<string>();
            _pageNames = new List<string>();
            _selectedIndex = -1;
            _previousIndex = -1;
        }

        public void Dispose()
        {
            RemoveEventListeners();
        }


        /// <summary>
        /// When controller page changed.
        /// 当控制器活动页面改变时，此事件被触发。
        /// </summary>
        public EventListener onChanged
        {
            get { return _onChanged ?? (_onChanged = new EventListener(this, "onChanged")); }
        }

        /// <summary>
        /// Current page index.
        /// 获得或设置当前活动页面索引。
        /// </summary>
        public int selectedIndex
        {
            get
            {
                return _selectedIndex;
            }
            set
            {
                if (_selectedIndex != value)
                {
                    if (value > _pageIds.Count - 1)
                        throw new IndexOutOfRangeException("" + value);

                    changing = true;

                    _previousIndex = _selectedIndex;
                    _selectedIndex = value;
                    parent.ApplyController(this);

                    DispatchEvent("onChanged", null);

                    changing = false;
                }
            }
        }

        /// <summary>
        /// Set current page index, no onChanged event.
        /// 通过索引设置当前活动页面，和selectedIndex的区别在于，这个方法不会触发onChanged事件。
        /// </summary>
        /// <param name="value">Page index</param>
        public void SetSelectedIndex(int value)
        {
            if (_selectedIndex != value)
            {
                if (value > _pageIds.Count - 1)
                    throw new IndexOutOfRangeException("" + value);

                changing = true;
                _previousIndex = _selectedIndex;
                _selectedIndex = value;
                parent.ApplyController(this);
                changing = false;
            }
        }

        /// <summary>
        /// Set current page by name, no onChanged event.
        /// 通过页面名称设置当前活动页面，和selectedPage的区别在于，这个方法不会触发onChanged事件。
        /// </summary>
        /// <param name="value">Page name</param>
        public void SetSelectedPage(string value)
        {
            int i = _pageNames.IndexOf(value);
            if (i == -1)
                i = 0;
            this.SetSelectedIndex(i);
        }

        /// <summary>
        /// Current page name.
        /// 获得当前活动页面名称
        /// </summary>
        public string selectedPage
        {
            get
            {
                if (_selectedIndex == -1)
                    return null;
                else
                    return _pageNames[_selectedIndex];
            }
            set
            {
                int i = _pageNames.IndexOf(value);
                if (i == -1)
                    i = 0;
                this.selectedIndex = i;
            }
        }

        /// <summary>
        /// Previouse page index.
        /// 获得上次活动页面索引
        /// </summary>
        public int previsousIndex
        {
            get { return _previousIndex; }
        }

        /// <summary>
        /// Previous page name.
        /// 获得上次活动页面名称。
        /// </summary>
        public string previousPage
        {
            get
            {
                if (_previousIndex == -1)
                    return null;
                else
                    return _pageNames[_previousIndex];
            }
        }

        /// <summary>
        /// Page count of this controller.
        /// 获得页面数量。
        /// </summary>
        public int pageCount
        {
            get { return _pageIds.Count; }<commit_msg>fix typo<commit_after>﻿using System.Collections.Generic;
using FairyGUI.Utils;
using System;

namespace FairyGUI
{
    /// <summary>
    /// Controller class.
    /// 控制器类。控制器的创建和设计需通过编辑器完成，不建议使用代码创建。
    /// 最常用的方法是通过selectedIndex获得或改变控制器的活动页面。如果要获得控制器页面改变的通知，使用onChanged事件。
    /// </summary>
    public class Controller : EventDispatcher
    {
        /// <summary>
        /// Name of the controller
        /// 控制器名称。
        /// </summary>
        public string name;

        internal GComponent parent;
        internal bool autoRadioGroupDepth;
        internal bool changing;

        int _selectedIndex;
        int _previousIndex;
        List<string> _pageIds;
        List<string> _pageNames;
        List<ControllerAction> _actions;

        EventListener _onChanged;

        static uint _nextPageId;

        public Controller()
        {
            _pageIds = new List<string>();
            _pageNames = new List<string>();
            _selectedIndex = -1;
            _previousIndex = -1;
        }

        public void Dispose()
        {
            RemoveEventListeners();
        }


        /// <summary>
        /// When controller page changed.
        /// 当控制器活动页面改变时，此事件被触发。
        /// </summary>
        public EventListener onChanged
        {
            get { return _onChanged ?? (_onChanged = new EventListener(this, "onChanged")); }
        }

        /// <summary>
        /// Current page index.
        /// 获得或设置当前活动页面索引。
        /// </summary>
        public int selectedIndex
        {
            get
            {
                return _selectedIndex;
            }
            set
            {
                if (_selectedIndex != value)
                {
                    if (value > _pageIds.Count - 1)
                        throw new IndexOutOfRangeException("" + value);

                    changing = true;

                    _previousIndex = _selectedIndex;
                    _selectedIndex = value;
                    parent.ApplyController(this);

                    DispatchEvent("onChanged", null);

                    changing = false;
                }
            }
        }

        /// <summary>
        /// Set current page index, no onChanged event.
        /// 通过索引设置当前活动页面，和selectedIndex的区别在于，这个方法不会触发onChanged事件。
        /// </summary>
        /// <param name="value">Page index</param>
        public void SetSelectedIndex(int value)
        {
            if (_selectedIndex != value)
            {
                if (value > _pageIds.Count - 1)
                    throw new IndexOutOfRangeException("" + value);

                changing = true;
                _previousIndex = _selectedIndex;
                _selectedIndex = value;
                parent.ApplyController(this);
                changing = false;
            }
        }

        /// <summary>
        /// Set current page by name, no onChanged event.
        /// 通过页面名称设置当前活动页面，和selectedPage的区别在于，这个方法不会触发onChanged事件。
        /// </summary>
        /// <param name="value">Page name</param>
        public void SetSelectedPage(string value)
        {
            int i = _pageNames.IndexOf(value);
            if (i == -1)
                i = 0;
            this.SetSelectedIndex(i);
        }

        /// <summary>
        /// Current page name.
        /// 获得当前活动页面名称
        /// </summary>
        public string selectedPage
        {
            get
            {
                if (_selectedIndex == -1)
                    return null;
                else
                    return _pageNames[_selectedIndex];
            }
            set
            {
                int i = _pageNames.IndexOf(value);
                if (i == -1)
                    i = 0;
                this.selectedIndex = i;
            }
        }

        [Obsolete("Use previousIndex")]
        public int previsousIndex
        {
            get { return _previousIndex; }
        }

        /// <summary>
        /// Previouse page index.
        /// 获得上次活动页面索引
        /// </summary>
        public int previousIndex
        {
            get { return _previousIndex; }
        }

        /// <summary>
        /// Previous page name.
        /// 获得上次活动页面名称。
        /// </summary>
        public string previousPage
        {
            get
            {
                if (_previousIndex == -1)
                    return null;
                else
                    return _pageNames[_previousIndex];
            }
        }

        /// <summary>
        /// Page count of this controller.
        /// 获得页面数量。
        /// </summary>
        public int pageCount
        {
            get { return _pageIds.Count; }
{'fraction_non_alphanumeric': 0.09806689834926151, 'fraction_numerical': 0.002172024326672459, 'mean_word_length': 1.1272811272811272, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 65, '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': '4245274', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2562, 'n_words': 523}