コード例 #1
0
        public static void ShowThesaurus()
        {
            string word = string.Empty;
            var    line = Far.Api.Line;

            if (line != null)
            {
                var match = MatchCaret(new Regex(Settings.Default.WordPattern, RegexOptions.IgnorePatternWhitespace), line.Text, line.Caret, false);
                if (match != null)
                {
                    word = match.Value;
                }
            }

            word = Far.Api.Input(My.Word, Settings.ModuleName, My.Thesaurus, word);
            if (word == null || (word = word.Trim()).Length == 0)
            {
                return;
            }

            var menu = Far.Api.CreateMenu();

            menu.Title = word;

            Far.Api.UI.SetProgressState(TaskbarProgressBarState.Indeterminate);
            Far.Api.UI.WindowTitle = My.Searching;
            try
            {
                using (var thesaurus = new MultiThesaurus(Dictionaries))
                {
                    foreach (var result in thesaurus.Lookup(word))
                    {
                        foreach (var meaning in result.Meanings)
                        {
                            menu.Add(meaning.Description).IsSeparator = true;
                            foreach (var term in meaning.Synonyms)
                            {
                                menu.Add(term);
                            }
                        }
                    }
                }
            }
            finally
            {
                Far.Api.UI.SetProgressState(TaskbarProgressBarState.NoProgress);
            }

            if (!menu.Show())
            {
                return;
            }

            Far.Api.CopyToClipboard(menu.Items[menu.Selected].Text);
        }
コード例 #2
0
        public static void ShowThesaurus()
        {
            string word = string.Empty;
            var    line = Far.Api.Line;

            if (line != null)
            {
                var match = MatchCaret(new Regex(Settings.Default.WordPattern, RegexOptions.IgnorePatternWhitespace), line.Text, line.Caret, false);
                if (match != null)
                {
                    word = match.Value;
                }
            }

            word = Far.Api.Input(My.Word, Settings.ModuleName, My.Thesaurus, word);
            if (word == null || (word = word.Trim()).Length == 0)
            {
                return;
            }

            var menu = Far.Api.CreateMenu();

            menu.Title     = word;
            menu.HelpTopic = Far.Api.GetHelpTopic("thesaurus-menu");
            menu.AddKey(KeyCode.C, ControlKeyStates.LeftCtrlPressed);
            menu.AddKey(KeyCode.Insert, ControlKeyStates.LeftCtrlPressed);

            Far.Api.UI.SetProgressState(TaskbarProgressBarState.Indeterminate);
            Far.Api.UI.WindowTitle = My.Searching;
            try
            {
                using (var thesaurus = new MultiThesaurus(Dictionaries))
                {
                    foreach (var result in thesaurus.Lookup(word))
                    {
                        foreach (var meaning in result.Meanings)
                        {
                            menu.Add(meaning.Description).IsSeparator = true;
                            foreach (var term in meaning.Synonyms)
                            {
                                menu.Add(term);
                            }
                        }
                    }
                }
            }
            finally
            {
                Far.Api.UI.SetProgressState(TaskbarProgressBarState.NoProgress);
            }

            if (!menu.Show() || menu.Selected < 0)
            {
                return;
            }

            // copy
            if (menu.Key.IsCtrl() && (menu.Key.VirtualKeyCode == KeyCode.C || menu.Key.VirtualKeyCode == KeyCode.Insert))
            {
                // get text and remove "(...)"
                var text  = menu.Items[menu.Selected].Text;
                var index = text.IndexOf('(');
                if (index >= 0)
                {
                    text = text.Substring(0, index).Trim();
                }

                Far.Api.CopyToClipboard(text);
            }
        }