public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { DateTime lastUpdate = DateTime.Now; documentWorkspace.History.BeginStepGroup(); using (new WaitCursorChanger(documentWorkspace)) { documentWorkspace.SuspendToolCursorChanges(); while (documentWorkspace.History.UndoStack.Count > 1) { documentWorkspace.History.StepBackward(); if ((DateTime.Now - lastUpdate).TotalMilliseconds >= 500) { documentWorkspace.History.EndStepGroup(); documentWorkspace.Update(); lastUpdate = DateTime.Now; documentWorkspace.History.BeginStepGroup(); } } documentWorkspace.ResumeToolCursorChanges(); } documentWorkspace.History.EndStepGroup(); Utility.GCFullCollect(); documentWorkspace.Document.Invalidate(); documentWorkspace.Update(); return(null); }
public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { DateTime lastUpdate = DateTime.Now; documentWorkspace.History.BeginStepGroup(); using (new WaitCursorChanger(documentWorkspace)) { documentWorkspace.SuspendToolCursorChanges(); while (documentWorkspace.History.RedoStack.Count > 0) { documentWorkspace.History.StepForward(); if ((DateTime.Now - lastUpdate).TotalMilliseconds >= 500) { documentWorkspace.History.EndStepGroup(); documentWorkspace.Update(); lastUpdate = DateTime.Now; documentWorkspace.History.BeginStepGroup(); } } documentWorkspace.ResumeToolCursorChanges(); } documentWorkspace.History.EndStepGroup(); Utility.GCFullCollect(); documentWorkspace.Document.Invalidate(); documentWorkspace.Update(); return null; }
public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { if (!ScanningAndPrinting.CanPrint) { Utility.ShowWiaError(documentWorkspace); return null; } using (new PushNullToolMode(documentWorkspace)) { // render image to a bitmap, save it to disk Surface scratch = documentWorkspace.BorrowScratchSurface(this.GetType().Name + ".PerformAction()"); try { scratch.Clear(); RenderArgs ra = new RenderArgs(scratch); documentWorkspace.Update(); using (new WaitCursorChanger(documentWorkspace)) { ra.Surface.Clear(ColorBgra.White); documentWorkspace.Document.Render(ra, false); } string tempName = Path.GetTempFileName() + ".bmp"; ra.Bitmap.Save(tempName, ImageFormat.Bmp); try { ScanningAndPrinting.Print(documentWorkspace, tempName); } catch (Exception ex) { Utility.ShowWiaError(documentWorkspace); Tracing.Ping(ex.ToString()); // TODO: do a "better" error dialog here } // Try to delete the temp file but don't worry if we can't bool result = FileSystem.TryDeleteFile(tempName); } finally { documentWorkspace.ReturnScratchSurface(scratch); } } return null; }
public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { if (!ScanningAndPrinting.CanPrint) { Utility.ShowWiaError(documentWorkspace); return(null); } using (new PushNullToolMode(documentWorkspace)) { // render image to a bitmap, save it to disk Surface scratch = documentWorkspace.BorrowScratchSurface(this.GetType().Name + ".PerformAction()"); try { scratch.Clear(); RenderArgs ra = new RenderArgs(scratch); documentWorkspace.Update(); using (new WaitCursorChanger(documentWorkspace)) { ra.Surface.Clear(ColorBgra.White); documentWorkspace.Document.Render(ra, false); } string tempName = Path.GetTempFileName() + ".bmp"; ra.Bitmap.Save(tempName, ImageFormat.Bmp); try { ScanningAndPrinting.Print(documentWorkspace, tempName); } catch (Exception ex) { Utility.ShowWiaError(documentWorkspace); Tracing.Ping(ex.ToString()); // TODO: do a "better" error dialog here } // Try to delete the temp file but don't worry if we can't bool result = FileSystem.TryDeleteFile(tempName); } finally { documentWorkspace.ReturnScratchSurface(scratch); } } return(null); }
public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { if (documentWorkspace.History.RedoStack.Count > 0) { if (!(documentWorkspace.History.RedoStack[documentWorkspace.History.RedoStack.Count - 1] is NullHistoryMemento)) { using (new WaitCursorChanger(documentWorkspace.FindForm())) { documentWorkspace.History.StepForward(); documentWorkspace.Update(); } } Utility.GCFullCollect(); } return null; }
public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { if (documentWorkspace.History.UndoStack.Count > 0) { if (!(documentWorkspace.History.UndoStack[documentWorkspace.History.UndoStack.Count - 1] is NullHistoryMemento)) { using (new WaitCursorChanger(documentWorkspace.FindForm())) { documentWorkspace.History.StepBackward(); documentWorkspace.Update(); } } Utility.GCFullCollect(); } return(null); }
protected void Update() { DocumentWorkspace.Update(); }
public static HistoryFunctionResult ApplyFunction(this DocumentWorkspace dw, HistoryFunction function) { HistoryFunctionResult successNoOp; bool flag = false; if ((function.ActionFlags & ActionFlags.KeepToolActive) != ActionFlags.KeepToolActive) { dw.PushNullTool(); dw.Update(); flag = true; } try { using (new WaitCursorChanger(dw)) { string localizedErrorText; HistoryMemento memento = null; Exception exception = null; try { memento = function.Execute(dw); if (memento == null) { successNoOp = HistoryFunctionResult.SuccessNoOp; } else { successNoOp = HistoryFunctionResult.Success; } localizedErrorText = null; } catch (HistoryFunctionNonFatalException exception2) { exception = exception2; if (exception2.InnerException is OutOfMemoryException) { successNoOp = HistoryFunctionResult.OutOfMemory; } else { successNoOp = HistoryFunctionResult.NonFatalError; } if (exception2.LocalizedErrorText != null) { localizedErrorText = exception2.LocalizedErrorText; } else if (exception2.InnerException is OutOfMemoryException) { localizedErrorText = PdnResources.GetString("ExecuteFunction.GenericOutOfMemory"); } else { localizedErrorText = PdnResources.GetString("ExecuteFunction.GenericError"); } } if ((localizedErrorText != null) && (exception != null)) { ExceptionDialog.ShowErrorDialog(dw, localizedErrorText, exception); } else if ((localizedErrorText != null) && (exception == null)) { MessageBoxUtil.ErrorBox(dw, localizedErrorText); } if (memento != null) { dw.History.PushNewMemento(memento); } } } finally { if (flag) { dw.PopNullTool(); } } return(successNoOp); }