///<summary> /// Called when an asynchronous operation finishes. ///</summary> void BitwiseOperationAsyncCallback(IAsyncResult ar) { BitwiseOperation state = (BitwiseOperation)ar.AsyncState; ThreadedAsyncOperation.OperationResult result = state.Result; // allow changes to the buffer state.Buffer.ModifyAllowed = true; state.Buffer.FileOperationsAllowed = true; switch (result) { case ThreadedAsyncOperation.OperationResult.Finished: break; case ThreadedAsyncOperation.OperationResult.Cancelled: state.Buffer.Undo(); break; case ThreadedAsyncOperation.OperationResult.CaughtException: break; default: break; } }
///<summary> /// Called when an asynchronous Find Next/Previous operation finishes. ///</summary> void FindAsyncCallback(IAsyncResult ar) { GenericFindOperation state = (GenericFindOperation)ar.AsyncState; ThreadedAsyncOperation.OperationResult result = state.Result; Range match = state.Match; DataView dv = null; // find DataView that owns bb foreach (DataViewDisplay dvtemp in dataBook.Children) { if (dvtemp.View.Buffer == strategy.Buffer) { dv = dvtemp.View; break; } } // decide what to do based on the result of the find operation switch (result) { case ThreadedAsyncOperation.OperationResult.Finished: if (match != null) { lastFound = match; dv.SetSelection(match.Start, match.End); //System.Console.WriteLine("Found at {0}-{1}", r.Start, r.End); dv.MoveCursor(match.End + 1, 0); dv.Display.MakeOffsetVisible(match.Start, DataViewDisplay.ShowType.Closest); } else { lastFound.Clear(); } break; case ThreadedAsyncOperation.OperationResult.Cancelled: dv.MoveCursor(strategy.Position, 0); dv.Display.MakeOffsetVisible(strategy.Position, DataViewDisplay.ShowType.Closest); break; case ThreadedAsyncOperation.OperationResult.CaughtException: break; default: break; } inUse = false; // if user provided a callback, call it now if (userFindAsyncCallback != null) { userFindAsyncCallback(ar); } // notify that the find operation has finished findFinishedEvent.Set(); }
///<summary> /// Called when an asynchronous Replace All operation finishes. ///</summary> void ReplaceAllAsyncCallback(IAsyncResult ar) { ReplaceAllOperation state = (ReplaceAllOperation)ar.AsyncState; ThreadedAsyncOperation.OperationResult result = state.Result; Range firstMatch = state.FirstMatch; DataView dv = null; // find DataView that owns bb foreach (DataViewDisplay dvtemp in dataBook.Children) { if (dvtemp.View.Buffer == strategy.Buffer) { dv = dvtemp.View; break; } } // decide what to do based on the result of the Replace All operation if (result == ThreadedAsyncOperation.OperationResult.Cancelled) { dv.Buffer.Undo(); } // if we have replaced at least one occurence, else if (result == ThreadedAsyncOperation.OperationResult.Finished && firstMatch != null) { lastFound = state.Match; // save the cursor state for undo/redo dv.CursorUndoDeque.AddFront(new CursorState(firstMatch.Start, 0, lastFound.Start + state.ReplacePattern.Length, 0)); // move cursor after final replacement dv.SetSelection(-1, -1); dv.MoveCursor(lastFound.Start + state.ReplacePattern.Length, 0); dv.Display.MakeOffsetVisible(lastFound.Start + state.ReplacePattern.Length, DataViewDisplay.ShowType.Closest); } inUse = false; // if user provided a callback, call it now if (userFindAsyncCallback != null) { userFindAsyncCallback(ar); } // notify that the replace all operation has finished findFinishedEvent.Set(); }