frmMain.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using System.Speech.Synthesis;
  12. using System.Text.RegularExpressions;
  13. namespace ContentEditor {
  14. public partial class frmMain : Form {
  15. public static Leah.Speech.text.Contents Content;
  16. private static string currentFile = "";
  17. private static string currentFileName = "Unknown.bpc";
  18. private static string currentDirectory;
  19. private DataSave save;
  20. public static bool bNeedAutoSave = false;
  21. private DateTime autosaveTime;
  22. private bool inUpdateMode = false;
  23. public static SpeechSynthesizer Speech = new SpeechSynthesizer();
  24. public static bool bIsPlaying = false;
  25. private static bool bIsSsml = false;
  26. public frmMain() {
  27. InitializeComponent();
  28. Application.ApplicationExit += Application_ApplicationExit;
  29. System.Diagnostics.Debug.WriteLine("UpdateMode start frmMain()");
  30. this.inUpdateMode = true;
  31. currentDirectory = System.IO.Directory.GetCurrentDirectory() + System.IO.Path.DirectorySeparatorChar;
  32. this.tabControl1.Selecting += TabControl1_Selecting;
  33. this.dgvTags.CellValueChanged += DgvTags_CellValueChanged;
  34. this.dgvOptionalTags.CellValueChanged += DgvOptionalTags_CellValueChanged;
  35. this.tvTags.AfterSelect += tvTags_AfterSelect;
  36. this.dgvTexts.RowsAdded += DgvTexts_RowsAdded;
  37. this.dgvTexts.CellEndEdit += DgvTexts_CellEndEdit;
  38. this.dgvTexts.UserDeletingRow += DgvTexts_UserDeletingRow;
  39. //this.cmdTexts_Edit.Click += new System.EventHandler(this.cmdTexts_Edit_Click);
  40. this.dgvTexts.CellBeginEdit += DgvTexts_CellBeginEdit;
  41. this.dgvTags.UserDeletingRow += DgvTags_UserDeletingRow;
  42. this.dgvOptionalTags.UserDeletingRow += DgvOptionalTags_UserDeletingRow;
  43. this.dgvTags.CellEndEdit += DgvTags_CellEndEdit;
  44. this.dgvOptionalTags.CellEndEdit += DgvOptionalTags_CellEndEdit;
  45. this.mnuFile_Last_Itm1.Click += new System.EventHandler(this.mnuFile_Last_Click);
  46. this.mnuFile_Last_Itm2.Click += new System.EventHandler(this.mnuFile_Last_Click);
  47. this.mnuFile_Last_Itm3.Click += new System.EventHandler(this.mnuFile_Last_Click);
  48. this.mnuFile_Last_Itm4.Click += new System.EventHandler(this.mnuFile_Last_Click);
  49. this.mnuFile_Last_Itm5.Click += new System.EventHandler(this.mnuFile_Last_Click);
  50. this.mnuFile_Last_Itm6.Click += new System.EventHandler(this.mnuFile_Last_Click);
  51. this.mnuFile_Last_Itm7.Click += new System.EventHandler(this.mnuFile_Last_Click);
  52. this.mnuFile_Last_Itm8.Click += new System.EventHandler(this.mnuFile_Last_Click);
  53. this.mnuFile_Last_Itm9.Click += new System.EventHandler(this.mnuFile_Last_Click);
  54. this.mnuFile_Last_Itm10.Click += new System.EventHandler(this.mnuFile_Last_Click);
  55. this.mnuText2Speach_Voice_Itm1.Click += mnuText2Speach_Voice_Click;
  56. this.mnuText2Speach_Voice_Itm2.Click += mnuText2Speach_Voice_Click;
  57. this.mnuText2Speach_Voice_Itm3.Click += mnuText2Speach_Voice_Click;
  58. this.mnuText2Speach_Voice_Itm4.Click += mnuText2Speach_Voice_Click;
  59. this.mnuText2Speach_Voice_Itm5.Click += mnuText2Speach_Voice_Click;
  60. this.mnuText2Speach_Voice_Itm6.Click += mnuText2Speach_Voice_Click;
  61. this.mnuText2Speach_Voice_Itm7.Click += mnuText2Speach_Voice_Click;
  62. this.mnuText2Speach_Voice_Itm8.Click += mnuText2Speach_Voice_Click;
  63. this.mnuText2Speach_Voice_Itm9.Click += mnuText2Speach_Voice_Click;
  64. this.mnuText2Speach_Voice_Itm10.Click += mnuText2Speach_Voice_Click;
  65. Speech.SpeakStarted += Speech_SpeakStarted;
  66. Speech.SpeakCompleted += Speech_SpeakCompleted;
  67. Speech.SelectVoiceByHints(VoiceGender.Female);
  68. RefreshVoiceList();
  69. this.dgvTexts.CellMouseDown += DgvTexts_CellMouseDown;
  70. System.Diagnostics.Debug.WriteLine("UpdateMode end frmMain()");
  71. this.inUpdateMode = false;
  72. if (File.Exists("settings.cfg")) {
  73. this.save = System.Fire.Serialize.Serializer.DeserializeObject<DataSave>("settings.cfg", System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8);
  74. this.RefreshLastFile();
  75. frmMain.currentDirectory = this.save.currentFolderDir;
  76. this.Size = this.save.windowSize;
  77. if (string.IsNullOrEmpty(this.save.autosave) || !File.Exists(this.save.autosave)) {
  78. FileNew();
  79. } else {
  80. frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(this.save.autosave, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8);
  81. }
  82. } else {
  83. this.save = new DataSave();
  84. this.save.lastTab = 0;
  85. FileNew();
  86. }
  87. System.Diagnostics.Debug.WriteLine(
  88. System.Speech.SpeechFormat.Format(
  89. "Um 18:45h schoss der FCK sein 1:0 gegen Bayern"
  90. )
  91. );
  92. frmMain.bNeedAutoSave = false;
  93. this.SelectTab(this.save.lastTab);
  94. }
  95. private void mnuText2Speach_Voice_Click(object sender, EventArgs e) {
  96. string VoiceName = "";
  97. if((ToolStripMenuItem)sender != null) {
  98. Speech.SelectVoice(((ToolStripMenuItem)sender).Tag.ToString());
  99. }
  100. }
  101. private void Speech_SpeakCompleted(object sender, SpeakCompletedEventArgs e) {
  102. bIsPlaying = false;
  103. }
  104. private void Speech_SpeakStarted(object sender, SpeakStartedEventArgs e) {
  105. bIsPlaying = true;
  106. }
  107. private void DgvOptionalTags_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
  108. frmMain.bNeedAutoSave = true;
  109. }
  110. private void DgvTags_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
  111. frmMain.bNeedAutoSave = true;
  112. }
  113. private bool SetLastFileMenuItem(string path, ToolStripMenuItem mnu = null) {
  114. if(mnu==null) {
  115. if (mnuFile_Last_Itm1.Tag == null)
  116. mnu = mnuFile_Last_Itm1;
  117. if (mnuFile_Last_Itm2.Tag == null)
  118. mnu = mnuFile_Last_Itm2;
  119. if (mnuFile_Last_Itm3.Tag == null)
  120. mnu = mnuFile_Last_Itm3;
  121. if (mnuFile_Last_Itm4.Tag == null)
  122. mnu = mnuFile_Last_Itm4;
  123. if (mnuFile_Last_Itm5.Tag == null)
  124. mnu = mnuFile_Last_Itm5;
  125. if (mnuFile_Last_Itm6.Tag == null)
  126. mnu = mnuFile_Last_Itm6;
  127. if (mnuFile_Last_Itm7.Tag == null)
  128. mnu = mnuFile_Last_Itm7;
  129. if (mnuFile_Last_Itm8.Tag == null)
  130. mnu = mnuFile_Last_Itm8;
  131. if (mnuFile_Last_Itm9.Tag == null)
  132. mnu = mnuFile_Last_Itm9;
  133. if (mnuFile_Last_Itm10.Tag == null)
  134. mnu = mnuFile_Last_Itm10;
  135. }
  136. if(string.IsNullOrEmpty(path)) {
  137. mnu.Tag = null;
  138. mnu.Text = "";
  139. mnu.Visible = false;
  140. return false;
  141. }
  142. FileInfo fi = new FileInfo(path);
  143. if (fi.Exists) {
  144. mnu.Tag = path;
  145. mnu.Visible = true;
  146. mnu.Text = fi.Name;
  147. return true;
  148. } else {
  149. mnu.Tag = null;
  150. mnu.Text = "";
  151. mnu.Visible = false;
  152. }
  153. return false;
  154. }
  155. private void DoAutosave() {
  156. System.Diagnostics.Debug.WriteLine("Check Autosave()");
  157. double sec = (DateTime.Now - this.autosaveTime).TotalSeconds;
  158. if (frmMain.bNeedAutoSave == false || sec < 20) {
  159. System.Diagnostics.Debug.WriteLine("- Abort: " + (frmMain.bNeedAutoSave?"True":"False") + "; " + sec.ToString());
  160. return;
  161. }
  162. frmMain.bNeedAutoSave = false;
  163. string file = "autosave.bak";
  164. this.save.autosave = file;
  165. System.Diagnostics.Debug.WriteLine("- Autosave: " + file);
  166. System.Fire.Serialize.Serializer.SerializeObject(file, frmMain.Content, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8);
  167. this.autosaveTime = DateTime.Now;
  168. }
  169. private void SetLastFile(string path) {
  170. if(this.save.lastFileUsed_1.ToLower() == path.ToLower()) {
  171. return;
  172. } else if(this.save.lastFileUsed_2.ToLower() == path.ToLower()) {
  173. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  174. this.save.lastFileUsed_1 = path;
  175. } else if (this.save.lastFileUsed_3.ToLower() == path.ToLower()) {
  176. this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
  177. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  178. this.save.lastFileUsed_1 = path;
  179. } else if (this.save.lastFileUsed_4.ToLower() == path.ToLower()) {
  180. this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
  181. this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
  182. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  183. this.save.lastFileUsed_1 = path;
  184. } else if (this.save.lastFileUsed_5.ToLower() == path.ToLower()) {
  185. this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
  186. this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
  187. this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
  188. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  189. this.save.lastFileUsed_1 = path;
  190. } else if (this.save.lastFileUsed_6.ToLower() == path.ToLower()) {
  191. this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
  192. this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
  193. this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
  194. this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
  195. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  196. this.save.lastFileUsed_1 = path;
  197. } else if (this.save.lastFileUsed_7.ToLower() == path.ToLower()) {
  198. this.save.lastFileUsed_7 = this.save.lastFileUsed_6;
  199. this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
  200. this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
  201. this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
  202. this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
  203. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  204. this.save.lastFileUsed_1 = path;
  205. } else if (this.save.lastFileUsed_8.ToLower() == path.ToLower()) {
  206. this.save.lastFileUsed_8 = this.save.lastFileUsed_7;
  207. this.save.lastFileUsed_7 = this.save.lastFileUsed_6;
  208. this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
  209. this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
  210. this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
  211. this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
  212. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  213. this.save.lastFileUsed_1 = path;
  214. } else if (this.save.lastFileUsed_9.ToLower() == path.ToLower()) {
  215. this.save.lastFileUsed_9 = this.save.lastFileUsed_8;
  216. this.save.lastFileUsed_8 = this.save.lastFileUsed_7;
  217. this.save.lastFileUsed_7 = this.save.lastFileUsed_6;
  218. this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
  219. this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
  220. this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
  221. this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
  222. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  223. this.save.lastFileUsed_1 = path;
  224. } else {
  225. this.save.lastFileUsed_10 = this.save.lastFileUsed_9;
  226. this.save.lastFileUsed_8 = this.save.lastFileUsed_7;
  227. this.save.lastFileUsed_7 = this.save.lastFileUsed_6;
  228. this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
  229. this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
  230. this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
  231. this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
  232. this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
  233. this.save.lastFileUsed_1 = path;
  234. }
  235. this.RefreshLastFile();
  236. }
  237. private void RefreshLastFile() {
  238. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm1);
  239. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm2);
  240. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm3);
  241. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm4);
  242. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm5);
  243. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm6);
  244. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm7);
  245. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm8);
  246. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm9);
  247. this.SetLastFileMenuItem("", this.mnuFile_Last_Itm10);
  248. this.SetLastFileMenuItem(this.save.lastFileUsed_1);
  249. this.SetLastFileMenuItem(this.save.lastFileUsed_2);
  250. this.SetLastFileMenuItem(this.save.lastFileUsed_3);
  251. this.SetLastFileMenuItem(this.save.lastFileUsed_4);
  252. this.SetLastFileMenuItem(this.save.lastFileUsed_5);
  253. this.SetLastFileMenuItem(this.save.lastFileUsed_6);
  254. this.SetLastFileMenuItem(this.save.lastFileUsed_7);
  255. this.SetLastFileMenuItem(this.save.lastFileUsed_8);
  256. this.SetLastFileMenuItem(this.save.lastFileUsed_9);
  257. this.SetLastFileMenuItem(this.save.lastFileUsed_10);
  258. }
  259. private void DgvTexts_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {
  260. ushort tag_id;
  261. if (ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) {
  262. frmMain.Content.RemoveAt(tag_id);
  263. this.SelectTab();
  264. }
  265. }
  266. private void DgvOptionalTags_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {
  267. int useages = 0;
  268. if (this.inUpdateMode == true) {
  269. e.Cancel = true;
  270. return;
  271. }
  272. this.inUpdateMode = true;
  273. Leah.Speech.text.ContentUseage[] use = frmMain.Content.TagUseage;
  274. ushort tag_id;
  275. if (e.Row.Tag == null) {
  276. tag_id=(ushort)dgvOptionalTags.Rows.IndexOf(e.Row);
  277. } else {
  278. if (!ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) {
  279. return;
  280. }
  281. }
  282. if (useages > 0) {
  283. 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) {
  284. this.inUpdateMode = false;
  285. e.Cancel = true;
  286. return;
  287. }
  288. }
  289. frmMain.Content.OptionalTag_RemoveAt(tag_id);
  290. frmMain.bNeedAutoSave = true;
  291. this.inUpdateMode = false;
  292. }
  293. private void DgvTags_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {
  294. int useages = 0;
  295. if (this.inUpdateMode == true) {
  296. e.Cancel = true;
  297. return;
  298. }
  299. this.inUpdateMode = true;
  300. Leah.Speech.text.ContentUseage[] use = frmMain.Content.TagUseage;
  301. ushort tag_id;
  302. if (e.Row.Tag == null) {
  303. tag_id = (ushort)dgvTags.Rows.IndexOf(e.Row);
  304. } else {
  305. if (!ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) {
  306. return;
  307. }
  308. }
  309. useages = use[tag_id].Count;
  310. if (useages > 0) {
  311. 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) {
  312. this.inUpdateMode = false;
  313. e.Cancel = true;
  314. return;
  315. }
  316. }
  317. frmMain.Content.Tag_RemoveAt(tag_id);
  318. frmMain.bNeedAutoSave = true;
  319. this.inUpdateMode = false;
  320. }
  321. private void DgvTexts_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) {
  322. if (this.tvTags.SelectedNode == null || this.tvTags.SelectedNode.Tag == null) {
  323. e.Cancel = true;
  324. return;
  325. }
  326. }
  327. private int selectedRow = -1;
  328. private void DgvTexts_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) {
  329. if(e.Button == MouseButtons.Right) {
  330. if (e.RowIndex < 0) {
  331. // Tabellen Header
  332. } else if (e.ColumnIndex < 0) {
  333. // Zeilennummer
  334. } else {
  335. this.selectedRow = e.RowIndex;
  336. int pos = 0;
  337. foreach (DataGridViewColumn col in dgvTexts.Columns)
  338. if (col.Index < e.ColumnIndex)
  339. pos += col.Width;
  340. Point p = new Point(e.Location.X + dgvTexts.RowHeadersWidth + pos, e.Location.Y + (22 * e.RowIndex) + 23);
  341. this.cmsTexts.Show(this.dgvTexts.PointToScreen(p));
  342. }
  343. }
  344. }
  345. private void DgvTexts_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
  346. System.Diagnostics.Debug.WriteLine("End edit: " + e.RowIndex);
  347. System.Diagnostics.Debug.WriteLine("UpdateMode start DgvTexts_CellEndEdit()");
  348. this.inUpdateMode = true;
  349. if (e.ColumnIndex==1) {
  350. if (dgvTexts.Rows[e.RowIndex].Cells[1].Value == null || dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == "")
  351. dgvTexts.Rows[e.RowIndex].Cells[1].Value = "all";
  352. }
  353. 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 != "") {
  354. dgvTexts.Rows[e.RowIndex].Cells[2].ErrorText = "At least one tag must be enterd";
  355. System.Diagnostics.Debug.WriteLine("- Error: At least one tag must be enterd");
  356. } else {
  357. dgvTexts.Rows[e.RowIndex].Cells[2].ErrorText = "";
  358. }
  359. Leah.Speech.text.ContentEntry entry;
  360. if(dgvTexts.Rows[e.RowIndex].Tag==null) {
  361. dgvTexts.Rows[e.RowIndex].Tag = Content.Count;
  362. System.Diagnostics.Debug.WriteLine("- New row added. Row: '" + dgvTexts.Rows[e.RowIndex].Tag.ToString() + "'");
  363. Content.Add(
  364. new Leah.Speech.text.ContentEntry(
  365. dgvTexts.Rows[e.RowIndex].Cells[0].Value==null?"":dgvTexts.Rows[e.RowIndex].Cells[0].Value.ToString(),
  366. Leah.Speech.text.Contents.GetMood(dgvTexts.Rows[e.RowIndex].Cells[1].Value.ToString()),
  367. this.GetUShortArray(dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString())
  368. )
  369. );
  370. }
  371. entry = Content.GetEntry((int)dgvTexts.Rows[e.RowIndex].Tag);
  372. //if (entry != null && dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) {
  373. if (dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) {
  374. if (e.ColumnIndex == 0) {
  375. //entry.Text = dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Trim();
  376. Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text = dgvTexts.Rows[e.RowIndex].Cells[0].Value.ToString().Trim();
  377. dgvTexts.Rows[e.RowIndex].Cells[0].Value = Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text;
  378. System.Diagnostics.Debug.WriteLine("- Text changed: " + Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text);
  379. } else if (e.ColumnIndex == 1) {
  380. //entry.MoodText = dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  381. //dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = entry.MoodText;
  382. Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText = dgvTexts.Rows[e.RowIndex].Cells[1].Value.ToString().Trim();
  383. dgvTexts.Rows[e.RowIndex].Cells[1].Value = Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText;
  384. System.Diagnostics.Debug.WriteLine("- Mood changed: " + Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText);
  385. } else if(e.ColumnIndex == 2) {
  386. System.Diagnostics.Debug.WriteLine("- Tag changed: " + dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString());
  387. Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tag_Clear();
  388. Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tag_Add(dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString());
  389. string rtag = "";
  390. foreach (ushort ustag in Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tags)
  391. rtag += (rtag == "" ? "" : ", ") + ustag.ToString();
  392. dgvTexts.Rows[e.RowIndex].Cells[2].Value = rtag;
  393. } else if (e.ColumnIndex == 3) {
  394. System.Diagnostics.Debug.WriteLine("- Optional Tag changed: " + dgvTexts.Rows[e.RowIndex].Cells[3].Value.ToString());
  395. Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTag_Clear();
  396. Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTag_Add(dgvTexts.Rows[e.RowIndex].Cells[3].Value.ToString());
  397. string rtag = "";
  398. foreach (ushort ustag in Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTags)
  399. rtag += (rtag==""?"":", ") + ustag.ToString();
  400. dgvTexts.Rows[e.RowIndex].Cells[3].Value = rtag;
  401. } else if (e.ColumnIndex == 4) {
  402. float s = entry.Score;
  403. if(float.TryParse(dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(), out s)) {
  404. entry.Score = s;
  405. System.Diagnostics.Debug.WriteLine("- Score changed: " + s.ToString());
  406. dgvTexts.Rows[e.RowIndex].Cells[4].Value = s.ToString("#,00");
  407. } else {
  408. System.Diagnostics.Debug.WriteLine("- Failed changing score. Not a number: " + dgvTexts.Rows[e.RowIndex].Cells[4].Value.ToString());
  409. dgvTexts.Rows[e.RowIndex].Cells[4].Value = entry.Score;
  410. }
  411. }
  412. } else {
  413. System.Diagnostics.Debug.WriteLine("- Error: No row tag");
  414. }
  415. System.Diagnostics.Debug.WriteLine("- Total Content count: "+Content.Count);
  416. System.Diagnostics.Debug.WriteLine("UpdateMode end DgvTexts_CellEndEdit()");
  417. this.inUpdateMode = false;
  418. frmMain.bNeedAutoSave = true;
  419. //Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag] = entry;
  420. }
  421. private ushort[] GetUShortArray(string s) {
  422. string[] x = s.Split(new char[] { ',',';','|' });
  423. List<ushort> res = new List<ushort>();
  424. foreach (string y in x) {
  425. string z = y.Trim();
  426. ushort itm = 0;
  427. if(ushort.TryParse(z,out itm)) {
  428. res.Add(itm);
  429. }
  430. }
  431. return res.ToArray();
  432. }
  433. private void DgvTexts_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) {
  434. for(int i=e.RowIndex, c = e.RowIndex+e.RowCount;i<c;i++) {
  435. dgvTexts.Rows[i].Cells[1].Value = "any";
  436. dgvTexts.Rows[i].Cells[2].Value = tvTags.SelectedNode.Tag;
  437. dgvTexts.Rows[i].Cells[3].Value = "";
  438. dgvTexts.Rows[i].Cells[4].Value = "0.0";
  439. }
  440. }
  441. private void TabControl1_Selecting(object sender, System.Windows.Forms.TabControlCancelEventArgs e) {
  442. this.SelectTab(e.TabPageIndex);
  443. }
  444. private void SelectTab() {
  445. this.SelectTab(this.tabControl1.SelectedIndex);
  446. }
  447. private void SelectTab(int index) {
  448. System.Diagnostics.Debug.WriteLine("UpdateMode start SelectTab()");
  449. this.inUpdateMode = true;
  450. System.Diagnostics.Debug.WriteLine("SelectTab(" + index.ToString() + ")");
  451. this.mnuView_TagOverview.Checked = false;
  452. this.mnuOptionalTags.Checked = false;
  453. this.mnuView_General.Checked = false;
  454. this.save.lastTab = index;
  455. this.DoAutosave();
  456. if (this.tabControl1.SelectedIndex == index) {
  457. switch(index) {
  458. case 0:
  459. this.mnuView_General.Checked = true;
  460. break;
  461. case 1:
  462. this.mnuView_TagOverview.Checked = true;
  463. System.Diagnostics.Debug.WriteLine("dgvTags.Clear()");
  464. dgvTags.Rows.Clear();
  465. System.Diagnostics.Debug.WriteLine("dgvOptionalTags.Clear()");
  466. dgvOptionalTags.Rows.Clear();
  467. System.Diagnostics.Debug.WriteLine("Try to fill");
  468. int i = 0;
  469. if (Content!=null) {
  470. foreach(Leah.Speech.text.ContentUseage tag in Content.TagUseage) {
  471. System.Diagnostics.Debug.WriteLine("Add Tag: "+tag.Tag);
  472. DataGridViewRow row = new DataGridViewRow();
  473. row.Tag = i;
  474. row.Cells.Add(new DataGridViewTextBoxCell() { Value = tag.Tag });
  475. row.Cells.Add(new DataGridViewTextBoxCell() { Value = tag.Count });
  476. dgvTags.Rows.Add(row);
  477. i++;
  478. }
  479. i = 0;
  480. foreach (Leah.Speech.text.ContentUseage tag in Content.OptionalTagUseage) {
  481. System.Diagnostics.Debug.WriteLine("Add OptionalTag: " + tag.Tag);
  482. DataGridViewRow row = new DataGridViewRow();
  483. row.Tag = i;
  484. row.Cells.Add(new DataGridViewTextBoxCell() { Value = tag.Tag });
  485. row.Cells.Add(new DataGridViewTextBoxCell() { Value = tag.Count });
  486. dgvOptionalTags.Rows.Add(row);
  487. i++;
  488. }
  489. } else {
  490. System.Diagnostics.Debug.WriteLine("No Content found");
  491. }
  492. break;
  493. case 2:
  494. this.mnuOptionalTags.Checked = true;
  495. List<TreeNode> childs = new List<TreeNode>();
  496. foreach (Leah.Speech.text.ContentUseage tag in Content.TagUseage) {
  497. TreeNode node = new TreeNode();
  498. node.Text = tag.Tag;
  499. node.Tag = tag.ID;
  500. childs.Add(node);
  501. }
  502. TreeNode tnRoot = new TreeNode("Root", childs.ToArray());
  503. tnRoot.Text = "Root";
  504. tvTags.BeginUpdate();
  505. tvTags.Nodes.Clear();
  506. tvTags.Nodes.Add(tnRoot);
  507. tvTags.ExpandAll();
  508. tvTags.EndUpdate();
  509. break;
  510. }
  511. } else {
  512. this.tabControl1.SelectedIndex = index;
  513. }
  514. System.Diagnostics.Debug.WriteLine("UpdateMode end SelectTab()");
  515. this.inUpdateMode = false;
  516. }
  517. private void DgvTags_CellValueChanged(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) {
  518. this.StoreTags();
  519. }
  520. private void DgvOptionalTags_CellValueChanged(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) {
  521. this.StoreOptionalTags();
  522. }
  523. private void StoreTags() {
  524. if (Content == null)
  525. return;
  526. System.Diagnostics.Debug.WriteLine("StoreTags()");
  527. List<string> res = new List<string>();
  528. for (int i = 0, c = dgvTags.Rows.Count; i < c; i++) {
  529. if (dgvTags.Rows[i].Cells[0].Value != null && dgvTags.Rows[i].Cells[0].Value.ToString()!="") {
  530. res.Add(dgvTags.Rows[i].Cells[0].Value.ToString());
  531. }
  532. }
  533. Content.Tags = res.ToArray();
  534. }
  535. private void StoreOptionalTags() {
  536. if (Content == null) return;
  537. System.Diagnostics.Debug.WriteLine("StoreOptionalTags()");
  538. List<string> res = new List<string>();
  539. for (int i = 0, c = dgvOptionalTags.Rows.Count; i < c; i++) {
  540. if (dgvOptionalTags.Rows[i].Cells[0].Value != null && dgvOptionalTags.Rows[i].Cells[0].Value.ToString() != "") {
  541. res.Add(dgvOptionalTags.Rows[i].Cells[0].Value.ToString());
  542. }
  543. }
  544. Content.OptionalTags = res.ToArray();
  545. }
  546. private void FileNew() {
  547. this.FileNew("");
  548. }
  549. private void FileNew(string newName) {
  550. currentFileName = newName;
  551. currentFile = currentDirectory + newName;
  552. Content = new Leah.Speech.text.Contents();
  553. this.SelectTab();
  554. }
  555. private void FileLoad(string path) {
  556. FileLoad(new FileInfo(path));
  557. }
  558. private void FileLoad(FileInfo path) {
  559. if (path.Exists) {
  560. currentDirectory = path.Directory.FullName;
  561. currentFile = path.FullName;
  562. currentFileName = path.Name;
  563. Content = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(path.FullName);
  564. this.SelectTab();
  565. }
  566. }
  567. private void tvTags_AfterSelect(object sender, TreeViewEventArgs e) {
  568. System.Diagnostics.Debug.WriteLine("Load Text-Category entries");
  569. dgvTexts.Rows.Clear();
  570. if(e.Node.Tag!=null) {
  571. ushort tag = ushort.Parse(e.Node.Tag.ToString());
  572. for(int i=0,c=Content.Count;i<c;i++) {
  573. Leah.Speech.text.ContentEntry txt = Content.GetEntry(i);
  574. if (txt.Tag_Has(tag)) {
  575. DataGridViewRow row = new DataGridViewRow();
  576. row.Tag = i;
  577. row.Cells.AddRange(
  578. new DataGridViewTextBoxCell() { Value = txt.Text },
  579. new DataGridViewTextBoxCell() { Value = txt.MoodText },
  580. new DataGridViewTextBoxCell() { Value = String.Join(", ", txt.Tags_String) },
  581. new DataGridViewTextBoxCell() { Value = String.Join(", ", txt.OptionalTags_String) }
  582. );
  583. dgvTexts.Rows.Add(row);
  584. }
  585. }
  586. } else {
  587. System.Diagnostics.Debug.WriteLine("- No tag");
  588. }
  589. }
  590. private void cmdTexts_Edit_Click(object sender, EventArgs e) {
  591. Leah.Speech.text.ContentEntry res = null;
  592. if (this.selectedRow >= 0 && this.dgvTexts.Rows[this.selectedRow].Tag != null) {
  593. System.Diagnostics.Debug.WriteLine("Edit item");
  594. res = frmContentEdit.EditItem((int)(this.dgvTexts.Rows[this.selectedRow].Tag));
  595. } else {
  596. System.Diagnostics.Debug.WriteLine("New item");
  597. res = frmContentEdit.NewItem();
  598. }
  599. }
  600. private void mnuFile_New_Click(object sender, EventArgs e) {
  601. frmMain.Content = new Leah.Speech.text.Contents();
  602. this.SelectTab();
  603. }
  604. private void mnuFile_Open_Click(object sender, EventArgs e) {
  605. openFileDialog1.Title = "Open Content File";
  606. openFileDialog1.Filter = "Content File (*.bpc)|*.bpc|All files (*.*)|*.*";
  607. openFileDialog1.Multiselect = false;
  608. openFileDialog1.InitialDirectory = frmMain.currentDirectory;
  609. if(openFileDialog1.ShowDialog() == DialogResult.OK) {
  610. FileInfo fi = new FileInfo(openFileDialog1.FileName);
  611. frmMain.currentFile = fi.FullName;
  612. frmMain.currentFileName = fi.Name;
  613. frmMain.currentDirectory = fi.Directory.FullName;
  614. frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(
  615. openFileDialog1.FileName,
  616. System.Fire.Serialize.Property.ArraySize.bits_16,
  617. System.Fire.Serialize.Property.StringEncoding.UTF8
  618. );
  619. this.save.currentFolderDir = frmMain.currentDirectory;
  620. this.SetLastFile(fi.FullName);
  621. this.SelectTab();
  622. }
  623. }
  624. private void mnuFile_Save_Click(object sender, EventArgs e) {
  625. if(frmMain.currentFileName.Length==0) {
  626. mnuFile_SaveAs_Click(sender, e);
  627. } else {
  628. System.Fire.Serialize.Serializer.SerializeObject(
  629. frmMain.currentFile,
  630. frmMain.Content,
  631. System.Fire.Serialize.Property.ArraySize.bits_16,
  632. System.Fire.Serialize.Property.StringEncoding.UTF8
  633. );
  634. this.save.currentFolderDir = frmMain.currentDirectory;
  635. this.SetLastFile(frmMain.currentFile);
  636. }
  637. }
  638. private void mnuFile_SaveAs_Click(object sender, EventArgs e) {
  639. saveFileDialog1.Title = "Save Content File";
  640. saveFileDialog1.Filter = "Content File (*.bpc)|*.bpc|All files (*.*)|*.*";
  641. saveFileDialog1.InitialDirectory = frmMain.currentDirectory;
  642. saveFileDialog1.FileName = frmMain.currentFileName;
  643. if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
  644. FileInfo fi = new FileInfo(saveFileDialog1.FileName);
  645. frmMain.currentFile = fi.FullName;
  646. frmMain.currentFileName = fi.Name;
  647. frmMain.currentDirectory = fi.Directory.FullName;
  648. System.Fire.Serialize.Serializer.SerializeObject(
  649. frmMain.currentFile,
  650. frmMain.Content,
  651. System.Fire.Serialize.Property.ArraySize.bits_16,
  652. System.Fire.Serialize.Property.StringEncoding.UTF8
  653. );
  654. this.save.currentFolderDir = frmMain.currentDirectory;
  655. this.SetLastFile(frmMain.currentFile);
  656. }
  657. }
  658. /*private void importTagsToolStripMenuItem_Click(object sender, EventArgs e) {
  659. openFileDialog1.Title = "Import Tags";
  660. openFileDialog1.Filter = "Textfile (*.txt)|*.txt|CSF File (*.csv)|*.csv|All files (*.*)|*.*";
  661. openFileDialog1.Multiselect = false;
  662. openFileDialog1.InitialDirectory = frmMain.currentDirectory;
  663. if (openFileDialog1.ShowDialog() == DialogResult.OK) {
  664. FileInfo fi = new FileInfo(openFileDialog1.FileName);
  665. using (StreamReader sr = fi.OpenText()) {
  666. while (sr.Peek() >= 0) {
  667. string line = sr.ReadLine();
  668. }
  669. }
  670. this.SelectTab();
  671. }
  672. }*/
  673. private void mnuTags_DeleteAll_Click(object sender, EventArgs e) {
  674. frmMain.Content.Tag_Clear();
  675. this.SelectTab();
  676. }
  677. private void mnuTags_Import_Click(object sender, EventArgs e) {
  678. openFileDialog1.Title = "Import Tags";
  679. openFileDialog1.Filter = "Textfile (*.txt)|*.txt|BlackPro Content File|*.bpc|All files (*.*)|*.*";
  680. openFileDialog1.Multiselect = false;
  681. openFileDialog1.InitialDirectory = frmMain.currentDirectory;
  682. if (openFileDialog1.ShowDialog() == DialogResult.OK) {
  683. FileInfo fi = new FileInfo(openFileDialog1.FileName);
  684. if (fi.Extension == ".bpc") {
  685. Leah.Speech.text.Contents imp = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(fi.FullName);
  686. foreach(string s in imp.Tags) {
  687. frmMain.Content.Tag_Add(s);
  688. }
  689. } else {
  690. using (StreamReader sr = fi.OpenText()) {
  691. while (sr.Peek() >= 0) {
  692. string line = sr.ReadLine().Trim();
  693. if (line.Length > 0) {
  694. frmMain.Content.Tag_Add(line);
  695. }
  696. }
  697. }
  698. }
  699. this.SelectTab();
  700. }
  701. }
  702. private void mnuTags_Export_Click(object sender, EventArgs e) {
  703. saveFileDialog1.Title = "Export Tags";
  704. saveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
  705. saveFileDialog1.InitialDirectory = frmMain.currentDirectory;
  706. saveFileDialog1.FileName = "tags.txt";
  707. if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
  708. FileInfo fi = new FileInfo(saveFileDialog1.FileName);
  709. bool bFirst = true;
  710. using (FileStream fs = fi.OpenWrite()) {
  711. foreach (DataGridViewRow row in dgvTags.Rows) {
  712. if (row.Cells[0].Value != null) {
  713. if (bFirst == false)
  714. fs.Write(new byte[] { 10 },0,1);
  715. bFirst = false;
  716. string s = row.Cells[0].Value.ToString();
  717. byte[] b = System.Text.Encoding.ASCII.GetBytes(s);
  718. fs.Write(b, 0, b.Length);
  719. }
  720. }
  721. }
  722. }
  723. }
  724. private void mnuOptionalTags_DeleteAll_Click(object sender, EventArgs e) {
  725. frmMain.Content.OptionalTag_Clear();
  726. this.SelectTab();
  727. }
  728. private void mnuOptionalTags_Import_Click(object sender, EventArgs e) {
  729. openFileDialog1.Title = "Import Optional Tags";
  730. openFileDialog1.Filter = "Textfile (*.txt)|*.txt|BlackPro Content File|*.bpc|All files (*.*)|*.*";
  731. openFileDialog1.Multiselect = false;
  732. openFileDialog1.InitialDirectory = frmMain.currentDirectory;
  733. if (openFileDialog1.ShowDialog() == DialogResult.OK) {
  734. FileInfo fi = new FileInfo(openFileDialog1.FileName);
  735. if (fi.Extension == ".bpc") {
  736. Leah.Speech.text.Contents imp = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(fi.FullName);
  737. foreach (string s in imp.OptionalTags) {
  738. frmMain.Content.OptionalTag_Add(s);
  739. }
  740. } else {
  741. using (StreamReader sr = fi.OpenText()) {
  742. while (sr.Peek() >= 0) {
  743. string line = sr.ReadLine().Trim();
  744. if (line.Length > 0) {
  745. frmMain.Content.OptionalTag_Add(line);
  746. }
  747. }
  748. }
  749. }
  750. this.SelectTab();
  751. }
  752. }
  753. private void mnuTexts_Editor_Click(object sender, EventArgs e) {
  754. if(tabControl1.SelectedIndex==2 && dgvTexts.SelectedRows.Count>0) {
  755. if(dgvTexts.SelectedRows[0].Tag!=null) {
  756. frmContentEdit.EditItem((int)dgvTexts.SelectedRows[0].Tag);
  757. } else {
  758. frmContentEdit.NewItem();
  759. }
  760. } else {
  761. frmContentEdit.NewItem();
  762. }
  763. }
  764. private void mnuView_General_Click(object sender, EventArgs e) {
  765. this.SelectTab(0);
  766. }
  767. private void mnuView_TagOverview_Click(object sender, EventArgs e) {
  768. this.SelectTab(1);
  769. }
  770. private void mnuView_TextOverview_Click(object sender, EventArgs e) {
  771. this.SelectTab(2);
  772. }
  773. private void mnuOptionalTags_Export_Click(object sender, EventArgs e) {
  774. saveFileDialog1.Title = "Export Optional Tags";
  775. saveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
  776. saveFileDialog1.InitialDirectory = frmMain.currentDirectory;
  777. saveFileDialog1.FileName = "optionalTags.txt";
  778. if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
  779. FileInfo fi = new FileInfo(saveFileDialog1.FileName);
  780. bool bFirst = true;
  781. using (FileStream fs = fi.OpenWrite()) {
  782. foreach (DataGridViewRow row in dgvOptionalTags.Rows) {
  783. if (row.Cells[0].Value != null) {
  784. if (bFirst == false)
  785. fs.Write(new byte[] { 10 }, 0, 1);
  786. bFirst = false;
  787. string s = row.Cells[0].Value.ToString();
  788. byte[] b = System.Text.Encoding.ASCII.GetBytes(s);
  789. fs.Write(b, 0, b.Length);
  790. }
  791. }
  792. }
  793. }
  794. }
  795. private void mnuFile_Quit_Click(object sender, EventArgs e) {
  796. Application.Exit();
  797. }
  798. private void Application_ApplicationExit(object sender, EventArgs e) {
  799. this.save.windowSize = this.Size;
  800. System.Fire.Serialize.Serializer.SerializeObject("settings.cfg", this.save);
  801. }
  802. private void mnuFile_Last_Click(object sender, EventArgs e) {
  803. ToolStripMenuItem mnu = (ToolStripMenuItem)sender;
  804. if (mnu != null) {
  805. string path = (string)mnu.Tag;
  806. FileInfo fi = new FileInfo(path);
  807. if(fi.Exists) {
  808. frmMain.currentFile = fi.FullName;
  809. frmMain.currentFileName = fi.Name;
  810. frmMain.currentDirectory = fi.Directory.FullName;
  811. frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(
  812. openFileDialog1.FileName,
  813. System.Fire.Serialize.Property.ArraySize.bits_16,
  814. System.Fire.Serialize.Property.StringEncoding.UTF8
  815. );
  816. this.SetLastFile(fi.FullName);
  817. this.save.currentFolderDir = frmMain.currentDirectory;
  818. this.SelectTab();
  819. }
  820. }
  821. }
  822. private void tmrAutosave_Tick(object sender, EventArgs e) {
  823. this.DoAutosave();
  824. }
  825. private void mnuText2Speech_Play_Click(object sender, EventArgs e) {
  826. if(dgvTexts.SelectedRows.Count==1) {
  827. if(dgvTexts.SelectedRows[0].Cells.Count>0) {
  828. Speak(dgvTexts.SelectedRows[0].Cells[0].Value.ToString());
  829. }
  830. }
  831. }
  832. private void RefreshVoiceList() {
  833. InstalledVoice[] voices = Speech.GetInstalledVoices().ToArray();
  834. this.mnuText2Speach_Voice_Itm1.Visible = false;
  835. this.mnuText2Speach_Voice_Itm2.Visible = false;
  836. this.mnuText2Speach_Voice_Itm3.Visible = false;
  837. this.mnuText2Speach_Voice_Itm4.Visible = false;
  838. this.mnuText2Speach_Voice_Itm5.Visible = false;
  839. this.mnuText2Speach_Voice_Itm6.Visible = false;
  840. this.mnuText2Speach_Voice_Itm7.Visible = false;
  841. this.mnuText2Speach_Voice_Itm8.Visible = false;
  842. this.mnuText2Speach_Voice_Itm9.Visible = false;
  843. this.mnuText2Speach_Voice_Itm10.Visible = false;
  844. if (voices.Length>=1) {
  845. this.mnuText2Speach_Voice_Itm1.Text = getVoiceInfo(voices[0]);
  846. this.mnuText2Speach_Voice_Itm1.Visible = true;
  847. this.mnuText2Speach_Voice_Itm1.Tag = voices[0].VoiceInfo.Name;
  848. }
  849. if (voices.Length >= 2) {
  850. this.mnuText2Speach_Voice_Itm2.Text = getVoiceInfo(voices[1]);
  851. this.mnuText2Speach_Voice_Itm2.Visible = true;
  852. this.mnuText2Speach_Voice_Itm2.Tag = voices[1].VoiceInfo.Name;
  853. }
  854. if (voices.Length >= 3) {
  855. this.mnuText2Speach_Voice_Itm3.Text = getVoiceInfo(voices[2]);
  856. this.mnuText2Speach_Voice_Itm3.Visible = true;
  857. this.mnuText2Speach_Voice_Itm3.Tag = voices[2].VoiceInfo.Name;
  858. }
  859. if (voices.Length >= 4) {
  860. this.mnuText2Speach_Voice_Itm4.Text = getVoiceInfo(voices[3]);
  861. this.mnuText2Speach_Voice_Itm4.Visible = true;
  862. this.mnuText2Speach_Voice_Itm4.Tag = voices[3].VoiceInfo.Name;
  863. }
  864. if (voices.Length >= 5) {
  865. this.mnuText2Speach_Voice_Itm5.Text = getVoiceInfo(voices[4]);
  866. this.mnuText2Speach_Voice_Itm5.Visible = true;
  867. this.mnuText2Speach_Voice_Itm5.Tag = voices[4].VoiceInfo.Name;
  868. }
  869. if (voices.Length >= 6) {
  870. this.mnuText2Speach_Voice_Itm6.Text = getVoiceInfo(voices[5]);
  871. this.mnuText2Speach_Voice_Itm6.Visible = true;
  872. this.mnuText2Speach_Voice_Itm6.Tag = voices[5].VoiceInfo.Name;
  873. }
  874. if (voices.Length >= 7) {
  875. this.mnuText2Speach_Voice_Itm7.Text = getVoiceInfo(voices[6]);
  876. this.mnuText2Speach_Voice_Itm7.Visible = true;
  877. this.mnuText2Speach_Voice_Itm7.Tag = voices[6].VoiceInfo.Name;
  878. }
  879. if (voices.Length >= 8) {
  880. this.mnuText2Speach_Voice_Itm8.Text = getVoiceInfo(voices[7]);
  881. this.mnuText2Speach_Voice_Itm8.Visible = true;
  882. this.mnuText2Speach_Voice_Itm8.Tag = voices[7].VoiceInfo.Name;
  883. }
  884. if (voices.Length >= 9) {
  885. this.mnuText2Speach_Voice_Itm9.Text = getVoiceInfo(voices[8]);
  886. this.mnuText2Speach_Voice_Itm9.Visible = true;
  887. this.mnuText2Speach_Voice_Itm9.Tag = voices[8].VoiceInfo.Name;
  888. }
  889. if (voices.Length >= 10) {
  890. this.mnuText2Speach_Voice_Itm10.Text = getVoiceInfo(voices[9]);
  891. this.mnuText2Speach_Voice_Itm10.Visible = true;
  892. this.mnuText2Speach_Voice_Itm10.Tag = voices[9].VoiceInfo.Name;
  893. }
  894. }
  895. private string getVoiceInfo(InstalledVoice voice) {
  896. string gender = "";
  897. string age = "";
  898. string lang = "";
  899. if (voice.VoiceInfo.Gender == VoiceGender.Female) gender = " female";
  900. else if (voice.VoiceInfo.Gender == VoiceGender.Male) gender = " male";
  901. else if (voice.VoiceInfo.Gender == VoiceGender.Neutral) gender = " neutral";
  902. if (voice.VoiceInfo.Age == VoiceAge.Adult) age = " adult";
  903. else if (voice.VoiceInfo.Age == VoiceAge.Child) age = " child";
  904. else if (voice.VoiceInfo.Age == VoiceAge.Senior) age = " old";
  905. else if (voice.VoiceInfo.Age == VoiceAge.Teen) age = " teen";
  906. lang = " (" + voice.VoiceInfo.Culture.Name + ")";
  907. return voice.VoiceInfo.Name + age + gender + lang;
  908. }
  909. public static void Speak(string Text) {
  910. if (bIsPlaying) {
  911. Speech.SpeakAsyncCancelAll();
  912. }
  913. string text = Text;
  914. bIsPlaying = true;
  915. text = System.Speech.SpeechFormat.Format(text);
  916. if (bIsSsml) {
  917. text = Regex.Replace(text, "<.*?>", String.Empty);
  918. Speech.SpeakAsync(text);
  919. } else {
  920. Speech.SpeakAsync(text);
  921. }
  922. }
  923. private void mnuText2Speech_SSML_Click(object sender, EventArgs e) {
  924. mnuText2Speech_SSML.Checked = !mnuText2Speech_SSML.Checked;
  925. bIsSsml = mnuText2Speech_SSML.Checked;
  926. }
  927. }
  928. }