Exemplo n.º 1
0
        public static void Execute(this NPTCommand command, Window window)
        {
            int index = LastCommands.FindIndex(c => c.Name.Equals(command.Name));

            if (index > -1)
            {
                LastCommands.RemoveAt(index);
            }
            LastCommands.Add(command);

            while (LastCommands.Count >= 10)
            {
                LastCommands.RemoveAt(0);
            }

            command.CommandAction?.Invoke(window);
        }
        public IEnumerable <NPTCommand> GetFilteredList(string filter)
        {
            if (filter != null)
            {
                Match expressionEvalMatch = expressionEvalRegex.Match(filter);

                if (expressionEvalMatch.Success)
                {
                    string expression = expressionEvalMatch.Groups["expression"].Value.Trim();

                    if (expressionEvalMatch.Groups["histo"].Success)
                    {
                        return(Config.Instance.LastScripts
                               .Select(script => new NPTCommand()
                        {
                            Name = script,
                            CommandAction = win =>
                            {
                                BNpp.Text = script;
                                BNpp.Scintilla.DocumentEnd();
                                win.Close();
                            }
                        })
                               .RegexFilterCommands(filter.Substring(2)));
                    }
                    else if (!string.IsNullOrEmpty(expression))
                    {
                        NPTCommand expressionCommand = new NPTCommand
                        {
                            Name = expression,
                        };

                        Evaluation.Process(true, expressionCommand.Name, result => expressionCommand.ResultOrInfoSup = result, true);

                        expressionCommand.CommandAction = win =>
                        {
                            BNpp.SelectedText = expressionCommand.ResultOrInfoSup.ToStringOutput();
                            win.Close();
                        };

                        SelectionIndex = 0;

                        return(new List <NPTCommand>
                        {
                            expressionCommand
                        });
                    }
                }
                else if (filter.StartsWith("@SetLanguage "))
                {
                    SelectionIndex = 0;
                    return(NPTCommands.Languages.RegexFilterCommands(filter.Substring("@SetLanguage ".Length)));
                }
                else
                {
                    SelectionIndex = 0;
                    return(NPTCommands.LastCommands
                           .Cast <NPTCommand>()
                           .Reverse()
                           .Concat(NPTCommands.Commands)
                           .Append(new NPTCommand()
                    {
                        Name = "[@GetCurrentLanguage]",
                        ResultOrInfoSup = "[" + BNpp.NotepadPP.GetCurrentLanguage().ToString() + "] : " + NPTCommands.Languages.Find(c => c.ResultOrInfoSup is LangType tmplangType && tmplangType == BNpp.NotepadPP.GetCurrentLanguage())?.Name,
                        CommandAction = win =>
                        {
                            BNpp.Text = BNpp.NotepadPP.GetCurrentLanguage().ToString();
                            win.Close();
                        }
                    })