private void regularExpressionHelpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // launch the ICU help
            string strCommandLine = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + @"\SIL\Help\ICU Regular Expression Plug-in About box.htm";

            OfficeApp.LaunchProgram(strCommandLine, null);
        }
 protected void ProcessButton(FormButtons eFormButton)
 {
     try
     {
         if (backgroundWorker.IsBusy)
         {
             throw new ApplicationException("Click the 'Stop' button to cancel the current search");
         }
         ProcessButtonEx(eFormButton);
     }
     catch (Exception ex)
     {
         OfficeApp.DisplayException(ex);
     }
 }
Exemplo n.º 3
0
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            Document.MoveFirst(); // to avoid an error on the first 'Edit'
            int nDontCare = 0;    // don't care

            while (!Document.EOF)
            {
                dao.Fields aFields = Document.Fields;
                dao.Field  aField  = aFields[m_strFieldName];
                if (aField.Value != System.DBNull.Value)
                {
                    AccessRange aWordRange = new AccessRange(aField, this);

                    try
                    {
                        if (!aWordProcessor.Process(aWordRange, ref nDontCare))
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        // this gets called whether we successfully process the word or not,
                        //  whether we're returning 'false' (in the try) or not, and whether we
                        //  have an exception or not... just exactly what we want, or MSAccess
                        //  process won't release when we exit.
                        OfficeApp.ReleaseComObject(aField);
                        OfficeApp.ReleaseComObject(aFields);
                    }
                }

                Document.MoveNext();
            }

            return(true);
        }
Exemplo n.º 4
0
        protected void DoWork(BackgroundWorker worker, OfficeDocument doc)
        {
            int nWordCount = doc.WordCount;

            /*
             * if (doc.GetType() == typeof(PubDocument))   // for publisher, we step when we've found a font
             * {
             *      progressBarFontsInUse.Maximum = nWordCount;
             *      progressBarFontsInUse.Step = 1;
             *      nWordCount = 0;
             * }
             */
            FontNamesInUseProcessor aDocumentProcess = new FontNamesInUseProcessor(nWordCount, worker);

            try
            {
                doc.ProcessWordByWord(aDocumentProcess);
            }
            catch (Exception ex)
            {
                OfficeApp.DisplayException(ex);
            }
        }
Exemplo n.º 5
0
        public DbFieldSelect(dao.TableDefs aTableDefs)
        {
            InitializeComponent();

            for (int i = 0; i < aTableDefs.Count; i++)
            {
                dao.TableDef aTable = aTableDefs[i];

                if (aTable.Attributes == 0)
                {
                    TreeNode   node    = this.treeViewTablesFields.Nodes.Add(aTable.Name);
                    dao.Fields aFields = aTable.Fields;
                    for (int j = 0; j < aFields.Count; j++)
                    {
                        dao.Field aField = aFields[j];
                        node.Nodes.Add(aField.Name);

                        OfficeApp.ReleaseComObject(aField); // needed or Access stays running after exit
                    }
                    OfficeApp.ReleaseComObject(aFields);
                }
                OfficeApp.ReleaseComObject(aTable);
            }
        }
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            bool bReplace  = (m_aWordByWordProcessor.FormButton == FormButtons.ReplaceOnce) || (m_aWordByWordProcessor.FormButton == FormButtons.ReplaceAll);
            bool bContinue = false;  // start again pessimistic

            if (e.Error != null)
            {
                OfficeApp.DisplayException(e.Error);
            }

            // if nothing was found in the search area, then see if they want to start over again
            else if (!e.Cancelled && !m_aWordByWordProcessor.IsFound)
            {
                bool   bSelection = (m_eSearchAreaType == SearchAreaType.eSelection);
                string strPrompt  = null;
                if (bSelection)
                {
                    if (bReplace)
                    {
                        strPrompt = "Finished searching the selection. {0} replacement{1} made. Would you like to search the rest of the document?";
                    }
                    else
                    {
                        strPrompt = "Finished searching the selection. Would you like to search the rest of the document?";
                    }
                }
                else if (m_doc.theRangeToSearch.Start == 0)  // otherwise, whole document
                {
                    if (bReplace)
                    {
                        strPrompt = String.Format("Finished searching the whole document. {0} replacement{1} made in all.",
                                                  m_aWordByWordProcessor.NumOfReplacements,
                                                  (m_aWordByWordProcessor.NumOfReplacements == 1) ? " was" : "s were");
                    }
                    else
                    {
                        strPrompt = "Finished searching the whole document. The search item was not found.";
                    }

                    MessageBox.Show(strPrompt, OfficeApp.cstrCaption, MessageBoxButtons.OK);

                    // reset the state so we start over if the user clicks it again.
                    m_doc.ResetPosition();
                    goto ExitRoutine;
                }
                else    // otherwise, rest of the document
                {
                    if (bReplace)
                    {
                        strPrompt = "Finished searching the rest of the document. {0} replacement{1} made. Would you like to continue searching at the beginning of the document?";
                    }
                    else
                    {
                        strPrompt = "Finished searching the rest of the document. Would you like to continue searching at the beginning of the document?";
                    }
                }

                if (bReplace)
                {
                    strPrompt = String.Format(strPrompt, m_aWordByWordProcessor.NumOfReplacements,
                                              (m_aWordByWordProcessor.NumOfReplacements == 1) ? " was" : "s were");
                }

                DialogResult res = MessageBox.Show(strPrompt, OfficeApp.cstrCaption, MessageBoxButtons.YesNoCancel);

                bool bReset = true; // most paths want us to reset.
                if (res == DialogResult.Cancel)
                {
                    this.Close();
                }
                else if (res == DialogResult.Yes)
                {
                    if (bSelection)
                    {
                        // start after where we just finished up (i.e. the end of the selection)
                        m_doc.SearchAreaStart = m_doc.theRangeToSearch.End + 1;
                        m_doc.ChangeToRestOfDocument(ref m_doc.theRangeToSearch, out m_eSearchAreaType);
                        bReset = false;
                    }
                    else    // doing ReplaceAll from beginning
                    {
                        // make the end of the search go up to the beginning of the original search
                        //  (if a) selection, b) rest, and c) beginning, then rangeToSearch.Start will
                        //  be the beginnin go of the selection (which is what we want).
                        m_doc.theRangeToSearch.End   = m_doc.theRangeToSearch.Start;
                        m_doc.theRangeToSearch.Start = 0;
                    }

                    bContinue = true;
                }

                if (bReset)
                {
                    m_doc.ResetPosition();
                }
            }

            // do it again!
            if (bContinue)
            {
                CallWorkerBee();
                return;
            }

ExitRoutine:
            this.buttonCancel.Text = cstrClose;
            progressBar.Visible    = false;
            m_doc.Document.Application.System.Cursor = Microsoft.Office.Interop.Word.WdCursorType.wdCursorNormal;
        }