/// <summary>
        /// Save current file
        /// </summary>
        /// <param name="saveAs">true: show save as diaglog</param>
        /// <param name="newEncoding">not null: use new encoding to save file</param>
        /// <returns>true : if file saved</returns>
        public bool SaveFile(bool saveAs, Encoding newEncoding = null)
        {
            string filePath2Save = CurrentFilePath;

            if (string.IsNullOrEmpty(CurrentFilePath) || saveAs)
            {
                filePath2Save = NewFilePath(CurrentFilePath);
                if (filePath2Save == null)
                {
                    return(false);
                }
            }

            if (newEncoding != null)
            {
                MainEditor.Encoding = newEncoding;
            }
            MainEditor.Save(filePath2Save);
            if (CurrentFilePath != filePath2Save)
            {
                UpdateLastUsedFile(filePath2Save);
            }

            UpdateEditor(filePath2Save);
            DocumentSavedEvent?.Invoke();
            return(true);
        }
        public void Rename(string filePath)
        {
            string newFilePath = NewFilePath(filePath);

            if (newFilePath == null)
            {
                return;
            }

            try
            {
                File.Move(filePath, newFilePath);
                if (CurrentFilePath != newFilePath)
                {
                    UpdateLastUsedFile(newFilePath);
                }
                UpdateEditor(newFilePath);

                DocumentSavedEvent?.Invoke();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                Properties.Resources.Message_RenameFailedTitle,
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }
Example #3
0
 private void OnDocumentSaved(DocumentSavedEvent documentSavedEvent)
 {
     if (documentSavedEvent.DocumentFullName == _filename)
     {
         RemoveEmptyTrackingSpans();
         FileDocumentation fileDocumentation = CreateFileDocumentationFromTrackingSpans();
         DocumentationFileSerializer.Serialize(CodyDocsFilename, fileDocumentation);
     }
 }