/// <summary> /// Called after a topic file (the MD file linked to a topic) /// has been saved on disk. This allows updating of topic /// info from the saved content. /// </summary> /// <param name="topic"></param> /// <param name="doc"></param> public void OnTopicFilesSaved(DocTopic topic, MarkdownDocument doc) { if (topic == null) { return; } var projectFilename = topic?.Project?.Filename; var filename = doc.Filename.ToLower(); if (topic.Body == "NoContent") { topic.Body = null; } // Save Project File if (projectFilename != null && filename.Equals(projectFilename, StringComparison.InvariantCultureIgnoreCase)) { // reload the project KavaDocsModel.LoadProject(KavaDocsModel.ActiveProject.Filename); return; } // Check for explicit KavaDocs Documents if (string.IsNullOrEmpty(doc.CurrentText)) { return; } // Save the underlying topic file if (filename.Equals(topic.GetTopicFileName(), StringComparison.InvariantCultureIgnoreCase)) { KavaDocsModel.ActiveProject.UpdateTopicFromMarkdown(doc, topic); KavaDocsModel.ActiveProject.SaveProject(); } // READ-ONLY this shouldn't really happen any more // Saving the KavaDocs.md file - assume we're on the active topic else if (filename.Equals(topic.GetKavaDocsEditorFilePath(), StringComparison.InvariantCultureIgnoreCase)) { topic.Body = doc.CurrentText; KavaDocsModel.ActiveProject.UpdateTopicFromMarkdown(doc, topic); KavaDocsModel.ActiveProject.SaveProject(); } // Any previously activated document file else if (KavaDocsModel.ActiveMarkdownEditor.Properties.TryGetValue(Constants.EditorPropertyNames.KavaDocsTopic, out object objTopic)) { KavaDocsModel.ActiveProject.UpdateTopicFromMarkdown(doc, objTopic as DocTopic); KavaDocsModel.ActiveProject.SaveProject(); } }
public override void OnAfterSaveDocument(MarkdownDocument doc) { base.OnAfterSaveDocument(doc); if (doc == null || KavaDocsModel == null) { return; } // Reload settings after saving them in the editor if (doc.Filename.IndexOf("kavadocsaddin.json", StringComparison.InvariantCultureIgnoreCase) > -1) { KavaDocsModel.Configuration.Read(); return; } // Reload Project file if editing project file if (KavaDocsModel.ActiveProject != null && KavaDocsModel.ActiveProject.Filename.Equals(doc.Filename, StringComparison.InvariantCultureIgnoreCase)) { KavaDocsModel.LoadProject(KavaDocsModel.ActiveProject.Filename); return; } if (KavaDocsModel?.ActiveTopic != null) { var topic = Model.ActiveEditor.GetProperty <DocTopic>(Constants.EditorPropertyNames.KavaDocsTopic); if (topic != null) { InitializeKavaDocs(); // will check if already loaded OnTopicFilesSaved(topic, doc); return; } } }