void KnowledgeItemPreviewSmartRepeater_ActiveListItemChanged(object o, EventArgs a) { if (Program.ActiveProjectShell.PrimaryMainForm.GetSelectedKnowledgeItems().Count == 0) { return; } KnowledgeItem activeQuotation = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedKnowledgeItems().FirstOrDefault(); if (activeQuotation.EntityLinks == null) { return; } if (activeQuotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() == 0) { return; } Annotation annotation = activeQuotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Target as Annotation; PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Document document = pdfViewControl.Document; if (document == null) { return; } if (previewControl.ActiveLocation != annotation.Location) { Program.ActiveProjectShell.ShowPreviewFullScreenForm(annotation.Location, previewControl, null); } pdfViewControl.GoToAnnotation(annotation); Program.ActiveProjectShell.PrimaryMainForm.Activate(); }
public static void CreateCommentAnnotation(List <KnowledgeItem> quotations) { PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Annotation lastAnnotation = null; foreach (KnowledgeItem quotation in quotations) { if (quotation.EntityLinks.Any() && quotation.EntityLinks.Where(link => link.Target is KnowledgeItem).FirstOrDefault() != null) { Reference reference = quotation.Reference; if (reference == null) { return; } Project project = reference.Project; if (project == null) { return; } KnowledgeItem mainQuotation = quotation.EntityLinks.ToList().Where(n => n != null && n.Indication == EntityLink.CommentOnQuotationIndication && n.Target as KnowledgeItem != null).ToList().FirstOrDefault().Target as KnowledgeItem; Annotation mainQuotationAnnotation = mainQuotation.EntityLinks.Where(link => link.Target is Annotation && link.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Target as Annotation; if (mainQuotationAnnotation == null) { return; } Location location = mainQuotationAnnotation.Location; if (location == null) { return; } List <Annotation> oldAnnotations = quotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Select(e => (Annotation)e.Target).ToList(); foreach (Annotation oldAnnotation in oldAnnotations) { location.Annotations.Remove(oldAnnotation); } Annotation newAnnotation = new Annotation(location); newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0); newAnnotation.Quads = mainQuotationAnnotation.Quads; newAnnotation.Visible = false; location.Annotations.Add(newAnnotation); EntityLink newEntityLink = new EntityLink(project); newEntityLink.Source = quotation; newEntityLink.Target = newAnnotation; newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(newEntityLink); lastAnnotation = newAnnotation; } pdfViewControl.GoToAnnotation(lastAnnotation); } }
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); }
public static void CreatesummaryOnQuotations(List <KnowledgeItem> quotations) { Reference reference = Program.ActiveProjectShell.PrimaryMainForm.ActiveReference; if (reference == null) { return; } Project project = reference.Project; if (project == null) { return; } PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl; if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Document document = pdfViewControl.Document; if (document == null) { return; } Location location = reference.Locations.Where ( l => l.LocationType == LocationType.ElectronicAddress && l.Address.Resolve().LocalPath.EndsWith(".pdf") && l.Address.Resolve().LocalPath == document.GetFileName() ) .FirstOrDefault(); if (location == null) { return; } Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault(); SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater; List <PageRange> pageRanges = new List <PageRange>(); List <Quad> quads = new List <Quad>(); Annotation newAnnotation = new Annotation(location); KnowledgeItem summary = new KnowledgeItem(reference, QuotationType.Summary); reference.Quotations.Add(summary); foreach (KnowledgeItem quotation in quotations) { pageRanges.Add(quotation.PageRange); EntityLink summaryQuotationLink = new EntityLink(project); summaryQuotationLink.Source = summary; summaryQuotationLink.Target = quotation; summaryQuotationLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(summaryQuotationLink); Annotation quotationAnnotation = quotation.EntityLinks.Where(link => link.Target is Annotation).FirstOrDefault().Target as Annotation; if (quotationAnnotation == null) { continue; } quads.AddRange(quotationAnnotation.Quads); } newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0); newAnnotation.Quads = quads; newAnnotation.Visible = false; location.Annotations.Add(newAnnotation); summary.PageRange = PageRangeMerger.PageRangeListToString(pageRanges); summary.CoreStatementUpdateType = UpdateType.Automatic; EntityLink summaryAnnotationLink = new EntityLink(project); summaryAnnotationLink.Source = summary; summaryAnnotationLink.Target = newAnnotation; summaryAnnotationLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(summaryAnnotationLink); quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(summary, true); pdfViewControl.GoToAnnotation(newAnnotation); }
public static void CreateCommentOnQuotation(List <KnowledgeItem> quotations) { Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault(); SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater; PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl; if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Annotation lastAnnotation = null; KnowledgeItem lastComment = null; foreach (KnowledgeItem quotation in quotations) { Reference reference = quotation.Reference; if (reference == null) { return; } Project project = reference.Project; if (project == null) { return; } Annotation mainQuotationAnnotation = quotation.EntityLinks.Where(link => link.Target is Annotation).FirstOrDefault().Target as Annotation; if (mainQuotationAnnotation == null) { return; } Location location = mainQuotationAnnotation.Location; if (location == null) { return; } KnowledgeItem comment = new KnowledgeItem(reference, QuotationType.Comment); comment.PageRange = quotation.PageRange; comment.PageRange.Update(quotation.PageRange.NumberingType); comment.PageRange.Update(quotation.PageRange.NumeralSystem); comment.CoreStatement = quotation.CoreStatement + " (Comment)"; comment.CoreStatementUpdateType = UpdateType.Manual; reference.Quotations.Add(comment); EntityLink commentQuotationLink = new EntityLink(project); commentQuotationLink.Source = comment; commentQuotationLink.Target = quotation; commentQuotationLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(commentQuotationLink); Annotation newAnnotation = new Annotation(location); newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0); newAnnotation.Quads = mainQuotationAnnotation.Quads; newAnnotation.Visible = false; location.Annotations.Add(newAnnotation); EntityLink commentAnnotationLink = new EntityLink(project); commentAnnotationLink.Source = comment; commentAnnotationLink.Target = newAnnotation; commentAnnotationLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(commentAnnotationLink); lastComment = comment; lastAnnotation = newAnnotation; } quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(lastComment, true); pdfViewControl.GoToAnnotation(lastAnnotation); Program.ActiveProjectShell.ShowKnowledgeItemFormForExistingItem(Program.ActiveProjectShell.PrimaryMainForm, lastComment); }
public static void AssignPageRangeManuallyAfterShowingAnnotation() { KnowledgeItem quotation = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().FirstOrDefault(); if (quotation.EntityLinks.FirstOrDefault() == null) { return; } Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault(); SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater; Reference reference = quotation.Reference; if (reference == null) { return; } List <KnowledgeItem> quotations = reference.Quotations.ToList(); int index = quotations.FindIndex(q => q == quotation); Annotation annotation = quotation.EntityLinks.FirstOrDefault().Target as Annotation; if (annotation == null) { return; } PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl; PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } pdfViewControl.GoToAnnotation(annotation); KnowledgeItemsForms.NewPageRangeForm("Please enter the new page range:", out string data); if (!String.IsNullOrEmpty(data)) { quotation.PageRange = quotation.PageRange.Update(data); } if (quotations[index - 1] == null) { return; } Program.ActiveProjectShell.PrimaryMainForm.ActiveControl = quotationSmartRepeater; quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(quotations[index - 1]); annotation = quotations[index - 1].EntityLinks.FirstOrDefault().Target as Annotation; if (annotation == null) { return; } pdfViewControl.GoToAnnotation(annotation); }