Esempio n. 1
0
        protected virtual FormButtons ConvertProcessing(OfficeRange aWordRange, FontConverter aThisFC, string strInput, ref int nCharIndex, ref string strReplace)
        {
            // here's the meat of the WordShowConversionDiffProcessor engine: only process
            //  the word if the input is different from the converted output
            string strOutput = aThisFC.DirectableEncConverter.Convert(strInput);

            FormButtons res = FormButtons.None;

            if (!Form.SkipIdenticalValues || (strInput != strOutput))
            {
                if (ReplaceAll)
                {
                    strReplace = strOutput;
                    res        = FormButtons.ReplaceAll;
                }
                else
                {
                    res = Form.Show(aThisFC, strInput, strOutput);

                    // just in case it's Replace or ReplaceAll, our replacement string is the 'Forward' conversion
                    strReplace = Form.ForwardString;
                }
            }

            return(res);
        }
Esempio n. 2
0
        protected override FormButtons ConvertProcessing(OfficeRange aWordRange, FontConverter aThisFC, string strInput, ref int nCharIndex, ref string strReplace)
        {
            // here's the meat of the RoundTripChecker engine: process the word both in the
            // forward and reverse directions and compare the 2nd output with the input
            string strOutput    = aThisFC.DirectableEncConverter.Convert(strInput);
            string strRoundtrip = aThisFC.DirectableEncConverter.ConvertDirectionOpposite(strOutput);

            // our 'form' is really a RoundTripProcessorForm (which has special methods/properties we need to call)
            RoundTripProcessorForm form = (RoundTripProcessorForm)Form;
            FormButtons            res  = FormButtons.None;

            if (!form.SkipIdenticalValues || (strInput != strRoundtrip))
            {
                if (ReplaceAll)
                {
                    strReplace = strRoundtrip;
                    res        = FormButtons.ReplaceAll;
                }
                else
                {
                    res = form.Show(aThisFC, strInput, strOutput, strRoundtrip);

                    // just in case it's Replace or ReplaceAll, our replacement string is the 'RoundTripString'
                    strReplace = form.RoundTripString;
                }
            }

            return(res);
        }
Esempio n. 3
0
        void SpellFixerWordByWord_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            if (!HookDocumentClose(Application.ActiveDocument))
            {
                return;
            }

            Application.System.Cursor = Word.WdCursorType.wdCursorWait;
            try
            {
                WordDocument doc = new WordDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);

                if (m_aWordByWordSpellFixerProcessor == null)
                {
                    SpellFixerProcessorForm form = new SpellFixerProcessorForm(GetSpellFixer);
                    FontConverter           aFC  = new FontConverter(GetSpellFixer);
                    m_aWordByWordSpellFixerProcessor = new OfficeDocumentProcessor(aFC, form);
                }

                if (doc.ProcessWordByWord(m_aWordByWordSpellFixerProcessor))
                {
                    m_aWordByWordSpellFixerProcessor = null;
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }
            Application.System.Cursor = Word.WdCursorType.wdCursorNormal;
        }
        public virtual FormButtons Show
        (
            FontConverter aFontPlusEC,
            string strInput,
            string strOutput
        )
        {
            m_aFontPlusEC = aFontPlusEC;

            if (m_aFontPlusEC.Font != null)
            {
                this.textBoxInput.Font = m_aFontPlusEC.Font;
            }

            if (m_aFontPlusEC.RhsFont != null)
            {
                this.textBoxConverted.Font = m_aFontPlusEC.RhsFont;
            }

            InputString   = strInput;
            ForwardString = strOutput;

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

            // get some info to show in the title bar
            this.Text = String.Format("{0}: {1}", OfficeApp.cstrCaption, m_aFontPlusEC.ToString());

            ShowDialog();

            return(ButtonPressed);
        }
