public bool Reload(IDsDocumentLoader documentLoader) { const bool isReload = true; if (documentLoader == null) { documentLoader = new DefaultDsDocumentLoader(documentTabService.DocumentTreeView.DocumentService); } if (!CanReload) { return(false); } if (!CheckCanLoad(isReload)) { return(false); } SaveCurrentDocumentsToList(); NotifyBeforeLoad(isReload); var tgws = documentTabSerializer.SaveTabs(); using (DisableSaveToList()) using (documentTabService.OnReloadAll()) { documentTabService.CloseAll(); documentTabService.DocumentTreeView.DocumentService.Clear(); var documents = documentListService.SelectedDocumentList.Documents.Select(a => new DocumentToLoad(a)).ToList(); foreach (var tgw in tgws) { foreach (var g in tgw.TabGroups) { foreach (var t in g.Tabs) { foreach (var f in t.AutoLoadedDocuments) { documents.Add(new DocumentToLoad(f, true)); } } } } documentLoader.Load(documents); } NotifyAfterLoad(isReload); // The documentss in the TV is loaded with a delay so make sure we delay before restoring // or the code that tries to find the nodes might fail to find them. disableLoadAndReload = true; Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { GC.Collect(); GC.WaitForPendingFinalizers(); foreach (var o in documentTabSerializer.Restore(tgws)) { } disableLoadAndReload = false; })); return(true); }
public IEnumerable <object> Load(ISettingsService settingsService, IAppCommandLineArgs args) { var section = settingsService.GetOrCreateSection(SETTINGS_GUID); foreach (var o in documentListLoader.Load(section.GetOrCreateSection(DOCUMENT_LISTS_SECTION), args.LoadFiles)) { yield return(o); } if (args.LoadFiles) { var tgws = new List <SerializedTabGroupWindow>(); var tgwsHash = new HashSet <string>(StringComparer.Ordinal); foreach (var tgwSection in section.SectionsWithName(TABGROUPWINDOW_SECTION)) { var tgw = SerializedTabGroupWindow.Load(tgwSection); yield return(null); if (tgwsHash.Contains(tgw.Name)) { continue; } tgws.Add(tgw); } // The documents are added to the treeview with a slight delay. Make sure the documents // have been added to the TV or the node lookup code will fail to find the nodes it needs. yield return(LoaderConstants.Delay); foreach (var o in documentTabSerializer.Restore(tgws)) { yield return(o); } } documentTabService.OnTabsLoaded(); }