public MainWindowViewModel() { SaveNote = new RelayCommand(_ => Save(), _ => true); OpenNote = new RelayCommand(_ => Open(_), _ => true); RevertNote = new RelayCommand(_ => Revert(), _ => false); CurrentNote = new Note(); }
public void SaveNote(Note note) { if (Path.IsPathRooted(note.FileName)) throw new Exception("Note paths are relative."); if (!Directory.Exists(_dataDirectory)) Directory.CreateDirectory(_dataDirectory); var filePath = Path.Combine(_dataDirectory, note.FileName); var contents = File.Exists(filePath) ? File.ReadAllText(filePath) : null; if (contents == note.Text) return; File.WriteAllText(filePath, note.Text); }
static void RegisterFeatures(Note note) { if (note == null || string.IsNullOrWhiteSpace(note.FileName)) return; if (Settings.Current.IsAutoSaveNote) AutoSaveFeature.Register(note); }