Esempio n. 1
0
        private void ExportUserFormModule(string path)
        {
            // VBIDE API inserts an extra newline when exporting a UserForm module.
            // this issue causes forms to always be treated as "modified" in source control, which causes conflicts.
            // we need to remove the extra newline before the file gets written to its output location.

            var visibleCode         = CodeModule.Content().Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            var legitEmptyLineCount = visibleCode.TakeWhile(string.IsNullOrWhiteSpace).Count();

            var tempFile              = ExportToTempFile();
            var contents              = File.ReadAllLines(tempFile);
            var nonAttributeLines     = contents.TakeWhile(line => !line.StartsWith("Attribute")).Count();
            var attributeLines        = contents.Skip(nonAttributeLines).TakeWhile(line => line.StartsWith("Attribute")).Count();
            var declarationsStartLine = nonAttributeLines + attributeLines + 1;

            var emptyLineCount = contents.Skip(declarationsStartLine - 1)
                                 .TakeWhile(string.IsNullOrWhiteSpace)
                                 .Count();

            var code = contents;

            if (emptyLineCount > legitEmptyLineCount)
            {
                code = contents.Take(declarationsStartLine).Union(
                    contents.Skip(declarationsStartLine + emptyLineCount - legitEmptyLineCount))
                       .ToArray();
            }
            File.WriteAllLines(path, code);
        }
Esempio n. 2
0
        private void ExportDocumentModule(string path)
        {
            var lineCount = CodeModule.CountOfLines;

            if (lineCount > 0)
            {
                var text = CodeModule.GetLines(1, lineCount);
                File.WriteAllText(path, text);
            }
        }
Esempio n. 3
0
        private Selection GetSelection()
        {
            if (IsWrappingNullReference)
            {
                return(new Selection(0, 0, 0, 0));
            }

            int startLine;
            int startColumn;
            int endLine;
            int endColumn;

            Target.GetSelection(out startLine, out startColumn, out endLine, out endColumn);

            if (endLine > startLine && endColumn == 1)
            {
                endLine  -= 1;
                endColumn = CodeModule.GetLines(endLine, 1).Length;
            }

            return(new Selection(startLine, startColumn, endLine, endColumn));
        }