private void add_note_to_ui(note_item last_note) {
bool add_to_ui = !last_note.deleted || (last_note.deleted && showDeletedLines.Checked);
if (!add_to_ui)
return;
int insert_idx = -1;
if (last_note.reply_id != "") {
// it's a note on reply to another note
for (int note_idx = 0; note_idx < notesCtrl.GetItemCount() && insert_idx < 0; ++note_idx) {
var i = notesCtrl.GetItem(note_idx).RowObject as note_item;
if (i.note_id == last_note.reply_id)
insert_idx = note_idx + 1;
}
} else {
// new note
if (!last_note.is_note_header)
for (int note_idx = 0; note_idx < notesCtrl.GetItemCount(); ++note_idx) {
var i = notesCtrl.GetItem(note_idx).RowObject as note_item;
string line_id = i.line_id != cur_line_id_ ? i.line_id : find_cur_line_id();
if (line_id == last_note.line_id) {
insert_idx = note_idx + 1;
bool insert_at_the_end = i.line_id == cur_line_id_;
if (insert_at_the_end) {
// we need to set_aliases the line, so that it does not point to current-line anymore
i.line_id = line_id;
}
}
}
else
// it's a new note header, add at the end
insert_idx = notesCtrl.GetItemCount();
}
Debug.Assert( insert_idx >= 0);
if (insert_idx >= 0) {
++ignore_change_;
notesCtrl.InsertObjects(insert_idx, new object[] {last_note});
// now, select it as well
notesCtrl.SelectObject(last_note);
// ... so that it recomputes its UI index correctly
notesCtrl.RefreshObject(last_note);
--ignore_change_;
notesCtrl.EnsureVisible(insert_idx);
refresh_note(last_note);
}
}