/// ------------------------------------------------------------------------------------ /// <summary> /// Handle the Replace All button click event. /// </summary> /// ------------------------------------------------------------------------------------ protected void OnReplaceAll(object sender, System.EventArgs e) { if (DataUpdateMonitor.IsUpdateInProgress(DataAccess)) return; // discard event using (new DataUpdateMonitor(this, DataAccess, m_vwRootsite, "ReplaceAll", true, true)) { Debug.Assert(m_tool != null); int replaceCount = 0; using (new WaitCursor(this, true)) { m_tool.SetAppModalState(true); PrepareToFind(); m_inReplace = true; if (MatchNotFound == null) MatchNotFound += new MatchNotFoundHandler(NoMatchFound); try { using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_vwRootsite, "kstidUndoReplace", true)) { DateTime start = DateTime.Now; // Do the replace all SetupFindPattern(); SaveDialogValues(); if (PatternIsValid()) { m_searchKiller.AbortRequest = false; m_searchKiller.Control = this; // used for redrawing m_searchKiller.StopControl = this.btnClose; // need to know the stop button m_vwPattern.ReplaceWith = ReplaceText; int hvoRoot, frag; IVwViewConstructor vc; IVwStylesheet styleSheet; m_vwRootsite.RootBox.GetRootObject(out hvoRoot, out vc, out frag, out styleSheet); ReplaceAllCollectorEnv replaceAll = new ReplaceAllCollectorEnv(vc, DataAccess, hvoRoot, frag, m_vwPattern, m_searchKiller); replaceCount = replaceAll.ReplaceAll(); Debug.WriteLine("Replace all took " + (DateTime.Now - start)); } } } finally { PostpareToFind(replaceCount > 0); m_tool.SetAppModalState(false); m_inReplace = false; } } // Display a dialog box if the replace all finished or was stopped if (replaceCount > 0) { bool fShowMsg = true; string msg = ""; if (m_searchKiller.AbortRequest) // if it's been aborted, change the msg displayed msg = string.Format(FwCoreDlgs.kstidReplaceAllStopped, replaceCount); else msg = string.Format(FwCoreDlgs.kstidReplaceAllDone, replaceCount); if (MatchNotFound != null) fShowMsg = MatchNotFound(this, msg, MatchType.ReplaceAllFinished); if (fShowMsg) MessageBox.Show(Owner, msg, Application.ProductName); } else if (replaceCount == 0) InternalMatchNotFound(true); } // After a replace, focus the find box and select the text in it. fweditFindText.FocusAndSelectAll(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Postpares to find. /// </summary> /// <param name="fMakeCloseBtnSayClose">True to change the the close button to say /// "close", otherwise it will go back to whatever it was"</param> /// ------------------------------------------------------------------------------------ private void PostpareToFind(bool fMakeCloseBtnSayClose) { // Enable controls EnableControls(true); // Restore the close button btnClose.Text = (fMakeCloseBtnSayClose) ? FwCoreDlgs.kstidClose : (string)btnClose.Tag; btnClose.Click += new EventHandler(btnClose_Click); btnClose.Click -= new EventHandler(OnStop); MatchNotFound -= new MatchNotFoundHandler(NoMatchFound); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public DummyFwFindReplaceDlg() : base() { MatchNotFound += new MatchNotFoundHandler(OnMatchNotFound); }