Example #1
0
		/// <summary>
		/// this constructor is used when the grid is passing a whole phrase worth of
		/// words (which is the cell's Value property). This ctor will first split it
		/// into words and if any of them are ambiguous, it will prompt for the correct
		/// value one-by-one. Then it will return the entire string with the selected
		/// ambiguities
		/// </summary>
		/// <param name="oPhrase"></param>
		public PickAmbiguity(object oPhrase, DirectableEncConverter aEC, Font fontSource, Font fontTarget)
		{
			InitializeComponent();
			m_fontSource = fontSource;
			m_fontTarget = fontTarget;

			if ((aEC != null) && (aEC.GetEncConverter.GetType() == typeof(AdaptItEncConverter)))
				m_aEC = (AdaptItEncConverter)aEC.GetEncConverter;

			if (oPhrase != null)
			{
				string strPhrase = (string)oPhrase;

				// first split it based on words:
				m_astrWords = new List<string>();
				string[] astrWords = strPhrase.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
				foreach (string strWord in astrWords)
					m_astrWords.Add(strWord);

				FixupListForPossibleMultiWordAmbiguity(ref m_astrWords);
			}

			if (AddToKb)
				Text = "Add to KB";
		}
Example #2
0
		public BaseConverterForm(DirectableEncConverter aEC, Font fontLhs, Font fontRhs, string strDocName)
		{
			InitializeComponent();

			m_aEC = aEC;
			this.textBoxInput.Font = fontLhs;
			this.textBoxConverted.Font = fontRhs;
			this.Text = String.Format("{0}: {1} -- {2}",
				FontsStylesForm.cstrCaption, strDocName, fontLhs.Name);
		}
		/// <summary>
		/// FontConvertersPicker: to choose the font you want to process in the Word document
		///
		/// This version of the constructor is for when you want the same (given) EncConverter
		/// used for all fonts.
		/// </summary>
		/// <param name="doc"></param>
		/// <param name="aEC"></param>
		public FontConvertersPicker(OfficeDocument doc, IEncConverter aEC)
		{
			System.Diagnostics.Debug.Assert(aEC != null);
			m_aECForAll = new DirectableEncConverter(aEC);
			m_strApplyEC = String.Format(cstrApplyECFormat, aEC.Name);
			CommonConstruct(doc);

			// no mapping in this mode
			converterMappingToolStripMenuItem.Visible = false;
		}
Example #4
0
		protected void UpdateConverterCellValue(DataGridViewCell theCell, DirectableEncConverter aEC)
		{
			if (aEC == null)
			{
				theCell.Value = (m_mapEncConverters.Count > 0) ? cstrDots : cstrClickMsg;
				theCell.ToolTipText = null;
			}
			else
			{
				string strName = aEC.Name;
				if (strName.Length > cnMaxConverterName)
					strName = strName.Substring(0, cnMaxConverterName);
				theCell.Value = strName;
				theCell.ToolTipText = aEC.ToString();
			}
		}
Example #5
0
        // [DispId(28)]
        public override string ToString()
        {
            // give something useful, for example, for a tooltip.
            string str = "Converter Details:";

            // indicate whether it's temporary or not
            if (!this.IsInRepository)
            {
                str = "Temporary " + str;
            }

            str += FormatTabbedTip("Name: '{0}'", Name);
            str += FormatTabbedTip("Identifier: '{0}'", ConverterIdentifier);
            str += FormatTabbedTip("Implementation Type: '{0}'", ImplementType);
            str += FormatTabbedTip("Conversion Type: '{0}'", ConversionType.ToString());
            if ((ProcessTypeFlags)ProcessType != ProcessTypeFlags.DontKnow)
            {
                str += FormatTabbedTip("Process Type: '{0}'", strProcessType(ProcessType));
            }
            if (!String.IsNullOrEmpty(LeftEncodingID))
            {
                str += FormatTabbedTip("Left side Encoding ID: '{0}'", LeftEncodingID);
            }
            if (!String.IsNullOrEmpty(RightEncodingID))
            {
                str += FormatTabbedTip("Right side Encoding ID: '{0}'", RightEncodingID);
            }

            // also include the current conversion option values
            str += String.Format("{0}{0}Current Conversion Options:", Environment.NewLine);
            str += FormatTabbedTip("Direction: '{0}'", (this.DirectionForward) ? "Forward" : "Reverse");
            str += FormatTabbedTip("Normalize Output: '{0}'", this.NormalizeOutput.ToString());
            str += FormatTabbedTip("Debug: '{0}'", this.Debug.ToString());

            DirectableEncConverter aDEC = new DirectableEncConverter(this);

            if (aDEC.IsLhsLegacy)
            {
                str += FormatTabbedTip("Input Code Page: '{0}'", aDEC.CodePageInput.ToString());
            }
            if (aDEC.IsRhsLegacy)
            {
                str += FormatTabbedTip("Output Code Page: '{0}'", aDEC.CodePageOutput.ToString());
            }
            return(str);
        }
