示例#1
0
        private void DefinitionBox_FormClosing(object sender, FormClosingEventArgs e)
        {
            ThisAddIn.DecreaseDialogCoords();

            WordHelpers.RunActionWithWaitCursor(() =>
            {
                if (HighlightAllUsages.Checked)
                {
                    if (_corectDefinitionOccurences.Count != 0)
                    {
                        DocumentHelpers.ClearHightlightOnAllInstancesOfTerm(_corectDefinitionOccurences);
                    }
                }
                if (HighlightIncorrectUsages.Checked)
                {
                    if (_incorrectDefinitionOccurences.Count != 0)
                    {
                        DocumentHelpers.ClearHightlightOnAllInstancesOfTerm(_incorrectDefinitionOccurences);
                    }
                }
                if (_currentPosition != null)
                {
                    Navigate.ToRange(_currentPosition);
                }
            });
        }
示例#2
0
        private void HighlightUsages_CheckedChanged(object sender, EventArgs e)
        {
            WordHelpers.RunActionWithWaitCursor(() =>
            {
                ResetTheCounters();
                var isFieldChecked = HighlightAllUsages.Checked;

                if (isFieldChecked)
                {
                    if (_corectDefinitionOccurences.Count != 0)
                    {
                        HighLightCorrectUsages();
                        NextDefinition.Enabled = true;
                    }
                    else
                    {
                        if (HighlightIncorrectUsages.Checked && _incorrectDefinitionOccurences.Count != 0)
                        {
                            NextDefinition.Enabled = true;
                        }
                    }
                    return;
                }

                if (!HighlightIncorrectUsages.Checked)
                {
                    NextDefinition.Enabled    = false;
                    PreviousDefiniton.Enabled = false;
                }
                DocumentHelpers.ClearHightlightOnAllInstancesOfTerm(_corectDefinitionOccurences);
            });
        }
示例#3
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.");
        }
示例#4
0
        private void ReportBtn_Click(object sender, RibbonControlEventArgs e)
        {
            LogHelper.Info("Report generation requested");

            WordHelpers.RunActionWithWaitCursor(() =>
            {
                new ReportBox().Show();
            });

            LogHelper.Info("Report generation complete");
        }
示例#5
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();
                }
            });
        }
示例#6
0
        private void richTextBoxEx1_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            WordHelpers.RunActionWithWaitCursor(() =>
            {
                var link = e.LinkText;
                var text = link;

                var match = Regex.Match(text, ReferencePattern);

                if (match.Groups.Count < 4)
                {
                    MessageBox.Show(new Form()
                    {
                        TopMost = true
                    }, @"Such Clause or Schedule was not found");
                    return;
                }

                var title           = match.Groups[3].Value;
                var listFormatValue = match.Groups[2].Value.Trim();
                listFormatValue     = Regex.Replace(listFormatValue, @"\p{C}+", string.Empty);

                Document document = Globals.ThisAddIn.Application.ActiveDocument;
                Range rng         = document.Content;

                rng.Find.ClearFormatting();
                rng.Find.Forward = true;
                rng.Find.Text    = title;
                rng.Find.Execute();

                while (rng.Find.Found)
                {
                    var listFormatFromWord = rng.ListFormat.ListString.Trim('.');
                    listFormatFromWord     = Regex.Replace(listFormatFromWord, @"\p{C}+", string.Empty);

                    if (listFormatFromWord.Equals(listFormatValue))
                    {
                        Navigate.ToRange(rng);
                        return;
                    }
                    rng.Find.Execute();
                }

                MessageBox.Show(new Form()
                {
                    TopMost = true
                }, @"Such Clause or Schedule was not found");
            });
        }
示例#7
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();
                    }
                });
            }
        }
示例#8
0
        private void ShowOccurancesButton_Click(object sender, EventArgs e)
        {
            WordHelpers.RunActionWithWaitCursor(() =>
            {
                SetDefinitionOccurences();
                var amountOfCorrectOccurences   = _corectDefinitionOccurences.Count;
                var amountOfIncorrectOccurences = _incorrectDefinitionOccurences.Count;
                if (amountOfCorrectOccurences > 0)
                {
                    HighlightAllUsages.Enabled = true;
                    HighlightAllUsages.Text    = $"Highlight Correct Usages ({amountOfCorrectOccurences})";
                }
                if (amountOfIncorrectOccurences > 0)
                {
                    HighlightIncorrectUsages.Enabled = true;
                    HighlightIncorrectUsages.Text    = $"Highlight Incorrect Usages ({amountOfIncorrectOccurences})";
                }

                CountLabel.Text = $"Occurrences: {_definitionOccurences.Count}";
            });
        }
示例#9
0
        private void ScanDocumentBtn_Click(object sender, RibbonControlEventArgs e)
        {
            LogHelper.Info("Scanning document...");

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

                var analyzer = Globals.ThisAddIn.AnalyzersByDocument[activeDocument.FullName];

                try
                {
                    analyzer.Analyze();
                }
                catch (Exception ex)
                {
                    LogHelper.Fatal("Failed to analyze doc.", ex);
                }
            })
                                                );
        }