예제 #1
0
        public void OnWindowSelectionChange()
        {
            if (currentDocumentController == null || currentDocumentController.IsUpdating) return;
            Debug.WriteLine("MainController.OnWindowSelectionChange()");

            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));

            addinModule.UpdateState(selectionManager);
        }
예제 #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);
        }
예제 #3
0
		void UpdateCurrentDocumentController()
		{
			var activeDocument = GetActiveDocument();
			if (activeDocument == null)
			{
				Debug.WriteLine("UpdateCurrentDocumentController(): No active Document.");
				currentDocumentController = null;
				addinModule.UpdateState(null);
				return;
			}

			Debug.WriteLine("WindowCount=" + wordApp.Application.Windows.Count);

			Debug.WriteLine("UpdateCurrentDocumentController(): Updating current");
			currentDocumentController = GetControllerForDocument(activeDocument);
			currentDocumentController.Activate();

			currentDocumentController.Document.Application.ScreenUpdating = false;
			try
			{

				addinModule.SetSelectedStyle(currentDocumentController.Style ?? DefaultStyle);

				using (var selectionManager = new SelectionManager(currentDocumentController))
				{
					addinModule.UpdateState(selectionManager);
				}
			}
			finally
			{
				currentDocumentController.Document.Application.ScreenUpdating = true;
			}
		}
예제 #4
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);
        }
예제 #5
0
		/// <summary>
		/// Called when user changes style from dropdown list.
		/// </summary>
		/// <param name="newStyle"></param>
		public void TryChangeStyle(StyleInfo newStyle)
		{
			Debug.Assert(currentDocumentController != null);

			if (newStyle == null)
			{
				Process.Start(StyleHelper.FindMoreCitationStylesUrl);

				addinModule.SetSelectedStyle(currentDocumentController.Style);

				return;
			}

			if (IsValidStyle(newStyle))
			{
				currentDocumentController.Style = newStyle;

				DefaultStyle = newStyle;
			}

			addinModule.SetSelectedStyle(currentDocumentController.Style);

			using (var selectionManager = new SelectionManager(currentDocumentController))
			{
				addinModule.UpdateState(selectionManager);
			}
		}
예제 #6
0
		public void OnWindowSelectionChange()
		{
			if (currentDocumentController == null || currentDocumentController.IsUpdating) return;

			if (currentDocumentController.IsReferencesTabSelected() == false)
			{
				addinModule.NotifySelectionChangedWhilstNotOnReferenceTab();
				return;
			}

			using (var selectionManager = new SelectionManager(currentDocumentController))
			{
				addinModule.UpdateState(selectionManager);
			}
		}
예제 #7
0
		public void UpdateState(SelectionManager selectionManager)
		{
			var hasSelectionManager = selectionManager != null;
			var currentDocumentControllerIsReady = mainController.CurrentDocumentControllerIsReady;

			var fullyEnabled = hasSelectionManager && currentDocumentControllerIsReady;
			var partlyEnabled = hasSelectionManager;
			var fieldMatchCount = hasSelectionManager ? selectionManager.FieldMatches.Count : 0;

			var canAdd = fullyEnabled && fieldMatchCount == 0;
			var canEdit = fullyEnabled && selectionManager.IsSingleCitation;
			var canInsertBibliography = fullyEnabled && fieldMatchCount == 0;

			rbAddReference.Visible = !canEdit;
			rbAddReference.Enabled = canAdd;
			rbEditReference.Visible = canEdit;
			rbRefresh.Enabled = fullyEnabled;
			rbInsertBibliography.Enabled = canInsertBibliography;
			rcbStyle.Enabled = partlyEnabled;
			rbMovePrevious.Enabled = partlyEnabled;
			rbMoveNext.Enabled = partlyEnabled;

			rbInsertTestData.Visible = showInsertTestDataButton;
			rbInsertTestData.Enabled = fullyEnabled;

			cbbAddReference.Visible = !canEdit;
			cbbAddReference.Enabled = canAdd;
			cbbEditReference.Visible = /*cbbEditReference.Enabled = */canEdit;
			cbbRefresh.Enabled = fullyEnabled;
			cbbInsertBibliography.Enabled = canInsertBibliography;
			ccbStyle.Enabled = partlyEnabled;
			cbbMovePrevious.Enabled = partlyEnabled;
			cbbMoveNext.Enabled = partlyEnabled;
		}