Example #6
0
		protected void CheckForFontHelps(string strSfm, DirectableEncConverter aEC, DataGridViewRow theRow)
		{
			if (!mapName2FontExampleData.ContainsKey(strSfm) && !mapName2FontExampleResult.ContainsKey(strSfm))
			{
				EncConverters aECs = GetEncConverters;
				if (aECs != null)
				{
					string strLhsName, strRhsName;
					if (aECs.GetFontMappingFromMapping(aEC.Name, out strLhsName, out strRhsName))
					{
						bool bDirForward = aEC.GetEncConverter.DirectionForward;
						Font fontData = CreateFontSafe((bDirForward) ? strLhsName : strRhsName);
						AddDataFont(strSfm, fontData);
						AdjustRowHeight(theRow, theRow.Cells[cnExampleDataColumn], fontData);

						Font fontTarget = CreateFontSafe((bDirForward) ? strRhsName : strLhsName);
						AddTargetFont(strSfm, fontTarget);
						AdjustRowHeight(theRow, theRow.Cells[cnExampleOutputColumn], fontTarget);
					}
				}
			}
		}
Example #7
0
		private void buttonPreview_Click(object sender, EventArgs e)
		{
			string strPreviewButtonLabel = buttonPreview.Text;
			string strPreviewButtonLabelPostfix = null;
			if (strPreviewButtonLabel[strPreviewButtonLabel.Length - 1] == '>')
			{
				// open the data preview window
				textBoxDataPreview.Show();
				tableLayoutPanel1.RowCount = 5;
				strPreviewButtonLabelPostfix = "<<";

				// if there is a converter already selected...
				IEncConverter aEC = IEncConverter;
				if (aEC != null)
				{
					DirectableEncConverter aDEC = new DirectableEncConverter(aEC);
					UpdateDataPreview(aDEC);
				}
			}
			else
			{
				// close the data preview window
				textBoxDataPreview.Hide();
				tableLayoutPanel1.RowCount = 4;
				strPreviewButtonLabelPostfix = ">>";
			}

			buttonPreview.Text = strPreviewButtonLabel.Substring(0, strPreviewButtonLabel.Length - 2) + strPreviewButtonLabelPostfix;
		}
Example #8
0
		// [DispId(28)]
		public override string ToString()
		{
			// give something useful, for example, for a tooltip.
			string str = "Converter Details:";

			// indicate whether it's temporary or not
			if( !this.IsInRepository )
				str = "Temporary " + str;

			str += FormatTabbedTip("Name: '{0}'", Name);
			str += FormatTabbedTip("Identifier: '{0}'", ConverterIdentifier);
			str += FormatTabbedTip("Implementation Type: '{0}'", ImplementType);
			str += FormatTabbedTip("Conversion Type: '{0}'", ConversionType.ToString());
			if( (ProcessTypeFlags)ProcessType != ProcessTypeFlags.DontKnow )
				str += FormatTabbedTip("Process Type: '{0}'", strProcessType(ProcessType));
			if( !String.IsNullOrEmpty(LeftEncodingID) )
				str += FormatTabbedTip("Left side Encoding ID: '{0}'", LeftEncodingID);
			if( !String.IsNullOrEmpty(RightEncodingID) )
				str += FormatTabbedTip("Right side Encoding ID: '{0}'", RightEncodingID);

			// also include the current conversion option values
			str += String.Format("{0}{0}Current Conversion Options:", Environment.NewLine);
			str += FormatTabbedTip("Direction: '{0}'", (this.DirectionForward) ? "Forward" : "Reverse");
			str += FormatTabbedTip("Normalize Output: '{0}'", this.NormalizeOutput.ToString());
			str += FormatTabbedTip("Debug: '{0}'", this.Debug.ToString());

			DirectableEncConverter aDEC = new DirectableEncConverter(this);
			if (aDEC.IsLhsLegacy)
				str += FormatTabbedTip("Input Code Page: '{0}'", aDEC.CodePageInput.ToString());
			if (aDEC.IsRhsLegacy)
				str += FormatTabbedTip("Output Code Page: '{0}'", aDEC.CodePageOutput.ToString());
			return str;
		}
Example #9
0
		private void checkBoxReverse_CheckedChanged(object sender, EventArgs e)
		{
			IEncConverter aEC = IEncConverter;
			if (aEC != null)
			{
				DirectableEncConverter aDEC = new DirectableEncConverter(aEC);
				UpdateCodePageDetails(aDEC);
				UpdateDataPreview(aDEC);
			}
		}
