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;
                }
            }
        }
        /// <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";
            }
        }
        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;
                    }
                }
            }
        }
Esempio n. 4
0
        private void setDefaultConverterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EncConverters aECs = OfficeApp.GetEncConverters;

            if (aECs != null)
            {
                IEncConverter aIEC = aECs.AutoSelectWithTitle(ConvType.Unknown, "Select Default Converter");
                if (aIEC != null)
                {
                    DirectableEncConverter aEC = new DirectableEncConverter(aIEC.Name, aIEC.DirectionForward, aIEC.NormalizeOutput);
                    foreach (DataGridViewRow aRow in dataGridViewFontsConverters.Rows)
                    {
                        string strFontName = (string)aRow.Cells[nColumnFontNames].Value;
                        if (!m_mapEncConverters.ContainsKey(strFontName))
                        {
                            m_mapEncConverters.Add(strFontName, aEC);                                // add it
                            DataGridViewCell cellConverter = aRow.Cells[nColumnConverterNames];
                            cellConverter.Value       = aEC.Name;
                            cellConverter.ToolTipText = aEC.ToString();
                        }
                    }

                    // clear the last one selected so that a right-click can be used to cancel the selection
                    m_aECLast = null;
                }
            }
        }
Esempio n. 5
0
        public virtual FormButtons Show
        (
            string strInput,
            string strOutput,
            DirectableEncConverter aEC,
            Font fontLhs,
            Font fontRhs,
            string strSFM,
            string strDocName,
            bool bShowErrorWarning
        )
        {
            m_aEC = aEC;
            this.textBoxInput.Font     = fontLhs;
            this.textBoxConverted.Font = fontRhs;
            this.Text = String.Format("{3}{0}: '{1}' field in {2}",
                                      SCConvForm.cstrCaption, strSFM, strDocName,
                                      (bShowErrorWarning) ? "Potential error detected: " : null);

            InputString   = strInput;
            ForwardString = strOutput;

            UpdateLhsUniCodes(InputString, this.labelInputCodePoints);
            UpdateRhsUniCodes(ForwardString, this.labelForwardCodePoints);

            ShowDialog();

            return(ButtonPressed);
        }
 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);
 }
Esempio n. 7
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);
        }
Esempio n. 8
0
        /// <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;
        }
Esempio n. 9
0
        /// <summary>
        /// FontConverter constructor for when we know the font name, but not
        /// the EncConverter to use (this triggers the IEC.AutoSelect method).
        /// </summary>
        /// <param name="strFontName"></param>
        public FontConverter(string strFontName)
        {
            m_font = CreateFontSafe(strFontName);
            string        strTitle = String.Format("Select Converter for '{0}' font", strFontName);
            EncConverters aECs     = OfficeApp.GetEncConverters;

            if (aECs != null)
            {
                m_aEC = new DirectableEncConverter(aECs.AutoSelectWithTitle(ConvType.Unknown, strTitle));
            }
        }
        protected void UpdateExampleDataColumns(DataGridViewRow theRow, string strSampleValue)
        {
            theRow.Cells[cnExampleDataColumn].Value = strSampleValue;
            string strXmlPath = (string)theRow.Cells[cnXmlPathsColumn].Value;

            if (!String.IsNullOrEmpty(strSampleValue) && IsConverterDefined(strXmlPath))
            {
                DirectableEncConverter aEC = (DirectableEncConverter)m_mapEncConverters[strXmlPath];
                strSampleValue = CallSafeConvert(aEC, strSampleValue);
            }
            theRow.Cells[cnExampleOutputColumn].Value = strSampleValue;
        }
        protected void InitConverterDetails(string strXmlPath, out string strConverterName, out string strTooltip)
        {
            strConverterName = (m_mapEncConverters.Count > 0) ? cstrDots : cstrClickMsg;
            strTooltip       = null;

            if (IsConverterDefined(strXmlPath))
            {
                DirectableEncConverter aEC = (DirectableEncConverter)m_mapEncConverters[strXmlPath];
                strConverterName = aEC.Name;
                strTooltip       = aEC.ToString();
            }
        }
        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);
        }
