using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Speech.Synthesis; using System.Text.RegularExpressions; namespace ContentEditor { public partial class frmMain : Form { public static Leah.Speech.text.Contents Content; private static string currentFile = ""; private static string currentFileName = "Unknown.bpc"; private static string currentDirectory; private DataSave save; public static bool bNeedAutoSave = false; private DateTime autosaveTime; private bool inUpdateMode = false; public static SpeechSynthesizer Speech = new SpeechSynthesizer(); public static bool bIsPlaying = false; private static bool bIsSsml = false; public frmMain() { InitializeComponent(); Application.ApplicationExit += Application_ApplicationExit; System.Diagnostics.Debug.WriteLine("UpdateMode start frmMain()"); this.inUpdateMode = true; currentDirectory = System.IO.Directory.GetCurrentDirectory() + System.IO.Path.DirectorySeparatorChar; this.tabControl1.Selecting += TabControl1_Selecting; this.dgvTags.CellValueChanged += DgvTags_CellValueChanged; this.dgvOptionalTags.CellValueChanged += DgvOptionalTags_CellValueChanged; this.tvTags.AfterSelect += tvTags_AfterSelect; this.dgvTexts.RowsAdded += DgvTexts_RowsAdded; this.dgvTexts.CellEndEdit += DgvTexts_CellEndEdit; this.dgvTexts.UserDeletingRow += DgvTexts_UserDeletingRow; //this.cmdTexts_Edit.Click += new System.EventHandler(this.cmdTexts_Edit_Click); this.dgvTexts.CellBeginEdit += DgvTexts_CellBeginEdit; this.dgvTags.UserDeletingRow += DgvTags_UserDeletingRow; this.dgvOptionalTags.UserDeletingRow += DgvOptionalTags_UserDeletingRow; this.dgvTags.CellEndEdit += DgvTags_CellEndEdit; this.dgvOptionalTags.CellEndEdit += DgvOptionalTags_CellEndEdit; this.mnuFile_Last_Itm1.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm2.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm3.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm4.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm5.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm6.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm7.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm8.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm9.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuFile_Last_Itm10.Click += new System.EventHandler(this.mnuFile_Last_Click); this.mnuText2Speach_Voice_Itm1.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm2.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm3.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm4.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm5.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm6.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm7.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm8.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm9.Click += mnuText2Speach_Voice_Click; this.mnuText2Speach_Voice_Itm10.Click += mnuText2Speach_Voice_Click; Speech.SpeakStarted += Speech_SpeakStarted; Speech.SpeakCompleted += Speech_SpeakCompleted; Speech.SelectVoiceByHints(VoiceGender.Female); RefreshVoiceList(); this.dgvTexts.CellMouseDown += DgvTexts_CellMouseDown; System.Diagnostics.Debug.WriteLine("UpdateMode end frmMain()"); this.inUpdateMode = false; if (File.Exists("settings.cfg")) { this.save = System.Fire.Serialize.Serializer.DeserializeObject("settings.cfg", System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8); this.RefreshLastFile(); frmMain.currentDirectory = this.save.currentFolderDir; this.Size = this.save.windowSize; if (string.IsNullOrEmpty(this.save.autosave) || !File.Exists(this.save.autosave)) { FileNew(); } else { frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject(this.save.autosave, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8); } } else { this.save = new DataSave(); this.save.lastTab = 0; FileNew(); } System.Diagnostics.Debug.WriteLine( System.Speech.SpeechFormat.Format( "Um 18:45h schoss der FCK sein 1:0 gegen Bayern" ) ); frmMain.bNeedAutoSave = false; this.SelectTab(this.save.lastTab); } private void mnuText2Speach_Voice_Click(object sender, EventArgs e) { string VoiceName = ""; if((ToolStripMenuItem)sender != null) { Speech.SelectVoice(((ToolStripMenuItem)sender).Tag.ToString()); } } private void Speech_SpeakCompleted(object sender, SpeakCompletedEventArgs e) { bIsPlaying = false; } private void Speech_SpeakStarted(object sender, SpeakStartedEventArgs e) { bIsPlaying = true; } private void DgvOptionalTags_CellEndEdit(object sender, DataGridViewCellEventArgs e) { frmMain.bNeedAutoSave = true; } private void DgvTags_CellEndEdit(object sender, DataGridViewCellEventArgs e) { frmMain.bNeedAutoSave = true; } private bool SetLastFileMenuItem(string path, ToolStripMenuItem mnu = null) { if(mnu==null) { if (mnuFile_Last_Itm1.Tag == null) mnu = mnuFile_Last_Itm1; if (mnuFile_Last_Itm2.Tag == null) mnu = mnuFile_Last_Itm2; if (mnuFile_Last_Itm3.Tag == null) mnu = mnuFile_Last_Itm3; if (mnuFile_Last_Itm4.Tag == null) mnu = mnuFile_Last_Itm4; if (mnuFile_Last_Itm5.Tag == null) mnu = mnuFile_Last_Itm5; if (mnuFile_Last_Itm6.Tag == null) mnu = mnuFile_Last_Itm6; if (mnuFile_Last_Itm7.Tag == null) mnu = mnuFile_Last_Itm7; if (mnuFile_Last_Itm8.Tag == null) mnu = mnuFile_Last_Itm8; if (mnuFile_Last_Itm9.Tag == null) mnu = mnuFile_Last_Itm9; if (mnuFile_Last_Itm10.Tag == null) mnu = mnuFile_Last_Itm10; } if(string.IsNullOrEmpty(path)) { mnu.Tag = null; mnu.Text = ""; mnu.Visible = false; return false; } FileInfo fi = new FileInfo(path); if (fi.Exists) { mnu.Tag = path; mnu.Visible = true; mnu.Text = fi.Name; return true; } else { mnu.Tag = null; mnu.Text = ""; mnu.Visible = false; } return false; } private void DoAutosave() { System.Diagnostics.Debug.WriteLine("Check Autosave()"); double sec = (DateTime.Now - this.autosaveTime).TotalSeconds; if (frmMain.bNeedAutoSave == false || sec < 20) { System.Diagnostics.Debug.WriteLine("- Abort: " + (frmMain.bNeedAutoSave?"True":"False") + "; " + sec.ToString()); return; } frmMain.bNeedAutoSave = false; string file = "autosave.bak"; this.save.autosave = file; System.Diagnostics.Debug.WriteLine("- Autosave: " + file); System.Fire.Serialize.Serializer.SerializeObject(file, frmMain.Content, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8); this.autosaveTime = DateTime.Now; } private void SetLastFile(string path) { if(this.save.lastFileUsed_1.ToLower() == path.ToLower()) { return; } else if(this.save.lastFileUsed_2.ToLower() == path.ToLower()) { this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } else if (this.save.lastFileUsed_3.ToLower() == path.ToLower()) { this.save.lastFileUsed_3 = this.save.lastFileUsed_2; this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } else if (this.save.lastFileUsed_4.ToLower() == path.ToLower()) { this.save.lastFileUsed_4 = this.save.lastFileUsed_3; this.save.lastFileUsed_3 = this.save.lastFileUsed_2; this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } else if (this.save.lastFileUsed_5.ToLower() == path.ToLower()) { this.save.lastFileUsed_5 = this.save.lastFileUsed_4; this.save.lastFileUsed_4 = this.save.lastFileUsed_3; this.save.lastFileUsed_3 = this.save.lastFileUsed_2; this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } else if (this.save.lastFileUsed_6.ToLower() == path.ToLower()) { this.save.lastFileUsed_6 = this.save.lastFileUsed_5; this.save.lastFileUsed_5 = this.save.lastFileUsed_4; this.save.lastFileUsed_4 = this.save.lastFileUsed_3; this.save.lastFileUsed_3 = this.save.lastFileUsed_2; this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } else if (this.save.lastFileUsed_7.ToLower() == path.ToLower()) { this.save.lastFileUsed_7 = this.save.lastFileUsed_6; this.save.lastFileUsed_6 = this.save.lastFileUsed_5; this.save.lastFileUsed_5 = this.save.lastFileUsed_4; this.save.lastFileUsed_4 = this.save.lastFileUsed_3; this.save.lastFileUsed_3 = this.save.lastFileUsed_2; this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } else if (this.save.lastFileUsed_8.ToLower() == path.ToLower()) { this.save.lastFileUsed_8 = this.save.lastFileUsed_7; this.save.lastFileUsed_7 = this.save.lastFileUsed_6; this.save.lastFileUsed_6 = this.save.lastFileUsed_5; this.save.lastFileUsed_5 = this.save.lastFileUsed_4; this.save.lastFileUsed_4 = this.save.lastFileUsed_3; this.save.lastFileUsed_3 = this.save.lastFileUsed_2; this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } else if (this.save.lastFileUsed_9.ToLower() == path.ToLower()) { this.save.lastFileUsed_9 = this.save.lastFileUsed_8; this.save.lastFileUsed_8 = this.save.lastFileUsed_7; this.save.lastFileUsed_7 = this.save.lastFileUsed_6; this.save.lastFileUsed_6 = this.save.lastFileUsed_5; this.save.lastFileUsed_5 = this.save.lastFileUsed_4; this.save.lastFileUsed_4 = this.save.lastFileUsed_3; this.save.lastFileUsed_3 = this.save.lastFileUsed_2; this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } else { this.save.lastFileUsed_10 = this.save.lastFileUsed_9; this.save.lastFileUsed_8 = this.save.lastFileUsed_7; this.save.lastFileUsed_7 = this.save.lastFileUsed_6; this.save.lastFileUsed_6 = this.save.lastFileUsed_5; this.save.lastFileUsed_5 = this.save.lastFileUsed_4; this.save.lastFileUsed_4 = this.save.lastFileUsed_3; this.save.lastFileUsed_3 = this.save.lastFileUsed_2; this.save.lastFileUsed_2 = this.save.lastFileUsed_1; this.save.lastFileUsed_1 = path; } this.RefreshLastFile(); } private void RefreshLastFile() { this.SetLastFileMenuItem("", this.mnuFile_Last_Itm1); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm2); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm3); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm4); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm5); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm6); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm7); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm8); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm9); this.SetLastFileMenuItem("", this.mnuFile_Last_Itm10); this.SetLastFileMenuItem(this.save.lastFileUsed_1); this.SetLastFileMenuItem(this.save.lastFileUsed_2); this.SetLastFileMenuItem(this.save.lastFileUsed_3); this.SetLastFileMenuItem(this.save.lastFileUsed_4); this.SetLastFileMenuItem(this.save.lastFileUsed_5); this.SetLastFileMenuItem(this.save.lastFileUsed_6); this.SetLastFileMenuItem(this.save.lastFileUsed_7); this.SetLastFileMenuItem(this.save.lastFileUsed_8); this.SetLastFileMenuItem(this.save.lastFileUsed_9); this.SetLastFileMenuItem(this.save.lastFileUsed_10); } private void DgvTexts_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { ushort tag_id; if (ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) { frmMain.Content.RemoveAt(tag_id); this.SelectTab(); } } private void DgvOptionalTags_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int useages = 0; if (this.inUpdateMode == true) { e.Cancel = true; return; } this.inUpdateMode = true; Leah.Speech.text.ContentUseage[] use = frmMain.Content.TagUseage; ushort tag_id; if (e.Row.Tag == null) { tag_id=(ushort)dgvOptionalTags.Rows.IndexOf(e.Row); } else { if (!ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) { return; } } if (useages > 0) { if (MessageBox.Show("The selected tag \"" + e.Row.Cells[0].Value.ToString() + "\" is used by " + useages.ToString() + " entries.\nDelete the Tag?", "Delete Optional Tags", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { this.inUpdateMode = false; e.Cancel = true; return; } } frmMain.Content.OptionalTag_RemoveAt(tag_id); frmMain.bNeedAutoSave = true; this.inUpdateMode = false; } private void DgvTags_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { int useages = 0; if (this.inUpdateMode == true) { e.Cancel = true; return; } this.inUpdateMode = true; Leah.Speech.text.ContentUseage[] use = frmMain.Content.TagUseage; ushort tag_id; if (e.Row.Tag == null) { tag_id = (ushort)dgvTags.Rows.IndexOf(e.Row); } else { if (!ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) { return; } } useages = use[tag_id].Count; if (useages > 0) { if (MessageBox.Show("The selected tag \""+e.Row.Cells[0].Value.ToString()+"\" is used by " + useages.ToString() + " entries.\nDelete the Tag?", "Delete Tags", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { this.inUpdateMode = false; e.Cancel = true; return; } } frmMain.Content.Tag_RemoveAt(tag_id); frmMain.bNeedAutoSave = true; this.inUpdateMode = false; } private void DgvTexts_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { if (this.tvTags.SelectedNode == null || this.tvTags.SelectedNode.Tag == null) { e.Cancel = true; return; } } private int selectedRow = -1; private void DgvTexts_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if(e.Button == MouseButtons.Right) { if (e.RowIndex < 0) { // Tabellen Header } else if (e.ColumnIndex < 0) { // Zeilennummer } else { this.selectedRow = e.RowIndex; int pos = 0; foreach (DataGridViewColumn col in dgvTexts.Columns) if (col.Index < e.ColumnIndex) pos += col.Width; Point p = new Point(e.Location.X + dgvTexts.RowHeadersWidth + pos, e.Location.Y + (22 * e.RowIndex) + 23); this.cmsTexts.Show(this.dgvTexts.PointToScreen(p)); } } } private void DgvTexts_CellEndEdit(object sender, DataGridViewCellEventArgs e) { System.Diagnostics.Debug.WriteLine("End edit: " + e.RowIndex); System.Diagnostics.Debug.WriteLine("UpdateMode start DgvTexts_CellEndEdit()"); this.inUpdateMode = true; if (e.ColumnIndex==1) { if (dgvTexts.Rows[e.RowIndex].Cells[1].Value == null || dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == "") dgvTexts.Rows[e.RowIndex].Cells[1].Value = "all"; } if ((dgvTexts.Rows[e.RowIndex].Cells[2].Value == null || dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == "") && dgvTexts.Rows[e.RowIndex].Cells[0].Value != null && dgvTexts.Rows[e.RowIndex].Cells[0].Value != "") { dgvTexts.Rows[e.RowIndex].Cells[2].ErrorText = "At least one tag must be enterd"; System.Diagnostics.Debug.WriteLine("- Error: At least one tag must be enterd"); } else { dgvTexts.Rows[e.RowIndex].Cells[2].ErrorText = ""; } Leah.Speech.text.ContentEntry entry; if(dgvTexts.Rows[e.RowIndex].Tag==null) { dgvTexts.Rows[e.RowIndex].Tag = Content.Count; System.Diagnostics.Debug.WriteLine("- New row added. Row: '" + dgvTexts.Rows[e.RowIndex].Tag.ToString() + "'"); Content.Add( new Leah.Speech.text.ContentEntry( dgvTexts.Rows[e.RowIndex].Cells[0].Value==null?"":dgvTexts.Rows[e.RowIndex].Cells[0].Value.ToString(), Leah.Speech.text.Contents.GetMood(dgvTexts.Rows[e.RowIndex].Cells[1].Value.ToString()), this.GetUShortArray(dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString()) ) ); } entry = Content.GetEntry((int)dgvTexts.Rows[e.RowIndex].Tag); //if (entry != null && dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { if (dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { if (e.ColumnIndex == 0) { //entry.Text = dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Trim(); Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text = dgvTexts.Rows[e.RowIndex].Cells[0].Value.ToString().Trim(); dgvTexts.Rows[e.RowIndex].Cells[0].Value = Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text; System.Diagnostics.Debug.WriteLine("- Text changed: " + Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text); } else if (e.ColumnIndex == 1) { //entry.MoodText = dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); //dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = entry.MoodText; Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText = dgvTexts.Rows[e.RowIndex].Cells[1].Value.ToString().Trim(); dgvTexts.Rows[e.RowIndex].Cells[1].Value = Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText; System.Diagnostics.Debug.WriteLine("- Mood changed: " + Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText); } else if(e.ColumnIndex == 2) { System.Diagnostics.Debug.WriteLine("- Tag changed: " + dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString()); Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tag_Clear(); Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tag_Add(dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString()); string rtag = ""; foreach (ushort ustag in Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tags) rtag += (rtag == "" ? "" : ", ") + ustag.ToString(); dgvTexts.Rows[e.RowIndex].Cells[2].Value = rtag; } else if (e.ColumnIndex == 3) { System.Diagnostics.Debug.WriteLine("- Optional Tag changed: " + dgvTexts.Rows[e.RowIndex].Cells[3].Value.ToString()); Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTag_Clear(); Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTag_Add(dgvTexts.Rows[e.RowIndex].Cells[3].Value.ToString()); string rtag = ""; foreach (ushort ustag in Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTags) rtag += (rtag==""?"":", ") + ustag.ToString(); dgvTexts.Rows[e.RowIndex].Cells[3].Value = rtag; } else if (e.ColumnIndex == 4) { float s = entry.Score; if(float.TryParse(dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(), out s)) { entry.Score = s; System.Diagnostics.Debug.WriteLine("- Score changed: " + s.ToString()); dgvTexts.Rows[e.RowIndex].Cells[4].Value = s.ToString("#,00"); } else { System.Diagnostics.Debug.WriteLine("- Failed changing score. Not a number: " + dgvTexts.Rows[e.RowIndex].Cells[4].Value.ToString()); dgvTexts.Rows[e.RowIndex].Cells[4].Value = entry.Score; } } } else { System.Diagnostics.Debug.WriteLine("- Error: No row tag"); } System.Diagnostics.Debug.WriteLine("- Total Content count: "+Content.Count); System.Diagnostics.Debug.WriteLine("UpdateMode end DgvTexts_CellEndEdit()"); this.inUpdateMode = false; frmMain.bNeedAutoSave = true; //Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag] = entry; } private ushort[] GetUShortArray(string s) { string[] x = s.Split(new char[] { ',',';','|' }); List res = new List(); foreach (string y in x) { string z = y.Trim(); ushort itm = 0; if(ushort.TryParse(z,out itm)) { res.Add(itm); } } return res.ToArray(); } private void DgvTexts_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { for(int i=e.RowIndex, c = e.RowIndex+e.RowCount;i childs = new List(); foreach (Leah.Speech.text.ContentUseage tag in Content.TagUseage) { TreeNode node = new TreeNode(); node.Text = tag.Tag; node.Tag = tag.ID; childs.Add(node); } TreeNode tnRoot = new TreeNode("Root", childs.ToArray()); tnRoot.Text = "Root"; tvTags.BeginUpdate(); tvTags.Nodes.Clear(); tvTags.Nodes.Add(tnRoot); tvTags.ExpandAll(); tvTags.EndUpdate(); break; } } else { this.tabControl1.SelectedIndex = index; } System.Diagnostics.Debug.WriteLine("UpdateMode end SelectTab()"); this.inUpdateMode = false; } private void DgvTags_CellValueChanged(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) { this.StoreTags(); } private void DgvOptionalTags_CellValueChanged(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) { this.StoreOptionalTags(); } private void StoreTags() { if (Content == null) return; System.Diagnostics.Debug.WriteLine("StoreTags()"); List res = new List(); for (int i = 0, c = dgvTags.Rows.Count; i < c; i++) { if (dgvTags.Rows[i].Cells[0].Value != null && dgvTags.Rows[i].Cells[0].Value.ToString()!="") { res.Add(dgvTags.Rows[i].Cells[0].Value.ToString()); } } Content.Tags = res.ToArray(); } private void StoreOptionalTags() { if (Content == null) return; System.Diagnostics.Debug.WriteLine("StoreOptionalTags()"); List res = new List(); for (int i = 0, c = dgvOptionalTags.Rows.Count; i < c; i++) { if (dgvOptionalTags.Rows[i].Cells[0].Value != null && dgvOptionalTags.Rows[i].Cells[0].Value.ToString() != "") { res.Add(dgvOptionalTags.Rows[i].Cells[0].Value.ToString()); } } Content.OptionalTags = res.ToArray(); } private void FileNew() { this.FileNew(""); } private void FileNew(string newName) { currentFileName = newName; currentFile = currentDirectory + newName; Content = new Leah.Speech.text.Contents(); this.SelectTab(); } private void FileLoad(string path) { FileLoad(new FileInfo(path)); } private void FileLoad(FileInfo path) { if (path.Exists) { currentDirectory = path.Directory.FullName; currentFile = path.FullName; currentFileName = path.Name; Content = System.Fire.Serialize.Serializer.DeserializeObject(path.FullName); this.SelectTab(); } } private void tvTags_AfterSelect(object sender, TreeViewEventArgs e) { System.Diagnostics.Debug.WriteLine("Load Text-Category entries"); dgvTexts.Rows.Clear(); if(e.Node.Tag!=null) { ushort tag = ushort.Parse(e.Node.Tag.ToString()); for(int i=0,c=Content.Count;i= 0 && this.dgvTexts.Rows[this.selectedRow].Tag != null) { System.Diagnostics.Debug.WriteLine("Edit item"); res = frmContentEdit.EditItem((int)(this.dgvTexts.Rows[this.selectedRow].Tag)); } else { System.Diagnostics.Debug.WriteLine("New item"); res = frmContentEdit.NewItem(); } } private void mnuFile_New_Click(object sender, EventArgs e) { frmMain.Content = new Leah.Speech.text.Contents(); this.SelectTab(); } private void mnuFile_Open_Click(object sender, EventArgs e) { openFileDialog1.Title = "Open Content File"; openFileDialog1.Filter = "Content File (*.bpc)|*.bpc|All files (*.*)|*.*"; openFileDialog1.Multiselect = false; openFileDialog1.InitialDirectory = frmMain.currentDirectory; if(openFileDialog1.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(openFileDialog1.FileName); frmMain.currentFile = fi.FullName; frmMain.currentFileName = fi.Name; frmMain.currentDirectory = fi.Directory.FullName; frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject( openFileDialog1.FileName, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8 ); this.save.currentFolderDir = frmMain.currentDirectory; this.SetLastFile(fi.FullName); this.SelectTab(); } } private void mnuFile_Save_Click(object sender, EventArgs e) { if(frmMain.currentFileName.Length==0) { mnuFile_SaveAs_Click(sender, e); } else { System.Fire.Serialize.Serializer.SerializeObject( frmMain.currentFile, frmMain.Content, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8 ); this.save.currentFolderDir = frmMain.currentDirectory; this.SetLastFile(frmMain.currentFile); } } private void mnuFile_SaveAs_Click(object sender, EventArgs e) { saveFileDialog1.Title = "Save Content File"; saveFileDialog1.Filter = "Content File (*.bpc)|*.bpc|All files (*.*)|*.*"; saveFileDialog1.InitialDirectory = frmMain.currentDirectory; saveFileDialog1.FileName = frmMain.currentFileName; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(saveFileDialog1.FileName); frmMain.currentFile = fi.FullName; frmMain.currentFileName = fi.Name; frmMain.currentDirectory = fi.Directory.FullName; System.Fire.Serialize.Serializer.SerializeObject( frmMain.currentFile, frmMain.Content, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8 ); this.save.currentFolderDir = frmMain.currentDirectory; this.SetLastFile(frmMain.currentFile); } } /*private void importTagsToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Title = "Import Tags"; openFileDialog1.Filter = "Textfile (*.txt)|*.txt|CSF File (*.csv)|*.csv|All files (*.*)|*.*"; openFileDialog1.Multiselect = false; openFileDialog1.InitialDirectory = frmMain.currentDirectory; if (openFileDialog1.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(openFileDialog1.FileName); using (StreamReader sr = fi.OpenText()) { while (sr.Peek() >= 0) { string line = sr.ReadLine(); } } this.SelectTab(); } }*/ private void mnuTags_DeleteAll_Click(object sender, EventArgs e) { frmMain.Content.Tag_Clear(); this.SelectTab(); } private void mnuTags_Import_Click(object sender, EventArgs e) { openFileDialog1.Title = "Import Tags"; openFileDialog1.Filter = "Textfile (*.txt)|*.txt|BlackPro Content File|*.bpc|All files (*.*)|*.*"; openFileDialog1.Multiselect = false; openFileDialog1.InitialDirectory = frmMain.currentDirectory; if (openFileDialog1.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(openFileDialog1.FileName); if (fi.Extension == ".bpc") { Leah.Speech.text.Contents imp = System.Fire.Serialize.Serializer.DeserializeObject(fi.FullName); foreach(string s in imp.Tags) { frmMain.Content.Tag_Add(s); } } else { using (StreamReader sr = fi.OpenText()) { while (sr.Peek() >= 0) { string line = sr.ReadLine().Trim(); if (line.Length > 0) { frmMain.Content.Tag_Add(line); } } } } this.SelectTab(); } } private void mnuTags_Export_Click(object sender, EventArgs e) { saveFileDialog1.Title = "Export Tags"; saveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDialog1.InitialDirectory = frmMain.currentDirectory; saveFileDialog1.FileName = "tags.txt"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(saveFileDialog1.FileName); bool bFirst = true; using (FileStream fs = fi.OpenWrite()) { foreach (DataGridViewRow row in dgvTags.Rows) { if (row.Cells[0].Value != null) { if (bFirst == false) fs.Write(new byte[] { 10 },0,1); bFirst = false; string s = row.Cells[0].Value.ToString(); byte[] b = System.Text.Encoding.ASCII.GetBytes(s); fs.Write(b, 0, b.Length); } } } } } private void mnuOptionalTags_DeleteAll_Click(object sender, EventArgs e) { frmMain.Content.OptionalTag_Clear(); this.SelectTab(); } private void mnuOptionalTags_Import_Click(object sender, EventArgs e) { openFileDialog1.Title = "Import Optional Tags"; openFileDialog1.Filter = "Textfile (*.txt)|*.txt|BlackPro Content File|*.bpc|All files (*.*)|*.*"; openFileDialog1.Multiselect = false; openFileDialog1.InitialDirectory = frmMain.currentDirectory; if (openFileDialog1.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(openFileDialog1.FileName); if (fi.Extension == ".bpc") { Leah.Speech.text.Contents imp = System.Fire.Serialize.Serializer.DeserializeObject(fi.FullName); foreach (string s in imp.OptionalTags) { frmMain.Content.OptionalTag_Add(s); } } else { using (StreamReader sr = fi.OpenText()) { while (sr.Peek() >= 0) { string line = sr.ReadLine().Trim(); if (line.Length > 0) { frmMain.Content.OptionalTag_Add(line); } } } } this.SelectTab(); } } private void mnuTexts_Editor_Click(object sender, EventArgs e) { if(tabControl1.SelectedIndex==2 && dgvTexts.SelectedRows.Count>0) { if(dgvTexts.SelectedRows[0].Tag!=null) { frmContentEdit.EditItem((int)dgvTexts.SelectedRows[0].Tag); } else { frmContentEdit.NewItem(); } } else { frmContentEdit.NewItem(); } } private void mnuView_General_Click(object sender, EventArgs e) { this.SelectTab(0); } private void mnuView_TagOverview_Click(object sender, EventArgs e) { this.SelectTab(1); } private void mnuView_TextOverview_Click(object sender, EventArgs e) { this.SelectTab(2); } private void mnuOptionalTags_Export_Click(object sender, EventArgs e) { saveFileDialog1.Title = "Export Optional Tags"; saveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDialog1.InitialDirectory = frmMain.currentDirectory; saveFileDialog1.FileName = "optionalTags.txt"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(saveFileDialog1.FileName); bool bFirst = true; using (FileStream fs = fi.OpenWrite()) { foreach (DataGridViewRow row in dgvOptionalTags.Rows) { if (row.Cells[0].Value != null) { if (bFirst == false) fs.Write(new byte[] { 10 }, 0, 1); bFirst = false; string s = row.Cells[0].Value.ToString(); byte[] b = System.Text.Encoding.ASCII.GetBytes(s); fs.Write(b, 0, b.Length); } } } } } private void mnuFile_Quit_Click(object sender, EventArgs e) { Application.Exit(); } private void Application_ApplicationExit(object sender, EventArgs e) { this.save.windowSize = this.Size; System.Fire.Serialize.Serializer.SerializeObject("settings.cfg", this.save); } private void mnuFile_Last_Click(object sender, EventArgs e) { ToolStripMenuItem mnu = (ToolStripMenuItem)sender; if (mnu != null) { string path = (string)mnu.Tag; FileInfo fi = new FileInfo(path); if(fi.Exists) { frmMain.currentFile = fi.FullName; frmMain.currentFileName = fi.Name; frmMain.currentDirectory = fi.Directory.FullName; frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject( openFileDialog1.FileName, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8 ); this.SetLastFile(fi.FullName); this.save.currentFolderDir = frmMain.currentDirectory; this.SelectTab(); } } } private void tmrAutosave_Tick(object sender, EventArgs e) { this.DoAutosave(); } private void mnuText2Speech_Play_Click(object sender, EventArgs e) { if(dgvTexts.SelectedRows.Count==1) { if(dgvTexts.SelectedRows[0].Cells.Count>0) { Speak(dgvTexts.SelectedRows[0].Cells[0].Value.ToString()); } } } private void RefreshVoiceList() { InstalledVoice[] voices = Speech.GetInstalledVoices().ToArray(); this.mnuText2Speach_Voice_Itm1.Visible = false; this.mnuText2Speach_Voice_Itm2.Visible = false; this.mnuText2Speach_Voice_Itm3.Visible = false; this.mnuText2Speach_Voice_Itm4.Visible = false; this.mnuText2Speach_Voice_Itm5.Visible = false; this.mnuText2Speach_Voice_Itm6.Visible = false; this.mnuText2Speach_Voice_Itm7.Visible = false; this.mnuText2Speach_Voice_Itm8.Visible = false; this.mnuText2Speach_Voice_Itm9.Visible = false; this.mnuText2Speach_Voice_Itm10.Visible = false; if (voices.Length>=1) { this.mnuText2Speach_Voice_Itm1.Text = getVoiceInfo(voices[0]); this.mnuText2Speach_Voice_Itm1.Visible = true; this.mnuText2Speach_Voice_Itm1.Tag = voices[0].VoiceInfo.Name; } if (voices.Length >= 2) { this.mnuText2Speach_Voice_Itm2.Text = getVoiceInfo(voices[1]); this.mnuText2Speach_Voice_Itm2.Visible = true; this.mnuText2Speach_Voice_Itm2.Tag = voices[1].VoiceInfo.Name; } if (voices.Length >= 3) { this.mnuText2Speach_Voice_Itm3.Text = getVoiceInfo(voices[2]); this.mnuText2Speach_Voice_Itm3.Visible = true; this.mnuText2Speach_Voice_Itm3.Tag = voices[2].VoiceInfo.Name; } if (voices.Length >= 4) { this.mnuText2Speach_Voice_Itm4.Text = getVoiceInfo(voices[3]); this.mnuText2Speach_Voice_Itm4.Visible = true; this.mnuText2Speach_Voice_Itm4.Tag = voices[3].VoiceInfo.Name; } if (voices.Length >= 5) { this.mnuText2Speach_Voice_Itm5.Text = getVoiceInfo(voices[4]); this.mnuText2Speach_Voice_Itm5.Visible = true; this.mnuText2Speach_Voice_Itm5.Tag = voices[4].VoiceInfo.Name; } if (voices.Length >= 6) { this.mnuText2Speach_Voice_Itm6.Text = getVoiceInfo(voices[5]); this.mnuText2Speach_Voice_Itm6.Visible = true; this.mnuText2Speach_Voice_Itm6.Tag = voices[5].VoiceInfo.Name; } if (voices.Length >= 7) { this.mnuText2Speach_Voice_Itm7.Text = getVoiceInfo(voices[6]); this.mnuText2Speach_Voice_Itm7.Visible = true; this.mnuText2Speach_Voice_Itm7.Tag = voices[6].VoiceInfo.Name; } if (voices.Length >= 8) { this.mnuText2Speach_Voice_Itm8.Text = getVoiceInfo(voices[7]); this.mnuText2Speach_Voice_Itm8.Visible = true; this.mnuText2Speach_Voice_Itm8.Tag = voices[7].VoiceInfo.Name; } if (voices.Length >= 9) { this.mnuText2Speach_Voice_Itm9.Text = getVoiceInfo(voices[8]); this.mnuText2Speach_Voice_Itm9.Visible = true; this.mnuText2Speach_Voice_Itm9.Tag = voices[8].VoiceInfo.Name; } if (voices.Length >= 10) { this.mnuText2Speach_Voice_Itm10.Text = getVoiceInfo(voices[9]); this.mnuText2Speach_Voice_Itm10.Visible = true; this.mnuText2Speach_Voice_Itm10.Tag = voices[9].VoiceInfo.Name; } } private string getVoiceInfo(InstalledVoice voice) { string gender = ""; string age = ""; string lang = ""; if (voice.VoiceInfo.Gender == VoiceGender.Female) gender = " female"; else if (voice.VoiceInfo.Gender == VoiceGender.Male) gender = " male"; else if (voice.VoiceInfo.Gender == VoiceGender.Neutral) gender = " neutral"; if (voice.VoiceInfo.Age == VoiceAge.Adult) age = " adult"; else if (voice.VoiceInfo.Age == VoiceAge.Child) age = " child"; else if (voice.VoiceInfo.Age == VoiceAge.Senior) age = " old"; else if (voice.VoiceInfo.Age == VoiceAge.Teen) age = " teen"; lang = " (" + voice.VoiceInfo.Culture.Name + ")"; return voice.VoiceInfo.Name + age + gender + lang; } public static void Speak(string Text) { if (bIsPlaying) { Speech.SpeakAsyncCancelAll(); } string text = Text; bIsPlaying = true; text = System.Speech.SpeechFormat.Format(text); if (bIsSsml) { text = Regex.Replace(text, "<.*?>", String.Empty); Speech.SpeakAsync(text); } else { Speech.SpeakAsync(text); } } private void mnuText2Speech_SSML_Click(object sender, EventArgs e) { mnuText2Speech_SSML.Checked = !mnuText2Speech_SSML.Checked; bIsSsml = mnuText2Speech_SSML.Checked; } } }