protected override void OnBeforePerformingCommand(SwissAcademic.Controls.BeforePerformingCommandEventArgs e) { switch (e.Key) { #region Annotation-based menus case "ImportComments": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.Comment); } break; case "ImportDirectQuotations": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.DirectQuotation); } break; case "ImportIndirectQuotations": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.IndirectQuotation); } break; case "ImportQuickReferences": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.QuickReference); } break; case "ImportSummaries": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.Summary); } break; case "MergeAnnotations": { e.Handled = true; AnnotationsAndQuotationsMerger.MergeAnnotations(); } break; case "SimplifyAnnotations": { e.Handled = true; AnnotationSimplifier.SimplifyAnnotations(); } break; #endregion #region Reference-based commands case "ExportAnnotations": { e.Handled = true; List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().ToList(); AnnotationsExporter.ExportAnnotations(references); } break; case "ExportBookmarks": { e.Handled = true; List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().ToList(); QuickReferenceBookmarkExporter.ExportBookmarks(references); } break; case "MoveAttachment": { e.Handled = true; LocationMover.MoveAttachment(); } break; #endregion #region Quotations Pop-Up Menu case "CleanQuotationsText": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuotationTextCleaner.CleanQuotationsText(quotations); } break; case "ConvertDirectQuoteToRedHighlight": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuotationTypeConverter.ConvertDirectQuoteToRedHighlight(quotations); } break; case "CreateCommentOnQuotation": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); CommentCreator.CreateCommentOnQuotation(quotations); } break; case "CreateSummaryOnQuotations": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); SummaryCreator.CreatesummaryOnQuotations(quotations); } break; case "KnowledgeItemsSortInReference": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuotationsSorter.SortQuotations(quotations); } break; case "CommentAnnotation": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); CommentAnnotationCreator.CreateCommentAnnotation(quotations); } break; case "LinkQuotations": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuotationLinker.LinkQuotations(quotations); } break; case "PageAssignFromPositionInPDF": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); PageRangeFromPositionInPDFAssigner.AssignPageRangeFromPositionInPDF(quotations); } break; case "PageAssignFromPreviousQuotation": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); PageRangeFromPrecedingQuotationAssigner.AssignPageRangeFromPrecedingQuotation(quotations); } break; case "QuotationsMerge": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); AnnotationsAndQuotationsMerger.MergeQuotations(quotations); } break; case "QuickReferenceTitleCase": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuickReferenceTitleCaser.TitleCaseQuickReference(quotations); } break; case "ShowQuotationAndSetPageRangeManually": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); PageRangeManualAssigner.AssignPageRangeManuallyAfterShowingAnnotation(); } break; #endregion #region ReferenceEditorUriLocationsPopupMenu #endregion #region KnowledgeOrganizerKnowledgeItemsContextMenu case "OpenKnowledgeItemAttachment": { e.Handled = true; MainForm mainForm = Program.ActiveProjectShell.PrimaryMainForm; if (mainForm.ActiveWorkspace == MainFormWorkspace.KnowledgeOrganizer) { KnowledgeItem knowledgeItem = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedKnowledgeItems().FirstOrDefault(); if (knowledgeItem.EntityLinks.FirstOrDefault() == null) { break; } Annotation annotation = knowledgeItem.EntityLinks.FirstOrDefault().Target as Annotation; if (annotation == null) { break; } Location location = annotation.Location; SwissAcademic.Citavi.Shell.Controls.Preview.PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl; Program.ActiveProjectShell.ShowPreviewFullScreenForm(location, previewControl, null); } } break; case "SelectLinkedKnowledgeItem": { e.Handled = true; MainForm mainForm = Program.ActiveProjectShell.PrimaryMainForm; KnowledgeItem target; KnowledgeItem knowledgeItem; if (mainForm.ActiveWorkspace == MainFormWorkspace.ReferenceEditor) { knowledgeItem = mainForm.GetSelectedQuotations().FirstOrDefault(); } else if (mainForm.ActiveWorkspace == MainFormWorkspace.KnowledgeOrganizer) { knowledgeItem = mainForm.ActiveKnowledgeItem; } else { return; } if (knowledgeItem == null) { return; } if (knowledgeItem.EntityLinks.Where(el => el.Indication == EntityLink.CommentOnQuotationIndication).Count() == 0) { return; } if (knowledgeItem.QuotationType == QuotationType.Comment) { target = knowledgeItem.EntityLinks.ToList().Where(n => n != null && n.Indication == EntityLink.CommentOnQuotationIndication && n.Target as KnowledgeItem != null).ToList().FirstOrDefault().Target as KnowledgeItem; } else { target = knowledgeItem.EntityLinks.ToList().Where(n => n != null && n.Indication == EntityLink.CommentOnQuotationIndication && n.Target as KnowledgeItem != null).ToList().FirstOrDefault().Source as KnowledgeItem; } if (target == null) { return; } if (mainForm.ActiveWorkspace == MainFormWorkspace.ReferenceEditor) { 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 = target.Reference; if (reference == null) { return; } List <KnowledgeItem> quotations = reference.Quotations.ToList(); int index = quotations.FindIndex(q => q == target); quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(quotations[index]); } else if (mainForm.ActiveWorkspace == MainFormWorkspace.KnowledgeOrganizer) { mainForm.ActiveKnowledgeItem = target; } else { return; } return; } case "SortKnowledgeItemsInSelection": { e.Handled = true; var mainForm = (MainForm)e.Form; if (mainForm.KnowledgeOrganizerFilterSet.Filters.Count() != 1 || mainForm.KnowledgeOrganizerFilterSet.Filters[0].Name == "Knowledge items without categories") { MessageBox.Show("You must select one category."); return; } KnowledgeItemInSelectionSorter.SortSelectedKnowledgeItems(mainForm); } break; case "SortKnowledgeItemsInCategory": { e.Handled = true; var mainForm = (MainForm)e.Form; if (mainForm.KnowledgeOrganizerFilterSet.Filters.Count() != 1 || mainForm.KnowledgeOrganizerFilterSet.Filters[0].Name == "Knowledge items without categories") { MessageBox.Show("You must select one category."); return; } KnowledgeItemInCategorySorter.SortKnowledgeItemsInCategorySorter(mainForm); } break; #endregion } base.OnBeforePerformingCommand(e); }
public static Annotation CombineAnnotations(List <Annotation> annotations) { if (annotations.Count() == 1) { return(annotations.FirstOrDefault()); } // Static Variables Project project = Program.ActiveProjectShell.Project; if (project == null) { return(null); } List <Location> locations = annotations.Select(a => a.Location).Distinct().ToList(); if (locations.Count != 1) { return(null); } Location location = locations.FirstOrDefault(); List <Annotation> originalAnnotations = annotations .Where ( a => a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() == 0 ) .ToList(); List <Annotation> redundantAnnotations = annotations .Where ( a => a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0 ) .ToList(); List <Annotation> soureAnnotations = annotations .Where ( a => a.EntityLinks.Where ( e => e.Indication == EntityLink.SourceAnnotLinkIndication && (Annotation)e.Source != null && (Annotation)e.Source != a ) .Count() > 0 ) .Select ( a => (Annotation) a.EntityLinks.Where ( e => e.Indication == EntityLink.SourceAnnotLinkIndication && (Annotation)e.Source != null && (Annotation)e.Source != a ) .FirstOrDefault().Source ).ToList(); // Dynamic Variables Annotation newAnnotation = new Annotation(location); List <Quad> quads = new List <Quad>(); // The Magic foreach (Annotation annotation in annotations) { quads.AddRange(annotation.Quads); } newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0); newAnnotation.Quads = quads; newAnnotation.Visible = true; location.Annotations.Add(newAnnotation); foreach (Annotation originalAnnotation in originalAnnotations) { originalAnnotation.Visible = false; AnnotationsImporter.LinkWithKnowledgeItemIndicationAnnotation(originalAnnotation, newAnnotation); } foreach (Annotation redundantAnnotation in redundantAnnotations) { location.Annotations.Remove(redundantAnnotation); } foreach (Annotation soureAnnotation in soureAnnotations) { soureAnnotation.Visible = false; AnnotationsImporter.LinkWithKnowledgeItemIndicationAnnotation(soureAnnotation, newAnnotation); } return(newAnnotation); }