コード例 #1
0
        /// <summary>
        /// Creates a new QuantifiedTextViewModel instance with all contents of this instance.
        /// </summary>
        /// <param name="ctVM">New CultureTextViewModel instance to connect the clone with.</param>
        /// <returns></returns>
        public QuantifiedTextViewModel Clone(CultureTextViewModel ctVM)
        {
            QuantifiedTextViewModel clone = new QuantifiedTextViewModel(ctVM);

            clone.Count  = Count;
            clone.Modulo = Modulo;
            clone.Text   = Text;
            return(clone);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new CultureTextViewModel instance with all contents of this instance.
        /// </summary>
        /// <param name="textKeyVM">New TextKeyViewModel instance to connect the clone with.</param>
        /// <returns></returns>
        public CultureTextViewModel Clone(TextKeyViewModel textKeyVM)
        {
            CultureTextViewModel clone = new CultureTextViewModel(CultureName, textKeyVM);

            clone.Text = Text;
            foreach (QuantifiedTextViewModel qtVM in QuantifiedTextVMs)
            {
                clone.QuantifiedTextVMs.Add(qtVM.Clone(clone));
            }
            return(clone);
        }
コード例 #3
0
        /// <summary>
        /// Copies all contents from another CultureTextViewModel instance to this one, merging all
        /// data.
        /// </summary>
        /// <param name="other"></param>
        public void MergeFrom(CultureTextViewModel other)
        {
            if (!string.IsNullOrEmpty(other.Text))
            {
                // Overwrite text AND quantified texts IF set
                this.Text = other.Text;

                this.QuantifiedTextVMs.Clear();
                foreach (QuantifiedTextViewModel qtVM in this.QuantifiedTextVMs)
                {
                    this.QuantifiedTextVMs.Add(qtVM.Clone(this));
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Creates a new QuantifiedTextViewModel instance with all contents of this instance.
 /// </summary>
 /// <param name="ctVM">New CultureTextViewModel instance to connect the clone with.</param>
 /// <returns></returns>
 public QuantifiedTextViewModel Clone(CultureTextViewModel ctVM)
 {
     QuantifiedTextViewModel clone = new QuantifiedTextViewModel(ctVM);
     clone.Count = Count;
     clone.Modulo = Modulo;
     clone.Text = Text;
     return clone;
 }
コード例 #5
0
 public QuantifiedTextViewModel(CultureTextViewModel cultureTextVM)
 {
     CultureTextVM = cultureTextVM;
 }
コード例 #6
0
        /// <summary>
        /// Copies all contents from another CultureTextViewModel instance to this one, merging all
        /// data.
        /// </summary>
        /// <param name="other"></param>
        public void MergeFrom(CultureTextViewModel other)
        {
            if (!string.IsNullOrEmpty(other.Text))
            {
                // Overwrite text AND quantified texts IF set
                this.Text = other.Text;

                this.QuantifiedTextVMs.Clear();
                foreach (QuantifiedTextViewModel qtVM in this.QuantifiedTextVMs)
                {
                    this.QuantifiedTextVMs.Add(qtVM.Clone(this));
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Compares this CultureTextViewModel instance with another instance to determine the sort
        /// order in the editor view.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(CultureTextViewModel other)
        {
            string otherName = other.CultureName;
            if (string.Compare(CultureName, otherName, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                //System.Diagnostics.Debug.WriteLine(CultureName + " = " + otherName + " (1)");
                return 0;   // Exact match
            }

            if (CultureName.Length >= 2 && otherName.Length >= 2)
            {
                // Prefer primary culture (with or without region; if set)
                if (!string.IsNullOrEmpty(TextKeyVM.MainWindowVM.PrimaryCulture))
                {
                    // tP:  thisPrimary
                    // oP:  otherPrimary
                    // oPR: otherPrimaryRelated
                    //
                    //             !tPR         tPR
                    //             !tP    tP    !tP   tP
                    //           --------------------------
                    // !oPR  !oP | cont.  xxx | -1    -1  |
                    //       oP  |  xxx   xxx | xxx   xxx |
                    //           --------------------------
                    // oPR   !oP |   1    xxx | cont. -1  |
                    //       oP  |   1    xxx |  1    xxx |
                    //           --------------------------

                    bool thisPrimary = string.Compare(CultureName, TextKeyVM.MainWindowVM.PrimaryCulture, StringComparison.InvariantCultureIgnoreCase) == 0;
                    bool thisPrimaryRelated = CultureName.StartsWith(TextKeyVM.MainWindowVM.PrimaryCulture.Substring(0, 2));
                    bool otherPrimary = string.Compare(otherName, TextKeyVM.MainWindowVM.PrimaryCulture, StringComparison.InvariantCultureIgnoreCase) == 0;
                    bool otherPrimaryRelated = otherName.StartsWith(TextKeyVM.MainWindowVM.PrimaryCulture.Substring(0, 2));

                    if (thisPrimary || thisPrimaryRelated && !otherPrimaryRelated)
                    {
                        //System.Diagnostics.Debug.WriteLine(CultureName + " < " + otherName + " (2)");
                        return -1;
                    }
                    if (otherPrimary || otherPrimaryRelated && !thisPrimaryRelated)
                    {
                        //System.Diagnostics.Debug.WriteLine(CultureName + " > " + otherName + " (2)");
                        return 1;
                    }
                }

                if (string.Compare(CultureName.Substring(0, 2), otherName.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    // Same language, prefer shorter names (without region)
                    if (CultureName.Length != otherName.Length)
                    {
                        int i = CultureName.Length - otherName.Length;
                        //if (i < 0)
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " < " + otherName + " (3)");
                        //else if (i > 0)
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " > " + otherName + " (3)");
                        //else
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " = " + otherName + " (3)");
                        return i;
                        // If this.length < other.length, then the result is negative and this comes before other
                    }
                }
            }
            return string.Compare(CultureName, otherName, StringComparison.InvariantCultureIgnoreCase);
        }
コード例 #8
0
 /// <summary>
 /// Creates a new CultureTextViewModel instance with all contents of this instance.
 /// </summary>
 /// <param name="textKeyVM">New TextKeyViewModel instance to connect the clone with.</param>
 /// <returns></returns>
 public CultureTextViewModel Clone(TextKeyViewModel textKeyVM)
 {
     CultureTextViewModel clone = new CultureTextViewModel(CultureName, textKeyVM);
     clone.Text = Text;
     foreach (QuantifiedTextViewModel qtVM in QuantifiedTextVMs)
     {
         clone.QuantifiedTextVMs.Add(qtVM.Clone(clone));
     }
     return clone;
 }
コード例 #9
0
 public QuantifiedTextViewModel(CultureTextViewModel cultureTextVM)
 {
     CultureTextVM = cultureTextVM;
 }
コード例 #10
0
        /// <summary>
        /// Compares this CultureTextViewModel instance with another instance to determine the sort
        /// order in the editor view.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(CultureTextViewModel other)
        {
            string otherName = other.CultureName;

            if (string.Compare(CultureName, otherName, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                //System.Diagnostics.Debug.WriteLine(CultureName + " = " + otherName + " (1)");
                return(0);                  // Exact match
            }

            if (CultureName.Length >= 2 && otherName.Length >= 2)
            {
                // Prefer primary culture (with or without region; if set)
                if (!string.IsNullOrEmpty(TextKeyVM.MainWindowVM.PrimaryCulture))
                {
                    // tP:  thisPrimary
                    // oP:  otherPrimary
                    // oPR: otherPrimaryRelated
                    //
                    //             !tPR         tPR
                    //             !tP    tP    !tP   tP
                    //           --------------------------
                    // !oPR  !oP | cont.  xxx | -1    -1  |
                    //       oP  |  xxx   xxx | xxx   xxx |
                    //           --------------------------
                    // oPR   !oP |   1    xxx | cont. -1  |
                    //       oP  |   1    xxx |  1    xxx |
                    //           --------------------------

                    bool thisPrimary         = string.Compare(CultureName, TextKeyVM.MainWindowVM.PrimaryCulture, StringComparison.InvariantCultureIgnoreCase) == 0;
                    bool thisPrimaryRelated  = CultureName.StartsWith(TextKeyVM.MainWindowVM.PrimaryCulture.Substring(0, 2));
                    bool otherPrimary        = string.Compare(otherName, TextKeyVM.MainWindowVM.PrimaryCulture, StringComparison.InvariantCultureIgnoreCase) == 0;
                    bool otherPrimaryRelated = otherName.StartsWith(TextKeyVM.MainWindowVM.PrimaryCulture.Substring(0, 2));

                    if (thisPrimary || thisPrimaryRelated && !otherPrimaryRelated)
                    {
                        //System.Diagnostics.Debug.WriteLine(CultureName + " < " + otherName + " (2)");
                        return(-1);
                    }
                    if (otherPrimary || otherPrimaryRelated && !thisPrimaryRelated)
                    {
                        //System.Diagnostics.Debug.WriteLine(CultureName + " > " + otherName + " (2)");
                        return(1);
                    }
                }

                if (string.Compare(CultureName.Substring(0, 2), otherName.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    // Same language, prefer shorter names (without region)
                    if (CultureName.Length != otherName.Length)
                    {
                        int i = CultureName.Length - otherName.Length;
                        //if (i < 0)
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " < " + otherName + " (3)");
                        //else if (i > 0)
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " > " + otherName + " (3)");
                        //else
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " = " + otherName + " (3)");
                        return(i);
                        // If this.length < other.length, then the result is negative and this comes before other
                    }
                }
            }
            return(string.Compare(CultureName, otherName, StringComparison.InvariantCultureIgnoreCase));
        }