private bool ConfirmAbandon() { bool Abandon = false; if (_document == null) { Abandon = true; } else if (_document.Dirty == false) { Abandon = true; } else if (_document.Dirty == true) { //Here's where move the text _document.Text = textEditBox.Text; MessageBoxResult r = MessageBox.Show("You have work in progress\nDo you want exit without saving?", "Please Confirm Action", MessageBoxButton.YesNoCancel); if (r == MessageBoxResult.Yes) { Abandon = true; _document = null; } } return Abandon; }
/* openFile_Click action... * if the document is modified this function prompts the user * to confirm that they want to overwrite their changes */ private void openFile_Click(object sender, RoutedEventArgs e) { if (ConfirmOverWrite()) { OpenFileDialog dlg = new OpenFileDialog(); if (true == dlg.ShowDialog()) { _document = new Document(); if (_document.Open(dlg.FileName)) { textEditBox.IsEnabled = true; textEditBox.Background = _openForm; textEditBox.Text = _document.Text; _document.Dirty = false; this.saveFile.IsEnabled = false; this.Title = dlg.FileName; } } } }
/* newFile_Click action... * if the document is modified this function prompts the user * to confirm that they want to overwrite their changes */ private void newFile_Click(object sender, RoutedEventArgs e) { if (ConfirmOverWrite()) { _document = new Document(); textEditBox.Text = null; textEditBox.IsEnabled = true; textEditBox.Background = _openForm; this.Title = "Untitled"; } }