Esempio n. 1
0
        private void Apply(string displayName, HtmlElement original, HtmlElement newElement, string tabsBefore)
        {
            if ((!string.IsNullOrEmpty(displayName) && (original != null)) && (newElement != null))
            {
                int         num            = original.NameRange.End.Offset - original.StartOffset;
                SourceRange insertionRange = GetInsertionRange(original);
                string      s = CodeRush.Language.GenerateElement(newElement);
                s = CodeRush.StrUtil.RemoveLastLineTerminator(s);
                if (Options.PutCloseTagOnOwnLine)
                {
                    var terminator = @"/>";
                    if (!s.EndsWith(terminator))
                    {
                        terminator = @">";
                    }

                    s  = s.Substring(0, s.Length - terminator.Length);
                    s += string.Format("\r\n{0}{1}", tabsBefore, terminator);
                }
                insertionRange.BindToCode(CodeRush.Documents.Active as TextDocument);
                ICompoundAction         action = CodeRush.TextBuffers.NewMultiFileCompoundAction(displayName, true);
                IMultiLidContainerGroup group  = CodeRush.LinkedIdentifiers.OpenMultiLidContainerGroup();
                try
                {
                    FileChangeCollection changes = new FileChangeCollection();
                    changes.Add(new FileChange(original.FileNode.Name, insertionRange, s));
                    CodeRush.File.ApplyChanges(changes, false, true);
                    CodeRush.Caret.MoveTo(insertionRange.Start.Line, (int)(insertionRange.Start.Offset + num));
                }
                catch (Exception exception)
                {
                    LogBase <Log> .SendException(displayName, exception);
                }
                finally
                {
                    if (_breakApartPreview != null)
                    {
                        _breakApartPreview.Clear();
                        _breakApartPreview = null;
                    }

                    group.Close();
                    action.Close();
                    insertionRange.RemoveAllBindings();
                }
            }
        }