public static SessionSettings LoadSettings(string fileName, bool createIfNotFound, bool displayError = false) { try { if (File.Exists(fileName)) { XmlReader xmlReader = XmlReader.Create(fileName); XmlSerializer serializer = new XmlSerializer(typeof(SessionSettings)); SessionSettings settings = serializer.Deserialize(xmlReader) as SessionSettings; xmlReader.Close(); if (settings != null) { return(settings); } } } catch (Exception e) { if (displayError) { System.Windows.MessageBox.Show("Settings file cannot be loaded. " + e.Message, "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); } } if (createIfNotFound) { return(new SessionSettings()); } return(null); }
public void CopyFrom(SessionSettings source, bool append) { if (!append) { this.Snippets.Clear(); this.Variables.Clear(); } this.SettingsHotKey = source.SettingsHotKey; this.SnippetSelectionHotKey = source.SnippetSelectionHotKey; this.EnableXmlDocumentation = source.EnableXmlDocumentation; this.AutoCloseElements = source.AutoCloseElements; this.DetectWordsInNames = source.DetectWordsInNames; this.SetZoom = source.SetZoom; this.Zoom = source.Zoom; //append snippets foreach (Snippet sourceSnippet in source.Snippets) { this.Snippets.Add(new Snippet(sourceSnippet)); } //append variables foreach (SnippetVariable sourceVariable in source.Variables) { this.Variables.Add(new SnippetVariable(sourceVariable)); } }
public void LoadSettings() { this.GlobalSettings = SessionSettings.LoadSettings(GlobalSettingsPath, true); this.Settings = SessionSettings.LoadSettings(UserSettingsPath, false); if (this.Settings == null) { this.Settings = new SessionSettings(this.GlobalSettings); } }
public bool ShowSettings() { SessionSettings editableSettings = new SessionSettings(this.Settings); ExtensionSettings settingsWindow = new ExtensionSettings(); settingsWindow.DataContext = editableSettings; bool?result = settingsWindow.ShowDialog(); if ((result.HasValue) && (result.Value)) { this.Settings.CopyFrom(editableSettings, false); SaveSettings(); return(true); } return(false); }
public SessionSettings(SessionSettings source) : this() { CopyFrom(source, false); }