Example #10
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 #11
0
		private void setDefaultConverterToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Cursor = Cursors.WaitCursor;

			EncConverters aECs = GetEncConverters;
			if (aECs != null)
			{
				IEncConverter aIEC = aECs.AutoSelectWithTitle(ConvType.Unknown, "Select Default Converter");
				if (aIEC != null)
				{
					DirectableEncConverter aEC = new DirectableEncConverter(aIEC);
					foreach (DataGridViewRow aRow in dataGridView.Rows)
					{
						string strFontStyle = (string)aRow.Cells[cnFontStyleColumn].Value;
						if (!IsConverterDefined(strFontStyle))
						{
							DefineConverter(strFontStyle, aEC);    // add it
							aRow.Cells[cnEncConverterColumn].Value = aEC.Name;
							aRow.Cells[cnEncConverterColumn].ToolTipText = aEC.ToString();
							string strInput = (string)aRow.Cells[cnExampleDataColumn].Value;
							aRow.Cells[cnExampleOutputColumn].Value = CallSafeConvert(aEC, strInput);
						}
					}

					// clear the last one selected so that a right-click can be used to cancel the selection
					m_aECLast = null;
				}
			}

			Cursor = Cursors.Default;
		}
Example #12
0
		private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
			int nColumnIndex = e.ColumnIndex;
			// if the user clicks on the header... that doesn't work
			if (((e.RowIndex < 0) || (e.RowIndex > dataGridView.Rows.Count))
				|| ((nColumnIndex < cnFontStyleColumn) || (nColumnIndex > cnTargetFontColumn)))
				return;

			DataGridViewRow theRow = this.dataGridView.Rows[e.RowIndex];
			string strFontStyleName = (string)theRow.Cells[cnFontStyleColumn].Value;
			DataGridViewCell theCell = theRow.Cells[e.ColumnIndex];
			DirectableEncConverter aEC = null;
			switch (nColumnIndex)
			{
				case cnExampleDataColumn:
					UpdateSampleValue(theRow);
					break;

				case cnEncConverterColumn:
					string strExampleData = (string)theRow.Cells[cnExampleDataColumn].Value;

					if (e.Button == MouseButtons.Right)
					{
						aEC = m_aECLast;
					}
					else
					{
						EncConverters aECs = GetEncConverters;
						if (aECs != null)
						{
							string strFontName = null;
							if (!radioButtonStylesOnly.Checked)
								strFontName = strFontStyleName;
							IEncConverter aIEC = aECs.AutoSelectWithData(strExampleData, strFontName, ConvType.Unknown, "Select Converter");
							if (aIEC != null)
								aEC = new DirectableEncConverter(aIEC);
						}
					}

					if (aEC != null)
					{
						DefineConverter(strFontStyleName, aEC);
					}
					else if (IsConverterDefined(strFontStyleName))
					{
						m_mapEncConverters.Remove(strFontStyleName);
					}

					UpdateExampleDataColumns(theRow, strExampleData);
					UpdateConverterCellValue(theCell, aEC);
					m_aECLast = aEC;
					break;

				case cnTargetFontColumn:
					Font font = null;
					if ((e.Button == MouseButtons.Right) && (m_aFontLast != null))
					{
						font = m_aFontLast;
					}
					else
					{
						fontDialog.Font = mapName2Font[strFontStyleName];
						if (fontDialog.ShowDialog() == DialogResult.OK)
						{
							m_aFontLast = font = fontDialog.Font;
						}
					}

					if (font != null)
					{
						if (mapName2Font.ContainsKey(strFontStyleName))
							mapName2Font.Remove(strFontStyleName);
						mapName2Font.Add(strFontStyleName, font);
						UpdateTargetFontCellValue(theRow, font);
					}
					break;
			}
		}
Example #13
0
		// allow these to be overidden by sub-class forms (e.g. to add a round-trip refresh as well)
		protected virtual void RefreshTextBoxes(DirectableEncConverter aEC)
		{
			ForwardString = aEC.Convert(InputString);
		}
Example #14
0
		protected void UpdateConverterCellValue(DataGridViewCell theCell, DirectableEncConverter aEC)
		{
			if (aEC == null)
			{
				theCell.Value = (selectProjectToolStripMenuItem.Checked) ? cstrCscClickMsg : cstrClickMsg;
				theCell.ToolTipText = null;
			}
			else
			{
				string strName = aEC.Name;
				if (strName.Length > cnMaxConverterName)
					strName = strName.Substring(0, cnMaxConverterName);
				theCell.Value = strName;
				theCell.ToolTipText = aEC.ToString();
			}
		}
