Docear4Word.DocumentController.DoInsertCitation C# (CSharp) Method

DoInsertCitation() public method

public DoInsertCitation ( List allEntries, bool isSequence, bool isLineSequence ) : void
allEntries List
isSequence bool
isLineSequence bool
return void
        public void DoInsertCitation(List<EntryAndPagePair> allEntries, bool isSequence, bool isLineSequence)
        {
            if (allEntries == null || allEntries.Count == 0) return;

            var authorProcessorControl = allEntries[0].AuthorProcessorControl;
            var isStandard = authorProcessorControl == AuthorProcessorControl.Standard;
            var isSplitAuthor = authorProcessorControl == AuthorProcessorControl.SplitAuthor;
            var isAuthorOnly = authorProcessorControl == AuthorProcessorControl.AuthorOnly;
            var isSuppressAuthor = authorProcessorControl == AuthorProcessorControl.SuppressAuthor;

            var insertionEntryList = new List<InsertionEntry>();

            try
            {
                isUpdating = true;

                // Is this a standard, non-sequential reference?
                if (isStandard && !isSequence)
                {
                    // Yes, so we have one Citation with all the entries
                    insertionEntryList.Add(new InlineCitationInsertionEntry(CreateInlineCitation(allEntries)));
                }
                // Is this a standard reference but sequential?
                else if (isStandard)
                {
                    // Yes, so we add each entry as a separate Citation
                    for (var i = 0; i < allEntries.Count; i++)
                    {
                        var entry = allEntries[i];

                        // Add a list separator except before the first item
                        if (i > 0) insertionEntryList.Add(new SeparatorInsertionEntry(null, true, isLineSequence));

                        // Add the citation
                        insertionEntryList.Add(new InlineCitationInsertionEntry(CreateInlineCitation(new[] { entry })));
                    }
                }
                else
                {
                    // This is a non-standard reference, so we group by Author
                    var authorGroups = GroupByAuthor(allEntries);

                    // Go through each author group
                    for (var i = 0; i < authorGroups.Count; i++)
                    {
                        // Get the entries for this author
                        var authorEntries = authorGroups[i];

                        // Add a list separator except before the first item
                        if (i > 0) insertionEntryList.Add(new SeparatorInsertionEntry(i < allEntries.Count - 1 ? ", " : " and ", isSequence, isLineSequence));

                        if (isSplitAuthor || isAuthorOnly)
                        {
                            // Add the AuthorOnly part
                            foreach (var authorEntry in authorEntries) authorEntry.AuthorProcessorControl = AuthorProcessorControl.AuthorOnly;
                            insertionEntryList.Add(new InlineCitationInsertionEntry(CreateInlineCitation(new [] { authorEntries[0] })));
                        }

                        if (isSplitAuthor)
                        {
                            // Add an Author/SuppressAuthor separator
                            insertionEntryList.Add(new SeparatorInsertionEntry(" "));
                        }

                        if (isSplitAuthor || isSuppressAuthor)
                        {
                            // Add the SuppressAuthor part
                            foreach (var authorEntry in authorEntries) authorEntry.AuthorProcessorControl = AuthorProcessorControl.SuppressAuthor;
                            insertionEntryList.Add(new InlineCitationInsertionEntry(CreateInlineCitation(authorEntries)));
                        }
                    }
                }

                // Perform the insertion
                InsertItemsList(insertionEntryList);
            }
            finally
            {
                isUpdating = false;
            }
        }

Usage Example

示例#1
0
        public void DoAddReference()
        {
            if (!CurrentDocumentControllerIsReady)
            {
                return;
            }

            if (addinModule.IsEditReference())
            {
                DoEditReference();
                return;
            }

            var currentDatabase = currentDocumentController.GetDatabase();

            if (currentDatabase == null)
            {
                ShowNoDatabaseMessage();
                return;
            }

            var addReferencesForm = new AddReferencesForm();

            addReferencesForm.Reset(currentDatabase);

            var result = addReferencesForm.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                addReferencesForm.Dispose();
                return;
            }

            // Keep a note of these as early as possible after closing dialog
            var isSequence     = (Control.ModifierKeys & Keys.Control) != 0;
            var isLineSequence = isSequence && (Control.ModifierKeys & Keys.Shift) != 0;

            var entryAndPagePairs = addReferencesForm.GetSelectedReferences();

            if (entryAndPagePairs.Count == 0)
            {
                return;
            }

            // Did the user change the database?
            if (addReferencesForm.Database != currentDatabase)
            {
                try
                {
                    // Yes, so store it with the document
                    currentDocumentController.SetDocumentDatabaseFilename(addReferencesForm.Database.Filename);
                }
                catch
                {}
            }

            addReferencesForm.Dispose();

            currentDocumentController.DoInsertCitation(entryAndPagePairs, isSequence, isLineSequence);
        }