Exemple #1
0
        /// <summary>
        /// Updates the table and selects next entry.
        /// </summary>
        /// <param name="deltaLength">The length delta of the replacement (resource call length minus string literal length).</param>
        /// <param name="deltaLine">The line delta (when alias has been inserted).</param>
        private void UpdateTableAndSelectNext(int deltaLength,
                                              int deltaLine)
        {
            if ((deltaLength != 0) || (deltaLine != 0))
            {
                #region update entries

                int replacedLocationX = m_SelectedStringResource.Location.X,
                    replacedLocationY = m_SelectedStringResource.Location.Y,
                    startGridRowIndex = (deltaLine != 0) ? 0 : m_SelectedGridRowIndex + 1; //touch all when alias has been inserted
                                                                                           //else only the following entries on the same line

                for (int gridRowIndex = startGridRowIndex; gridRowIndex < m_StringResources.Count; ++gridRowIndex)
                {
                    if (gridRowIndex == m_SelectedGridRowIndex)
                    {
                        continue;
                    }

                    StringResource stringResource = m_StringResources[gridRowIndex] as StringResource;

                    if ((deltaLength != 0) && (stringResource.Location.X == replacedLocationX) && (stringResource.Location.Y > replacedLocationY))
                    {
                        //same line as replaced entry -> heed column shift and a possible alias insertion
                        Debug.Print("{0}: col  {1} -> {2}, {3}", gridRowIndex,
                                    stringResource.Location.ToString(),
                                    stringResource.Location.X + deltaLine,
                                    stringResource.Location.Y + deltaLength);

                        stringResource.Offset(deltaLine, deltaLength);
                    }
                    else if (deltaLine != 0)
                    {
                        //heed alias insertion
                        Debug.Print("{0}: line {1} -> {2}, {3}", gridRowIndex,
                                    stringResource.Location.ToString(),
                                    stringResource.Location.X + deltaLine,
                                    stringResource.Location.Y + deltaLength);

                        stringResource.Offset(deltaLine, 0);
                    }
                    else
                    {
                        break; //nothing left to update
                    }
                } //for

#if never //[12-10-03 DR]: Indexing no longer in use
                //[12-10-03 DR]: search for resource names with selected name plus index ("_#")
                string name = string.Concat(m_SelectedStringResource.Name, "_");

                List <StringResource> stringResources = m_StringResources.FindAll(sr => sr.Name.StartsWith(name));

                if (stringResources.Count > 0)
                {
                    //[12-10-03 DR]: calculate new indexes (remove first index entirely)
                    int nameLength = name.Length,
                        firstIndex = -1,
                        index      = 1,
                        indexValue;

                    foreach (StringResource item in stringResources)
                    {
                        if (int.TryParse(item.Name.Substring(nameLength), out indexValue))
                        {
                            if (firstIndex == -1)
                            {
                                firstIndex = indexValue;
                                item.Name  = item.Name.Substring(0, nameLength - 1); //remove entire index ("_#")
                            }
                            else
                            {
                                item.Name = item.Name.Substring(0, nameLength);         //remove old index number
                                item.Name = string.Concat(item.Name, index.ToString()); //append new index number
                                ++index;
                            } //else
                        } //if
                    }     //foreach
                }         //if
#endif

                #endregion
            } //if

            #region remove entry and goto next entry

            //this.ClearGrid();

            RemoveStringResource(m_SelectedGridRowIndex);

            //this.SetGridItemsSource(m_StringResources);
            this.RefreshGrid();

            this.SelectCell(m_SelectedGridRowIndex, this.GetSelectedColIndex());

            #endregion

            SelectStringInTextDocument();
        }
        /// <summary>Parses for strings by iterating through the FileCodeModel.</summary>
        /// <param name="startPoint">The start point.</param>
        /// <param name="endPoint">The end point.</param>
        /// <param name="lastDocumentLength">Last length of the document.</param>
        private void ParseForStrings(TextPoint startPoint,
                                     TextPoint endPoint,
                                     int lastDocumentLength)
        {
            //0.35-0.06 seconds (threaded: 2.47-1.77 seconds)
            List <StringResource> stringResources = new List <StringResource>();

            bool isFullDocument          = startPoint.AtStartOfDocument && endPoint.AtEndOfDocument,
                 isTextWithStringLiteral = true;
            int startLine      = startPoint.Line,
                startCol       = startPoint.LineCharOffset,
                endLine        = endPoint.Line,
                endCol         = endPoint.LineCharOffset,
                documentLength = endPoint.Parent.EndPoint.Line,
                insertIndex    = 0;

            if (isFullDocument)
            {
                m_StringResources.Clear();
            }
            else
            {
                #region document manipulated -> adapt string resources and locations

                //determine whether the text between startLine and endLine (including) contains double quotes
                EditPoint editPoint = startPoint.CreateEditPoint() as EditPoint2;
                if (!startPoint.AtStartOfLine)
                {
                    editPoint.StartOfLine();
                }
                isTextWithStringLiteral = editPoint.GetLines(startLine, endLine + 1).Contains("\"");

                //move trailing locations behind changed lines if needed and
                //remove string resources on changed lines

                int lineOffset = documentLength - lastDocumentLength;
#if DEBUG_OUTPUT
                System.Diagnostics.Debug.Print("  Line offset is {0}", lineOffset);
#endif

                for (int i = m_StringResources.Count - 1; i >= 0; --i)
                {
                    StringResource stringResource = m_StringResources[i];
                    int            lineNo         = stringResource.Location.X;

                    if (lineNo + lineOffset > endLine)
                    {
                        if (lineOffset != 0)
                        {
#if DEBUG_OUTPUT
                            System.Diagnostics.Debug.Print("  Move string literal from line {0} to {1}", lineNo, lineNo + lineOffset);
#endif
                            stringResource.Offset(lineOffset, 0); //move
                        } //if
                    }
                    else if (lineNo >= startLine)
                    {
#if DEBUG_OUTPUT
                        System.Diagnostics.Debug.Print("  Remove string literal {0} ({1}): {2}", i, stringResource.Location, stringResource.Text);
#endif
                        m_StringResources.RemoveAt(i); //remove changed line
                    }
                    else if (insertIndex == 0)
                    {
#if DEBUG_OUTPUT
                        System.Diagnostics.Debug.Print("  List insert index is {0} / {1}", i + 1, m_StringResources.Count - 1);
#endif
                        insertIndex = i + 1;
                    } //else if
                }     //for

                #endregion
            } //else

#if DEBUG_OUTPUT
            System.Diagnostics.Debug.Print("  Text has{0} string literals.", isTextWithStringLiteral ? string.Empty : " no");
#endif

            if (isTextWithStringLiteral)
            {
                CodeElements elements = m_Window.Document.ProjectItem.FileCodeModel.CodeElements;

                foreach (CodeElement element in elements)
                {
                    ParseForStrings(element, m_DoProgress, stringResources, m_Settings, m_IsCSharp, startLine, endLine);

#if DEBUG
                    if (element.Kind == vsCMElement.vsCMElementProperty)
                    {
                        CodeProperty prop = element as CodeProperty;

                        if ((prop.Getter == null) && (prop.Setter == null))
                        {
                            //here we have an expression bodied property
                            //if (m_IVsTextView != null)
                            //{
                            //  m_IVsTextView.
                            //}
                        }
                    }
#endif
                } //foreach

#if DEBUG_OUTPUT
                System.Diagnostics.Debug.Print("  Found {0} string literals", stringResources.Count);
#endif

                if (isFullDocument)
                {
                    m_StringResources.AddRange(stringResources);
                }
                else if (stringResources.Count > 0)
                {
                    m_StringResources.InsertRange(insertIndex, stringResources);
                }
            } //if

            m_DoCompleted(isFullDocument || (stringResources.Count > 0));
        }