Example #1
0
		protected string GetDataSample(XPathIterator xpIterator)
		{
			return xpIterator.CurrentValue;
		}
Example #2
0
		public int RowMaxHeight = 28;    // start with this

		protected void DisplayInGrid(string strName, XPathIterator xpIterator)
		{
			string strTextSample = GetDataSample(xpIterator);
			string strConverterName = cstrClickMsg;
			string strOutput = strTextSample;
			string strTooltip = cstrClickMsg;

			// if there's not already a mapping, see if the repository can help us
			if (!IsConverterDefined(strName))
			{
				EncConverters aECs = GetEncConverters;
				if (aECs != null)
				{
					string strMappingName = aECs.GetMappingNameFromFont(strName);
					if (!String.IsNullOrEmpty(strMappingName))
					{
						strConverterName = strMappingName;
						IEncConverter aIEC = aECs[strConverterName];

						if (aIEC != null)
						{
							DirectableEncConverter aEC = new DirectableEncConverter(aIEC);
							DefineConverter(strName, aEC);
						}
					}
				}
			}

			if (IsConverterDefined(strName))
			{
				DirectableEncConverter aEC = GetConverter(strName);
				strConverterName = aEC.Name;
				strOutput = CallSafeConvert(aEC, strTextSample);
				strTooltip = aEC.ToString();
			}

			if (!mapName2Font.ContainsKey(strName))
			{
				string strTargetFontName = strName;
				if (IsConverterDefined(strName))
				{
					EncConverters aECs = GetEncConverters;
					if (aECs != null)
					{
						DirectableEncConverter aEC = GetConverter(strName);
						string[] astrFontnames = aECs.GetFontMapping(aEC.Name, strName);
						if (astrFontnames.Length > 0)
						{
							strTargetFontName = astrFontnames[0];
						}
					}
				}

				Font font = CreateFontSafe(strTargetFontName);
				mapName2Font.Add(strName, font);
			}

			Font fontSource = CreateFontSafe(strName);
			Font fontTarget = mapName2Font[strName];

			string[] row = { strName, strTextSample, strConverterName, strOutput, fontTarget.Name };
			int nIndex = this.dataGridView.Rows.Add(row);
			DataGridViewRow thisRow = dataGridView.Rows[nIndex];
			thisRow.Cells[cnEncConverterColumn].ToolTipText = strTooltip;
			thisRow.Tag = xpIterator;
			thisRow.Cells[cnExampleDataColumn].Style.Font = fontSource;
			thisRow.Cells[cnExampleOutputColumn].Style.Font = fontTarget;
			thisRow.Height = RowMaxHeight;
		}
Example #3
0
		protected bool SetValues(XPathIterator xpIterator, string strFontStyleName,
			DirectableEncConverter aEC, Font fontLhs, Font fontRhs, bool bConvertCharValue)
		{
			BaseConverterForm dlg = null;
			if (SingleStep)
				dlg = new BaseConverterForm(aEC, fontLhs, fontRhs, m_strCurrentDocument);

			FormButtons res = FormButtons.Replace;  // default behavior
			bool bModified = false, bContinue = true;
			string strReplacementCharacter = (aEC.IsRhsLegacy) ? "?" : "\ufffd";
			do
			{
				string strInput = xpIterator.CurrentValue;
				string strOutput = CallSafeConvert(aEC, strInput);

				UpdateStatusBar(String.Format("In '{0}', converting: '{1}' to '{2}'",
					m_strCurrentDocument, strInput, strOutput));

				// if this string gets converted as a bunch of "?"s, it's probably an error. Show it to the
				//  user as a potential problem (unless we're already in single-step mode).
				bool bShowPotentialError = false;
				if (!SingleStep)
				{
					const double cfMinErrorDetectPercentage = 0.9;
					string strWithoutErrors = strOutput.Replace(strReplacementCharacter, "");
					if (strWithoutErrors.Length < (strOutput.Length * cfMinErrorDetectPercentage))
					{
						bShowPotentialError = true;
						if (dlg == null)
						{
							dlg = new BaseConverterForm(aEC, fontLhs, fontRhs, m_strCurrentDocument);
							dlg.Text = "Potential error detected: " + dlg.Text;
						}
					}
				}

				// show user this one
				if (    (   (res != FormButtons.ReplaceAll)
						&&  SingleStep
						&&  (!dlg.SkipIdenticalValues || (strInput != strOutput))
						)
					||  bShowPotentialError)
				{
					res = dlg.Show(strInput, strOutput);
					strOutput = dlg.ForwardString;  // just in case the user re-typed it
				}

				if ((res == FormButtons.Replace) || (res == FormButtons.ReplaceAll))
				{
					xpIterator.SetCurrentValue(strOutput);
					bModified = true;
				}
				else if (res == FormButtons.Cancel)
				{
					DialogResult dres = MessageBox.Show("If you have converted some of the document already, then cancelling now will leave your document in an unuseable state (unless you are doing 'spell fixing' or something which doesn't change the encoding). Click 'Yes' to confirm the cancellation or 'No' to continue with the conversion.", cstrCaption, MessageBoxButtons.YesNo);
					if (dres == DialogResult.Yes)
						throw new ApplicationException("User cancelled");
					continue;
				}
				else
				{
					System.Diagnostics.Debug.Assert(res == FormButtons.Next);
					res = FormButtons.Replace;  // reset for next time.
				}

				// don't put this in the while look in case the above 'continue' is executed (which will cause
				//  us to repeat the last word again)
				bContinue = xpIterator.MoveNext();

			} while (bContinue);

			return bModified;
		}