Esempio n. 1
0
        /**
         * Function: SaveAsExtern
         *
         * Serves as 'save as' functionality. See the function documentation below this one.
         *
         * Author: wellinthatcase
         *
         * Date: 12/25/2020
         *
         * Parameters:
         * file -      The file.
         * content -   The content.
         *
         * Returns: True if it succeeds, false if it fails.
         */

        private string SaveAsExtern(string file, string content)
        {
            SaveFileDialog dialog = new SaveFileDialog
            {
                Filter          = Metadata["DialogFilters"],
                FileName        = Metadata["ActualNoteName"],
                AddExtension    = true,
                ValidateNames   = true,
                OverwritePrompt = true
            };

            if (dialog.ShowDialog() == true)
            {
                file = dialog.FileName;

                using (FileStream stream = File.OpenWrite(file))
                {
                    content = Lmd.Embed(file, content, TextEntry);

                    byte[] encodedContent = Encoding.UTF8.GetBytes(content);
                    int    encodedMaxByte = Encoding.UTF8.GetByteCount(content);
                    int    encodedOffset  = 0;

                    stream.Write(encodedContent, encodedOffset, encodedMaxByte);
                }
            }

            return(file);
        }
Esempio n. 2
0
        /**
         * Function: Save
         *
         * If the note corresponds to a file, then this saves the content into the file.
         * This serves much more as 'save' than 'save as' functionality.
         *
         * If there is no file to correspond with, then 'save as' functionality is invoked.
         *
         * In addition to saving the note, we also may inject LMD, or 'Lively metadata'
         * into the beginning of the file.
         *
         * This sort of functionality is only supported among files with the '.lmd' extension.
         *
         * Author: wellinthatcase
         *
         * Date: 12/25/2020
         *
         * Parameters:
         * file -      The file.
         * content -   The content.
         *
         * Returns: True if it succeeds, false if it fails.
         */

        private string Save(string file, string content)
        {
            if (file != string.Empty)
            {
                File.WriteAllText(file, Lmd.Embed(file, content, TextEntry));
                return(file);
            }
            else
            {
                return(SaveAsExtern(file, content));
            }
        }
Esempio n. 3
0
    /**
     * Function: FullProcess
     *
     * Parses LMD from the described filePath, then modifies the supplied TextEntry with the attained LMD.
     *
     * Author: wellinthatcase
     *
     * Date: 12/31/2020
     *
     * Parameters:
     * filePath -  Full pathname of the file.
     */

    public static string Process(string filePath, ref RichTextBox TextEntry)
    {
        string text = StripLmdFromFile(filePath);

        TextEntry.Document.Blocks.Clear();
        TextEntry.Document.Blocks.Add(new Paragraph(new Run(text)));

        Lmd possibleLmd = ParseFromFile(filePath);

        if (possibleLmd is Lmd)
        {
            possibleLmd.ProcessStyles(ref TextEntry);
        }

        return(text);
    }
Esempio n. 4
0
        /**
         * Function: KeybinderOpen
         *
         * Opens & processes the open file dialog for the keybinder.
         *
         * Author: wellinthatcase
         *
         * Date: 12/25/2020
         */

        private string KeybinderOpen()
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter = Metadata["DialogFilters"]
            };

            if (dialog.ShowDialog() == true)
            {
                string filName = dialog.FileName;
                string content = Lmd.Process(filName, ref TextEntry);
                string nNoteId = Path.GetFileNameWithoutExtension(filName);

                Metadata["ActualNoteName"] = nNoteId;
                NoteName.Text = MeasureNoteName(nNoteId);

                return(filName);
            }

            return(string.Empty);
        }
Esempio n. 5
0
        /**
         * Function: RenderPotentialNoteName
         *
         * Control: NoteName
         *
         * Event: Loaded
         *
         * Renders the potential note name. Both from the Splash-Screen & Windows.
         *
         * Author: wellinthatcase.
         *
         * Date: 12/22/2020.
         *
         * Param:
         * sender -  Source of the event.
         * e -       Routed event information.
         */

        private void RenderPotentialNoteName(object sender, RoutedEventArgs e)
        {
            string[] lpCmdLineArgs = Environment.GetCommandLineArgs();

            try
            {
                Metadata["ActualNoteName"] = lpCmdLineArgs[1];
                Metadata["AlreadyRunFile"] = lpCmdLineArgs[1];

                if (File.Exists(Metadata["AlreadyRunFile"]))
                {
                    Lmd.Process(Metadata["AlreadyRunFile"], ref TextEntry);
                    HideUnsve();
                }
            }
            catch (IndexOutOfRangeException)
            {
                Metadata["ActualNoteName"] = "Untitled note";
            }

            NoteName.Text = MeasureNoteName(Path.GetFileNameWithoutExtension(Metadata["ActualNoteName"]));
        }