void OnLoadingWorkspaceUserPreferences(object s, UserPreferencesEventArgs args) { WorkbenchUserPrefs prefs = args.Properties.GetValue <WorkbenchUserPrefs> ("MonoDevelop.Ide.Workbench"); if (prefs == null) { return; } string currentFileName = prefs.ActiveDocument != null?Path.GetFullPath(Path.Combine(args.Item.BaseDirectory, prefs.ActiveDocument)) : null; foreach (DocumentUserPrefs doc in prefs.Files) { FilePath fileName = args.Item.BaseDirectory.Combine(doc.FileName).FullPath; if (File.Exists(fileName)) { OpenDocumentOptions ops = OpenDocumentOptions.OnlyInternalViewer; if (fileName == currentFileName) { ops |= OpenDocumentOptions.BringToFront; } IdeApp.Workbench.OpenDocument(fileName, doc.Line, doc.Column, ops, null, null); } } foreach (PadUserPrefs pi in prefs.Pads) { foreach (Pad pad in IdeApp.Workbench.Pads) { if (pi.Id == pad.Id && pad.Content is IMementoCapable) { try { string xml = pi.State.OuterXml; IMementoCapable m = (IMementoCapable)pad.Content; XmlReader innerReader = new XmlTextReader(new StringReader(xml)); innerReader.MoveToContent(); ICustomXmlSerializer cs = (ICustomXmlSerializer)m.Memento; if (cs != null) { m.Memento = cs.ReadFrom(innerReader); } } catch (Exception ex) { LoggingService.LogError("Error loading view memento.", ex); } break; } } } }
void ApplyPreferences() { var memento = content as IMementoCapable; if (memento == null || preferences == null) { return; } try { string xml = preferences.State.OuterXml; var innerReader = new XmlTextReader(new StringReader(xml)); innerReader.MoveToContent(); ICustomXmlSerializer cs = (ICustomXmlSerializer)memento.Memento; if (cs != null) { memento.Memento = cs.ReadFrom(innerReader); } } catch (Exception ex) { LoggingService.LogError("Error loading view memento.", ex); } }
void OnLoadingWorkspaceUserPreferences(object s, UserPreferencesEventArgs args) { WorkbenchUserPrefs prefs = args.Properties.GetValue <WorkbenchUserPrefs> ("MonoDevelop.Ide.Workbench"); if (prefs == null) { return; } NavigationHistoryService.LogActiveDocument(); List <IViewContent> docViews = new List <IViewContent> (); FilePath baseDir = args.Item.BaseDirectory; IViewContent currentView = null; using (IProgressMonitor pm = ProgressMonitors.GetStatusProgressMonitor(GettextCatalog.GetString("Loading workspace documents"), Stock.OpenFileIcon, true)) { string currentFileName = prefs.ActiveDocument != null?baseDir.Combine(prefs.ActiveDocument).FullPath : null; foreach (DocumentUserPrefs doc in prefs.Files.Distinct(new DocumentUserPrefsFilenameComparer())) { string fileName = baseDir.Combine(doc.FileName).FullPath; if (File.Exists(fileName)) { var view = IdeApp.Workbench.BatchOpenDocument(pm, fileName, doc.Line, doc.Column); if (fileName == currentFileName) { currentView = view; } if (view != null) { docViews.Add(view); } } } // Note: At this point, the progress monitor will be disposed which causes the gtk main-loop to be pumped. // This is EXTREMELY important, because without this main-loop pumping action, the next foreach() loop will // not cause the Solution tree-view to properly expand, nor will the ActiveDocument be set properly. } foreach (var view in docViews) { Document doc = WrapDocument(view.WorkbenchWindow); if (view == currentView) { Present(); doc.RunWhenLoaded(() => { var window = doc.Window; if (window != null) { window.SelectWindow(); } }); } } foreach (PadUserPrefs pi in prefs.Pads) { foreach (Pad pad in IdeApp.Workbench.Pads) { if (pi.Id == pad.Id && pad.Content is IMementoCapable) { try { string xml = pi.State.OuterXml; IMementoCapable m = (IMementoCapable)pad.Content; XmlReader innerReader = new XmlTextReader(new StringReader(xml)); innerReader.MoveToContent(); ICustomXmlSerializer cs = (ICustomXmlSerializer)m.Memento; if (cs != null) { m.Memento = cs.ReadFrom(innerReader); } } catch (Exception ex) { LoggingService.LogError("Error loading view memento.", ex); } break; } } } }