/// <summary> /// Shows the Preferences dialog. If the user exits the dialog /// successfully, we save the preferences to disk and set the new /// preferences to our instance variable. /// </summary> private void preferencesMenuItem__Click(object sender, EventArgs e) { if (preferencesDialog_ != null && preferencesDialog_.Visible) { preferencesDialog_.Activate(); } else { preferencesDialog_ = new PreferencesDialog(preferences_); if (preferencesDialog_.ShowDialog(this) == DialogResult.OK) { bool wasSynchronized = (preferences_.SynchronizeSettings != null); preferences_ = preferencesDialog_.GetPreferences(); try { preferences_.Save(); } catch (Exception ex) { ShowError(String.Format(Messages.ErrorPreferencesSave, ex.Message)); } ReloadPreferences(); UpdateMenus(); if (!wasSynchronized && preferences_.SynchronizeSettings != null) { SynchronizeOnlineNotes(false); } } } }
/// <summary> /// Loads the application preferences from disk. If it doesn't exist, we /// create a new set of preferences, save them to disk, and show a welcome /// message to the user since this is (presumably) the first time they /// have used the application. Likewise, if Stickies has been upgraded, /// show an upgrade message. /// </summary> private Preferences LoadPreferences() { try { Preferences preferences = Preferences.Load(); if (preferences.Version != Application.ProductVersion) { ShowMessage(String.Format(Messages.MessageUpgraded, Application.ProductName, Application.ProductVersion)); try { preferences.Version = Application.ProductVersion; preferences.Save(); } catch (Exception e) { ShowError(String.Format(Messages.ErrorPreferencesSave, e.Message)); } } return preferences; } catch (Exception) { Preferences newPreferences = new Preferences(); ShowMessage(String.Format(Messages.MessageIntroduction, Application.ProductName)); try { newPreferences.Save(); } catch (Exception e) { ShowError(String.Format(Messages.ErrorPreferencesSave, e.Message)); } return newPreferences; } }