Example #1
0
    public static MainEdit readFrom(String path)
    {
        var      reader = new System.Xml.Serialization.XmlSerializer(typeof(MainEdit));
        var      file   = new System.IO.StreamReader(path);
        MainEdit me     = reader.Deserialize(file) as MainEdit;

        file.Close();
        return(me);
    }
Example #2
0
        public async void LoadDocument()
        {
            storageFolder = ApplicationData.Current.LocalFolder;
            Debug.WriteLine("Loading document: StorageFolder found");
            string filepath = storageFolder.Path.ToString() + "/" + documentName;

            Debug.WriteLine("Loading document: filepath set");
            if (File.Exists(filepath))
            {
                Debug.WriteLine(filepath + " exists. It will be loaded now.");
            }
            else
            {
                Debug.WriteLine(filepath + " exists not. It will be created now.");
                file = await storageFolder.CreateFileAsync(documentName);

                Debug.WriteLine(filepath + "File was created. It will be loaded now.");
            }
            file = await storageFolder.GetFileAsync(documentName);

            if (File.Exists(storageFolder.Path.ToString() + "/" + documentTempName) == false)
            {
                await storageFolder.CreateFileAsync(documentTempName);
            }
            tempFile = await storageFolder.GetFileAsync(documentTempName);

            Debug.WriteLine("Temp file found.");
            await file.CopyAndReplaceAsync(tempFile);

            Debug.WriteLine("file copied");
            IRandomAccessStream randAccStream = await tempFile.OpenAsync(FileAccessMode.Read);

            MainEdit.Document.LoadFromStream(TextSetOptions.FormatRtf, randAccStream);
            Debug.WriteLine("File loaded");
            randAccStream.Dispose();
            MainEdit.Focus(FocusState.Keyboard); MainEdit.Document.GetText(TextGetOptions.None, out string txt);
            MainEdit.Document.Selection.SetRange(startPosition: txt.Length, endPosition: txt.Length);
            timer.Start();
            settingsMenu.fontList     = FontList;
            settingsMenu.EncodingList = EncodingList;
            if (Settings.Default.MenuOpenOnStartup)
            {
                AddMenus();
            }
        }
Example #3
0
 public MainEdit from(String path)
 {
     return(MainEdit.readFrom(path));
 }
Example #4
0
        public async void Import(int i)
        {
            ChangeLoading(true);
            Windows.Storage.Pickers.FileOpenPicker openpicker = new Windows.Storage.Pickers.FileOpenPicker();
            openpicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            openpicker.FileTypeFilter.Add(".rtf");
            openpicker.FileTypeFilter.Add(".doc");
            openpicker.FileTypeFilter.Add(".docx");
            openpicker.FileTypeFilter.Add(".epub");
            openpicker.FileTypeFilter.Add(".html");
            openpicker.FileTypeFilter.Add(".txt");
            openpicker.CommitButtonText = resourceLoader.GetString("CommitImportText");
            StorageFile importfile = await openpicker.PickSingleFileAsync();

            if (importfile != null)
            {
                if (importfile.FileType != ".rtf")
                {
                    if (importfile.FileType == ".doc")
                    {
                        await SfImport(importfile, FormatType.Doc);
                    }
                    else if (importfile.FileType == ".docx")
                    {
                        await SfImport(importfile, FormatType.Docx);
                    }
                    else if (importfile.FileType == ".epub")
                    {
                        await SfImport(importfile, FormatType.EPub);
                    }
                    else if (importfile.FileType == ".html")
                    {
                        await SfImport(importfile, FormatType.Html);
                    }
                    else if (importfile.FileType == ".txt")
                    {
                        await SfImport(importfile, FormatType.Txt);
                    }


                    importfile = await ApplicationData.Current.LocalCacheFolder.GetFileAsync("sfimportcache.rtf");
                }

                MainEdit.Document.GetText(TextGetOptions.FormatRtf, out string content);

                IRandomAccessStream randAccStream = await importfile.OpenAsync(FileAccessMode.Read);

                MainEdit.Document.SetText(TextSetOptions.None, string.Empty);
                MainEdit.Document.LoadFromStream(TextSetOptions.FormatRtf, randAccStream);
                MainEdit.Document.GetText(TextGetOptions.FormatRtf, out string importcontent);
                Debug.WriteLine(content);
                Debug.WriteLine(importcontent);
                if (i == 0)
                {
                    Debug.WriteLine("Import before content");
                    MainEdit.Document.SetText(TextSetOptions.None, string.Empty);
                    // Sets importcontent as the content of the document
                    MainEdit.Document.SetText(TextSetOptions.FormatRtf, importcontent);
                    // Get a new text range for the active story of the document.
                    var range = MainEdit.Document.GetRange(0, importcontent.Length);
                    // Collapses the text range into a degenerate point at the end of the range for inserting.
                    range.Collapse(false);
                    // Inserts original content
                    range.SetText(TextSetOptions.FormatRtf, content);
                }
                else if (i == 1)
                {
                    Debug.WriteLine("Import after content");
                    MainEdit.Document.SetText(TextSetOptions.None, string.Empty);
                    // Sets original content as the content of the document
                    MainEdit.Document.SetText(TextSetOptions.FormatRtf, content);
                    // Get a new text range for the active story of the document.
                    var range = MainEdit.Document.GetRange(0, content.Length);
                    // Collapses the text range into a degenerate point at the end of the range for inserting.
                    range.Collapse(false);
                    // Inserts importcontent
                    range.SetText(TextSetOptions.FormatRtf, importcontent);
                }
                else
                {
                    Debug.WriteLine("Replace existing");
                }
                MainEdit.Focus(FocusState.Keyboard);
            }
            else
            {
                MessageDialog md = new MessageDialog(resourceLoader.GetString("DialogCancelled"), resourceLoader.GetString("Dialog_OperationCancelled"));
                await md.ShowAsync();
            }
            ChangeLoading(false);
        }