Exemplo n.º 1
0
		private void OpenSavedGrid(string strFilename)
		{
			Reset();
			bool bXML = (Path.GetExtension(strFilename).ToLower() == ".xml");
			if (bXML)
			{
				DiscourseChartDataClass file = new DiscourseChartDataClass();
				file.ReadXml(strFilename);

				// get the font colors
				if (file.VernacularFont.Count > 0)
				{
					DiscourseChartDataClass.VernacularFontRow aVFRow = file.VernacularFont[0];
					m_fontVernacular = new Font(aVFRow.FontName, aVFRow.FontSize);
					m_colorVernacular = Color.FromName(aVFRow.FontColor);
					SetVernacularFontColor();
				}

				if (file.GlossFont.Count > 0)
				{
					DiscourseChartDataClass.GlossFontRow aGFRow = file.GlossFont[0];
					m_fontGloss = new Font(aGFRow.FontName, aGFRow.FontSize);
					m_colorGloss = Color.FromName(aGFRow.FontColor);
				}

				if (file.TransliterationFont.Count > 0)
				{
					DiscourseChartDataClass.TransliterationFontRow aTFRow = file.TransliterationFont[0];
					m_fontTransliteration = new Font(aTFRow.FontName, aTFRow.FontSize);
					m_colorTransliteration = Color.FromName(aTFRow.FontColor);
				}

				foreach (DiscourseChartDataClass.DiscourseClauseRow aClause in file.DiscourseClause)
				{
					Debug.Assert(aClause.GetVernacularRows().Length > 0);
					DiscourseChartDataClass.VernacularRow aVernRow = aClause.GetVernacularRows()[0];
					int nIndex = dataGridViewChart.Rows.Add();
					DataGridViewRow aRow = dataGridViewChart.Rows[nIndex];
					aRow.Height = m_fontVernacular.Height + CnExtraHeight;
					aRow.HeaderCell.ToolTipText = "Right-click to add/edit a free translation";

					aRow.Cells[0].Value = aClause.Ref;
					aRow.Cells[1].Value = (aVernRow.IsPreSNull()) ? null : aVernRow.PreS;
					aRow.Cells[2].Value = (aVernRow.IsSubjectNull()) ? null : aVernRow.Subject;
					aRow.Cells[3].Value = (aVernRow.IsX1Null()) ? null : aVernRow.X1;
					aRow.Cells[4].Value = (aVernRow.IsX2Null()) ? null : aVernRow.X2;
					aRow.Cells[5].Value = (aVernRow.IsVerbNull()) ? null : aVernRow.Verb;
					aRow.Cells[6].Value = (aVernRow.IsPostSNull()) ? null : aVernRow.PostS;

					GlossTranslations gts = new GlossTranslations
												{
													Reference = aClause.Ref,
													FreeTranslation = (!aClause.IsFreeTranslationNull()) ? aClause.FreeTranslation : null
												};

					aRow.Tag = gts;

					DiscourseChartDataClass.GlossRow[] aGRs = aClause.GetGlossRows();
					if (aGRs.Length > 0)
					{
						DiscourseChartDataClass.GlossRow aGlossRow = aGRs[0];
						gts.GlossInfo = new GlossTranslationInfo
											{
												PreS = (aGlossRow.IsPreSNull()) ? null : aGlossRow.PreS,
												Subject = (aGlossRow.IsSubjectNull()) ? null : aGlossRow.Subject,
												X1 = (aGlossRow.IsX1Null()) ? null : aGlossRow.X1,
												X2 = (aGlossRow.IsX2Null()) ? null : aGlossRow.X2,
												Verb = (aGlossRow.IsVerbNull()) ? null : aGlossRow.Verb,
												PostS = (aGlossRow.IsPostSNull()) ? null : aGlossRow.PostS
											};
					}

					DiscourseChartDataClass.TransliterationRow[] theTRs = aClause.GetTransliterationRows();
					if (theTRs.Length > 0)
					{
						DiscourseChartDataClass.TransliterationRow aTransliterationRow = theTRs[0];
						gts.TransInfo = new GlossTranslationInfo
											{
												PreS = (aTransliterationRow.IsPreSNull()) ? null : aTransliterationRow.PreS,
												Subject = (aTransliterationRow.IsSubjectNull()) ? null : aTransliterationRow.Subject,
												X1 = (aTransliterationRow.IsX1Null()) ? null : aTransliterationRow.X1,
												X2 = (aTransliterationRow.IsX2Null()) ? null : aTransliterationRow.X2,
												Verb = (aTransliterationRow.IsVerbNull()) ? null : aTransliterationRow.Verb,
												PostS = (aTransliterationRow.IsPostSNull()) ? null : aTransliterationRow.PostS
											};
					}
				}

				// adjust the column indices
				if (file.DiscourseChartData.Count > 0)
				{
					DiscourseChartDataClass.DiscourseChartDataRow aDCDRow = file.DiscourseChartData[0];
					dataGridViewChart.Columns[6].DisplayIndex = aDCDRow.DisplayIndexPostS;
					dataGridViewChart.Columns[5].DisplayIndex = aDCDRow.DisplayIndexVerb;
					dataGridViewChart.Columns[4].DisplayIndex = aDCDRow.DisplayIndexX2;
					dataGridViewChart.Columns[3].DisplayIndex = aDCDRow.DisplayIndexX1;
					dataGridViewChart.Columns[2].DisplayIndex = aDCDRow.DisplayIndexSubject;
					dataGridViewChart.Columns[1].DisplayIndex = aDCDRow.DisplayIndexPreS;
					dataGridViewChart.Columns[0].DisplayIndex = aDCDRow.DisplayIndexRef;
				}

				saveFileDialog.FileName = strFilename;  // so we know what file to save later
			}
			else
			{
				Debug.Assert(false);
				string[] astrLines = File.ReadAllLines(strFilename, Encoding.UTF8);
				if (astrLines[0] != cstrHeader)
				{
					MessageBox.Show("This doesn't look like a file that I've written!", cstrCaption);
				}
				else
				{
					for (int i = 1; i < astrLines.Length; i++)
					{
						string strLine = astrLines[i];
						string[] astrWords = strLine.Split(new char[] { ',' });

						int nIndex = dataGridViewChart.Rows.Add();
						DataGridViewRow aRow = dataGridViewChart.Rows[nIndex];
						aRow.Height = m_fontVernacular.Height + CnExtraHeight;
						for (int j = 0, k = 0; j < astrWords.Length; j++, k++ )
						{
							string strWord = astrWords[j];
							if ((strWord != null) && (strWord.Length > 1))
							{
								while(strWord[strWord.Length - 1] != cDelim)
									// this means that this word had a comma in it
									//  (which mistakenly was tokenized away), so add the
									//  next word as well. (probably should count "s to make
									//  sure they're even
									strWord += ',' + astrWords[++j];

								// then strip off the delimiters
								Debug.Assert(strWord.Length > 2);
								strWord = strWord.Substring(1, strWord.Length - 2);

								// remove the extra double-quote(s) added
								int nQuoteIndex = 0;
								while ((nQuoteIndex = strWord.IndexOf('"', nQuoteIndex)) != -1)
									strWord = strWord.Remove(++nQuoteIndex, 1);
							}

							aRow.Cells[k].Value = strWord;
						}
					}
				}
			}

			AddFilenameToTitle(strFilename);
			m_bModified = false;
		}
