Example #1
0
 private void DebugValidateTrackedStringBelongsToThisManager(TrackedString ts)
 {
     if (!m_trackedStrings.Contains(ts))
     {
         throw new Exception("Attempting to use a TrackedString with a TrackedStringManager who is not managing said TrackedString.");
     }
 }
Example #2
0
 internal void TrackForPlaceholder(TrackedString item, int endIndex)
 {
     if (this.IsInPlaceholderMode)
     {
         m_placeholderData.AddPlaceholderItem(item, endIndex);
     }
 }
Example #3
0
        private void DebugValidateTextRemainsTheSameAfterOffsetChange(TrackedString ts)
        {
            string stringValueAfterOffsetChange = this.Text.Substring(ts.OffsetInSource, ts.StringValue.Length);

            if (ts.StringValue != stringValueAfterOffsetChange)
            {
                throw new Exception(
                          String.Format("After OffsetInotSource changed, the StringValue has erroneously changed from '{0}' to '{1}'",
                                        ts.StringValue, stringValueAfterOffsetChange));
            }
        }
Example #4
0
        /// <summary>
        /// Begins tracking substring
        /// </summary>
        public TrackedString Track(int startIndex, int length)
        {
            this.HasChanges = true;

            int endIndex = startIndex + length - 1;

            if (this.IsInPlaceholderMode)
            {
                TrackedString s = new TrackedString(this, startIndex, endIndex);
                m_placeholderData.AddPlaceholderItem(s, endIndex);
                return(s);
            }
            else
            {
                TrackedString s = new TrackedString(this, startIndex, endIndex);
                this.AddItem(s);
                return(s);
            }
        }
Example #5
0
        /// <summary>
        /// Updates the <see cref="TrackedString"/>'s value and updates indexing of all <see cref="TrackedString"/>s that are affected by the change.
        /// </summary>
        /// <param name="item">The item to update</param>
        /// <param name="newValue">The new string for the item to hold</param>
        public bool UpdateTrackedString(TrackedString item, string newValue)
        {
            if (item.StringValue == newValue)
            {
                return(false);
            }

            DebugValidateTrackedStringBelongsToThisManager(item);

            int offsetLength = newValue.Length - item.StringValue.Length;

            int replaceStartIndex = item.OffsetInSource;
            int replaceEndIndex   = item.OffsetInSource + item.StringValue.Length - 1;

            this.Text = this.Text.Replace(replaceStartIndex, replaceEndIndex, newValue);

            this.UpdateItemsInRange(item.OffsetInSource, offsetLength, item);

            this.HasChanges = true;
            item.SetValueInternal(newValue);
            return(true);
        }
Example #6
0
        /// <summary>
        /// If you built your SubstringTracker in placeholder mode (see placeholder mode constructor), then
        /// you must call this once your text is all setup.
        /// </summary>
        internal void PlaceholderSetupComplete()
        {
            string toInsert    = m_placeholderData.Source.Builder.ToString();
            int    insertIndex = m_placeholderData.Source.StartIndex;

            // Update the text to contain the string builder's result
            if (m_placeholderData.Reset)
            {
                this.Text = toInsert;

                // We're doing a hard reset
                this.m_trackedStrings.Clear();
            }
            else
            {
                this.Text = this.Text.Insert(insertIndex, toInsert);
            }

            // Insert the placeholders first.
            //  Note: This must be done first so that when we update the existing tracked strings
            TrackedString[] updateSkiplist = new TrackedString[m_placeholderData.PlaceholderItems.Count];
            for (int ind = 0; ind < m_placeholderData.PlaceholderItems.Count; ++ind)
            {
                Tuple <TrackedString, int> placeholderItem = m_placeholderData.PlaceholderItems[ind];
                placeholderItem.Item1.ResetStringInternal(placeholderItem.Item2);
                this.AddItem(placeholderItem.Item1);
                updateSkiplist[ind] = placeholderItem.Item1;
            }

            if (!m_placeholderData.Reset)
            {
                this.UpdateItemsInRange(insertIndex, toInsert.Length, updateSkiplist);
            }

            m_placeholderData = null;
            this.HasChanges   = true;
        }
Example #7
0
 public void AddPlaceholderItem(TrackedString placeholderTrackedString, int end)
 {
     this.PlaceholderItems.Add(new Tuple <TrackedString, int>(placeholderTrackedString, end));
 }
Example #8
0
 private void AddItem(TrackedString item)
 {
     //m_trackedStrings.InsertSorted(item);
     m_trackedStrings.Add(item);
 }
Example #9
0
 /// <summary>
 /// (Internal) Begins tracking an item constructed outside of the other Track methods.
 /// </summary>
 protected internal void Track(TrackedString item)
 {
     this.AddItem(item);
 }
Example #10
0
 public int IndexOf(TrackedString trackedString)
 {
     return(m_trackedStrings.IndexOf(trackedString));
 }