/// <summary> /// Creates a new preferences dialog, initializing our form based on the /// settings in the given Preferences instance. /// </summary> public PreferencesDialog(Preferences preferences) { InitializeComponent(); this.Icon = Media.StickiesIcon; this.Text = String.Format(Messages.PreferencesTitle, Application.ProductName); saveButton_.Text = Messages.PreferencesSave; cancelButton_.Text = Messages.PreferencesCancel; appearanceTabPage_.Text = Messages.PreferencesAppearanceTab; settingsTabPage_.Text = Messages.PreferencesSettingsTab; startOnWindowsCheckBox_.Text = Messages.PreferencesStartWithWindows; iconCheckBox_.Text = Messages.PreferencesCustomIcon; // Start the preferences dialog under the mouse cursor. Since we are // a ContainedControl, this will work correctly even if the mouse is // near the edge of the screen. this.StartPosition = FormStartPosition.Manual; this.Location = Control.MousePosition; // Reflect the initial set of preferences in our form notePreferencesControl_.NoteBackgroundColor = Color.FromArgb(preferences.Note.BackColor); notePreferencesControl_.NoteBorderColor = Color.FromArgb(preferences.Note.BorderColor); noteTextBox_.ForeColor = Color.FromArgb(preferences.Note.FontColor); notePreferencesControl_.NoteTransparency = preferences.Note.Transparency; if (preferences.Note.Rtf != null) { noteTextBox_.Rtf = preferences.Note.Rtf; notePreferencesControl_.NoteFont = noteTextBox_.SelectionFont; notePreferencesControl_.NoteFontColor = noteTextBox_.SelectionColor; } notePreferencesControl_.NoteAlwaysOnTop = preferences.Note.AlwaysOnTop; noteTextBox_.Text = Messages.PreferencesNoteText; if (preferences.TrayIconPath != null) { iconTextBox_.Text = preferences.TrayIconPath; } iconCheckBox_.Checked = preferences.TrayIconPath != null; iconTextBox_.Enabled = iconCheckBox_.Checked; iconBrowseButton_.Enabled = iconCheckBox_.Checked; startOnWindowsCheckBox_.Checked = Preferences.StartWithWindows(); synchronizationSettings_ = preferences.SynchronizeSettings; if (synchronizationSettings_ != null) { synchronizeCheckBox_.Checked = true; amazonAccessKeyIdTextBox_.Text = synchronizationSettings_.AmazonAccessKeyId; amazonSecretAccessKeyTextBox_.Text = synchronizationSettings_.AmazonSecretAccessKey; } // Hack to make slider bar look right on top of the light colored // TabControl. The slider bar control does not support transparent // background colors. notePreferencesControl_.SliderBarBackColor = Color.FromArgb(244, 243, 239); UpdateSynchronizationEnabled(); }
/// <summary> /// Load our preferences from disk, set up our tray icon, and load all of /// our notes from disk. Send an asynchronous request to check for newer /// versions of the product in parallel. /// </summary> public MainForm() { // Set up our tray icon and context menu InitializeComponent(); this.Text = Application.ProductName; showAllNotesMenuItem_.Text = Messages.MainShowAllNotes; deleteAllNotesMenuItem_.Text = Messages.MainDeleteAllNotes; aboutMenuItem_.Text = String.Format(Messages.MainAbout, Application.ProductName); newNoteMenuItem_.Text = Messages.MainNewNote; reportBugMenuItem_.Text = Messages.MainReportBug; preferencesMenuItem_.Text = Messages.MainPreferences; exitMenuItem_.Text = Messages.MainExit; notifyIcon_.Text = Application.ProductName; // Name our window so we can find it via inter-process communication this.Text = kWindowTitle; // Load the preferences from disk preferences_ = LoadPreferences(); ReloadPreferences(); // Load the notes from disk noteForms_ = new List<NoteForm>(); List<Note> notes = LoadNotes(); foreach (Note note in notes) { ShowNote(new NoteForm(this, note, false)); } UpdateMenus(); // Register a global hot-key to create new sticky notes RegisterGlobalHotKey(); // Check for new versions of Stickies UpdateChecker checker = new UpdateChecker(GetVersionCheckURL(), new UpdateChecker.Callback(OnUpdateCheck)); checker.Run(); // Start the synchronization timer and do one initial synchronization synchronizationTimer_.Start(); SynchronizeOnlineNotes(false); }
/// <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; } }
/// <summary> /// Generates a Preferences instance from the settings the user has /// input into this dialog. Use this to get Preferences after the dialog /// closes. /// </summary> public Preferences GetPreferences() { Preferences preferences = new Preferences(); preferences.Note.BackColor = notePreferencesControl_.NoteBackgroundColor.ToArgb(); preferences.Note.BorderColor = notePreferencesControl_.NoteBorderColor.ToArgb(); preferences.Note.FontColor = notePreferencesControl_.NoteFontColor.ToArgb(); preferences.Note.Transparency = notePreferencesControl_.NoteTransparency; preferences.Note.AlwaysOnTop = notePreferencesControl_.NoteAlwaysOnTop; if (iconCheckBox_.Checked && iconTextBox_.Text.Length > 0) { preferences.TrayIconPath = iconTextBox_.Text; } if (synchronizeCheckBox_.Checked && amazonAccessKeyIdTextBox_.Text.Length > 0 && amazonSecretAccessKeyTextBox_.Text.Length > 0) { // Preserve the old synchronization (and LastSync timestamp) unless the // Amazon key has changed. if (synchronizationSettings_ != null && synchronizationSettings_.AmazonAccessKeyId == amazonAccessKeyIdTextBox_.Text && synchronizationSettings_.AmazonSecretAccessKey == amazonSecretAccessKeyTextBox_.Text) { preferences.SynchronizeSettings = synchronizationSettings_; } else { preferences.SynchronizeSettings = new SynchronizationSettings(amazonAccessKeyIdTextBox_.Text, amazonSecretAccessKeyTextBox_.Text); } } // Save the font by deleting the text and saving the emtpy RTF noteTextBox_.Text = ""; preferences.Note.Rtf = noteTextBox_.Rtf; return preferences; }