Exemplo n.º 2
0
		private DiscourseChartDataClass GetDataSet(bool bSelectedOnly)
		{
			DiscourseChartDataClass file = new DiscourseChartDataClass();
			file.DiscourseChartData.AddDiscourseChartDataRow(
				dataGridViewChart.Columns[0].DisplayIndex,
				dataGridViewChart.Columns[1].DisplayIndex,
				dataGridViewChart.Columns[2].DisplayIndex,
				dataGridViewChart.Columns[3].DisplayIndex,
				dataGridViewChart.Columns[4].DisplayIndex,
				dataGridViewChart.Columns[5].DisplayIndex,
				dataGridViewChart.Columns[6].DisplayIndex);

			DiscourseChartDataClass.DiscourseChartDataRow aDCDRow = file.DiscourseChartData[0];
			DiscourseChartDataClass.FontsRow fonts = file.Fonts.AddFontsRow(aDCDRow);
			file.VernacularFont.AddVernacularFontRow(m_fontVernacular.Name, m_fontVernacular.Size, m_colorVernacular.Name, fonts);
			file.TransliterationFont.AddTransliterationFontRow(m_fontTransliteration.Name, m_fontTransliteration.Size, m_colorTransliteration.Name, fonts);
			file.GlossFont.AddGlossFontRow(m_fontGloss.Name, m_fontGloss.Size, m_colorGloss.Name, fonts);

			foreach (DataGridViewRow aRow in dataGridViewChart.Rows)
			{
				string strRef = (string)aRow.Cells[0].Value;
				if (String.IsNullOrEmpty(strRef) || (bSelectedOnly && !aRow.Selected))
					continue;
				Debug.Assert(aRow.Tag != null);
				GlossTranslations gts = (GlossTranslations)aRow.Tag;
				string strFreeTr = gts.FreeTranslation;
				DiscourseChartDataClass.DiscourseClauseRow aClause = file.DiscourseClause.AddDiscourseClauseRow(strRef, strFreeTr, aDCDRow);

				string strPreS = Trim((string)aRow.Cells[1].Value);
				string strSubj = Trim((string)aRow.Cells[2].Value);
				string strX1 = Trim((string)aRow.Cells[3].Value);
				string strX2 = Trim((string)aRow.Cells[4].Value);
				string strVerb = Trim((string)aRow.Cells[5].Value);
				string strPostV = Trim((string)aRow.Cells[6].Value);

				file.Vernacular.AddVernacularRow(strPreS, strSubj, strX1, strX2,
						strVerb, strPostV, aClause);

				if ((!bSelectedOnly || showTransToolStripMenuItem.Checked) && (GetTransliterator != null))
				{
					GlossTranslationInfo ti = gts.TransInfo;
					if (ti != null)
					{
						strPreS = ti.PreS;
						strSubj = ti.Subject;
						strX1 = ti.X1;
						strX2 = ti.X2;
						strVerb = ti.Verb;
						strPostV = ti.PostS;
					}
					else if (!String.IsNullOrEmpty(GetTransliterator.Name))
					{
						strPreS = Transliterate(strPreS);
						strSubj = Transliterate(strSubj);
						strX1 = Transliterate(strX1);
						strX2 = Transliterate(strX2);
						strVerb = Transliterate(strVerb);
						strPostV = Transliterate(strPostV);
					}

					file.Transliteration.AddTransliterationRow(strPreS, strSubj, strX1, strX2,
						strVerb, strPostV, aClause);
				}

				if ((!bSelectedOnly || showToolStripMenuItem.Checked) && (GetMeaningLookupConverter != null))
				{
					GlossTranslationInfo gi = gts.GlossInfo;
					if (gi != null)
					{
						strPreS = gi.PreS;
						strSubj = gi.Subject;
						strX1 = gi.X1;
						strX2 = gi.X2;
						strVerb = gi.Verb;
						strPostV = gi.PostS;
					}
					else if (!String.IsNullOrEmpty(GetMeaningLookupConverter.Name))
					{
						strPreS = Gloss(strPreS);
						strSubj = Gloss(strSubj);
						strX1 = Gloss(strX1);
						strX2 = Gloss(strX2);
						strVerb = Gloss(strVerb);
						strPostV = Gloss(strPostV);
					}

					file.Gloss.AddGlossRow(strPreS, strSubj, strX1, strX2,
						strVerb, strPostV, aClause);
				}
			}
			return file;
		}