private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            var button = sender as RadioButton;

            if (button.Content.ToString().Contains("Windows"))
            {
                this.lineEndings = LineEndingsChanger.LineEndings.Windows;
            }
            else if (button.Content.ToString().Contains("Linux"))
            {
                this.lineEndings = LineEndingsChanger.LineEndings.Linux;
            }
            else if (button.Content.ToString().Contains("Macintosh"))
            {
                this.lineEndings = LineEndingsChanger.LineEndings.Macintosh;
            }
            else if (button.Content.ToString().Contains("Dominant"))
            {
                this.lineEndings = LineEndingsChanger.LineEndings.Dominant;
            }
            else
            {
                this.lineEndings = LineEndingsChanger.LineEndings.None;
            }
        }
Example #2
0
        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            var button = sender as RadioButton;

            if (button.Content.ToString().Contains("Windows"))
            {
                this.lineEndings = LineEndingsChanger.LineEndings.Windows;
            }
            else if (button.Content.ToString().Contains("Linux"))
            {
                this.lineEndings = LineEndingsChanger.LineEndings.Linux;
            }
            else if (button.Content.ToString().Contains("Macintosh"))
            {
                this.lineEndings = LineEndingsChanger.LineEndings.Macintosh;
            }
            else if (button.Content.ToString().Contains("Dominant"))
            {
                this.lineEndings = LineEndingsChanger.LineEndings.Dominant;
            }
            else
            {
                this.lineEndings = LineEndingsChanger.LineEndings.None;
            }
        }
Example #3
0
        private void UnifyLineEndingsInProjectItem(ProjectItem item, LineEndingsChanger.LineEndings lineEndings, ref int numberOfChanges)
        {
            Window documentWindow = null;

            if (!item.IsOpen)
            {
                documentWindow = item.Open();
            }
            var document = item.Document;

            if (document != null)
            {
                var numberOfIndividualChanges = 0;

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

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

            if (documentWindow != null)
            {
                documentWindow.Close();
            }
        }
Example #4
0
        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;
            }
        }
Example #5
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);
        }
Example #6
0
        public static string GetNewlineString(LineEndingsChanger.LineEndings lineEnding)
        {
            switch (lineEnding)
            {
            case LineEndingsChanger.LineEndings.Macintosh:
                return("\r");

            case LineEndingsChanger.LineEndings.Windows:
                return("\r\n");

            case LineEndingsChanger.LineEndings.Linux:
            default:
                return("\n");
            }
        }
        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;

                if (!this.OptionsPage.TrackChanges ||
                    (this.OptionsPage.TrackChanges && this.changeLog != null && (!this.changeLog.ContainsKey(document.FullName) ||
                                                                                 this.changeLog[document.FullName].LineEndings != lineEndings ||
                                                                                 this.changeLog[document.FullName].Ticks < File.GetLastWriteTime(document.FullName).Ticks)))
                {
                    var textDocument = document.Object("TextDocument") as TextDocument;
                    UnifyLineEndingsInDocument(textDocument, lineEndings, ref numberOfChanges, out numberOfIndividualChanges, out numberOfAllLineEndings);
                    if (documentWindow != null || (documentWindow == null && this.OptionsPage.SaveFilesAfterUnifying))
                    {
                        this.isUnifyingLocked = true;
                        document.Save();
                        this.isUnifyingLocked = false;
                    }

                    this.changeLog[document.FullName] = new LastChanges(DateTime.Now.Ticks, lineEndings);

                    Output(string.Format("{0}: changed {1} out of {2} line endings\n", document.FullName, numberOfIndividualChanges, numberOfAllLineEndings));
                }
                else
                {
                    Output(string.Format("{0}: no need to modify this file\n", document.FullName));
                }
            }

            if (documentWindow != null)
            {
                documentWindow.Close();
            }
        }
        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);
                }

                if (item.Name.EndsWithAny(supportedFileFormats) || item.Name.EqualsAny(supportedFileNames))
                {
                    UnifyLineEndingsInProjectItem(item, lineEndings, ref numberOfChanges, saveAllWasHit);
                }
            }
        }
Example #9
0
        private void UnifyLineEndingsInProjectItems(ProjectItems projectItems, LineEndingsChanger.LineEndings lineEndings, ref int numberOfChanges)
        {
            var supportedFileFormats = this.SupportedFileFormats;

            foreach (ProjectItem item in projectItems)
            {
                if (item.ProjectItems != null && item.ProjectItems.Count > 0)
                {
                    UnifyLineEndingsInProjectItems(item.ProjectItems, lineEndings, ref numberOfChanges);
                }
                else
                {
                    if (item.Name.EndsWithAny(supportedFileFormats))
                    {
                        UnifyLineEndingsInProjectItem(item, lineEndings, ref numberOfChanges);
                    }
                }
            }
        }
        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);
        }
Example #11
0
        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 Cancel_Button_Click(object sender, RoutedEventArgs e)
 {
     this.lineEndings = LineEndingsChanger.LineEndings.None;
     this.DialogResult = false;
     this.Close();
 }
Example #13
0
 private void Cancel_Button_Click(object sender, RoutedEventArgs e)
 {
     this.lineEndings  = LineEndingsChanger.LineEndings.None;
     this.DialogResult = false;
     this.Close();
 }
Example #14
0
 public LastChanges(long ticks, LineEndingsChanger.LineEndings lineEndings)
 {
     Ticks       = ticks;
     LineEndings = lineEndings;
 }