Exemple #1
0
        public void CreateScene()
        {
            NameItemDialog dialog = new NameItemDialog(DialogOwner, "New Scene");
            bool?          result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                FlowDocument doc = new FlowDocument(Model.Connection);
                doc.UniverseId = StoryVm.Model.UniverseId;
                doc.WordCount  = 0;
                doc.PlainText  = "";
                doc.Xml        = FlowDocumentViewModel.GetEmptyFlowDocXml();
                doc.Create();

                Scene scene = new Scene(Model.Connection);
                scene.ChapterId = Model.id;
                scene.Name      = dialog.UserInput;
                if (Scenes.Count == 0)
                {
                    scene.SortIndex = 0;
                }
                else
                {
                    scene.SortIndex = Scenes.Max(i => i.Model.SortIndex) + 1;
                }
                scene.FlowDocumentId = doc.id;
                scene.Create();
                SceneViewModel sceneVm = new SceneViewModel(scene);
                sceneVm.ChapterVm = this;
                Scenes.Add(sceneVm);
            }
        }
Exemple #2
0
        public void Encrypt()
        {
            FlowDocument fd = new FlowDocument(Model.Connection);

            fd.id = Model.FlowDocumentId;
            fd.Load();
            FlowDocumentViewModel vm = new FlowDocumentViewModel(fd, DialogOwner);

            fd.IsEncrypted = true;
            vm.GetAesPassword(true);
            vm.Save();
            IsEncrypted = true;
        }
Exemple #3
0
        public void ExportToWord(Docx.DocX doc)
        {
            FlowDocument flowDoc = new FlowDocument(Model.Connection);

            flowDoc.id = Model.FlowDocumentId;
            flowDoc.Load();

            FlowDocumentViewModel vm = new FlowDocumentViewModel(flowDoc, DialogOwner);

            foreach (WinDoc.Block block in vm.Document.Blocks)
            {
                if (block is WinDoc.Paragraph)
                {
                    FlowDocumentExporter.AddParagraph((WinDoc.Paragraph)block, doc);
                }
            }
        }
        public void EditCopyrightPage()
        {
            if (!Model.FlowDocumentId.HasValue)
            {
                FlowDocument doc = new FlowDocument(Model.Connection);
                doc.UniverseId  = Model.UniverseId;
                doc.IsEncrypted = false;
                doc.WordCount   = 0;
                doc.PlainText   = "";
                doc.Xml         = FlowDocumentViewModel.GetEmptyFlowDocXml();
                doc.Create();

                Model.FlowDocumentId = doc.id;
                Model.Save();
            }
            if (Model.FlowDocumentId.HasValue)
            {
                FlowDocumentEditorWindow.ShowEditorWindow(Model.FlowDocumentId.Value, Model.Connection, UniverseVm.SpellcheckDictionary, string.Format("Copyright Page: {0}", Model.Name));
            }
        }
Exemple #5
0
 public void Decrypt()
 {
     try
     {
         FlowDocument fd = new FlowDocument(Model.Connection);
         fd.id = Model.FlowDocumentId;
         fd.Load();
         FlowDocumentViewModel vm = new FlowDocumentViewModel(fd, DialogOwner);
         fd.IsEncrypted = false;
         fd.Save();
         vm.Save();
         IsEncrypted = false;
     }
     catch (CryptographicException)
     {
         MessageBox.Show("Invalid password. Decryption operation canceled.", "Invalid password", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (ApplicationException)
     {
         MessageBox.Show("Invalid password. Decryption operation canceled.", "Invalid password", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        public void ExportToWord(Docx.DocX doc)
        {
            // Format title page of the document.
            Xceed.Document.NET.Paragraph p = doc.InsertParagraph();
            p.Append("\n\n" + Model.Name);
            p.StyleId = "Title";

            if (!string.IsNullOrWhiteSpace(Model.Subtitle))
            {
                p = doc.InsertParagraph();
                p.Append(Model.Subtitle);
                p.StyleId = "Subtitle";
            }
            if (!string.IsNullOrWhiteSpace(Model.Author))
            {
                p = doc.InsertParagraph();
                p.Append("\n\n" + Model.Author);
                p.StyleId = "Subtitle";
            }
            p.InsertPageBreakAfterSelf();

            // Insert copyright page.
            if (Model.FlowDocumentId.HasValue)
            {
                FlowDocument copyrightFd = new FlowDocument(Model.Connection);
                copyrightFd.id = Model.FlowDocumentId.Value;
                copyrightFd.Load();

                FlowDocumentViewModel copyrightVm = new FlowDocumentViewModel(copyrightFd, DialogOwner);

                foreach (WinDoc.Block block in copyrightVm.Document.Blocks)
                {
                    if (block is WinDoc.Paragraph)
                    {
                        FlowDocumentExporter.AddParagraph((WinDoc.Paragraph)block, doc);
                    }
                }

                p.InsertPageBreakAfterSelf();
            }

            // Insert eBook table of contents.

            // This doesn't make sense to me. Xceed's documentation says "A key-value dictionary where the key is a TableOfContentSwitches
            // and the value is the parameter of the switch."
            // I have no idea what the string values are supposed to be. Empty strings seem to work.
            Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string> tocParams = new Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string>();

            tocParams[Xceed.Document.NET.TableOfContentsSwitches.H] = ""; // TOC entries are clickable hyperlinks.
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.N] = ""; // Omits page numbers.
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.Z] = ""; // Hides tab leader and page numbers...?
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.U] = ""; // Uses the applied paragraph outline level...?
            Xceed.Document.NET.TableOfContents toc = doc.InsertTableOfContents("Table of Contents", tocParams);
            doc.Paragraphs.Last().InsertPageBreakAfterSelf();

            for (int i = 0; i < Chapters.Count; i++)
            {
                ChapterViewModel chapter = Chapters[i];
                chapter.ExportToWord(doc);
            }
        }