public static Span GetSpan(this DocumentationFragment fragment) { int startPos = fragment.Selection.StartPosition; int length = fragment.Selection.EndPosition - fragment.Selection.StartPosition; var span = new Span(startPos, length); return(span); }
public static void AddDocumentationFragment(DocumentationFragment fragment, string filepath) { var content = DocumentationFileSerializer.Deserialize(filepath); var newFragments = content.Fragments .Where(f => !f.Selection.StartPosition.Equals(fragment.Selection.StartPosition) || !f.Selection.EndPosition.Equals(fragment.Selection.EndPosition)); newFragments = newFragments.Concat(new List <DocumentationFragment>() { fragment }); content.Fragments = newFragments.ToList(); DocumentationFileSerializer.Serialize(filepath, content); }
private void SaveDocumentation(object obj) { if (DocumentationText.Trim() == "") { MessageBox.Show("Documentation can't be empty."); return; } if (_existingDocumentation) { Result = AddDocumentationResult.Save; CloseRequest?.Invoke(); return; } var newDocFragment = new DocumentationFragment() { Documentation = DocumentationText, Selection = this._selection, }; try { string filepath = this._documentPath + Consts.CODY_DOCS_EXTENSION; DocumentationFileHandler.AddDocumentationFragment(newDocFragment, filepath); MessageBox.Show("Documentation added successfully."); EventAggregator.SendMessage <DocumentationAddedEvent>( new DocumentationAddedEvent() { Filepath = filepath, DocumentationFragment = newDocFragment }); Result = AddDocumentationResult.Save; CloseRequest?.Invoke(); } catch (Exception ex) { MessageBox.Show("Documentation add failed. Exception: " + ex.ToString()); } }