private void readd_everything() { // at this point, I have all the notes in "sorted notes" set up correctly - I need to show them in the UI var copy = notes_sorted_by_line_index_.ToList(); var sel_note_id = notesCtrl.SelectedIndex >= 0 ? (notesCtrl.GetItem(notesCtrl.SelectedIndex).RowObject as note_item).note_id : ""; var sel_note_id_above = find_note_id_above_selection(); ++ignore_change_; notes_sorted_by_line_index_.Clear(); notesCtrl.ClearObjects(); // ... re-add everything // // note: if any chidren of a deleted note/line is !deleted, we need to show that note/line (even if shown in gray) // normally, this should not happen - however, I see this as a possibility when merging two notes files // say X deletes note N, but Y replies on it foreach ( var n in copy) { if (n.is_note_header) add_note_header(n.line_id, n.note_id, n.ui_deleted, n.utc_last_edited).deleted = n.deleted; else add_note(lines_[n.line_id], n.the_note, n.note_id, n.reply_id, n.ui_deleted, n.utc_last_edited).deleted = n.deleted; } Debug.Assert(notes_sorted_by_line_index_.Count == copy.Count); // set current line if (showDeletedLines.Checked) { var cur_line_copy = new line(); cur_line_copy.copy_from(cur_line); cur_line.clear(); set_current_line_impl(cur_line_copy); } else cur_line.clear(); string new_sel = showDeletedLines.Checked ? sel_note_id : sel_note_id_above; if ( new_sel != "") for ( int idx = 0; idx < notesCtrl.GetItemCount(); ++idx) if ((notesCtrl.GetItem(idx).RowObject as note_item).note_id == new_sel) { notesCtrl.SelectedIndex = idx; notesCtrl.EnsureVisible(idx); break; } --ignore_change_; refresh_notes(); }
// helper - add to the currently selected line private note_item add_note(note n, string note_id, string reply_to_note_id, bool deleted, DateTime utc_added) { Debug.Assert(cur_line != null); if (cur_line == null) { Debug.Assert(false); return null; } line new_ = new line(); if (reply_to_note_id == "") new_.copy_from(cur_line); else { // find the line we're replying to var reply_to_note = notes_sorted_by_line_index_.FirstOrDefault(x => x.note_id == reply_to_note_id); Debug.Assert(reply_to_note != null && lines_.ContainsKey(reply_to_note.line_id)); new_.copy_from( lines_[reply_to_note.line_id] ); } return add_note(new_, n, note_id, reply_to_note_id, deleted, utc_added); }