Exemplo n.º 1
0
        private void tmrCheckCompletion_Tick(object sender, EventArgs e)
        {
            if (Options.TimeGoal != null)
            {
                _status = _startTime.Add(Options.TimeGoal.Value).Subtract(DateTime.Now).TotalMinutes.ToString("N0") +
                          " minutes left";
                if (DateTime.Now > _startTime.Add(Options.TimeGoal.Value))
                {
                    tmrCheckCompletion.Stop();
                    GoalFinished();
                }
            }

            if (Options.WordGoal != null)
            {
                var wordCount = CompletionUtils.GetWordCount(textBox.Text, Options.ExcludeGibberish);
                _status = $"{Options.WordGoal - wordCount} words left";
                if (wordCount >=
                    Options.WordGoal)
                {
                    tmrCheckCompletion.Stop();
                    GoalFinished();
                }
            }
        }
Exemplo n.º 2
0
        public void TriggerCompletion()
        {
            var caretPosition     = -1;
            var lineTextUpToCaret = string.Empty;
            var script            = string.Empty;

            Execute.OnUIThread(() =>
            {
                caretPosition = _textArea.Caret.Offset;

                // Get the text from the line which the caret is placed
                var line          = _textArea.Document.GetLineByOffset(caretPosition);
                lineTextUpToCaret = _textArea.Document.GetText(line);
                script            = _textArea.Document.Text;
            });

            if (CompletionUtils.IsInCommentArea(caretPosition, _textArea) || CompletionUtils.IsInStringArea(caretPosition, _textArea))
            {
                Logger.DebugFormat("Is in comment area, skip.");
                return;
            }

            var completionWord = GetWordNextToCaret(lineTextUpToCaret, lineTextUpToCaret.Length - 1);

            /*var token = default(Token);
             * if ((token = IsPreviousTokenCommand(caretPosition)) != null)
             * {
             *  // ReSharper disable once AssignmentInConditionalExpression
             *  if (_completionProvider.IsRunbook(token))
             *  {
             *      // We need to retrieve completion for runbook parameters
             *      Task.Factory.StartNew(() =>
             *      {
             *          Interlocked.Increment(ref _triggerTag);
             *
             *          _completionProvider.GetParameterCompletionData(token, completionWord, _triggerTag);
             *      });
             *
             *      return;
             *  }
             * }*/

            //var runbookToken = IsPreviousTokenCommand(caretPosition);
            var runbookToken = GetCommandFromCaretPosition(caretPosition);

            if (runbookToken != null && !_completionProvider.IsRunbook(runbookToken))
            {
                runbookToken = null;
            }

            Task.Factory.StartNew(() =>
            {
                Interlocked.Increment(ref _triggerTag);

                _completionProvider.GetCompletionData(completionWord, script, lineTextUpToCaret, null, runbookToken, caretPosition,
                                                      null, _triggerTag);
            });
        }
Exemplo n.º 3
0
        public void Initialize(ExtendedRichTextBox textBox, Func <string> getStatus)
        {
            _textBox   = textBox;
            _getStatus = getStatus;

            _textBox.TextChanged += (sender, e) =>
            {
                lblWordCount.Text = $"Words: {CompletionUtils.GetWordCount(_textBox.Text, false)}";
            };
        }