Example #15
0
		protected string CallSafeConvert(DirectableEncConverter aDEC, string strPreviewData)
		{
			string strOutput = null;
			try
			{
				// this might throw up, so don't let it crash the program.
				strOutput = aDEC.Convert(strPreviewData);
			}
			catch (Exception ex)
			{
				MessageBox.Show(String.Format("Unable to convert data for preview because: '{0}'", ex.Message), EncConverters.cstrCaption);
			}
			return strOutput;
		}
Example #16
0
		protected void UpdateDataPreview(DirectableEncConverter aDEC)
		{
			// if we're doing preview (i.e. the preview pain in the fifth row of the table layout is visible)...
			if (tableLayoutPanel1.RowCount == 5)
			{
				// ... and if we're doing byte data (which could be UTF-8)
				string strPreviewData;
				if (m_byPreviewData != null)
				{
					EncodingForm eOrigForm = aDEC.GetEncConverter.EncodingIn;
					if (aDEC.IsLhsLegacy)
						aDEC.GetEncConverter.EncodingIn = EncodingForm.LegacyBytes;
					else
						aDEC.GetEncConverter.EncodingIn = EncodingForm.UTF8Bytes;

					strPreviewData = EncConverters.ByteArrToBytesString(m_byPreviewData);

					// this might throw up, so don't let it crash the program.
					textBoxDataPreview.Text = CallSafeConvert(aDEC, strPreviewData);

					aDEC.GetEncConverter.EncodingIn = eOrigForm;
				}
				else if (!String.IsNullOrEmpty(m_strPreviewData))
				{
					// ... otherwise, the user has already converted it (if legacy) to wide
					//  and we should just show her what she gets.
					textBoxDataPreview.Text = CallSafeConvert(aDEC, m_strPreviewData);
				}

				// if we weren't given a font name by the client, then let's see if the repository has a suggestion
				if (String.IsNullOrEmpty(m_strFontName))
				{
					string strLhsName, strRhsName;
					if (DirectableEncConverter.EncConverters.GetFontMappingFromMapping(aDEC.Name, out strLhsName, out strRhsName))
					{
						bool bDirForward = aDEC.GetEncConverter.DirectionForward;
						textBoxDataPreview.Font = CreateFontSafe((bDirForward) ? strRhsName : strLhsName);
					}
				}
			}
		}
Example #17
0
		private void dlgSelectConverter_FormClosing(object sender, FormClosingEventArgs e)
		{
			// before going away, set the CodePage values (so the caller will have them to use)
			IEncConverter aEC = IEncConverter;
			if (aEC != null)
			{
				try
				{
					DirectableEncConverter aDEC = new DirectableEncConverter(aEC);
					aDEC.CodePageInput = ProcessCodePage(textBoxCodePageInput.Text);
					aDEC.CodePageOutput = ProcessCodePage(textBoxCodePageOutput.Text);
				}
				catch
				{
					e.Cancel = true;
				}
			}
		}
Example #18
0
		protected string CallSafeConvert(DirectableEncConverter aEC, string strInput, bool bAllowAbort)
		{
			try
			{
				if (!String.IsNullOrEmpty(strInput))
				{
					// if the input side is legacy and the code page of the converter is not the same as the
					//  code page we opened the file with, then we'll be passing the wrong values...
					if (aEC.IsLhsLegacy)
					{
						IEncConverter aIEC = aEC.GetEncConverter;   // IsLhsLegacy will throw if GetEncConverter returns null
						if (aIEC.DirectionForward && (aIEC.CodePageInput != 0) && (aIEC.CodePageInput != m_encOpen.CodePage))
						{
							// we opened the SFM files with Encoding 0 == CP_ACP (or the default code page for this computer)
							//  but if the CodePageInput used by EncConverters is a different code page, then this will fail.
							//  If so, then convert it to a byte array and pass that
							byte[] abyInput = m_encOpen.GetBytes(strInput);
							strInput = ECNormalizeData.ByteArrToString(abyInput);
							aEC.GetEncConverter.EncodingIn = EncodingForm.LegacyBytes;
						}
					}

					string strOutput = aEC.Convert(strInput);
					aEC.GetEncConverter.EncodingIn = EncodingForm.Unspecified;  // in case the user switches directions

					// similarly, if the output is legacy, then if the code page used was not the same as the
					//  default code page, then we have to convert it so it'll produce the correct answer
					//  (this probably doesn't work for Legacy<>Legacy code pages)
					if (aEC.IsRhsLegacy)
					{
						IEncConverter aIEC = aEC.GetEncConverter;
						if (    (!aIEC.DirectionForward && (aIEC.CodePageInput != 0) && (Encoding.Default.CodePage != aIEC.CodePageInput))
							||  (aIEC.DirectionForward && (aIEC.CodePageOutput != 0) && (Encoding.Default.CodePage != aIEC.CodePageOutput)))
						{
							int nCP = (!aIEC.DirectionForward) ? aIEC.CodePageInput : aIEC.CodePageOutput;
							byte[] abyOutput = EncConverters.GetBytesFromEncoding(nCP, strOutput, true);
							strOutput = new string(Encoding.Default.GetChars(abyOutput));
						}
					}

					return strOutput;
				}
			}
			catch (Exception ex)
			{
				DialogResult res = MessageBox.Show(String.Format("Conversion failed! Reason: {0}", ex.Message),
					cstrCaption, (bAllowAbort) ? MessageBoxButtons.AbortRetryIgnore : MessageBoxButtons.OK);

				if (res == DialogResult.Abort)
					throw;
			}

			return strInput;
		}
