// plays back a command in the UI creating new commands private void RedoCommand(INoteViewModel note, Control sender, INoteCommand command) { if (command is CreateNoteCommand) { var createCommand = command as CreateNoteCommand; var text = createCommand.Text; vm.CreateNote(text); //UpdateUI(note, sender, text); } else if (command is DeleteTextFromNoteCommand) { var deleteTextCommand = command as DeleteTextFromNoteCommand; note.RemoveText(deleteTextCommand.Offset, deleteTextCommand.Text.Length, true); //UpdateUI(note, sender, text); } else if (command is InsertTextIntoNoteCommand) { var insertTextCommand = command as InsertTextIntoNoteCommand; vm.InsertText(note, insertTextCommand.Offset, insertTextCommand.Text, true); //UpdateUI(note, sender, note.Text); } else if (command is DeleteNoteCommand) { vm.DeleteNote(command.NoteGuid); //UpdateUI(note, sender, note.Text); } }
// plays back the command history of a note visually private void PlayCommand(INoteViewModel note, Control sender, INoteCommand command, int delayCount) { Task.Delay(delayCount).Wait(); Debug.WriteLine(command.ToString()); if (command is CreateNoteCommand) { var createCommand = command as CreateNoteCommand; var text = createCommand.Text; UpdateUI(note, sender, text); //note.Text = createCommand.Text; } else if (command is DeleteTextFromNoteCommand) { var deleteTextCommand = command as DeleteTextFromNoteCommand; var text = note.Text; text = text.Remove(deleteTextCommand.Offset, deleteTextCommand.Text.Length); UpdateUI(note, sender, text); } else if (command is InsertTextIntoNoteCommand) { var insertTextCommand = command as InsertTextIntoNoteCommand; var text = note.Text; if (insertTextCommand.Offset == note.Text.Length) { text += insertTextCommand.Text; UpdateUI(note, sender, text); } else { text = text.Insert(insertTextCommand.Offset, insertTextCommand.Text); UpdateUI(note, sender, text); } } }
public void PostTextChanges(INoteViewModel note, ICollection <TextChange> changes, string orgText) { if (note is NoteEditModel) { var noteEdit = note as NoteEditModel; if (!noteEdit.IsEditComplete) // prevent triggers from changes from Edit to View models { foreach (var change in changes) { // the order matters - if we select something and then start overwriting that, // we have a delete and add in one change. if (change.RemovedLength > 0) { var text = orgText.Substring(change.Offset, change.RemovedLength); RemoveText(noteEdit, change.Offset, text, false); } if (change.AddedLength > 0) { var text = note.Text.Substring(change.Offset, change.AddedLength); InsertText(noteEdit, change.Offset, text, false); } } } } }
internal void SelectNote(INoteViewModel note) { DisplayCommands.Clear(); foreach (var command in note.Commands) { DisplayCommands.Add(command); } }
internal void RemoveText(INoteViewModel note, int offset, string text, bool asNotify) { var updatedText = note.Text; // already updated at this point if coming from UI var command = _commandFactory.DeleteText(note.Guid, offset, text); AddCommand(command, note); note.UpdateText(updatedText, false); // update without notify to prevent loop }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { var note = _notesRepository.Table.ToList()[listBox1.SelectedIndex]; _currentNoteViewModel = NotesFactory.CreateViewModel(note); _currentNoteViewModel.InitControl(flowLayoutPanel1); label3.Text = $@"Date : {note.CreationDate:yyyy/MM/dd HH:mm:ss}"; }
internal void InsertText(INoteViewModel note, int offset, string text, bool asNotify) { var updatedText = note.Text; // not yet updated at this point updatedText = InsertText(note, offset, text, updatedText); var command = _commandFactory.InsertText(note.Guid, offset, text); AddCommand(command, note); note.UpdateText(updatedText, false); // update without notify to prevent loop }
private string InsertText(INoteViewModel note, int offset, string text, string updatedText) { if (note.Text.Length == offset) { updatedText += text; } else { updatedText = note.Text.Insert(offset, text); } return(updatedText); }
private void NoteAdded(INoteViewModel noteVm) { Task.AddNote(noteVm.Note); }
private void UpdateUI(INoteViewModel note, Control sender, string text) { sender.Parent.Dispatcher.Invoke(() => note.Text = text, System.Windows.Threading.DispatcherPriority.Render); Debug.WriteLine(text); }
public NoteChangedEventArgs(INoteViewModel note, string propertyName) : base(propertyName) { Note = note; }
private void AddCommand(INoteCommand noteCommand, INoteViewModel note) { AllCommands.Insert(0, noteCommand); DisplayCommands.Insert(0, noteCommand); note.Commands.Insert(0, noteCommand); }