private static DialogResult EditAnnotation(Annotation.Annotation value) { using (var editFrm = new EditAnnotationForm()) { editFrm.Value = value; return(editFrm.ShowDialog()); } }
private void DeleteAnnotation(Annotation.Annotation annotation) { // each annotation will only be in the dict once var item = _ctx.Annotations.First(kvp => kvp.Value == annotation); _ctx.Annotations.Remove(item.Key); _ctx.Unsaved = true; SaveToDb(); }
private Annotation.Annotation AddAnnotation(IWord word, string content) { var ann = new Annotation.Annotation(word) { Content = content }; AddAnnotation(word, ann); return(ann); }
private void AddAnnotation(IWord word, Annotation.Annotation value) { _ctx.Annotations.Add(word, value); var lvi = new ListViewItem { Text = word.Text, Tag = value }; lvi.SubItems.Add(value.Content); annotationsListView.Items.Add(lvi); }
private void takeAnnotationButton_Click(object sender, EventArgs e) { if (_context == null) { return; } var focused = annotationsListView.FocusedItem; if (focused?.Selected != true || !(focused.Tag is WordAnnotation annotation)) { MessageBox.Show("Please select an annotation word first.", "No annotation selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var wrd = _context.Words.FirstOrDefault(x => x.Text.ToLower() == annotation.Word.ToLower()); if (wrd == null) { MessageBox.Show($"The word {annotation.Word} is not part of the current document.", "Word not part of document", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (_context.Annotations.TryGetValue(wrd, out var ann)) { if (annotation.Content == ann.Content) { return; } if (MessageBox.Show($"The word {wrd.Text} is already annotated: \n\n{ann.Content}\n\nDo you want to overwrite the existing annotation?", "Overwrite existing annotation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } ann.Content = annotation.Content; } else { ann = new Annotation.Annotation(wrd) { Content = annotation.Content }; _context.Annotations.Add(wrd, ann); } _context.SaveToDb(); DidChangesToAnnotationsInContext = true; }
private void TakeAllRelevantAnnotationsButton_Click(object sender, EventArgs e) { var added = 0; var skipped = 0; // get relevant words using hashset in O(n*1) var rels = _annotations.Where(a => _wordsInDoc.Contains(a.Word.ToLower())); foreach (var rel in rels) { var wrd = _context.Words.FirstOrDefault(x => x.Text.ToLower() == rel.Word.ToLower()); if (!_context.Annotations.TryGetValue(wrd, out var ann)) { ann = new Annotation.Annotation(wrd) { Content = rel.Content }; _context.Annotations.Add(wrd, ann); ++added; } else { ++skipped; } } if (added > 0) { _context.SaveToDb(); DidChangesToAnnotationsInContext = true; } var msg = $"Added {added} new annotations to your open document."; if (skipped > 0) { msg += $" Skipped {skipped} annotations because an annotation for the same word already exists."; } MessageBox.Show(this, msg, "Take All Relevant Annotations", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void CreateAnnotationForFocusedWord(bool silent = false) { var focused = wordsView.FocusedItem; if (focused?.Selected != true || !(focused.Tag is IWord word)) { if (!silent) { MessageBox.Show("Please select a word first.", "No word selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return; } Annotation.Annotation annot; if (_ctx.Annotations.TryGetValue(word, out annot)) { if (EditAnnotation(annot) != DialogResult.OK) { return; } _ctx.Unsaved = true; RefreshAnnotationsList(); SaveToDb(); return; } annot = new Annotation.Annotation(word); if (EditAnnotation(annot) != DialogResult.OK) { return; } AddAnnotation(word, annot); _ctx.Unsaved = true; SaveToDb(); }