public static bool CreateNewQuotationAndAnnotationFromHighlight(this Highlight highlight, QuotationType quotationType, bool ImportEmptyAnnotations, bool RedrawAnnotations, List <Annotation> temporaryAnnotations) { string highlightContents = highlight.GetContents(); if (string.IsNullOrEmpty(highlightContents) && !ImportEmptyAnnotations) { return(false); } Project project = Program.ActiveProjectShell.Project; if (project == null) { return(false); } PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return(false); } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return(false); } Document document = pdfViewControl.Document; if (document == null) { return(false); } Location location = previewControl.ActiveLocation; if (location == null) { return(false); } Reference reference = location.Reference; if (reference == null) { return(false); } // Dynamic variables KnowledgeItem newQuotation = null; KnowledgeItem newDirectQuotation = null; TextContent textContent = null; // Does any other annotation with the same quads already exist? Annotation existingAnnotation = highlight.EquivalentAnnotations().FirstOrDefault(); if ((string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) || quotationType == QuotationType.Comment) { Annotation temporaryAnnotation = temporaryAnnotations.Where(a => !highlight.AsAnnotationQuads().TemporaryQuads().Except(a.Quads.ToList()).Any()).FirstOrDefault(); if (temporaryAnnotation != null) { pdfViewControl.GoToAnnotation(temporaryAnnotation); textContent = (TextContent)pdfViewControl.GetSelectedContentFromType(pdfViewControl.GetSelectedContentType(), -1, false, true); location.Annotations.Remove(temporaryAnnotation); } else { return(false); } } int startPage = 1; if (reference.PageRange.StartPage.Number != null) { startPage = reference.PageRange.StartPage.Number.Value; } string pageRangeString = (startPage + highlight.GetPage().GetIndex() - 1).ToString(); Annotation knowledgeItemIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations); switch (quotationType) { case QuotationType.Comment: if (!string.IsNullOrEmpty(highlightContents)) { newQuotation = highlightContents.CreateNewQuotationFromHighlightContents(pageRangeString, reference, quotationType); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); if (AnnotationsImporterColorPicker.ImportDirectQuotationLinkedWithCommentSelected) { Annotation newDirectQuotationIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations); newDirectQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, QuotationType.DirectQuotation); reference.Quotations.Add(newDirectQuotation); project.AllKnowledgeItems.Add(newDirectQuotation); newDirectQuotation.LinkWithKnowledgeItemIndicationAnnotation(newDirectQuotationIndicationAnnotation); EntityLink commentDirectQuotationLink = new EntityLink(project); commentDirectQuotationLink.Source = newQuotation; commentDirectQuotationLink.Target = newDirectQuotation; commentDirectQuotationLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(commentDirectQuotationLink); newQuotation.CoreStatement = newDirectQuotation.CoreStatement + " (Comment)"; newQuotation.CoreStatementUpdateType = UpdateType.Manual; } } else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) { newQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, quotationType); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); if (AnnotationsImporterColorPicker.ImportDirectQuotationLinkedWithCommentSelected) { Annotation newDirectQuotationIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations); newDirectQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, QuotationType.DirectQuotation); reference.Quotations.Add(newDirectQuotation); project.AllKnowledgeItems.Add(newDirectQuotation); newDirectQuotation.LinkWithKnowledgeItemIndicationAnnotation(newDirectQuotationIndicationAnnotation); EntityLink commentDirectQuotationLink = new EntityLink(project); commentDirectQuotationLink.Source = newQuotation; commentDirectQuotationLink.Target = newDirectQuotation; commentDirectQuotationLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(commentDirectQuotationLink); newQuotation.CoreStatement = newDirectQuotation.CoreStatement + " (Comment)"; newQuotation.CoreStatementUpdateType = UpdateType.Manual; } } break; case QuotationType.QuickReference: if (!string.IsNullOrEmpty(highlightContents)) { newQuotation = highlightContents.CreateNewQuickReferenceFromHighlightContents(pageRangeString, reference, quotationType); } else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) { newQuotation = textContent.CreateNewQuickReferenceFromAnnotationContent(pageRangeString, reference, quotationType); } reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); break; default: if (!string.IsNullOrEmpty(highlightContents)) { newQuotation = highlightContents.CreateNewQuotationFromHighlightContents(pageRangeString, reference, quotationType); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); } else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) { newQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, quotationType); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); } break; } if (existingAnnotation != null) { existingAnnotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); existingAnnotation.Visible = false; } return(true); }