//TODO (Web Viewer): remove protected once we start hosting each app in it's own app domain. /// <summary> /// Opens this object. /// </summary> protected internal void Open() { // call initialize before opening // any exception thrown from initialize will therefore abort before opening, not after Initialize(); _state = DesktopObjectState.Opening; OnOpening(EventArgs.Empty); _view = CreateView(); _view.SetTitle(_title); _view.ActiveChanged += delegate(object sender, EventArgs args) { this.Active = _view.Active; }; _view.VisibleChanged += delegate(object sender, EventArgs args) { this.Visible = _view.Visible; }; _view.CloseRequested += delegate(object sender, EventArgs args) { // the request should always come from the active object, so interaction should be allowed Close(UserInteraction.Allowed, CloseReason.UserInterface); }; _view.Open(); _state = DesktopObjectState.Open; OnOpened(EventArgs.Empty); }
/// <summary> /// Closes this object. /// </summary> /// <returns>True if the object was closed, otherwise false.</returns> protected internal bool Close(UserInteraction interactive, CloseReason reason) { // easy case - bail if interaction is prohibited and we can't close without interacting if (interactive == UserInteraction.NotAllowed && !CanClose()) { return(false); } // either we can close without interacting, or interaction is allowed, so let's try and close // begin closing - the operation may yet be cancelled _state = DesktopObjectState.Closing; ClosingEventArgs args = new ClosingEventArgs(reason, interactive); OnClosing(args); if (args.Cancel || !PrepareClose(reason)) { _state = DesktopObjectState.Open; return(false); } _view.CloseRequested -= OnViewCloseRequested; _view.VisibleChanged -= OnViewVisibleChanged; _view.ActiveChanged -= OnViewActiveChanged; // notify inactive this.Active = false; try { // close the view _view.Dispose(); } catch (Exception e) { Platform.Log(LogLevel.Error, e); } _view = null; // close was successful _state = DesktopObjectState.Closed; OnClosed(new ClosedEventArgs(reason)); // dispose of this object after firing the Closed event // (reason being that handlers of the Closed event may expect this object to be intact) (this as IDisposable).Dispose(); return(true); }
/// <summary> /// Called to dispose of this object. /// </summary> protected virtual void Dispose(bool disposing) { if (disposing) { Application.CurrentUICultureChanged -= Application_CurrentUICultureChanged; // view may have already been disposed in the Close method if (_view != null) { _view.Dispose(); _view = null; } } }
//TODO (Web Viewer): remove protected once we start hosting each app in it's own app domain. /// <summary> /// Opens this object. /// </summary> protected internal void Open() { // call initialize before opening // any exception thrown from initialize will therefore abort before opening, not after Initialize(); _state = DesktopObjectState.Opening; OnOpening(EventArgs.Empty); _view = CreateView(); _view.SetTitle(_title); _view.ActiveChanged += OnViewActiveChanged; _view.VisibleChanged += OnViewVisibleChanged; _view.CloseRequested += OnViewCloseRequested; _view.Open(); _state = DesktopObjectState.Open; OnOpened(EventArgs.Empty); }
/// <summary> /// Closes this object. /// </summary> /// <returns>True if the object was closed, otherwise false.</returns> protected internal bool Close(UserInteraction interactive, CloseReason reason) { // easy case - bail if interaction is prohibited and we can't close without interacting if (interactive == UserInteraction.NotAllowed && !CanClose()) return false; // either we can close without interacting, or interaction is allowed, so let's try and close // begin closing - the operation may yet be cancelled _state = DesktopObjectState.Closing; ClosingEventArgs args = new ClosingEventArgs(reason, interactive); OnClosing(args); if (args.Cancel || !PrepareClose(reason)) { _state = DesktopObjectState.Open; return false; } _view.CloseRequested -= OnViewCloseRequested; _view.VisibleChanged -= OnViewVisibleChanged; _view.ActiveChanged -= OnViewActiveChanged; // notify inactive this.Active = false; try { // close the view _view.Dispose(); } catch (Exception e) { Platform.Log(LogLevel.Error, e); } _view = null; // close was successful _state = DesktopObjectState.Closed; OnClosed(new ClosedEventArgs(reason)); // dispose of this object after firing the Closed event // (reason being that handlers of the Closed event may expect this object to be intact) (this as IDisposable).Dispose(); return true; }