Example #19
0
		private void textBoxCodePageOutput_TextChanged(object sender, EventArgs e)
		{
			if (m_bTurnOffTextChangedEvents)
				return;

			try
			{
				string strCodePage = textBoxCodePageInput.Text;
				if (strCodePage == "42")    // symbol code page
					strCodePage = "28591";  // use ISO 8859_1 instead

				int nCP = Convert.ToInt32(strCodePage);
				Encoding enc = Encoding.GetEncoding(nCP);

				// if either of the above don't throw an exception, then potentially recalculate the Data Preview
				IEncConverter aEC = IEncConverter;
				if (aEC != null)
				{
					DirectableEncConverter aDEC = new DirectableEncConverter(aEC);
					UpdateDataPreview(aDEC);
				}
			}
			catch
			{
			}
		}
Example #20
0
		private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
			// prevent the false click that occurs when the user chooses a menu item
			if ((DateTime.Now - m_dtStarted) < m_timeMinStartup)
				return;

			// if the user clicks on the header... that doesn't work
			if(     ((e.RowIndex < 0) || (e.RowIndex > dataGridView.Rows.Count))
				|| ((e.ColumnIndex < cnExampleDataColumn) || e.ColumnIndex > cnExampleOutputColumn))
				return;

			DataGridViewRow row = this.dataGridView.Rows[e.RowIndex];
			DataGridViewCell theCell = row.Cells[e.ColumnIndex];
			string strSfm = (string)row.Cells[cnSfmMarkerColumn].Value;
			switch (e.ColumnIndex)
			{
				case cnExampleOutputColumn:
					if (e.Button == MouseButtons.Right)
					{
						// if we didn't just set a font in the data column (in which case, we want
						//  the last font chosen to be the default), then get the font currently
						//  configured for the cell.
						if (!m_bLastFontSetWasDataColumn)
						{
							fontDialog.Font = theCell.Style.Font;
							m_bLastFontSetWasDataColumn = true;
						}

						if (fontDialog.ShowDialog() == DialogResult.OK)
						{
							AddTargetFont(strSfm, fontDialog.Font);
							AdjustRowHeight(row, theCell, fontDialog.Font);
						}
						else
						{
							ResetTargetFont(strSfm, theCell);
						}
					}
					/*  remove this or it'll be different behavior between the ExampleData and ExampleResults columns
					else if (e.Button == MouseButtons.Right)
					{
						if (m_aFontLast != null)
						{
							AddTargetFont(strSfm, m_aFontLast);
							AdjustRowHeight(row, m_aFontLast);
						}
						else
						{
							ResetTargetFont(strSfm, theCell);
						}
					}
					*/
					break;

				case cnExampleDataColumn: // clicked on example data column
					{
						if (e.Button == MouseButtons.Left)
						{
							string strTooltip;
							string strInput = FindNextDataSample(strSfm, (string)row.Cells[cnExampleDataColumn].Value, out strTooltip);
							row.Cells[cnExampleDataColumn].Value = strInput;
							string strOutput = strInput;
							if (IsConverterDefined(strSfm))
							{
								DirectableEncConverter aEC = GetConverter(strSfm);
								strOutput = CallSafeConvert(aEC, strInput, false);
							}
							row.Cells[cnExampleOutputColumn].Value = strOutput;

							// finally, adjust the tooltip as well to include the file and line numbers
							row.Cells[cnExampleDataColumn].ToolTipText = strTooltip;
						}
						else if (e.Button == MouseButtons.Right)
						{
							// if we just set a font in the data column, then get the font currently
							//  configured for the cell (because they don't likely want the *same* font as above)
							if (m_bLastFontSetWasDataColumn)
							{
								m_bLastFontSetWasDataColumn = false;
								fontDialog.Font = theCell.Style.Font;
							}

							// fontDialog.Font = theCell.Style.Font;
							if (fontDialog.ShowDialog() == DialogResult.OK)
							{
								AddDataFont(strSfm, fontDialog.Font);
								AdjustRowHeight(row, theCell, fontDialog.Font);
							}
							else
							{
								ResetDataFont(strSfm, theCell);
							}
						}
					}
					break;

				case cnEncConverterColumn: // clicked on the Converter column
					{
#if !TurnOffSpellFixer30
						if (selectProjectToolStripMenuItem.Checked)
						{
							System.Diagnostics.Debug.Assert(m_cscProject != null);
							if (cstrCscClickMsg == (string)theCell.Value)
							{
								IEncConverter aIEC = m_cscProject.SpellFixerEncConverter;
								if (aIEC != null)
								{
									DirectableEncConverter aEC = new DirectableEncConverter(aIEC);
									DefineConverter(strSfm, aEC);
									UpdateConverterCellValue(theCell, aEC);
								}
								else
								{
									DirectableEncConverter aEC = new DirectableEncConverter(m_cscProject.SpellFixerEncConverterName, true, NormalizeFlags.None);
									DefineConverter(strSfm, aEC);
									UpdateConverterCellValue(theCell, aEC);
									// theCell.Value = cstrCscFieldClickMsg;
								}
							}
							else
								theCell.Value = cstrCscClickMsg;

						}
						else
#endif
						{
							DirectableEncConverter aEC = null;

							// if the user right-clicked, then just repeat the last converter.
							//  (which now may be 'null' if cancelling an association)
							if (e.Button == MouseButtons.Right)
							{
								aEC = m_aECLast;
							}
							else
							{
								EncConverters aECs = GetEncConverters;
								if (aECs != null)
								{
									string strPreviewData = (string)row.Cells[cnExampleDataColumn].Value;
									IEncConverter aIEC = aECs.AutoSelectWithData(strPreviewData, null, ConvType.Unknown, "Choose Converter");
									if (aIEC != null)
										aEC = new DirectableEncConverter(aIEC);
								}
							}

							if (aEC != null)
							{
								DefineConverter(strSfm, aEC);
								UpdateConverterCellValue(row.Cells[cnEncConverterColumn], aEC);
								string strInput = (string)row.Cells[cnExampleDataColumn].Value;
								row.Cells[cnExampleOutputColumn].Value = CallSafeConvert(aEC, strInput, false);
								m_aECLast = aEC;
								CheckForFontHelps(strSfm, aEC, row);
							}
							else
							{
								// if the mapping was just removed (i.e. click + Cancel), then remove it
								//  from the list
								if (IsConverterDefined(strSfm))
									m_mapEncConverters.Remove(strSfm);

								UpdateConverterCellValue(row.Cells[cnEncConverterColumn], aEC);
								row.Cells[cnExampleOutputColumn].Value = row.Cells[cnExampleDataColumn].Value;
								m_aECLast = null;
								ResetDataFont(strSfm, row.Cells[cnExampleDataColumn]);
								ResetTargetFont(strSfm, row.Cells[cnExampleOutputColumn]);
							}

							if (m_mapEncConverters.Count > 0)
							{
								foreach (DataGridViewRow row2 in this.dataGridView.Rows)
								{
									DataGridViewCell cellConverter = row2.Cells[cnEncConverterColumn];
									if ((string)cellConverter.Value == cstrClickMsg)
									{
										cellConverter.Value = cstrDots;
										cellConverter.ToolTipText = null;
									}
								}
							}
						}
						break;
					}

				default:
					break;
			}
		}
