コード例 #1
0
        /// <summary>
        /// Saves a topic in the tree and then saves the project to
        /// disk.
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="project"></param>
        /// <param name="async"></param>
        /// <returns>false if data wasn't written (could be because there's nothing that's changed)</returns>
        public bool SaveProjectFileForTopic(DocTopic topic, DocProject project = null, bool async = false)
        {
            if (topic == null)
            {
                return(false);
            }

            if (!topic.TopicState.IsDirty)
            {
                return(false);
            }

            if (project == null)
            {
                project = kavaUi.AddinModel.ActiveProject;
            }


            if (async)
            {
                project.SaveProjectAsync();
                topic.TopicState.IsDirty = false;
                return(true);
            }

            bool result = project.SaveProject();

            if (result)
            {
                topic.TopicState.IsDirty = false;
            }

            return(result);
        }
コード例 #2
0
        public bool SaveProjectFileForTopic(DocTopic topic, DocProject project = null)
        {
            if (topic == null)
            {
                return(false);
            }

            if (!topic.TopicState.IsDirty)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(topic.TopicState.OldLink) && topic.TopicState.OldLink != topic.Link)
            {
                if (MessageBox.Show(
                        $@"Link has changed from {topic.TopicState.OldLink} to {
                                topic.Link
                            }.\r\n\rnDo you want to fix up the link and file?",
                        "Topic Link Changed",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    var oldFile = topic.GetTopicFileName(topic.TopicState.OldLink);
                    topic.SaveTopicFile(); // save new file
                    File.Delete(oldFile);
                }
            }


            if (project == null)
            {
                project = kavaUi.AddinModel.ActiveProject;
            }

            project.SaveProjectAsync();
            return(true);
        }