private static void RestoreMemento(IFileViewContent viewContent, object memento) { if (memento != null) { ((IMementoCapable)viewContent).SetMemento(memento); } }
/// <inheritdoc/> public IFileViewContent OpenFile(FileName fileName, bool switchToOpenedView) { if (fileName == null) { throw new ArgumentNullException("fileName"); } Current.Log.Info("Open file " + fileName); IFileViewContent viewContent = GetOpenFile(fileName); if (viewContent != null) { if (switchToOpenedView) { viewContent.IsSelected = true; } return(viewContent); } IDisplayBinding binding = Altaxo.Current.GetRequiredService <IDisplayBindingService>().GetBindingPerFileName(fileName); if (binding == null) { binding = new ErrorFallbackBinding("Could not find any display binding for " + Path.GetFileName(fileName)); } if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK) { RecentOpen.AddRecentFile(fileName); } return(GetOpenFile(fileName)); }
public override void RegisterView(IFileViewContent view) { if (view == null) { throw new ArgumentNullException("view"); } if (registeredViews.Contains(view)) { throw new ArgumentException("registeredViews already contains view"); } registeredViews.Add(view); if (Altaxo.Current.GetService <IWorkbench>() != null) { Altaxo.Current.GetRequiredService <IWorkbenchEx>().ActiveViewContentChanged += WorkbenchActiveViewContentChanged; if (Altaxo.Current.Workbench.ActiveViewContent == view) { SwitchedToView(view); } } #if DEBUG view.Disposed += ViewDisposed; #endif }
public override void UnregisterView(IFileViewContent view) { if (view == null) { throw new ArgumentNullException("view"); } Debug.Assert(registeredViews.Contains(view)); if (Altaxo.Current.GetService <IWorkbench>() != null) { Altaxo.Current.GetRequiredService <IWorkbenchEx>().ActiveViewContentChanged -= WorkbenchActiveViewContentChanged; } #if DEBUG view.Disposed -= ViewDisposed; #endif registeredViews.Remove(view); if (registeredViews.Count > 0) { if (currentView == view) { SaveCurrentView(); currentView = null; } } else { // all views to the file were closed CloseIfAllViewsClosed(); } }
private static bool IsUntitled(IFileViewContent viewContent) { OpenedFile file = viewContent.PrimaryFile; if (file == null) { return(false); } else { return(file.IsUntitled); } }
public override void ForceInitializeView(IFileViewContent view) { if (view == null) { throw new ArgumentNullException("view"); } if (!registeredViews.Contains(view)) { throw new ArgumentException("registeredViews must contain view"); } base.ForceInitializeView(view); }
private bool IsStateOk(IFileViewContent viewContent) { if (viewContent == null) { return(false); } // use IWorkbenchWindow instead of IViewContent because maybe window info is needed in the future (for example: sub view content info.) bool isWindowStateOk = false; if (windowState != WindowState.None) { if ((windowState & WindowState.Dirty) > 0) { isWindowStateOk |= viewContent.IsDirty; } if ((windowState & WindowState.Untitled) > 0) { isWindowStateOk |= IsUntitled(viewContent); } if ((windowState & WindowState.ViewOnly) > 0) { isWindowStateOk |= viewContent.IsViewOnly; } } else { isWindowStateOk = true; } if (nowindowState != WindowState.None) { if ((nowindowState & WindowState.Dirty) > 0) { isWindowStateOk &= !viewContent.IsDirty; } if ((nowindowState & WindowState.Untitled) > 0) { isWindowStateOk &= !IsUntitled(viewContent); } if ((nowindowState & WindowState.ViewOnly) > 0) { isWindowStateOk &= !viewContent.IsViewOnly; } } return(isWindowStateOk); }
/// <summary> /// Forces initialization of the specified view. /// </summary> public virtual void ForceInitializeView(IFileViewContent view) { if (view == null) { throw new ArgumentNullException("view"); } bool success = false; try { if (currentView != view) { if (currentView == null) { SwitchedToView(view); } else { try { inLoadOperation = true; using (Stream sourceStream = OpenRead()) { view.Load(this, sourceStream); } } finally { inLoadOperation = false; } } } success = true; } finally { // Only in case of exceptions: // (try-finally with bool is better than try-catch-rethrow because it causes the debugger to stop // at the original error location, not at the rethrow) if (!success) { view.Dispose(); } } }
private static object GetMemento(IFileViewContent viewContent) { return(viewContent.GetService <IMementoCapable>()?.CreateMemento()); }
public void SwitchedToView(IFileViewContent newView) { if (newView == null) { throw new ArgumentNullException("newView"); } if (currentView == newView) { return; } if (currentView != null) { if (newView.SupportsSwitchToThisWithoutSaveLoad(this, currentView) || currentView.SupportsSwitchFromThisWithoutSaveLoad(this, newView)) { // switch without Save/Load currentView.SwitchFromThisWithoutSaveLoad(this, newView); newView.SwitchToThisWithoutSaveLoad(this, currentView); currentView = newView; return; } SaveCurrentView(); } try { inLoadOperation = true; var memento = GetMemento(newView); using (Stream sourceStream = OpenRead()) { var oldView = currentView; bool success = false; try { currentView = newView; // don't reset fileData if the file is untitled, because OpenRead() wouldn't be able to read it otherwise if (IsUntitled == false) { fileData = null; } newView.Load(this, sourceStream); success = true; } finally { // Use finally instead of catch+rethrow so that the debugger // breaks at the original crash location. if (!success) { // stay with old view in case of exceptions currentView = oldView; } } } RestoreMemento(newView, memento); } finally { inLoadOperation = false; } }
public abstract void UnregisterView(IFileViewContent view);