Example #21
0
		protected void RevaluateButtonState()
		{
			int nIndex = this.listBoxExistingConverters.SelectedIndex;
			this.buttonPreview.Enabled = this.buttonOK.Enabled = (nIndex >= 0);

			// if it's exactly 1, then enable 'OK' and set the 'last selected' name.
			if( this.buttonOK.Enabled )
			{
				m_strConverterName = (string)listBoxExistingConverters.SelectedItem;
				if (DirectableEncConverter.EncConverters.ContainsKey(m_strConverterName))    // should exist, but sometimes, doesn't!
				{
					IEncConverter aEC = DirectableEncConverter.EncConverters[m_strConverterName];
					Debug.Assert(aEC != null);

					// enable the options
					this.checkBoxDebug.Enabled =
						this.labelNormalizationType.Enabled =
						this.radioButtonNone.Enabled =
						this.radioButtonFullyComposed.Enabled =
						this.radioButtonFullyDecomposed.Enabled = true;

					// the reverse box is only enabled if the converter is bi-directional
					this.checkBoxReverse.Enabled = !EncConverters.IsUnidirectional(aEC.ConversionType);

					// the check state is dependent on the converter configuration.
					this.checkBoxReverse.Checked = !aEC.DirectionForward;
					this.checkBoxDebug.Checked = aEC.Debug;
					switch(aEC.NormalizeOutput)
					{
						case NormalizeFlags.FullyComposed:
							this.radioButtonFullyComposed.Checked = true;
							break;
						case NormalizeFlags.FullyDecomposed:
							this.radioButtonFullyDecomposed.Checked = true;
							break;
						case NormalizeFlags.None:
						default:
							this.radioButtonNone.Checked = true;
							break;
					};

					// indicate the code pages we're going to use for legacy encodings so that the
					//  user can change it if needed.
					DirectableEncConverter aDEC = new DirectableEncConverter(aEC);
					UpdateCodePageDetails(aDEC);
					UpdateDataPreview(aDEC);
				}
			}
			else
			{
				m_strConverterName = null;
				this.checkBoxReverse.Enabled =
				this.checkBoxDebug.Enabled =
				this.labelNormalizationType.Enabled =
				this.radioButtonNone.Enabled =
				this.radioButtonFullyComposed.Enabled =
				this.radioButtonFullyDecomposed.Enabled =
				labelCodePageInput.Visible = textBoxCodePageInput.Visible =
				labelCodePageOutput.Visible = textBoxCodePageOutput.Visible = false;
			}
		}
