Beispiel #1
0
        private void ShowSubDefinition_Click(object sender, EventArgs e)
        {
            WordHelpers.RunActionWithWaitCursor(() =>
            {
                var selection     = StringExtensions.RefineSelectionText(richTextBoxEx1.SelectedText.Trim());
                var newDefinition = Globals.ThisAddIn.AnalyzersByDocument[Globals.ThisAddIn.Application.ActiveDocument.FullName].GetWordDefinition(selection);

                if (newDefinition == null)
                {
                    MessageBox.Show(new Form()
                    {
                        TopMost = true
                    }, @"Definition could not be found");
                    return;
                }
                if (newDefinition.Locations.Count > 1)
                {
                    var listOfDefinitions = new ListOfDefinitions(newDefinition, Globals.ThisAddIn.Application.Selection.Range, Globals.ThisAddIn.Application.ActiveDocument.FullName);
                    listOfDefinitions.Show();
                }
                else
                {
                    var definitionBox = new DefinitionBox {
                        Definition = newDefinition, SourceFile = Globals.ThisAddIn.Application.ActiveDocument.FullName, _currentPosition = Globals.ThisAddIn.Application.Selection.Range
                    };
                    definitionBox.Show();
                }
            });

            LogHelper.Info("Nested definiton shown.");
        }
Beispiel #2
0
        private void ShowDefinitionBtn_Click(object sender, RibbonControlEventArgs e)
        {
            LogHelper.Info($"Showing definition");

            WordHelpers.RunActionWithWaitCursor(() =>
            {
                var activeDocument = Globals.ThisAddIn.Application.ActiveDocument;

                LogHelper.Debug($"Getting selected text...");
                var selectedText = Globals.ThisAddIn.Application.Selection.Text.RefineSelectionText();

                LogHelper.Debug($"Selected text: {selectedText}");

                if (string.IsNullOrWhiteSpace(selectedText))
                {
                    return;
                }

                var definition = Globals.ThisAddIn.AnalyzersByDocument[activeDocument.FullName].GetWordDefinition(selectedText);

                // TODO Leave here commented, we will re-implement this as a final fallback
                //if (string.IsNullOrWhiteSpace(definition.Text))
                //{
                //    definition = FindFirstInstanceOfTerm(selection);
                //}

                if (definition == null)
                {
                    MessageBox.Show(new Form()
                    {
                        TopMost = true
                    }, $"Cannot find the definition '{selectedText}'");
                    return;
                }
                if (definition.Locations.Count > 1)
                {
                    var listOfDefinitions = new ListOfDefinitions(definition, Globals.ThisAddIn.Application.Selection.Range, activeDocument.FullName);
                    listOfDefinitions.Show();
                }
                else
                {
                    LogHelper.Info("Borders: start=" + definition.Locations[0].Start + " ; end=" + definition.Locations[0].End);
                    var definitionBox = new DefinitionBox {
                        Definition = definition, SourceFile = activeDocument.FullName, _currentPosition = Globals.ThisAddIn.Application.Selection.Range
                    };
                    definitionBox.Show();
                }
            });
        }
Beispiel #3
0
        private void ApplicationOnWindowSelectionChange(Selection sel)
        {
            if (Globals.ThisAddIn.ShouldIgnoreNextSelection)
            {
                Globals.ThisAddIn.ShouldIgnoreNextSelection = false;
                return;
            }
            if (Globals.ThisAddIn.FlagOfSelection)
            {
                WordHelpers.RunActionWithWaitCursor(() =>
                {
                    var selectionRange = Globals.ThisAddIn.Application.Selection.Range;
                    var selection      = selectionRange.Text.RefineSelectionText();
                    LogHelper.Info(string.Format("Find Definition Request for '{0}'", selection));

                    if (string.IsNullOrWhiteSpace(selection))
                    {
                        return;
                    }
                    var start          = DateTime.Now;
                    var activeDocument = Globals.ThisAddIn.Application.ActiveDocument;
                    var definition     = AnalyzersByDocument[activeDocument.FullName].GetWordDefinition(selection);

                    if (definition == null)
                    {
                        MessageBox.Show(new Form()
                        {
                            TopMost = true
                        }, @"Definition could not be found");
                        return;
                    }
                    var finish = (DateTime.Now - start);
                    LogHelper.Info($"Word \"{selection}\" was found in {finish.TotalSeconds} seconds");
                    if (definition.Locations.Count > 1)
                    {
                        var listOfDefinitions = new ListOfDefinitions(definition, selectionRange, activeDocument.FullName);
                        listOfDefinitions.Show();
                    }
                    else
                    {
                        var definitionBox = new DefinitionBox {
                            Definition = definition, SourceFile = activeDocument.FullName, _currentPosition = selectionRange
                        };
                        definitionBox.Show();
                    }
                });
            }
        }