Exemplo n.º 1
0
        /// <summary>
        /// Finalize and save the active file under the main root folder after executing
        /// the given action. If the unselect input is true, the active file is unselected
        /// after saving
        /// </summary>
        /// <param name="rootFolder"></param>
        /// <param name="action"></param>
        /// <param name="unselect"></param>
        /// <returns>True if saving file resulted in no errors</returns>
        public bool SaveActiveFile(string rootFolder, Action <TextFileComposer> action, bool unselect = true)
        {
            if (HasActiveFile == false)
            {
                return(false);
            }

            action?.Invoke(ActiveFileComposer);

            ActiveFileComposer.FinalizeText();

            try
            {
                ActiveFileComposer.SaveToDisk(rootFolder, true, FilesEncoding);
                if (unselect)
                {
                    UnselectActiveFile();
                }
            }
            catch (Exception ex)
            {
                _log
                .AppendLineAtNewLine($"Error saving file <{ActiveFilePath}>")
                .AppendLineAtNewLine(ex.Message);

                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finalize the text of the active file of this composer. If AutoSaveFinalizedFiles
        /// is true, this saves the file to disk under the main root folder
        /// </summary>
        /// <returns></returns>
        public FilesComposer FinalizeActiveFile()
        {
            if (HasActiveFile == false || ActiveFileComposer.IsFinalized)
            {
                return(this);
            }

            ActiveFileComposer.FinalizeText();

            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Finalize the text of the active file if not already finalized after executing
        /// the given action. If AutoSaveFinalizedFiles is true, this saves the file to
        /// disk under the main root folder
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public FilesComposer FinalizeActiveFile(Action <TextFileComposer> action)
        {
            if (HasActiveFile == false || ActiveFileComposer.IsFinalized)
            {
                return(this);
            }

            action?.Invoke(ActiveFileComposer);

            ActiveFileComposer.FinalizeText();

            return(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set the given file to be the active file and clear its composer.
        /// If the file doesn't exist it's created.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public FilesComposer InitalizeFile(string fileName)
        {
            SelectFile(fileName);

            if (HasActiveFile == false)
            {
                return(this);
            }

            ActiveFileComposer.Clear();

            return(this);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set the given file to be the active file and clear its composer.
        /// If the file doesn't exist it's created. After that it executes the given action.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="initAction"></param>
        /// <returns></returns>
        public FilesComposer InitalizeFile(string fileName, Action <TextFileComposer> initAction)
        {
            SelectFile(fileName);

            if (HasActiveFile == false)
            {
                return(this);
            }

            ActiveFileComposer.Clear();

            initAction?.Invoke(ActiveFileComposer);

            return(this);
        }