예제 #8
0
        public void UpdateState(SelectionManager selectionManager)
        {
            selectionChangedWhilstNotOnReferencesTab = false;

            var hasSelectionManager = selectionManager != null;
            var currentDocumentControllerIsReady = mainController.CurrentDocumentControllerIsReady;

            var fullyEnabled     = hasSelectionManager && currentDocumentControllerIsReady;
            var partlyEnabled    = hasSelectionManager;
            var noFieldsSelected = !hasSelectionManager || selectionManager.IsNoFieldsSelected;

            var canAdd  = fullyEnabled && noFieldsSelected;
            var canEdit = fullyEnabled && selectionManager.IsAtOrBeforeSingleCitation;
            var canInsertBibliography = fullyEnabled && noFieldsSelected && !selectionManager.IsAtOrBeforeSingleCitation && !selectionManager.IsInBibliography;

            //var canInsertBibliography = fullyEnabled && noFieldsSelected && !selectionManager.IsAtOrBeforeSingleCitation;

            // The properties don't seem to perform a NOP when assigning the existing value
            // therefore we have to check ourselves! Unbelievable but true!
            // Setting the properties takes no measureable time (tested by Stopwatch) but Word
            // must be using the new values outside this call as moving the cursor by keyboard
            // becomes noticable slowly if we don't do this.
            // ReSharper disable RedundantCheckBeforeAssignment
            if (rbAddReference.Visible != !canEdit)
            {
                rbAddReference.Visible = !canEdit;
            }
            if (rbAddReference.Enabled != canAdd)
            {
                rbAddReference.Enabled = canAdd;
            }
            if (rbEditReference.Visible != canEdit)
            {
                rbEditReference.Visible = canEdit;
            }
            if (rbRefresh.Enabled != fullyEnabled)
            {
                rbRefresh.Enabled = fullyEnabled;
            }
            if (rbInsertBibliography.Enabled != canInsertBibliography)
            {
                rbInsertBibliography.Enabled = canInsertBibliography;
            }
            if (rcbStyle.Enabled != partlyEnabled)
            {
                rcbStyle.Enabled = partlyEnabled;
            }
            if (rbMovePrevious.Enabled != partlyEnabled)
            {
                rbMovePrevious.Enabled = partlyEnabled;
            }
            if (rbMoveNext.Enabled != partlyEnabled)
            {
                rbMoveNext.Enabled = partlyEnabled;
            }

            if (rbInsertTestData.Visible != showInsertTestDataButton)
            {
                rbInsertTestData.Visible = showInsertTestDataButton;
            }
            if (rbInsertTestData.Enabled != fullyEnabled)
            {
                rbInsertTestData.Enabled = fullyEnabled;
            }

            if (cbbAddReference.Visible != !canEdit)
            {
                cbbAddReference.Visible = !canEdit;
            }
            if (cbbAddReference.Enabled != canAdd)
            {
                cbbAddReference.Enabled = canAdd;
            }
            if (cbbEditReference.Visible != canEdit)
            {
                cbbEditReference.Visible = canEdit;
            }
            if (cbbRefresh.Enabled != fullyEnabled)
            {
                cbbRefresh.Enabled = fullyEnabled;
            }
            if (cbbInsertBibliography.Enabled != canInsertBibliography)
            {
                cbbInsertBibliography.Enabled = canInsertBibliography;
            }
            if (ccbStyle.Enabled != partlyEnabled)
            {
                ccbStyle.Enabled = partlyEnabled;
            }
            if (cbbMovePrevious.Enabled != partlyEnabled)
            {
                cbbMovePrevious.Enabled = partlyEnabled;
            }
            if (cbbMoveNext.Enabled != partlyEnabled)
            {
                cbbMoveNext.Enabled = partlyEnabled;
            }
            // ReSharper restore RedundantCheckBeforeAssignment
        }
예제 #9
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);
        }
