public static void CopyToDocument(MNDocument doc) { foreach (MNPage page in internalDocument.Data.Templates) { if (AddTemplateToArray(doc, page, false)) { page.Document = doc; page.Id = doc.Data.GetNextId(); foreach (SMControl sc in page.Objects) { long oldId = sc.Id; sc.Id = doc.Data.GetNextId(); sc.Page = page; } } } foreach (MNReferencedImage img in internalDocument.DefaultLanguage.Images) { if (AddImageToArray(doc, img, false)) { img.Id = doc.Data.GetNextId(); } } foreach (MNReferencedStyle st in internalDocument.DefaultLanguage.Styles) { AddStyleToArray(doc, st, false); } // load again, since we have most probably destroyed structure of document Load(); }
private void checkTransitionPagesToolStripMenuItem_Click(object sender, EventArgs e) { DialogInsertTransPages dlg = new DialogInsertTransPages(); MNDocument doc = MNNotificationCenter.CurrentDocument; dlg.SetDocument(doc); if (dlg.ShowDialog() == DialogResult.OK) { for (int i = 2; i >= 0; i--) { int afterPage, pageType; dlg.GetPageToInsert(i, out afterPage, out pageType); MNPage p = null; switch (pageType) { case 1: doc.Data.Pages[afterPage].NextPage = ""; p = AddNewPage(doc, "End of Book", "EOPBook", 0, afterPage); break; case 2: doc.Data.Pages[afterPage].NextPage = ""; p = AddNewPage(doc, "End of Exercises Before", "EOPExBefore", 0, afterPage); break; case 3: doc.Data.Pages[afterPage].NextPage = ""; p = AddNewPage(doc, "End of Exercises After", "EOPExAfter", 0, afterPage); break; } } } }
public void SetDocument(MNDocument doc) { Document = doc; doc.Viewer = p_docexec; p_docexec.Document = doc; p_docexec.OnEvent("OnLoad", doc); }
private static bool LoadBookHeader(string fileName) { bool r = true; using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\load_book.txt")) { using (BinaryReader br = new BinaryReader(File.OpenRead(fileName))) { MNDocument document = new MNDocument(); RSFileReader fr = new RSFileReader(br); fr.logStream = sw; try { document.Book.Load(fr); document.Book.FilePath = fileName; MNNotificationCenter.CurrentFileName = fileName; MNNotificationCenter.CurrentDocument = document; } catch (Exception ex) { sw.Flush(); sw.WriteLine("Exception:"); sw.WriteLine(ex.Message); sw.WriteLine(ex.StackTrace); sw.Flush(); r = false; } } } return(r); }
public void OnNotificationReceived(object sender, string message, params object[] args) { if (message.Equals("DocumentChanged")) { MNDocument doc = args[0] as MNDocument; StopDocumentReview(); StartDocumentReview(doc, doc.Book.FilePath); } else if (message.Equals("StartDocumentReview")) { StopDocumentReview(); StartDocumentReview(args[0] as MNDocument, args[1] as string); } else if (message.Equals("AppWillClose")) { StopDocumentReview(); } else if (message.Equals("StopDocumentReview")) { StopDocumentReview(); } else if (message.Equals("PageDidAppear")) { SetPage(args[0] as MNPage); } else if (message.Equals("ObjectForReview")) { } }
private void testAction1ToolStripMenuItem_Click(object sender, EventArgs e) { MNDocument doc = MNNotificationCenter.CurrentDocument; if (doc == null) { return; } MNPage page = MNNotificationCenter.CurrentPage; if (page == null) { return; } foreach (SMControl c in page.Objects) { if (c is SMTextContainer) { SMTextContainer tc = c as SMTextContainer; tc.Text = "Here is text for dropping <drop text=\"______\" tag=\"word1\">. Be sure to place here correct word"; } } }
public TVAction(TreeObjectView v, string t, MNDocument d) : base(t) { Script = ""; View = v; Page = null; Document = d; }
public void SetObject(MNDocument data) { this.Tree = new TItemDocument(this) { Document = data, Name = "Document" }; this.Tree.Expand(true); }
public void SetDocument(MNDocument doc) { lastDocument = doc; if (lastDocument != null) { RefreshContent(lastDocument); } }
private void SaveDocument(string filePath) { if (filePath != null) { MNNotificationCenter.CurrentFileName = filePath; } else { filePath = MNNotificationCenter.CurrentFileName; } RSFileWriter fw; string fileName = filePath; MNDocument doc = MNNotificationCenter.CurrentDocument; using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\save_book.txt")) { using (BinaryWriter bw = new BinaryWriter(File.Create(fileName))) { fw = new RSFileWriter(bw); fw.logStream = sw; doc.Book.Save(fw); } } fileName = fileName.Replace(".smb", ".smd"); using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\save_data.txt")) { using (BinaryWriter bw = new BinaryWriter(File.Create(fileName))) { fw = new RSFileWriter(bw); fw.logStream = sw; doc.Data.Save(fw); } } if (doc.DefaultLanguage.IsModified()) { fileName = fileName.Replace(".smd", ".sme"); using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\save_lang.txt")) { using (BinaryWriter bw = new BinaryWriter(File.Create(fileName))) { fw = new RSFileWriter(bw); fw.logStream = sw; MNLocalisation loc = doc.DefaultLanguage; loc.SetProperty("BookCode", doc.Book.BookCode); loc.SetProperty("LanguageName", "Default"); loc.Save(fw); loc.Modified = false; } } } lastSaved = DateTime.Now; }
public void SetDocument(MNDocument doci) { doc = doci; comboBox1.Items.Clear(); foreach (MNReferencedImage img in doc.DefaultLanguage.Images) { comboBox1.Items.Add(img); } control = null; }
public void Set(MNDocument doc, MNPage page, MNPageTextObject obj) { Document = doc; Page = page; Object = obj; noupdate = true; richTextBox1.Text = obj.Text; noupdate = false; }
private void generateInitialPagesToolStripMenuItem_Click(object sender, EventArgs e) { MNDocument doc = MNNotificationCenter.CurrentDocument; if (doc == null) { return; } MNBookData data = doc.Data; MNLocalisation lang = doc.DefaultLanguage; if (data == null || lang == null) { return; } if (data.Pages.Count != 1) { return; } data.Pages[0].Title = "Title"; SetPageHeaderControls(0, data.Pages[0]); SetControlsToPage("Title page", data.Pages[0]); AddNewPage(doc, "start", "startPage", 0); AddNewPage(doc, "tp", "tpPage", 0); AddNewPage(doc, "new_letters", "tpNewLetters", 1); AddNewPage(doc, "teaching_plan", "tpTeachingPlan", 1); List <int> pageNos = new List <int>(); foreach (MNReferencedSound snd in lang.Sounds) { if (snd.Name.StartsWith("Page ")) { int i; if (int.TryParse(snd.Name.Substring(5).Trim(), out i)) { pageNos.Add(i); } } } pageNos.Sort(); foreach (int a in pageNos) { AddNewPage(doc, "Page " + a, "mainAbove", 3); } AddNewPage(doc, "ex_before", "", 2); AddNewPage(doc, "ex_after", "", 2); }
private static void LoadBookLang(string fileName) { if (MNNotificationCenter.CurrentDocument == null) { return; } if (!File.Exists(fileName)) { return; } using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\load_lang.txt")) { using (BinaryReader br = new BinaryReader(File.OpenRead(fileName))) { MNDocument document = MNNotificationCenter.CurrentDocument; RSFileReader fr = new RSFileReader(br); fr.logStream = sw; try { document.DefaultLanguage.Load(fr, true); } catch (Exception ex) { sw.Flush(); sw.WriteLine("Exception:"); sw.WriteLine(ex.Message); sw.WriteLine(ex.StackTrace); sw.Flush(); } } } MNDocument doc = MNNotificationCenter.CurrentDocument; if (doc.DefaultLanguage.Styles.Count == 0) { doc.InitialiseDefaultStyles(); } foreach (MNReferencedImage ri in doc.DefaultLanguage.Images) { if (ri.Id < 1) { ri.Id = doc.Data.GetNextId(); } } }
private void convertAllFilesToHTMLToolStripMenuItem_Click(object sender, EventArgs e) { PageEditView pev = pageDetailPanel1.GetEditView(); MNPageContext ctx = pev.Context; string rootDir = Properties.Settings.Default.ExportHTMLFolder; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "SlideViewer books (*.smb)|*.smb"; ofd.FilterIndex = 0; if (ofd.ShowDialog() == DialogResult.OK) { if (MessageBox.Show("Now select folder where output will be writen (in the form of many HTml files and images)") == DialogResult.OK) { FolderBrowserDialog folderBrowser = new FolderBrowserDialog(); folderBrowser.SelectedPath = rootDir; if (folderBrowser.ShowDialog() == DialogResult.OK) { rootDir = folderBrowser.SelectedPath; Properties.Settings.Default.ExportHTMLFolder = rootDir; Properties.Settings.Default.Save(); MNExportContext etx = new MNExportContext(); etx.DirAllBooks = rootDir; foreach (string file in Directory.EnumerateFiles(Path.GetDirectoryName(ofd.FileName))) { if (file.EndsWith(".smb")) { MNDocument docx = LoadDocument(file); //ConvertDocToHtml(pev, docx, file.Replace(".smb", ".html"), rootDir); docx.ExportToHtml(etx, Path.GetFileNameWithoutExtension(file)); Debugger.Log(0, "", "Converted " + Path.GetFileName(file) + ".\n"); docx = null; } MNNotificationCenter.CurrentDocument = null; GC.Collect(); GC.WaitForPendingFinalizers(); if (etx.Files >= etx.MaxFiles) { break; } } Debugger.Log(0, "", "Finished.\n"); MessageBox.Show("Files were converted."); } } } }
private void convertAllFilesToVersion3ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (string s in Directory.EnumerateFiles(@"c:\Users\Gopa702\Documents\")) { if (Path.GetExtension(s) == ".smb") { Debugger.Log(0, "", "File: " + s + "\n"); MNDocument doc = new MNDocument(); using (Stream str = File.OpenRead(s)) { using (BinaryReader br = new BinaryReader(str)) { RSFileReader fr = new RSFileReader(br); doc.Book.Load(fr); } } using (Stream str = File.OpenWrite(s)) { using (BinaryWriter br = new BinaryWriter(str)) { RSFileWriter fr = new RSFileWriter(br); doc.Book.Save(fr); } } } else if (Path.GetExtension(s) == ".smd") { Debugger.Log(0, "", "File: " + s + "\n"); MNDocument doc = new MNDocument(); using (Stream str = File.OpenRead(s)) { using (BinaryReader br = new BinaryReader(str)) { RSFileReader fr = new RSFileReader(br); doc.Data.Load(fr); } } using (Stream str = File.OpenWrite(s)) { using (BinaryWriter bw = new BinaryWriter(str)) { RSFileWriter fw = new RSFileWriter(bw); doc.Data.Save(fw); } } } } }
private void StartDocumentReview(MNDocument doc, string filePath) { Document = doc; ClearUI(); labelBookTitle.Text = Document.Book.BookTitle; tabControl1.SelectedTab = tabBook; LoadData(filePath.Replace(".smb", ".smr")); p_PageOrig = null; p_ItemOrig = null; p_Page = new ReviewPage(); p_Item = new ReviewItem(); }
private void exportDocumentToHTMLToolStripMenuItem_Click(object sender, EventArgs e) { PageEditView pev = pageDetailPanel1.GetEditView(); MNPageContext ctx = pev.Context; MNDocument doc = MNNotificationCenter.CurrentDocument; string rootDir = "d:\\temp\\books"; SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = doc.Book.BookCode + ".html"; if (sfd.ShowDialog() == DialogResult.OK) { ConvertDocToHtml(pev, doc, sfd.FileName, rootDir); } }
private static bool AddTemplateToArray(MNDocument doc, MNPage page, bool overwrite) { bool added = false; int index = -1; List <MNPage> array = doc.Data.Templates; for (int i = 0; i < array.Count; i++) { if (array[i].APIName == page.APIName) { index = i; break; } } if (index >= 0) { if (overwrite) { array.RemoveAt(index); array.Insert(index, page); added = true; } } else { array.Add(page); added = true; } if (added) { foreach (SMControl sc in page.Objects) { if (sc is SMImage) { AddImageToArray(doc, (sc as SMImage).Img.Image, overwrite); } else if (sc is SMImageButton) { AddImageToArray(doc, (sc as SMImageButton).ImgA.Image, overwrite); } } } return(added); }
private void ExtractObjectConnections(GSCore obj, List <string> scheduled, string name) { if (obj is MNDocument) { MNDocument doc = obj as MNDocument; foreach (MNReferencedText rs in doc.Data.Scripts) { if (rs.Name.Equals(name)) { scheduled.Add(rs.Text); } } foreach (MNPage page in doc.Data.Pages) { ExtractObjectConnections(page, scheduled, name); } } else if (obj is MNPage) { MNPage page = obj as MNPage; foreach (MNReferencedText rt in page.Scripts) { if (rt.Name.Equals(name)) { scheduled.Add(rt.Text); } } foreach (SMControl smc in page.Objects) { if (smc.ContainsScript(name)) { ExtractObjectConnections(smc, scheduled, name); } } } else if (obj is SMControl) { MNReferencedText rt = (obj as SMControl).FindScript(name); if (rt != null) { scheduled.Add(rt.Text); } } }
public static void Load() { if (File.Exists(FilePath)) { using (Stream sr = File.OpenRead(FilePath)) { using (BinaryReader br = new BinaryReader(sr)) { RSFileReader fr = new RSFileReader(br); byte b = 0; internalDocument = new MNDocument(); while ((b = fr.ReadByte()) != 0) { switch (b) { case 10: MNPage p = new MNPage(internalDocument); p.Load(fr); p.TemplateName = ""; p.TemplateId = -1; internalDocument.Data.Templates.Add(p); break; case 11: MNReferencedImage img = new MNReferencedImage(); img.Load(fr); internalDocument.DefaultLanguage.Images.Add(img); break; case 12: MNReferencedStyle st = new MNReferencedStyle(); st.Load(fr); internalDocument.DefaultLanguage.Styles.Add(st); break; } } } } //internalDocument.ReapplyStyles(); } }
private void RefreshContent(MNDocument doc) { StringBuilder sb = new StringBuilder(); sb.AppendLine("PAGES"); foreach (MNPage p in doc.Data.Pages) { WritePage(sb, p, 1); } sb.AppendLine("END PAGES"); sb.AppendLine("TEMPLATES"); foreach (MNPage p in doc.Data.Templates) { WritePage(sb, p, 1); } sb.AppendLine("END TEMPLATES"); richTextBox1.Text = sb.ToString(); }
private static void LoadBookData(string fileName) { if (MNNotificationCenter.CurrentDocument == null) { return; } if (!File.Exists(fileName)) { return; } using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\load_data.txt")) { using (BinaryReader br = new BinaryReader(File.OpenRead(fileName))) { MNDocument document = MNNotificationCenter.CurrentDocument; RSFileReader fr = new RSFileReader(br); fr.logStream = sw; try { document.Data.Load(fr); } catch (Exception ex) { sw.Flush(); sw.WriteLine("Exception:"); sw.WriteLine(ex.Message); sw.WriteLine(ex.StackTrace); sw.Flush(); } } } MNDocument doc = MNNotificationCenter.CurrentDocument; if (doc.Data.Pages.Count == 0) { doc.CreateNewPage(); } }
static void Main(string[] args) { MNExportContext etx = new MNExportContext(); etx.DirAllBooks = @"e:\temp"; string file = @"e:\Dropbox\ReaderBooks\STFK.smb"; if (!File.Exists(file)) { Console.WriteLine("File {0} does not exist.", file); return; } Console.WriteLine("File: {0}", file); MNDocument docx = Program.LoadDocument(file); docx.ExportToHtml(etx, Path.GetFileNameWithoutExtension(file)); docx = null; StringBuilder Consolereport = new StringBuilder(); Consolereport.AppendLine("Used controls:"); foreach (string s in etx.UsedControls.Keys) { HashSet <long> hash = etx.UsedControls[s]; Consolereport.AppendFormat("{0}:", s); foreach (long l in hash) { Consolereport.AppendFormat(" {0}", l); } Consolereport.AppendLine(); } Console.WriteLine(Consolereport.ToString()); File.WriteAllText(Path.Combine(etx.DirCurrentBook, "info.txt"), Consolereport.ToString()); Console.ReadLine(); }
private void StartDocumentReview(MNDocument doc, string filePath) { Document = doc; doc.Reviews = p_Book; ClearUI(); labelBookTitle.Text = Document.Book.BookTitle; tabControl1.SelectedTab = tabBook; string folder = Properties.Settings.Default.ReviewsDirectory; if (Directory.Exists(folder)) { string path = Path.Combine(folder, Path.GetFileNameWithoutExtension(Document.Book.FilePath) + ".smr"); LoadData(path); } p_PageOrig = null; p_ItemOrig = null; p_Page = new ReviewPage(); p_Item = new ReviewItem(); }
private static bool AddStyleToArray(MNDocument doc, MNReferencedStyle style, bool overwrite) { bool added = false; if (style == null || style.Name.Length == 0) { return(false); } List <MNReferencedStyle> array = doc.DefaultLanguage.Styles; int index = -1; for (int i = 0; i < array.Count; i++) { if (array[i].Name == style.Name) { index = i; break; } } if (index >= 0) { if (overwrite) { array.RemoveAt(index); array.Insert(index, style); added = true; } } else { array.Add(style); added = true; } return(added); }
private static bool AddImageToArray(MNDocument doc, MNReferencedImage img, bool overwrite) { bool added = false; if (img == null || img.Name.Length == 0) { return(false); } int index = -1; List <MNReferencedImage> array = doc.DefaultLanguage.Images; for (int i = 0; i < array.Count; i++) { if (array[i].Name == img.Name) { index = i; break; } } if (index >= 0) { if (overwrite) { array.RemoveAt(index); array.Insert(index, img); added = true; } } else { array.Add(img); added = true; } return(added); }
public MNDocument LoadDocument(string fileName) { MNDocument prevDocument = MNNotificationCenter.CurrentDocument; string prevFilename = MNNotificationCenter.CurrentFileName; if (LoadBookHeader(fileName)) { MNNotificationCenter.CurrentDocument.Book.FindLanguageFiles(Path.GetDirectoryName(fileName)); fileName = fileName.Replace(".smb", ".smd"); LoadBookData(fileName); fileName = fileName.Replace(".smd", ".sme"); LoadBookLang(fileName); } MNDocument newDocument = MNNotificationCenter.CurrentDocument; MNNotificationCenter.CurrentDocument = prevDocument; MNNotificationCenter.CurrentFileName = prevFilename; return(newDocument); }
public void SetDocument(MNDocument d) { int groupIndex = 0; doc = d; int m = doc.Data.Pages.Count; for (int i = 0; i < m; i++) { comboPage1.Items.Add(doc.Data.Pages[i].Title); comboPage2.Items.Add(doc.Data.Pages[i].Title); comboPage3.Items.Add(doc.Data.Pages[i].Title); } for (int pageNo = 0; pageNo < m; pageNo++) { if (doc.Data.Pages[pageNo].NextPage.Equals(doc.Book.HomePage)) { SetPage(groupIndex, pageNo, doc.Data.Pages[pageNo]); groupIndex++; } } }
public void SetImage(MNLazyImage li) { doc = li.Document; image = li; comboBox1.Items.Clear(); int i = 0; int selected = -1; foreach (MNReferencedImage img in doc.DefaultLanguage.Images) { comboBox1.Items.Add(img); if (img == li.Image) { selected = i; } i++; } if (selected >= 0) { comboBox1.SelectedIndex = selected; } control = null; }