/// <summary>
        /// Create a new blank spreadsheet document.
        /// </summary>
        public void New()
        {
            this.LoadBlankContent();

            this.NamespaceManager = TextDocumentHelper.NameSpace(this._xmldoc.NameTable);

            this.DocumentConfigurations2 = new DocumentConfiguration2();

            this.DocumentManifest = new DocumentManifest();
            this.DocumentManifest.New();

            this.DocumentMetadata = new DocumentMetadata(this);
            this.DocumentMetadata.New();

            this.DocumentPictures = new DocumentPictureCollection();

            this.DocumentSetting = new DocumentSetting();
            this.DocumentSetting.New();

            this.DocumentStyles = new DocumentStyles();
            this.DocumentStyles.New();
            this.ReadCommonStyles();

            this.DocumentThumbnails = new DocumentPictureCollection();
        }
示例#2
0
        /// <summary>
        /// aspx页面中整体样式替换方法--编辑页面
        /// </summary>
        /// <param name="textDocument"></param>
        /// <param name="patternString"></param>
        internal void PrcoessAspxPageEdit(TextDocument textDocument)
        {
            string pattern = @"(?isx)       #匹配模式(i:忽略大小写 s:单行支持跨行 x:忽略表达式中空格)
                                <table.*?<td[^>]*?>
                                (?<title>\s*[\u4e00-\u9fa5]+\s*)                         #标题匹配
                                </td\s*>(?:.*?)<table[^>]*?>[^<>]*?
                                (?:<tr[^>]*?>[^<>]*?<td[^>]*?>(?<where>.*?)</td\s*>[^<>]*?</tr>\s*)+                      #查询条件匹配
                                ((?!<table).)*?(?<dataHead><asp:GridView(((?!class|>).)*?))(?<cls>(class|CssClass)\s*=\s*\"".*?\"")?(?<dataFooter>(((?!class|>).)*?)>.*?</asp:GridView>)
                                ((?!<table).)*?<td[^<]*?(?<page><uc1:(?:(?!/>).)*?/>\s*)*</td\s*>           #分页匹配
                                ((?!</table>).)*?</table>";

            //替换表达式拼接
            string        strBody         = "<div class=\"card-body\">";
            string        strGroup        = "<div class=\"form-group\">";
            StringBuilder replaceMentBody = new StringBuilder();

            replaceMentBody.AppendLine(@"<div class=""container-fluid row"">
          <div class=""col-lg-12"">
          <div class=""card"">");
            replaceMentBody.AppendLine(strBody);
            replaceMentBody.AppendLine("<div class=\"right-title\">${title}</div>");
            replaceMentBody.AppendLine(strGroup);
            replaceMentBody.AppendLine("${where}");
            replaceMentBody.AppendLine("</div>");
            replaceMentBody.AppendLine("</div>");
            replaceMentBody.AppendLine(strBody);
            replaceMentBody.AppendLine("${dataHead} class=\"table table-bordered table-hover table-striped\"${dataFooter}");
            replaceMentBody.AppendLine("${page}");
            replaceMentBody.AppendLine("</div>");
            replaceMentBody.AppendLine(@"</div>
          </div>
          </div>");
            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replaceMentBody.ToString());
        }
示例#3
0
        /// <summary>
        /// Called to execute the command.
        /// </summary>
        protected override void OnExecute()
        {
            base.OnExecute();

            var spade = Package.Spade;

            if (spade != null)
            {
                var region = new CodeItemRegion {
                    Name = "New Region"
                };
                var startPoint = spade.SelectedItems.OrderBy(x => x.StartOffset).First().StartPoint;
                var endPoint   = spade.SelectedItems.OrderBy(x => x.EndOffset).Last().EndPoint;

                _undoTransactionHelper.Run(() =>
                {
                    // Create the new region.
                    _generateRegionLogic.InsertEndRegionTag(region, endPoint);
                    _generateRegionLogic.InsertRegionTag(region, startPoint);

                    // Move to that element.
                    TextDocumentHelper.MoveToCodeItem(spade.Document, region, Settings.Default.Digging_CenterOnWhole);

                    // Highlight the line of text for renaming.
                    var textDocument = spade.Document.GetTextDocument();
                    textDocument.Selection.EndOfLine(true);
                    textDocument.Selection.SwapAnchor();
                });

                spade.Refresh();
            }
        }
示例#4
0
        /// <summary>
        /// Run the visual studio built-in remove unused using statements command.
        /// </summary>
        /// <param name="textDocument">The text document to update.</param>
        /// <param name="isAutoSave">A flag indicating if occurring due to auto-save.</param>
        public void RemoveUnusedUsingStatements(TextDocument textDocument, bool isAutoSave)
        {
            if (!Settings.Default.Cleaning_RunVisualStudioRemoveUnusedUsingStatements)
            {
                return;
            }
            if (isAutoSave && Settings.Default.Cleaning_SkipRemoveUnusedUsingStatementsDuringAutoCleanupOnSave)
            {
                return;
            }

            // Capture all existing using statements that should be re-inserted if removed.
            string patternFormat = _package.UsePOSIXRegEx
                                       ? @"^:b*{0}:b*\n"
                                       : @"^[ \t]*{0}[ \t]*\r?\n";

            var points = (from usingStatement in _usingStatementsToReinsertWhenRemoved.Value
                          from editPoint in TextDocumentHelper.FindMatches(textDocument, string.Format(patternFormat, usingStatement))
                          select new { editPoint, text = editPoint.GetLine() }).Reverse().ToList();

            _package.IDE.ExecuteCommand("Edit.RemoveUnusedUsings", String.Empty);

            // Check each using statement point and re-insert it if removed.
            foreach (var point in points)
            {
                string text = point.editPoint.GetLine();
                if (text != point.text)
                {
                    point.editPoint.StartOfLine();
                    point.editPoint.Insert(point.text);
                    point.editPoint.Insert(Environment.NewLine);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Get helper for processing a document, based on document extension
        /// </summary>
        /// <param name="path">Source document full path</param>
        /// <returns></returns>
        private static DocumentHelper GetHelperForDocument(String path)
        {
            DocumentHelper helper = null;
            FileInfo       fi     = new FileInfo(path);
            String         ext    = fi.Extension.Substring(1).ToLower();

            if (ext.Equals("docx"))
            {
                helper = new WordDocumentHelper();
            }
            else if (ext.Equals("xlsx"))
            {
                helper = new ExcelDocumentHelper();
            }
            else if (ext.Equals("pptx"))
            {
                helper = new PowerPointDocumentHelper();
            }
            else if (ext.Equals("jpeg") || ext.Equals("jpg") || ext.Equals("png") || ext.Equals("bmp") || ext.Equals("gif") || ext.Equals("tiff"))
            {
                helper = new PictureDocumentHelper();
            }
            else
            {
                if (TextHighlightConfiguration.GetTextHighlightForTextFile(path) != null)
                {
                    helper = new TextDocumentHelper();
                }
            }
            return(helper);
        }
        /// <summary>
        /// Removes blank spaces before a closing angle bracket.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankSpacesBeforeClosingAngleBracket(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankSpacesBeforeClosingAngleBrackets)
            {
                return;
            }

            // Remove blank spaces before regular closing angle brackets.
            string pattern     = _package.UsePOSIXRegEx ? @"\n*:b+\>\n" : @"(\r?\n)*[ \t]+>\r?\n";
            string replacement = @">" + Environment.NewLine;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);

            // Handle blank spaces before self closing angle brackets based on insert blank space setting.
            if (Settings.Default.Cleaning_InsertBlankSpaceBeforeSelfClosingAngleBrackets)
            {
                string oneSpacePattern     = _package.UsePOSIXRegEx ? @"\n*:b:b+/\>\n" : @"(\r?\n)*[ \t]{2,}/>\r?\n";
                string oneSpaceReplacement = @" />" + Environment.NewLine;

                TextDocumentHelper.SubstituteAllStringMatches(textDocument, oneSpacePattern, oneSpaceReplacement);
            }
            else
            {
                string noSpacePattern     = _package.UsePOSIXRegEx ? @"\n*:b+/\>\n" : @"(\r?\n)*[ \t]+/>\r?\n";
                string noSpaceReplacement = @"/>" + Environment.NewLine;

                TextDocumentHelper.SubstituteAllStringMatches(textDocument, noSpacePattern, noSpaceReplacement);
            }
        }
示例#7
0
 /// <summary>
 /// Inserts a blank line after the specified code elements except where adjacent to a brace.
 /// </summary>
 /// <typeparam name="T">The type of the code element.</typeparam>
 /// <param name="codeElements">The code elements to pad.</param>
 internal void InsertPaddingAfterCodeElements <T>(IEnumerable <T> codeElements)
     where T : BaseCodeItemElement
 {
     foreach (T codeElement in codeElements.Where(ShouldBeFollowedByBlankLine))
     {
         TextDocumentHelper.InsertBlankLineAfterPoint(codeElement.EndPoint);
     }
 }
示例#8
0
 /// <summary>
 /// Inserts a blank line before the specified code elements except where adjacent to a brace.
 /// </summary>
 /// <typeparam name="T">The type of the code element.</typeparam>
 /// <param name="codeElements">The code elements to pad.</param>
 internal void InsertPaddingBeforeCodeElements <T>(IEnumerable <T> codeElements)
     where T : BaseCodeItemElement
 {
     foreach (T codeElement in codeElements.Where(ShouldBePrecededByBlankLine))
     {
         TextDocumentHelper.InsertBlankLineBeforePoint(codeElement.StartPoint);
     }
 }
示例#9
0
        /// <summary>
        /// Joins the specified multi-line method onto a single line.
        /// </summary>
        /// <param name="method">The method to update.</param>
        private void JoinMultiLineMethodOntoSingleLine(CodeFunction method)
        {
            var start = method.StartPoint.CreateEditPoint();
            var end   = method.EndPoint.CreateEditPoint();

            const string pattern     = @"[ \t]*\r?\n[ \t]*";
            const string replacement = @" ";

            // Substitute all new lines (and optional surrounding whitespace) with a single space.
            TextDocumentHelper.SubstituteAllStringMatches(start, end, pattern, replacement);
        }
示例#10
0
        /// <summary>
        /// Removes blank lines after attributes.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankLinesAfterAttributes(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankLinesAfterAttributes)
            {
                return;
            }

            const string pattern     = @"(^[ \t]*\[[^\]]+\][ \t]*(//[^\r\n]*)*)(\r?\n){2}(?![ \t]*//)";
            string       replacement = @"$1" + Environment.NewLine;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#11
0
        /// <summary>
        /// Jumps to the specified code item.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        private void JumpToCodeItem(BaseCodeItem codeItem)
        {
            var viewModel = ViewModel;

            if (codeItem == null || viewModel == null || codeItem.StartOffset <= 0)
            {
                return;
            }

            Dispatcher.BeginInvoke(
                new Action(() => TextDocumentHelper.MoveToCodeItem(viewModel.Document, codeItem, Settings.Default.Digging_CenterOnWhole)));
        }
示例#12
0
        /// <summary>
        /// Removes blank lines between chained statements.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankLinesBetweenChainedStatements(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankLinesBetweenChainedStatements)
            {
                return;
            }

            const string pattern     = @"(\r?\n){2,}([ \t]*)(else|catch|finally)( |\t|\r?\n)";
            string       replacement = Environment.NewLine + @"$2$3$4";

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#13
0
        /// <summary>
        /// Removes blank lines before a closing tag.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankLinesBeforeClosingTag(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankLinesBeforeClosingTags)
            {
                return;
            }

            const string pattern     = @"(\r?\n){2,}([ \t]*)</";
            string       replacement = Environment.NewLine + @"$2</";

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#14
0
        /// <summary>
        /// Removes blank lines after an opening brace.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankLinesAfterOpeningBrace(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankLinesAfterOpeningBrace)
            {
                return;
            }

            const string pattern     = @"\{([ \t]*(//[^\r\n]*)*)(\r?\n){2,}";
            string       replacement = @"{$1" + Environment.NewLine;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#15
0
        /// <summary>
        /// Inserts a blank line before single line comments except where adjacent to a brace,
        /// another single line comment line or a quadruple slash comment.
        /// </summary>
        /// <param name="textDocument">The text document.</param>
        internal void InsertPaddingBeforeSingleLineComments(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_InsertBlankLinePaddingBeforeSingleLineComments)
            {
                return;
            }

            const string pattern     = @"(^[ \t]*(?!//)[^ \t\r\n\{].*\r?\n)([ \t]*//)(?!//)";
            string       replacement = @"$1" + Environment.NewLine + @"$2";

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#16
0
        /// <summary>
        /// Inserts a blank line before case statements except for single-line case statements.
        /// </summary>
        /// <param name="textDocument">The text document.</param>
        internal void InsertPaddingBeforeCaseStatements(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_InsertBlankLinePaddingBeforeCaseStatements)
            {
                return;
            }

            const string pattern     = @"(^[ \t]*)(break;|return([ \t][^;]*)?;)\r?\n([ \t]*)(case|default)";
            string       replacement = @"$1$2" + Environment.NewLine + Environment.NewLine + @"$4$5";

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#17
0
        /// <summary>
        /// Selects the specified code item.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        private void SelectCodeItem(BaseCodeItem codeItem)
        {
            var viewModel = ViewModel;

            if (codeItem == null || viewModel == null || codeItem.StartOffset <= 0)
            {
                return;
            }

            Dispatcher.BeginInvoke(
                new Action(() => TextDocumentHelper.SelectCodeItem(viewModel.Document, codeItem)));
        }
示例#18
0
        /// <summary>
        /// Inserts a single blank space before a self-closing angle bracket.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void InsertBlankSpaceBeforeSelfClosingAngleBracket(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_InsertBlankSpaceBeforeSelfClosingAngleBrackets)
            {
                return;
            }

            const string pattern     = @"([^ \t])/>";
            const string replacement = @"$1 />";

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#19
0
        /// <summary>
        /// Removes multiple consecutive blank lines from the specified text document.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveMultipleConsecutiveBlankLines(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveMultipleConsecutiveBlankLines)
            {
                return;
            }

            const string pattern     = @"(?<!@""(""""|[^""])*)(\r?\n){3,}";
            string       replacement = Environment.NewLine + Environment.NewLine;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#20
0
        /// <summary>
        /// Removes multiple consecutive blank lines from the specified text document.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveMultipleConsecutiveBlankLines(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveMultipleConsecutiveBlankLines)
            {
                return;
            }

            string pattern     = _package.UsePOSIXRegEx ? @"\n\n\n+" : @"(\r?\n){3,}";
            string replacement = Environment.NewLine + Environment.NewLine;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
        /// <summary>
        /// Removes all blank lines from the specified text document.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveAllBlankLines(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveAllBlankLines)
            {
                return;
            }

            string pattern     = @"(?m)^[ \t]*[\r?\n]+";
            string replacement = String.Empty;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#22
0
        /// <summary>
        /// Removes all end of line whitespace from the specified text document.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveEOLWhitespace(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveEndOfLineWhitespace)
            {
                return;
            }

            string pattern     = _package.UsePOSIXRegEx ? @":b+\n" : @"[ \t]+\r?\n";
            string replacement = Environment.NewLine;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#23
0
        /// <summary>
        /// Inserts a blank line after #endregion tags except where adjacent to a brace.
        /// </summary>
        /// <param name="regions">The regions to pad.</param>
        internal void InsertPaddingAfterEndRegionTags(IEnumerable <CodeItemRegion> regions)
        {
            if (!Settings.Default.Cleaning_InsertBlankLinePaddingAfterEndRegionTags)
            {
                return;
            }

            foreach (var region in regions.Where(x => !x.IsInvalidated))
            {
                var endPoint = region.EndPoint.CreateEditPoint();

                TextDocumentHelper.InsertBlankLineAfterPoint(endPoint);
            }
        }
示例#24
0
        /// <summary>
        /// aspx页面中整体样式替换方法-列表页面
        /// </summary>
        /// <param name="textDocument"></param>
        /// <param name="patternString"></param>
        internal void PrcoessAspxPageList(TextDocument textDocument)
        {
            //string pattern = "(?isx)<table.*?<td[^>]*?>(?<title>[\u4e00-\u9fa5]+)(?:.*?)<table[^>]*?>[^<>]*?(?:<tr[^>]*?>[^<>]*?<td[^>]*?>(?<row>.*?)</td>[^<>]*?</tr>\\s*)+((?!<table).)*?(?<dataHead><asp:GridView(((?!class|>).)*?))(?<cls>(class|CssClass)\\s*=\\s*\".*?\")?(?<dataFooter>(((?!class|>).)*?)>.*?</asp:GridView>)((?!</table>).)*?</table>";
            string pattern = @"(?isx)       #匹配模式(i:忽略大小写 s:单行支持跨行 x:忽略表达式中空格)
                                <table.*?<td[^>]*?>
                                (?<title>\s*[\u4e00-\u9fa5]+\s*)                         #标题匹配
                                </td\s*>(?:.*?)<table[^>]*?>[^<>]*?
                                (?:<tr[^>]*?>[^<>]*?<td[^>]*?>(?<where>.*?)(?<btns><asp:Button(?:(?(?!</td>).)*)/>)\s*</td\s*>[^<>]*?</tr>\s*)+                       #查询条件匹配
                                ((?!<table).)*?(?<dataHead><asp:GridView(((?!class|>).)*?))(?<cls>(class|CssClass)\s*=\s*\"".*?\"")?(?<dataFooter>(((?!class|>).)*?)>.*?</asp:GridView>)
                                ((?!<table).)*?<td.*?(?<page>(?(<%--)<%--|)<uc1:(?:(?!/>).)*?/>(?(--%>)--%>|)\s*).*</td\s*>    #分页匹配
                                ((?!</table>).)*?</table>";

            //替换表达式拼接
            string        strBody         = "<div class=\"card-body\">";
            string        strGroup        = "<div class=\"form-group\">";
            StringBuilder replaceMentBody = new StringBuilder();

            replaceMentBody.AppendLine(@"<div class=""container-fluid row"">
          <div class=""col-lg-12"">
          <div class=""card"">");
            replaceMentBody.AppendLine(strBody);
            replaceMentBody.AppendLine("<div class=\"right-title\">${title}</div>");
            replaceMentBody.AppendLine("${where}");
            replaceMentBody.AppendLine(strGroup); //添加查询条件按钮的样式开始标签
            replaceMentBody.AppendLine("${btns}");
            replaceMentBody.AppendLine("</div>"); //添加查询条件按钮的样式结束标签
            replaceMentBody.AppendLine("</div>");
            replaceMentBody.AppendLine(strBody);
            replaceMentBody.AppendLine("${dataHead} class=\"table table-bordered table-hover table-striped\"${dataFooter}");
            replaceMentBody.AppendLine("${page}");
            replaceMentBody.AppendLine("</div>");
            replaceMentBody.AppendLine(@"</div>
          </div>
          </div>");
            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replaceMentBody.ToString());

            //页面的查询条件控件样式替换表达式
            pattern = @"(?isx)       #匹配模式(i:忽略大小写 s:单行支持跨行 x:忽略表达式中空格)
                        (?<title>[\u4e00-\u9fa5]+[::])[\s&nbsp;]*(?<body><asp:(?<tag>[^>]*?)\b[^>]*?>(?:(?![\u4e00-\u9fa5]+[::]).)*</asp:\k<tag>>)\s*(?:&nbsp;)*";

            //替换表达式拼接
            replaceMentBody = new StringBuilder();
            replaceMentBody.AppendLine("<div class=\"form-group\">");
            replaceMentBody.AppendLine("<label class=\"lf formlabel\">${title}</label>");
            replaceMentBody.AppendLine("<div class=\"col-xs-1\">");
            replaceMentBody.AppendLine("${body}");//页面的查询条件样式通过其他替换表达式来完成效果
            replaceMentBody.AppendLine("</div>");
            replaceMentBody.AppendLine("</div>");
            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replaceMentBody.ToString());
        }
示例#25
0
        /// <summary>
        /// Load the given file.
        /// </summary>
        /// <param name="file"></param>
        public void Load(string file)
        {
            try
            {
                this._isLoadedFile = true;
                this.LoadBlankContent();

                this.NamespaceManager = TextDocumentHelper.NameSpace(this._xmldoc.NameTable);

                ImportHandler importHandler = new ImportHandler();
                IImporter     importer      = importHandler.GetFirstImporter(DocumentTypes.SpreadsheetDocument, file);

                if (importer != null)
                {
                    if (importer.NeedNewOpenDocument)
                    {
                        this.New();
                    }
                    importer.Import(this, file);

                    if (importer.ImportError != null)
                    {
                        if (importer.ImportError.Count > 0)
                        {
                            foreach (object ob in importer.ImportError)
                            {
                                if (ob is AODLWarning)
                                {
                                    if (((AODLWarning)ob).Message != null)
                                    {
                                        Console.WriteLine("Err: {0}", ((AODLWarning)ob).Message);
                                    }
                                    if (((AODLWarning)ob).Node != null)
                                    {
                                        XmlTextWriter writer = new XmlTextWriter(Console.Out);
                                        writer.Formatting = Formatting.Indented;
                                        ((AODLWarning)ob).Node.WriteContentTo(writer);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#26
0
        /// <summary>
        /// Inserts a blank line before single line comments except where adjacent to a brace,
        /// another single line comment line or a quadruple slash comment.
        /// </summary>
        /// <param name="textDocument">The text document.</param>
        internal void InsertPaddingBeforeSingleLineComments(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_InsertBlankLinePaddingBeforeSingleLineComments)
            {
                return;
            }

            string pattern = _package.UsePOSIXRegEx
                                 ? @"{^:b*~(//)[^:b\r\n\{].*\n}{:b*//}~(//)"
                                 : @"(^[ \t]*(?!//)[^ \t\r\n\{].*\r?\n)([ \t]*//)(?!//)";
            string replacement = _package.UsePOSIXRegEx
                                     ? @"\1" + Environment.NewLine + @"\2"
                                     : @"$1" + Environment.NewLine + @"$2";

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#27
0
        /// <summary>
        /// Removes blank lines after attributes.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankLinesAfterAttributes(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankLinesAfterAttributes)
            {
                return;
            }

            string pattern = _package.UsePOSIXRegEx
                                 ? @"\]{:b*(//.*)*}\n\n~(:b*//)"
                                 : @"\]([ \t]*(//[^\r\n]*)*)(\r?\n){2}(?![ \t]*//)";
            string replacement = _package.UsePOSIXRegEx
                                     ? @"\]\1" + Environment.NewLine
                                     : @"]$1" + Environment.NewLine;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#28
0
        /// <summary>
        /// Removes blank lines between chained statements.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankLinesBetweenChainedStatements(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankLinesBetweenChainedStatements)
            {
                return;
            }

            string pattern = _package.UsePOSIXRegEx
                                 ? @"\n\n{:b*}{else|catch|finally}{:b|\n}"
                                 : @"(\r?\n){2,}([ \t]*)(else|catch|finally)( |\t|\r?\n)";
            string replacement = _package.UsePOSIXRegEx
                                     ? Environment.NewLine + @"\1\2\3"
                                     : Environment.NewLine + @"$2$3$4";

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#29
0
        /// <summary>
        /// Removes blank lines before a closing tag.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankLinesBeforeClosingTag(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankLinesBeforeClosingTags)
            {
                return;
            }

            string pattern = _package.UsePOSIXRegEx
                                 ? @"\n\n{:b*}\</"
                                 : @"(\r?\n){2,}([ \t]*)</";
            string replacement = _package.UsePOSIXRegEx
                                     ? Environment.NewLine + @"\1</"
                                     : Environment.NewLine + @"$2</";

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }
示例#30
0
        /// <summary>
        /// Removes blank lines after an opening brace.
        /// </summary>
        /// <param name="textDocument">The text document to cleanup.</param>
        internal void RemoveBlankLinesAfterOpeningBrace(TextDocument textDocument)
        {
            if (!Settings.Default.Cleaning_RemoveBlankLinesAfterOpeningBrace)
            {
                return;
            }

            string pattern = _package.UsePOSIXRegEx
                                 ? @"\{{:b*(//.*)*}\n\n"
                                 : @"\{([ \t]*(//[^\r\n]*)*)(\r?\n){2,}";
            string replacement = _package.UsePOSIXRegEx
                                     ? @"\{\1" + Environment.NewLine
                                     : @"{$1" + Environment.NewLine;

            TextDocumentHelper.SubstituteAllStringMatches(textDocument, pattern, replacement);
        }