示例#1
0
        /// <summary>
        /// Called on buffer save
        /// </summary>
        private void FixBufferOnSave(ITextBuffer buffer, int tabSize, string filePath)
        {
            if (!AlwaysAlignedConfigurationService.Instance.GetConfiguration().ConvertOnLoadSave)
            {
                return;
            }

            using (StreamWriter streamWriter = new StreamWriter(filePath))
            {
                string text          = buffer.CurrentSnapshot.GetText();
                string convertedText = ElasticTabstopsConverter.ToSpaces(text, tabSize);
                streamWriter.Write(convertedText);
            }
        }
示例#2
0
        private void _btnAlignSpaces_Click()
        {
            if (AppInfo.appObject.ActiveDocument == null)
            {
                return;
            }

            var doc = (TextDocument)AppInfo.appObject.ActiveDocument.Object("TextDocument");

            if (doc == null)
            {
                return;
            }

            string text          = doc.StartPoint.CreateEditPoint().GetText(doc.EndPoint);
            string convertedText = ElasticTabstopsConverter.ToSpaces(text, doc.TabSize);

            doc.ReplaceText(text, convertedText);
        }
示例#3
0
        /// <summary>
        /// Called on buffer load
        /// </summary>
        private static void FixBufferOnLoad(ITextBuffer buffer, int tabSize)
        {
            if (!AlwaysAlignedConfigurationService.Instance.GetConfiguration().ConvertOnLoadSave)
            {
                return;
            }

            string str = buffer.CurrentSnapshot.GetText();

            if (str.Contains("\t"))
            {
                MiscGui.WriteOutput("Always Aligned is set to convert files from using spaces when loading, but at least one tab was found. The file will be left alone.");
            }
            else
            {
                string    convertedText = ElasticTabstopsConverter.ToElasticTabstops(str, tabSize);
                ITextEdit tb            = buffer.CreateEdit();
                tb.Replace(new Span(0, buffer.CurrentSnapshot.Length), convertedText);
                tb.Apply();
            }
        }