public void Save ()
{
// Prevent any other condition forcing a save on the note
// if Delete has been called.
if (is_deleting)
return;
// Do nothing if we don't need to save. Avoids unneccessary saves
// e.g on forced quit when we call save for every note.
if (!save_needed)
return;
// Do nothing if an error happened and we are presenting an error dialog
if (save_errordlg_active) {
Logger.Debug("Error dialog is active - skipping saving");
return;
}
string new_note_pattern = String.Format (Catalog.GetString ("New Note {0}"), @"\d+");
Note template_note = manager.GetOrCreateTemplateNote ();
string template_content = template_note.TextContent.Replace (template_note.Title, Title);
// Do nothing if this note contains the unchanged template content
// and if the title matches the new note title template to prevent
// lots of unwanted "New Note NNN" notes: Bug #545252
if (Regex.IsMatch (Title, new_note_pattern) && TextContent.Equals (template_content))
return;
Logger.Debug ("Saving '{0}'...", data.Data.Title);
try {
NoteArchiver.Write (filepath, data.GetDataSynchronized ());
} catch (Exception e) {
// Probably IOException or UnauthorizedAccessException?
Logger.Error ("Exception while saving note: " + e.ToString ());
// This will disable note saving until the user takes an action
// and closes the error dialog.
save_errordlg_active = true;
save_timeout.Cancel ();
NoteUtils.ShowIOErrorDialog (window);
save_errordlg_active = false;
save_timeout.Reset(SAVE_TIMEOUT_MS);
}
if (Saved != null)
Saved (this);
}