예제 #10
0
		public void UpdateState(SelectionManager selectionManager)
		{
			selectionChangedWhilstNotOnReferencesTab = false;

			var hasSelectionManager = selectionManager != null;
			var currentDocumentControllerIsReady = mainController.CurrentDocumentControllerIsReady;

			var fullyEnabled = hasSelectionManager && currentDocumentControllerIsReady;
			var partlyEnabled = hasSelectionManager;
			var noFieldsSelected = !hasSelectionManager || selectionManager.IsNoFieldsSelected;

			var canAdd = fullyEnabled && noFieldsSelected;
			var canEdit = fullyEnabled && selectionManager.IsAtOrBeforeSingleCitation;
			var canInsertBibliography = fullyEnabled && noFieldsSelected && !selectionManager.IsAtOrBeforeSingleCitation && !selectionManager.IsInBibliography;
			//var canInsertBibliography = fullyEnabled && noFieldsSelected && !selectionManager.IsAtOrBeforeSingleCitation;

			// The properties don't seem to perform a NOP when assigning the existing value
			// therefore we have to check ourselves! Unbelievable but true!
			// Setting the properties takes no measureable time (tested by Stopwatch) but Word
			// must be using the new values outside this call as moving the cursor by keyboard
			// becomes noticable slowly if we don't do this.
			// ReSharper disable RedundantCheckBeforeAssignment
			if (rbAddReference.Visible != !canEdit) rbAddReference.Visible = !canEdit;
			if (rbAddReference.Enabled != canAdd) rbAddReference.Enabled = canAdd;
			if (rbEditReference.Visible != canEdit) rbEditReference.Visible = canEdit;
			if (rbRefresh.Enabled != fullyEnabled) rbRefresh.Enabled = fullyEnabled;
			if (rbInsertBibliography.Enabled != canInsertBibliography) rbInsertBibliography.Enabled = canInsertBibliography;
			if (rcbStyle.Enabled != partlyEnabled) rcbStyle.Enabled = partlyEnabled;
			if (rbMovePrevious.Enabled != partlyEnabled) rbMovePrevious.Enabled = partlyEnabled;
			if (rbMoveNext.Enabled != partlyEnabled) rbMoveNext.Enabled = partlyEnabled;

			if (rbInsertTestData.Visible != showInsertTestDataButton) rbInsertTestData.Visible = showInsertTestDataButton;
			if (rbInsertTestData.Enabled != fullyEnabled) rbInsertTestData.Enabled = fullyEnabled;

			if (cbbAddReference.Visible != !canEdit) cbbAddReference.Visible = !canEdit;
			if (cbbAddReference.Enabled != canAdd) cbbAddReference.Enabled = canAdd;
			if (cbbEditReference.Visible != canEdit) cbbEditReference.Visible = canEdit;
			if (cbbRefresh.Enabled != fullyEnabled) cbbRefresh.Enabled = fullyEnabled;
			if (cbbInsertBibliography.Enabled != canInsertBibliography) cbbInsertBibliography.Enabled = canInsertBibliography;
			if (ccbStyle.Enabled != partlyEnabled) ccbStyle.Enabled = partlyEnabled;
			if (cbbMovePrevious.Enabled != partlyEnabled) cbbMovePrevious.Enabled = partlyEnabled;
			if (cbbMoveNext.Enabled != partlyEnabled) cbbMoveNext.Enabled = partlyEnabled;
			// ReSharper restore RedundantCheckBeforeAssignment
		}
예제 #11
0
		void OnRefreshPropertyChanging(object sender, ADXRibbonPropertyChangingEventArgs e)
		{
			if (e.PropertyType != ADXRibbonControlPropertyType.Visible) return;

			if (selectionChangedWhilstNotOnReferencesTab)
			{
				if (mainController.CurrentDocumentController != null)
				{
					selectionChangedWhilstNotOnReferencesTab = false;

					try
					{
						using (var selectionManager = new SelectionManager(mainController.CurrentDocumentController))
						{
							UpdateState(selectionManager);
						}
					}
					catch(Exception ex)
					{
						Debug.WriteLine("Attempting to update via RefreshButton but an exception occurred: " + ex);
					}
				}
				else
				{
					Debug.WriteLine("Attempting to update via RefreshButton but CurrentDocumentController is null so doing nothing");
				}
			}
			else
			{
				Debug.WriteLine("Refresh button is updating but selectionChangedWhilstNotOnReferencesTab=false so doing nothing");
			}
		}