EditCitation() public method

public EditCitation ( Field field, List entryAndPagePairs ) : void
field Field
entryAndPagePairs List
return void
Example #1
0
        public void DoEditReference()
        {
            if (!CurrentDocumentControllerIsReady)
            {
                return;
            }

            var currentDatabase = currentDocumentController.GetDatabase();

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

            var selectionManager = new SelectionManager(currentDocumentController);

            if (selectionManager.IsRange)
            {
                Debug.WriteLine("Has Range");
            }
            if (selectionManager.FieldMatches.Count != 0)
            {
                Debug.WriteLine(String.Format("Has {0} field(s)", selectionManager.FieldMatches.Count));
            }

            if (!selectionManager.IsSingleCitation)
            {
                return;
            }

            var fieldMatch     = selectionManager.FieldMatches[0];
            var field          = fieldMatch.Field;
            var inlineCitation = currentDocumentController.CiteProc.CreateInlineCitationFromFieldJSON(field);

            var entryAndPagePairs = Helper.ExtractSources(inlineCitation, currentDatabase);

            var expectedItemCount = inlineCitation.CitationItems.Length;
            var foundItemCount    = entryAndPagePairs.Count;

            if (foundItemCount != expectedItemCount)
            {
                var missingItemCount = expectedItemCount - foundItemCount;
                var message          = expectedItemCount == 1
                                                ? "The reference"
                                                : foundItemCount == 0
                                                        ? "None of references"
                                                        : missingItemCount == 1
                                                                ? "One of the references"
                                                                : missingItemCount + " references";

                message += " could not be found in the current database\r\nIf you continue and make changes, these will be lost.\r\n\r\nAre you sure you want to continue?";

                if (MessageBox.Show(message, "Edit Items Missing References Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                {
                    return;
                }
            }

            var editReferencesForm = new AddReferencesForm();

            editReferencesForm.Reset(currentDatabase);
            editReferencesForm.SetSelectedReferences(entryAndPagePairs);

            var result = editReferencesForm.ShowDialog();

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

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

            currentDocumentController.EditCitation(field, entryAndPagePairs);
        }
Example #2
0
        public void DoEditReference()
        {
            if (!CurrentDocumentControllerIsReady)
            {
                return;
            }

            var currentDatabase = currentDocumentController.GetDatabase();

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

            var selectionManager = new SelectionManager(currentDocumentController);

            if (!selectionManager.IsAtOrBeforeSingleCitation)
            {
                return;
            }

            var fieldMatch     = selectionManager.FirstFieldMatch;
            var field          = fieldMatch.Field;
            var inlineCitation = currentDocumentController.CiteProc.CreateInlineCitationFromFieldJSON(field);

            var entryAndPagePairs = Helper.ExtractSources(inlineCitation, currentDatabase);

            var expectedItemCount = inlineCitation.CitationItems.Length;
            var foundItemCount    = entryAndPagePairs.Count;

            if (foundItemCount != expectedItemCount)
            {
                var missingItemCount = expectedItemCount - foundItemCount;
                var message          = expectedItemCount == 1
                                                ? "The reference"
                                                : foundItemCount == 0
                                                        ? "None of references"
                                                        : missingItemCount == 1
                                                                ? "One of the references"
                                                                : missingItemCount + " references";

                message += " could not be found in the current database.\r\n";

                var f = new List <String>();
                for (var i = 0; i < inlineCitation.CitationItems.Length; i++)
                {
                    var ci = inlineCitation.CitationItems[i];
                    if (null == entryAndPagePairs.Find(item => item.ID == ci.ID))
                    {
                        f.Add(ci.ID);
                    }
                }
                f.Sort();
                message += "Missing: " + String.Join(", ", f.ToArray()) + "\r\n";

                message += "If you continue and make changes, these will be lost.\r\n\r\nAre you sure you want to continue?";

                if (MessageBox.Show(message, "Edit Items Missing References Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                {
                    return;
                }
            }

            var editReferencesForm = new AddReferencesForm();

            editReferencesForm.Reset(currentDatabase);
            editReferencesForm.SetSelectedReferences(entryAndPagePairs);

            var result = editReferencesForm.ShowDialog();

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

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

            currentDocumentController.EditCitation(field, entryAndPagePairs);
        }