Esempio n. 13
0
        protected void InitConverterDetails(string strFontName, out string strConverterName, out string strTooltip, out string strFontNameOutput)
        {
            strConverterName  = (UsingSameEncConverter) ? m_strApplyEC : cstrClickMsg;
            strTooltip        = strConverterName;
            strFontNameOutput = (UsingSameEncConverter) ? strFontName : cstrFontClickMsg;

            // if there is no converted selected, then see if the repository has a suggestion
            if (!m_mapEncConverters.ContainsKey(strFontName) && (strConverterName == cstrClickMsg))
            {
                EncConverters aECs = OfficeApp.GetEncConverters;
                if (aECs != null)
                {
                    string strMappingName = aECs.GetMappingNameFromFont(strFontName);
                    if (!String.IsNullOrEmpty(strMappingName))
                    {
                        strConverterName = strMappingName;
                        IEncConverter aIEC = aECs[strConverterName];

                        if (aIEC != null)
                        {
                            DirectableEncConverter aEC = new DirectableEncConverter(aIEC);
                            m_mapEncConverters.Add(strFontName, aEC);
                        }
                    }
                }
            }

            if (m_mapEncConverters.ContainsKey(strFontName))
            {
                DirectableEncConverter aEC = (DirectableEncConverter)m_mapEncConverters[strFontName];
                strConverterName = aEC.Name;
                strTooltip       = aEC.ToString();
                if (aEC.TargetFont != null)
                {
                    strFontNameOutput = aEC.TargetFont.Name;
                }
                else                 // otherwise, the repository might be able to tell us what font to use
                {
                    EncConverters aECs = OfficeApp.GetEncConverters;
                    if (aECs != null)
                    {
                        string[] astrFontnames = aECs.GetFontMapping(aEC.Name, strFontName);
                        if (astrFontnames.Length > 0)
                        {
                            strFontNameOutput = astrFontnames[0];
                            aEC.TargetFont    = new Font(strFontNameOutput, 14);
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        public VerseBtControl(StoryEditor theSE, LineFlowLayoutPanel parentFlowLayoutPanel,
                              VerseData dataVerse, int nVerseNumber)
            : base(theSE.theCurrentStory.ProjStage, nVerseNumber, theSE,
                   parentFlowLayoutPanel)
        {
            _verseData = dataVerse;
            InitializeComponent();

            tableLayoutPanel.Controls.Add(labelReference, 0, 0);
            tableLayoutPanel.Controls.Add(buttonDragDropHandle, 1, 0);
            labelReference.Text = CstrVerseName + VerseNumber;

            if (theSE.viewTransliterationVernacular.Checked &&
                !String.IsNullOrEmpty(theSE.LoggedOnMember.TransliteratorVernacular))
            {
                if (TransliteratorVernacular == null)
                {
                    TransliteratorVernacular = new DirectableEncConverter(theSE.LoggedOnMember.TransliteratorVernacular,
                                                                          theSE.LoggedOnMember.
                                                                          TransliteratorDirectionForwardVernacular,
                                                                          NormalizeFlags.None);
                }
            }
            else
            {
                TransliteratorVernacular = null;                  // in case it was set from before
            }
            if (theSE.viewTransliterationNationalBT.Checked &&
                !String.IsNullOrEmpty(theSE.LoggedOnMember.TransliteratorNationalBT))
            {
                if (TransliteratorNationalBT == null)
                {
                    TransliteratorNationalBT = new DirectableEncConverter(theSE.LoggedOnMember.TransliteratorNationalBT,
                                                                          theSE.LoggedOnMember.
                                                                          TransliteratorDirectionForwardNationalBT,
                                                                          NormalizeFlags.None);
                }
            }
            else
            {
                TransliteratorNationalBT = null;
            }

            InitControls(theSE);
        }
        private void buttonDebug_Click(object sender, EventArgs e)
        {
            DirectableEncConverter aEC = m_aFontPlusEC.DirectableEncConverter;

            if (aEC != null)
            {
                IEncConverter aIEC = aEC.GetEncConverter;
                if (aIEC != null)
                {
                    bool bOrigValue = aIEC.Debug;
                    aIEC.Debug = true;

                    RefreshTextBoxes(aEC);

                    aIEC.Debug = bOrigValue;
                }
            }
        }
 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();
     }
 }
Esempio n. 17
0
 /// <summary>
 /// FontConverter constructor for when you know both the font and EncConverter to use
 /// </summary>
 public FontConverter(string strFontName, DirectableEncConverter aEC)
 {
     m_font = CreateFontSafe(strFontName);
     m_aEC  = aEC;
 }
Esempio n. 18
0
 /*
  * /// <summary>
  * /// FontConverter constructor for when you know the SpellingFixer30 project to use,
  * /// (which includes the EncConverter and the Font associated with the project.
  * /// </summary>
  * /// <param name="aSF"></param>
  #if !Csc30
  * public FontConverter(SpellingFixer aSF)
  #else
  * public FontConverter(SpellingFixerEC aSF)
  #endif
  * {
  *      m_aEC = new DirectableEncConverter(aSF.SpellFixerEncConverter);
  *      m_font = aSF.ProjectFont;
  * }
  */
 /// <summary>
 /// FontConverter constructor for when you know the EncConverter to use, and it
 /// works for all fonts (i.e. without prompting the user)
 /// </summary>
 /// <param name="aEC"></param>
 public FontConverter(DirectableEncConverter aEC)
 {
     m_aEC = aEC;
 }
Esempio n. 19
0
        private void dataGridViewFontsConverters_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 > dataGridViewFontsConverters.Rows.Count)) ||
                ((nColumnIndex < nColumnConverterNames) || (nColumnIndex > nColumnTargetFontNames)))
            {
                return;
            }

            DataGridViewRow        row         = this.dataGridViewFontsConverters.Rows[e.RowIndex];
            string                 strFontname = (string)row.Cells[nColumnFontNames].Value;
            DirectableEncConverter aEC         = null;

            // don't allow the font to be configured before the converter
            if (!m_mapEncConverters.ContainsKey(strFontname))
            {
                nColumnIndex = nColumnConverterNames;
            }

            switch (nColumnIndex)
            {
            case nColumnConverterNames:
                // if the user right-clicked, then just repeat the last converter.
                //  (which now may be 'null' if cancelling an association)
                if (UsingSameEncConverter)
                {
                    if (e.Button == MouseButtons.Right)
                    {
                        if (m_mapEncConverters.ContainsKey(strFontname))
                        {
                            m_mapEncConverters.Remove(strFontname);
                        }
                    }
                    else
                    {
                        aEC = m_aECForAll;
                    }
                }
                else
                {
                    if (e.Button == MouseButtons.Right)
                    {
                        aEC = m_aECLast;
                        if ((m_aECLast == null) && m_mapEncConverters.ContainsKey(strFontname))
                        {
                            m_mapEncConverters.Remove(strFontname);
                        }
                    }
                    else
                    {
                        EncConverters aECs = OfficeApp.GetEncConverters;
                        if (aECs != null)
                        {
                            IEncConverter aIEC = aECs.AutoSelectWithTitle(ConvType.Unknown, "Select Converter");

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

                if (aEC != null)
                {
                    if (m_mapEncConverters.ContainsKey(strFontname))
                    {
                        m_mapEncConverters.Remove(strFontname);
                    }
                    m_mapEncConverters.Add(strFontname, aEC);
                }

                string strConverterName, strTooltip, strFontNameOutput;
                InitConverterDetails(strFontname, out strConverterName, out strTooltip, out strFontNameOutput);

                DataGridViewCell cellConverter = row.Cells[nColumnConverterNames];
                cellConverter.Value       = strConverterName;
                cellConverter.ToolTipText = strTooltip;
                row.Cells[nColumnTargetFontNames].Value = strFontNameOutput;
                m_aECLast = aEC;

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

            case nColumnTargetFontNames:
                System.Diagnostics.Debug.Assert(m_mapEncConverters[strFontname] != null);
                aEC = (DirectableEncConverter)m_mapEncConverters[strFontname];
                if (fontTargetDialog.ShowDialog() == DialogResult.OK)
                {
                    aEC.TargetFont = fontTargetDialog.Font;
                    row.Cells[nColumnTargetFontNames].Value = fontTargetDialog.Font.Name;
                }
                break;
            }
        }
Esempio n. 20
0
 // override theses to add the Round-trip fields
 protected override void RefreshTextBoxes(DirectableEncConverter aEC)
 {
     base.RefreshTextBoxes(aEC);
     RoundTripString = aEC.ConvertDirectionOpposite(ForwardString);
 }
Esempio n. 21
0
        public void ProcessAndSave(bool bShowUI, string strOutputFileSpec)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                bool bModified = Program.Modified;
                int  nIndex    = 0;
                while (nIndex < dataGridViewConverterMapping.Rows.Count)
                {
                    DataGridViewRow        aRow       = dataGridViewConverterMapping.Rows[nIndex];
                    string                 strXmlPath = (string)aRow.Cells[cnXmlPathsColumn].Value;
                    DirectableEncConverter aEC        = (DirectableEncConverter)m_mapEncConverters[strXmlPath];
                    if (aEC == null)
                    {
                        nIndex++;
                        continue;
                    }

                    XPathNavigator    navigator  = m_doc.CreateNavigator();
                    XPathNodeIterator xpIterator = null;
                    if (IsNamespaceRequired)
                    {
                        XmlNamespaceManager manager;
                        GetNamespaceManager(navigator, out manager);
                        xpIterator = navigator.Select(strXmlPath, manager);
                    }
                    else
                    {
                        xpIterator = navigator.Select(strXmlPath);
                    }

                    System.Diagnostics.Trace.WriteLine(String.Format("Selected: {0} records", xpIterator.Count));
                    while (xpIterator.MoveNext())
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("Position: {0} Count: {1}", xpIterator.CurrentPosition, xpIterator.Count));
                        string strInput  = xpIterator.Current.Value;
                        string strOutput = CallSafeConvert(aEC, strInput);
                        if (bShowUI)
                        {
                            textBoxInput.Text  = strInput;
                            textBoxOutput.Text = strOutput;
                            Application.DoEvents();
                        }
                        bModified |= (strInput != strOutput);
                        xpIterator.Current.SetValue(strOutput);
                    }

                    dataGridViewConverterMapping.Rows.RemoveAt(nIndex);
                }

                // update in case Save is cancelled
                Program.Modified = bModified;

                // reset this so we can do new versions
                m_mapEncConverters.Clear();

                bool bHaveOutputFilename = false;
                do
                {
                    if (String.IsNullOrEmpty(strOutputFileSpec))
                    {
                        System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(m_strFileSpec));
                        string strOutputFilenameOrig = String.Format(@"{0}{1}{2}{3}",
                                                                     GetDirEnsureFinalSlash(m_strFileSpec),
                                                                     Path.GetFileNameWithoutExtension(m_strFileSpec),
                                                                     cstrOutputFileAddn,
                                                                     Path.GetExtension(m_strFileSpec));

                        saveFileDialog.FileName = strOutputFilenameOrig;
                        DialogResult res = saveFileDialog.ShowDialog();
                        if (res == DialogResult.OK)
                        {
                            strOutputFileSpec   = saveFileDialog.FileName;
                            bHaveOutputFilename = true;
                        }
                        else
                        {
                            DialogResult dres = MessageBox.Show("The document has already been converted. If you cancel saving it now, that 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");
                            }
                        }
                    }
                } while (!bHaveOutputFilename);

                if (!Directory.Exists(Path.GetDirectoryName(strOutputFileSpec)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(strOutputFileSpec));
                }

                // if the user is insisting on saving it with the same name, then make a backup.
                if (m_strFileSpec == strOutputFileSpec)
                {
                    File.Copy(m_strFileSpec, m_strFileSpec + ".bak", true);
                }

                // Save the document to a file and auto-indent the output.
                XmlTextWriter writer = new XmlTextWriter(strOutputFileSpec, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                m_doc.Save(writer);
                m_strFileSpec    = strOutputFileSpec;
                Program.Modified = false;
                Program.AddFilenameToTitle(strOutputFileSpec);
            }
            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);
            }
            finally
            {
                textBoxInput.Text  = null;
                textBoxOutput.Text = null;
                Cursor             = Cursors.Default;
            }
        }
        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;
            }
        }
        public void LoadConverterMappingFile(string strFileSpec)
        {
            FileStream fs = new FileStream(strFileSpec, FileMode.Open);

            // Construct a SoapFormatter and use it
            // to serialize the data to the stream.
            try
            {
                SoapFormatter formatter = new SoapFormatter();
                Hashtable     map       = (Hashtable)formatter.Deserialize(fs);
                foreach (string strXPath in map.Keys)
                {
                    DirectableEncConverter aFileEc = (DirectableEncConverter)map[strXPath];

                    // see if this one is even valid anymore
                    if (aFileEc.GetEncConverter == null)
                    {
                        // there's one case we probably ought to handle: the user sets a temporary converter of the
                        //  fixed value flavor. (since we created it, we should recreated it).
                        if (aFileEc.Name.IndexOf(cstrFixedStringConverterPrefix) != -1)
                        {
                            aFileEc = GetTempFixedValueConverter(aFileEc.Name.Substring(cstrFixedStringConverterPrefix.Length));
                        }
                        else
                        {
                            MessageBox.Show(String.Format("The converter '{0}' is no longer available on this system... skipping", aFileEc.Name), XMLViewForm.cstrCaption);
                            continue;
                        }
                    }

                    if (IsConverterDefined(strXPath))
                    {
                        DirectableEncConverter aExistingEc = (DirectableEncConverter)m_mapEncConverters[strXPath];
                        if (aExistingEc.Name != aFileEc.Name)
                        {
                            DialogResult res = MessageBox.Show(String.Format("The XPath expression {0}{0}{1}{0}{0} is already defined to use the '{2}' converter. Would you like to replace this mapping with the one from the file (i.e. '{3}')?",
                                                                             Environment.NewLine, strXPath, aExistingEc.Name, aFileEc.Name), XMLViewForm.cstrCaption, MessageBoxButtons.YesNo);
                            if (res == DialogResult.Yes)
                            {
                                m_mapEncConverters.Remove(strXPath);
                                DefineConverter(strXPath, aFileEc);
                            }
                        }
                    }
                    else
                    {
                        DefineConverter(strXPath, (DirectableEncConverter)map[strXPath]);
                    }
                }

                ArrayList arLstXPaths = (ArrayList)formatter.Deserialize(fs);

                foreach (string strXPath in arLstXPaths)
                {
                    string            strXmlPath = strXPath;
                    XPathNodeIterator xpIterator = GetIterator(ref strXmlPath, false);
                    AddRow(strXPath, xpIterator);
                }

                UpdateConverterNames();
            }
            catch (SerializationException ex)
            {
                MessageBox.Show("Failed to open mapping file. Reason: " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, cstrCaption);
            }
            finally
            {
                fs.Close();
            }
        }
 // 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);
 }