Esempio n. 5
0
        void ConvertTableField_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            try
            {
                if (Application.Selection == null)
                {
                    throw new ApplicationException("First select the cells that you want to convert using a system converter");
                }

                ExcelDocument doc = new ExcelDocument(Application.Selection);
                if (m_aSelectionProcessor == null)
                {
                    string        strTitle = "Choose the converter for the selected areas/cells";
                    EncConverters aECs     = GetEncConverters;
                    if (aECs != null)
                    {
                        IEncConverter aIEC = aECs.AutoSelectWithTitle(ConvType.Unknown, strTitle);
                        FontConverter aFC  = new FontConverter(new DirectableEncConverter(aIEC));
                        m_aSelectionProcessor = new OfficeDocumentProcessor(aFC, new SILConverterProcessorForm());
                    }
                }

                if (m_aSelectionProcessor != null)
                {
                    if (doc.ProcessWordByWord(m_aSelectionProcessor))
                    {
                        m_aSelectionProcessor = null;
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }
        }
Esempio n. 6
0
        protected virtual FontConverter QueryForFontConvert(string strFontName)
        {
            FontConverter        aFC = null;
            FontConvertersPicker aFontConverterPicker = new FontConvertersPicker(strFontName);

            if (aFontConverterPicker.ShowDialog() == DialogResult.OK)
            {
                aFC = aFontConverterPicker.SelectedFontConverters[strFontName];
            }
            return(aFC);
        }
Esempio n. 7
0
        public virtual FormButtons Show
        (
            FontConverter aFontPlusEC,
            string strInput,
            string strOutput,
            string strRoundtrip
        )
        {
            m_aFontPlusEC   = aFontPlusEC;
            RoundTripString = strRoundtrip;

            if (m_aFontPlusEC.Font != null)
            {
                this.textBoxRoundTrip.Font = m_aFontPlusEC.Font;
            }

            UpdateLhsUniCodes(RoundTripString, this.labelRoundTripCodePoints);

            return(base.Show(aFontPlusEC, strInput, strOutput));
        }
Esempio n. 8
0
        protected FontConverter QueryUserForFontScan(string strFontName)
        {
            if ((strFontName == null) || (strFontName.Length == 0))
            {
                return(null);
            }

            // make sure our collection exists
            if (m_mapFontsEncountered == null)
            {
                m_mapFontsEncountered = new FontConverters();
            }

            if (!m_mapFontsEncountered.ContainsKey(strFontName))
            {
                DialogResult res = MessageBox.Show(String.Format("Do you want to convert words in the {0} font?", strFontName), OfficeApp.cstrCaption, MessageBoxButtons.YesNoCancel);

                FontConverter aFC = null;
                if (res == DialogResult.Cancel)
                {
                    throw new ApplicationException(OfficeApp.cstrAbortMessage);
                }
                if (res == DialogResult.Yes)
                {
                    aFC = QueryForFontConvert(strFontName);

                    /*
                     * FontConvertersPicker aFontConverterPicker = new FontConvertersPicker(strFontName);
                     * if( aFontConverterPicker.ShowDialog() == DialogResult.OK )
                     *  aFC = aFontConverterPicker.SelectedFontConverters[strFontName];
                     */
                    // aFC = new FontConverter(strFontName);
                }

                m_mapFontsEncountered.Add(strFontName, aFC);
            }

            return(m_mapFontsEncountered[strFontName]);
        }
Esempio n. 9
0
        public bool CompareInputOutputProcess(OfficeRange aWordRange, ref int nCharIndex)
        {
            FormButtons res = FormButtons.None;

            do
            {
                string strInput = aWordRange.Text;
                if (String.IsNullOrEmpty(strInput))
                {
                    return(true);
                }

                // not technically required, but this'll help users (but only for the font we're looking for.
                if (!SuspendUI)
                {
                    aWordRange.Select();
                }

                // did the caller give us a set of Fonts to scan?
                string        strFontName = aWordRange.FontName;
                FontConverter aThisFC     = null;
                if (m_aFC != null)
                {
                    aThisFC = m_aFC;
                }
                else if (m_aFCs != null)
                {
                    if (m_aFCs.ContainsKey(strFontName))
                    {
                        aThisFC = m_aFCs[strFontName];
                    }
                }
                else // otherwise, query the user directly
                {
                    aThisFC = QueryUserForFontScan(strFontName);
                }

                res = FormButtons.None;
                if (aThisFC == null)
                {
                    // not a font that we're processing
                    continue;
                }

                // see if we've already checked this word
                string strReplace = null;
                if (!m_mapCheckedInputStrings.TryGetValue(strInput, out strReplace))
                {
                    res = ConvertProcessing(aWordRange, aThisFC, strInput, ref nCharIndex, ref strReplace);

                    if (res == FormButtons.Cancel)
                    {
                        return(false);
                    }
                    else if ((res == FormButtons.ReplaceAll) || (res == FormButtons.ReplaceOnce) || (res == FormButtons.ReplaceEvery))
                    {
                        ReplaceAll |= (res == FormButtons.ReplaceAll);

                        // this means replace the word in situ, with what was converted
                        ReplaceText(aWordRange, aThisFC.DirectableEncConverter.TargetFont, ref nCharIndex, strReplace);

                        // keep track of this word so that if it comes up again, we'll replace it as is.
                        if (AutoReplaceOnNextFind || (res == FormButtons.ReplaceEvery))
                        {
                            m_mapCheckedInputStrings.Add(strInput, strReplace);
                        }
                    }
                    else if ((aThisFC.RhsFont != null) && (res != FormButtons.Next))
                    {
                        // even if the string doesn't change, if we have an output font, we have to set it.
                        SetRangeFont(aWordRange, aThisFC.RhsFont.Name);
                    }
                }
                else
                {
                    // this particular input string has already been approved for replacement
                    ReplaceText(aWordRange, aThisFC.DirectableEncConverter.TargetFont, ref nCharIndex, strReplace);
                }
            } while (res == FormButtons.Redo);

            return(true);
        }
Esempio n. 10
0
 /// <summary>
 /// This constructor is for when you have a single IEncConverter that is to be applied to
 /// all the data regardless of the font AND when you have your own form to use to display the
 /// differences.
 /// </summary>
 /// <param name="aFC"></param>
 /// <param name="form"></param>
 public OfficeDocumentProcessor(FontConverter aFC, BaseConverterForm form)
 {
     m_aFC   = aFC;
     Form    = form;
     Process = CompareInputOutputProcess;    // good default
 }
Esempio n. 11
0
        void ConvertTableFieldDialog_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
#endif
        {
#if DEBUG
            MessageBox.Show("ConvertTableFieldDialog_Click");
#endif
            dao.Database aDb = Application.CurrentDb();
            if (aDb == null)
            {
                return;
            }

            dao.TableDefs aTableDefs = null;
            dao.TableDef  aTableDef  = null;
            dao.Recordset aRecordSet = null;
            try
            {
                aTableDefs = aDb.TableDefs;
                DbFieldSelect dlg = new DbFieldSelect(aTableDefs);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    aTableDef  = aTableDefs[dlg.TableName];
                    aRecordSet = aTableDef.OpenRecordset(dao.RecordsetTypeEnum.dbOpenTable, 0);
                    // dao.RecordsetOptionEnum.);

                    if (!aRecordSet.Updatable)
                    {
                        throw new ApplicationException("Can't edit this table? Is it opened? If so, then close it and try again.");
                    }

                    string        strTitle = String.Format("Select the Converter for the {0}.{1} field", dlg.TableName, dlg.FieldName);
                    EncConverters aECs     = GetEncConverters;
                    if (aECs != null)
                    {
                        IEncConverter           aIEC            = aECs.AutoSelectWithTitle(ConvType.Unknown, strTitle);
                        FontConverter           aFC             = new FontConverter(new DirectableEncConverter(aIEC));
                        OfficeDocumentProcessor aTableProcessor = new OfficeDocumentProcessor(aFC, new SILConverterProcessorForm());
                        AccessDocument          rsDoc           = new AccessDocument(aRecordSet, dlg.FieldName);

                        // do a transaction just in case we throw an exception trying to update and the user
                        //  wants to rollback.
                        aDb.BeginTrans();
                        rsDoc.ProcessWordByWord(aTableProcessor);
                        aDb.CommitTrans((int)dao.CommitTransOptionsEnum.dbForceOSFlush);
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
                if (ex.Message != cstrAbortMessage)
                {
                    if (MessageBox.Show("Would you like to rollback the transaction?", OfficeApp.cstrCaption, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        aDb.Rollback();
                    }
                    else
                    {
                        aDb.CommitTrans((int)dao.CommitTransOptionsEnum.dbForceOSFlush);
                    }
                }
            }
            finally
            {
                if (aRecordSet != null)
                {
                    aRecordSet.Close();
                }
                ReleaseComObject(aRecordSet);
                ReleaseComObject(aTableDef);
                ReleaseComObject(aTableDefs);
                ReleaseComObject(aDb);
            }
        }