private void btnOK_Click(object sender, EventArgs e) { ContentInfo info = new ContentInfo(ProjectIO.GenerateUniqueID(), txtTitle.Text, BeingAdded, AddingExtension); AddContentToTree(txtTitle.Text, info); btnCancel.PerformClick(); }
// Content present in the tree on-load private void frmMain_Load(object sender, EventArgs e) { AddContentToTree("Notes", new ContentInfo(ProjectIO.GenerateUniqueID(), "Notes", "folder", "")); AddContentToTree("Chapters", new ContentInfo(ProjectIO.GenerateUniqueID(), "Notes", "folder", "")); AddContentToTree("Characters", new ContentInfo(ProjectIO.GenerateUniqueID(), "Notes", "folder", "")); AddContentToTree("Locations", new ContentInfo(ProjectIO.GenerateUniqueID(), "Notes", "folder", "")); ProjectInfo.Dirty = false; panRecent.Visible = true; }
// Add node properly to TreeView. Takes advantage of the "tag" property to help load relevant info into the // appropriate feature. private void AddContentToTree(string title, ContentInfo info) { tmrSnapshots.Enabled = true; TreeNode node = new TreeNode(title); switch (info.Type) { case "folder": node.ImageIndex = 0; node.Tag = JsonConvert.SerializeObject(new ContentInfo(ProjectIO.GenerateUniqueID(), title, "folder", ""));; break; case "note": node.ImageIndex = 1; string nodeid = ProjectIO.GenerateUniqueID(); frmNote noteform = new frmNote(nodeid, title, ""); node.Tag = JsonConvert.SerializeObject(new ContentInfo(nodeid, title, "note", ".txt")); noteform.MdiParent = this; noteform.Text = title; noteform.Show(); break; case "richtext": node.ImageIndex = 2; string nodeidRT = ProjectIO.GenerateUniqueID(); frmRichText richtextform = new frmRichText(nodeidRT, title, false); node.Tag = JsonConvert.SerializeObject(new ContentInfo(nodeidRT, title, "richtext", ".rtf")); richtextform.MdiParent = this; richtextform.Text = title; richtextform.Show(); break; case "image": node.ImageIndex = 3; string nodeidimg = ProjectIO.GenerateUniqueID(); FileInfo imageinfo = null; using (OpenFileDialog open = new OpenFileDialog()) { open.Filter = "PNG Images (*.png)|*.png|JPEG Images (*.jpg)|*.jpg|Bitmap Images (*.bmp)|*.bmp|GIF Images (*.gif)|*.gif|All Files (*.*)|*.*"; if (open.ShowDialog() == DialogResult.Cancel) { return; } imageinfo = new FileInfo(open.FileName); File.Copy(open.FileName, ProjectInfo.ProjectPath + "/" + nodeidimg + imageinfo.Extension); } frmImage imageform = new frmImage(nodeidimg, title, ProjectInfo.ProjectPath + "/" + nodeidimg + imageinfo.Extension); node.Tag = JsonConvert.SerializeObject(new ContentInfo(nodeidimg, title, "image", imageinfo.Extension)); imageform.MdiParent = this; imageform.Text = title; imageform.Show(); break; case "character": node.ImageIndex = 4; string nodeidchar = ProjectIO.GenerateUniqueID(); frmPrompt promptform = new frmPrompt(nodeidchar, title, "character"); node.Tag = JsonConvert.SerializeObject(new ContentInfo(nodeidchar, title, "character", ".prompt")); promptform.MdiParent = this; promptform.Text = title; promptform.Show(); break; case "location": node.ImageIndex = 5; string nodeidloc = ProjectIO.GenerateUniqueID(); frmPrompt promptform2 = new frmPrompt(nodeidloc, title, "location"); node.Tag = JsonConvert.SerializeObject(new ContentInfo(nodeidloc, title, "location", ".prompt")); promptform2.MdiParent = this; promptform2.Text = title; promptform2.Show(); break; case "customprompt": node.ImageIndex = 6; string nodeidprompt = ProjectIO.GenerateUniqueID(); frmPrompt promptform3 = new frmPrompt(nodeidprompt, title, "customprompt"); node.Tag = JsonConvert.SerializeObject(new ContentInfo(nodeidprompt, title, "customprompt", ".prompt")); promptform3.MdiParent = this; promptform3.Text = title; promptform3.Show(); break; default: return; } node.SelectedImageIndex = node.ImageIndex; if (tvContent.SelectedNode == null) { tvContent.Nodes.Add(node); } else { tvContent.SelectedNode.Nodes.Add(node); tvContent.SelectedNode.Expand(); } ProjectInfo.Dirty = true; }