public ClosingState CheckForChanges() { IFlowSharpCanvasService canvasService = ServiceManager.Get <IFlowSharpCanvasService>(); bool changed = canvasService.Controllers.Any(c => GetSavePoint(c) != c.UndoStack.UndoStackSize); ClosingState ret = ClosingState.NoChanges; if (changed) { DialogResult res = MessageBox.Show("Do you wish to save changes to this drawing?", "Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (res) { case DialogResult.Cancel: ret = ClosingState.CancelClose; break; case DialogResult.Yes: ret = ClosingState.SaveChanges; break; case DialogResult.No: ret = ClosingState.ExitWithoutSaving; break; } } return(ret); }
public CloseWindowController(IAppWindow win, IIOPortHandler[] portHandlers) { _win = win; _state = ClosingState.NoClosing; _portHandlers = portHandlers; _portHandlerClosedStates = new Dictionary<IIOPortHandler, bool>(); foreach (IIOPortHandler handler in portHandlers) _portHandlerClosedStates[handler] = false; }
public StateBankAccount() { confirmingIdentityState = new ConfirmingIdentityState(this); activeState = new ActiveState(this); frozenState = new FrozenState(this); closingState = new ClosingState(this); closedState = new ClosedState(this); state = confirmingIdentityState; balance = 0.0; }
/// <summary> /// Return true if operation should be cancelled. /// </summary> protected bool CheckForChanges() { bool ret = true; ClosingState state = serviceManager.Get <IFlowSharpEditService>().CheckForChanges(); if (state == ClosingState.SaveChanges) { ret = !SaveOrSaveAs(); // override because of possible cancel in save operation. } else if (state != ClosingState.CancelClose) { BaseController canvasController = serviceManager.Get <IFlowSharpCanvasService>().ActiveController; canvasController.UndoStack.ClearStacks(); // Prevents second "are you sure" when exiting with Ctrl+X ret = false; } return(ret); }
protected void OnFormClosing(object sender, FormClosingEventArgs e) { ClosingState state = ServiceManager.Get <IFlowSharpEditService>().CheckForChanges(); if (state == ClosingState.SaveChanges) { if (!ServiceManager.Get <IFlowSharpMenuService>().SaveOrSaveAs()) { e.Cancel = true; } } else { e.Cancel = state == ClosingState.CancelClose; } if (!e.Cancel) { dockingService.SaveLayout("layout.xml"); } }
protected void Close(Exception exception) { if (!this.TryClose()) { return; } var closingState = new ClosingState(); if (exception != null) { closingState.RegisterException(exception); } // Closing logic should be executed on the loop thread if (this.Worker != null && Thread.CurrentThread.ManagedThreadId != this.BaseSocket.ThreadId) { this.Worker.EnqueueFinalJob(this.CloseCallback, closingState); } else { this.CloseCallback(closingState); } }
public void closePortHandlers() { _state = ClosingState.ClosingResources; foreach (IIOPortHandler handler in _portHandlers) handler.terminate(); }