Example #1
0
        private void UnifyLineEndingsInDocument(TextDocument textDocument, LineEndingsChanger.LineEndings lineEndings, ref int numberOfChanges, out int numberOfIndividualChanges, out int numberOfAllLineEndings)
        {
            var startPoint = textDocument.StartPoint.CreateEditPoint();
            var endPoint   = textDocument.EndPoint.CreateEditPoint();

            var text        = startPoint.GetText(endPoint.AbsoluteCharOffset);
            var changedText = LineEndingsChanger.ChangeLineEndings(text, lineEndings, ref numberOfChanges, out numberOfIndividualChanges, out numberOfAllLineEndings);

            startPoint.ReplaceText(text.Length, changedText, (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
        }
        public LineEndingChoice(string fileName, LineEndingsChanger.LineEndings defaultLineEnding)
        {
            InitializeComponent();
            this.Title = fileName;

            switch (defaultLineEnding)
            {
                case LineEndingsChanger.LineEndings.Dominant:
                    this.Dominant_RadioButton.IsChecked = true;
                    break;
                case LineEndingsChanger.LineEndings.Linux:
                    this.Linux_RadioButton.IsChecked = true;
                    break;
                case LineEndingsChanger.LineEndings.Macintosh:
                    this.Macintosh_RadioButton.IsChecked = true;
                    break;
                case LineEndingsChanger.LineEndings.Windows:
                    this.Windows_RadioButton.IsChecked = true;
                    break;
                default:
                    break;
            }
        }
        private void UnifyLineEndingsInDocument(TextDocument textDocument, LineEndingsChanger.LineEndings lineEndings, ref int numberOfChanges, out int numberOfIndividualChanges, out int numberOfAllLineEndings)
        {
            var startPoint = textDocument.StartPoint.CreateEditPoint();
            var endPoint   = textDocument.EndPoint.CreateEditPoint();

            var text           = startPoint.GetText(endPoint.AbsoluteCharOffset);
            var originalLength = text.Length;

            if (this.OptionsPage.RemoveTrailingWhitespace)
            {
                text = TrailingWhitespaceRemover.RemoveTrailingWhitespace(text);
            }
            var changedText = LineEndingsChanger.ChangeLineEndings(text, lineEndings, ref numberOfChanges, out numberOfIndividualChanges, out numberOfAllLineEndings);

            if (this.OptionsPage.AddNewlineOnLastLine)
            {
                if (!changedText.EndsWith(Utilities.GetNewlineString(lineEndings)))
                {
                    changedText += Utilities.GetNewlineString(lineEndings);
                }
            }

            startPoint.ReplaceText(originalLength, changedText, (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
        }
        private void UnifyLineEndingsInProjectItems(ProjectItems projectItems, LineEndingsChanger.LineEndings lineEndings, ref int numberOfChanges, bool saveAllWasHit = false)
        {
            var supportedFileFormats = this.SupportedFileFormats;
            var supportedFileNames = this.SupportedFileNames;

            foreach (ProjectItem item in projectItems)
            {
                if (item.ProjectItems != null && item.ProjectItems.Count > 0)
                {
                    UnifyLineEndingsInProjectItems(item.ProjectItems, lineEndings, ref numberOfChanges, saveAllWasHit);
                }
                else
                {
                    if (item.Name.EndsWithAny(supportedFileFormats) || item.Name.EqualsAny(supportedFileNames))
                    {
                        UnifyLineEndingsInProjectItem(item, lineEndings, ref numberOfChanges, saveAllWasHit);
                    }
                }
            }
        }
        private void UnifyLineEndingsInProjectItem(ProjectItem item, LineEndingsChanger.LineEndings lineEndings, ref int numberOfChanges, bool saveAllWasHit = false)
        {
            Window documentWindow = null;

            if (!item.IsOpen)
            {
                if (!saveAllWasHit || (saveAllWasHit && !this.OptionsPage.UnifyOnlyOpenFiles))
                {
                    documentWindow = item.Open();
                }
            }

            var document = item.Document;
            if (document != null)
            {
                var numberOfIndividualChanges = 0;
                var numberOfAllLineEndings = 0;

                var textDocument = document.Object("TextDocument") as TextDocument;
                UnifyLineEndingsInDocument(textDocument, lineEndings, ref numberOfChanges, out numberOfIndividualChanges, out numberOfAllLineEndings);
                if (this.OptionsPage.SaveFilesAfterUnifying)
                {
                    this.isUnifyingLocked = true;
                    document.Save();
                    this.isUnifyingLocked = false;
                }

                Output(string.Format("{0}: changed {1} out of {2} line endings\n", document.FullName, numberOfIndividualChanges, numberOfAllLineEndings));
            }

            if (documentWindow != null)
            {
                documentWindow.Close();
            }
        }
        private void UnifyLineEndingsInDocument(TextDocument textDocument, LineEndingsChanger.LineEndings lineEndings, ref int numberOfChanges, out int numberOfIndividualChanges, out int numberOfAllLineEndings)
        {
            var startPoint = textDocument.StartPoint.CreateEditPoint();
            var endPoint = textDocument.EndPoint.CreateEditPoint();

            var text = startPoint.GetText(endPoint.AbsoluteCharOffset);
            var changedText = LineEndingsChanger.ChangeLineEndings(text, lineEndings, ref numberOfChanges, out numberOfIndividualChanges, out numberOfAllLineEndings);
            startPoint.ReplaceText(text.Length, changedText, (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
        }