public static void LinkQuotations(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;

            List <KnowledgeItem> quotesOrSummaries = quotations.Where(q => q.QuotationType == QuotationType.DirectQuotation || q.QuotationType == QuotationType.IndirectQuotation || q.QuotationType == QuotationType.Summary).ToList();

            List <KnowledgeItem> comments = quotations.Where(q => q.QuotationType == QuotationType.Comment).ToList();

            if (quotesOrSummaries.Count != 1 || comments.Count != 1)
            {
                MessageBox.Show("Please select exactly one direct or indirect quote or summary and exactly one comment.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Project project = Program.ActiveProjectShell.Project;

            if (project == null)
            {
                return;
            }

            KnowledgeItem comment        = comments.FirstOrDefault();
            KnowledgeItem quoteOrSummary = quotesOrSummaries.FirstOrDefault();

            if (comment.EntityLinks.Where(e => e.Indication == EntityLink.CommentOnQuotationIndication).Count() > 0)
            {
                DialogResult dialogResult = MessageBox.Show("The selected comment is already linked to a knowledge item. Do you want to reset the comment's core statement?", "Comment Already Linked", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    comment.CoreStatement = ((KnowledgeItem)comment.EntityLinks.Where(e => e.Indication == EntityLink.CommentOnQuotationIndication).FirstOrDefault().Target).CoreStatement + " (Comment)";
                }
                else if (dialogResult == DialogResult.No)
                {
                    quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate((KnowledgeItem)comment.EntityLinks.Where(e => e.Indication == EntityLink.CommentOnQuotationIndication).FirstOrDefault().Target, true);
                }
                return;
            }

            EntityLink commentDirectQuoteLink = new EntityLink(project);

            commentDirectQuoteLink.Source     = comment;
            commentDirectQuoteLink.Target     = quoteOrSummary;
            commentDirectQuoteLink.Indication = EntityLink.CommentOnQuotationIndication;
            project.EntityLinks.Add(commentDirectQuoteLink);

            comment.CoreStatement = quoteOrSummary.CoreStatement + " (Comment)";

            return;
        }
        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);
        }
Exemple #3
0
        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 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);
        }