Example #22
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;
		}
Example #23
0
		protected void UpdateCodePageDetails(DirectableEncConverter aDEC)
		{
			// indicate the code pages we're going to use for legacy encodings so that the
			//  user can change it if needed.
			m_bTurnOffTextChangedEvents = true;
			textBoxCodePageInput.Text = aDEC.CodePageInput.ToString();
			textBoxCodePageOutput.Text = aDEC.CodePageOutput.ToString();
			m_bTurnOffTextChangedEvents = false;

			// turn them all invisible to start with (so they get visiblized in the correct order)
			textBoxCodePageInput.Visible = labelCodePageInput.Visible =
				textBoxCodePageOutput.Visible = labelCodePageOutput.Visible = false;
			if (aDEC.IsLhsLegacy)
				textBoxCodePageInput.Visible = labelCodePageInput.Visible = true;
			if (aDEC.IsRhsLegacy)
				textBoxCodePageOutput.Visible = labelCodePageOutput.Visible = true;
		}
Example #24
0
		public void DefineConverter(string strFontStyleName, DirectableEncConverter aEC)
		{
			if (IsConverterDefined(strFontStyleName))
				m_mapEncConverters.Remove(strFontStyleName);
			m_mapEncConverters.Add(strFontStyleName, aEC);
		}
Example #25
0
		private void dataGridViewConverterMapping_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
			int nColumnIndex = e.ColumnIndex;
			// if the user clicks on the header... that doesn't work
			if (((e.RowIndex < 0) || (e.RowIndex > dataGridViewConverterMapping.Rows.Count))
				|| ((nColumnIndex < cnXmlPathsColumn) || (nColumnIndex > cnEncConverterColumn)))
				return;

			DataGridViewRow theRow = this.dataGridViewConverterMapping.Rows[e.RowIndex];
			string strXmlPath = (string)theRow.Cells[cnXmlPathsColumn].Value;
			DataGridViewCell theCell = theRow.Cells[e.ColumnIndex];
			DirectableEncConverter aEC = null;
			XPathNodeIterator xpIterator = null;
			switch (nColumnIndex)
			{
				case cnXmlPathsColumn:
					if (e.Button == MouseButtons.Right)
					{
						XPathFilterForm dlg = new XPathFilterForm(strXmlPath);
						if ((dlg.ShowDialog() == DialogResult.OK) && (strXmlPath != dlg.FilterExpression))
						{
							strXmlPath = dlg.FilterExpression;
							UpdateConverterCellValue(theRow.Cells[cnEncConverterColumn],
								(IsConverterDefined(strXmlPath)) ? (DirectableEncConverter)m_mapEncConverters[strXmlPath]
									: (DefaultConverterDefined) ? m_aEcDefault : null);

							theCell.Value = strXmlPath;
							Program.AddRecentXPathExpression(strXmlPath);
							try
							{
								xpIterator = GetIterator(ref strXmlPath, false);
								theRow.Tag = xpIterator;
								UpdateSampleValue(xpIterator, theRow);
							}
							catch (ApplicationException ex)
							{
								// we throw this to cancel
								if (ex.Message != cstrCaption)
									MessageBox.Show(ex.Message, cstrCaption);
							}
							catch (Exception ex)
							{
								MessageBox.Show(ex.Message, cstrCaption);
							}
						}
					}
					break;

				case cnExampleDataColumn:
					xpIterator = (XPathNodeIterator)theRow.Tag;
					UpdateSampleValue(xpIterator, theRow);
					break;

				case cnExampleOutputColumn:
					break;

				case cnEncConverterColumn:
					string strExampleData = (string)theRow.Cells[cnExampleDataColumn].Value;

					if (e.Button == MouseButtons.Right)
					{
						aEC = m_aECLast;
						if ((m_aECLast == null) && IsConverterDefined(strXmlPath))
							m_mapEncConverters.Remove(strXmlPath);
					}
					else
					{
						EncConverters aECs = GetEncConverters;
						if (aECs != null)
						{
							IEncConverter aIEC = aECs.AutoSelectWithData(strExampleData, null, ConvType.Unknown, "Choose Converter");
							if (aIEC != null)
								aEC = new DirectableEncConverter(aIEC);
							else
							{
								CheckForFixedValue(theRow);
								return;
							}
						}
					}

					if (aEC != null)
					{
						if (IsConverterDefined(strXmlPath))
							m_mapEncConverters.Remove(strXmlPath);
						DefineConverter(strXmlPath, aEC);
					}

					UpdateExampleDataColumns(theRow, strExampleData);
					UpdateConverterCellValue(theCell, aEC);
					m_aECLast = aEC;
					break;
			}
		}
