示例#1
0
        private void LoadSavedAnnotationsForOpenFile()
        {
            var saved = Annotations.GetAnnotations(_ctx.OpenFile.Md5);

            if (saved == null)
            {
                (var oldPdf, var annotations) = Annotations.GetAnnotationsByPath(_ctx.OpenFile.Path);
                if (oldPdf == null || annotations == null)
                {
                    return;
                }
                if (MessageBox.Show(
                        $@"There are no saved annotations for the file you opened, but for another file which existed at the same path. 
Possibly you updated the file's contents. Do you want to load the saved annotations corresponding to the old file, which was last modified {oldPdf.LastSeen}?",
                        "File mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                saved = annotations;
            }

            var added = 0;

            foreach (var a in saved)
            {
                var wrd = _ctx.Words.FirstOrDefault(w => w.Text == a.Word);
                if (wrd == null)
                {
                    continue;
                }
                AddAnnotation(wrd, a.Content);
                added++;
            }

            if (added != saved.Count)
            {
                MessageBox.Show(
                    $"{added} of {saved.Count} saved annotations had corresponding words in this PDF document and were loaded.",
                    "Not all annotations loaded", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }