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