Example #26
0
		internal static void UpdateConverterCellValue(DataGridViewCell theCell, DirectableEncConverter aEC)
		{
			if (aEC == null)
			{
				theCell.Value = cstrClickMsg;
				theCell.ToolTipText = null;
			}
			else
			{
				string strName = aEC.Name;
				if (strName.Length > cnMaxConverterName)
					strName = strName.Substring(0, cnMaxConverterName);
				theCell.Value = strName;
				theCell.ToolTipText = aEC.ToString();
			}
		}
Example #27
0
		protected void CheckForFixedValue(DataGridViewRow theRow)
		{
			DialogResult res = MessageBox.Show("Do you want to specify a fixed value to be applied to all matching records (i.e. rather than using a converter from the system repository)?", cstrCaption, MessageBoxButtons.YesNoCancel);
			if (res == DialogResult.Yes)
			{
				string strSampleValue = (string)theRow.Cells[cnExampleDataColumn].Value;
				QueryFixedValueForm dlg = new QueryFixedValueForm(strSampleValue);
				if (dlg.ShowDialog() == DialogResult.OK)
				{
					string strXmlPath = (string)theRow.Cells[cnXmlPathsColumn].Value;
					DirectableEncConverter aEC = GetTempFixedValueConverter(dlg.FixedValue);
					if (aEC != null)
					{
						if (IsConverterDefined(strXmlPath))
							m_mapEncConverters.Remove(strXmlPath);
						DefineConverter(strXmlPath, aEC);
						UpdateConverterCellValue(theRow.Cells[cnEncConverterColumn], aEC);
						UpdateExampleDataColumns(theRow, strSampleValue);
						m_aECLast = aEC;
					}
				}
			}
		}
Example #28
0
		protected string CallSafeConvert(DirectableEncConverter aEC, string strInput)
		{
			try
			{
				return aEC.Convert(strInput);
			}
			catch (Exception ex)
			{
				MessageBox.Show(String.Format("Conversion failed! Reason: {0}", ex.Message), cstrCaption);
			}

			return null;
		}
Example #29
0
		private void setDefaultConverterToolStripMenuItem_Click(object sender, EventArgs e)
		{
			m_aEcDefault = null;
			EncConverters aECs = GetEncConverters;
			if (aECs != null)
			{
				IEncConverter aIEC = aECs.AutoSelectWithTitle(ConvType.Unknown, "Choose Default Converter");
				if (aIEC != null)
				{
					m_aEcDefault = new DirectableEncConverter(aIEC);

					foreach (DataGridViewRow aRow in dataGridViewConverterMapping.Rows)
					{
						string strXmlPath = (string)aRow.Cells[cnXmlPathsColumn].Value;
						if (!IsConverterDefined(strXmlPath))
						{
							DataGridViewCell cellConverter = aRow.Cells[cnEncConverterColumn];
							cellConverter.Value = m_aEcDefault.Name;
							cellConverter.ToolTipText = m_aEcDefault.ToString();
							string strInput = (string)aRow.Cells[cnExampleDataColumn].Value;
							aRow.Cells[cnExampleOutputColumn].Value = CallSafeConvert(m_aEcDefault, strInput);
							DefineConverter(strXmlPath, m_aEcDefault);
						}
					}

					m_aECLast = null;
				}
			}
		}
		// override theses to add the Round-trip fields
		protected override void RefreshTextBoxes(DirectableEncConverter aEC)
		{
			base.RefreshTextBoxes(aEC);
			RoundTripString = aEC.ConvertDirectionOpposite(ForwardString);
		}
Example #31
0
		public void DefineConverter(string strXmlPath, DirectableEncConverter aEC)
		{
			if (m_mapEncConverters.ContainsKey(strXmlPath))
				throw new ApplicationException("You already have a converter defined for this XPath expression! (try again after you've processed this one)");
			m_mapEncConverters.Add(strXmlPath, aEC);
		}