Ejemplo n.º 1
0
 public static CompletionSelection Create(CompletionContext context, Action onComplete)
 {
     try
     {
         return new CompletionSelection(context, onComplete);
     }
     catch(System.Exception )
     {
         return null;
     }
 }
Ejemplo n.º 2
0
        private CompletionSelection(CompletionContext context, Action onComplete)
        {
            _context = context;
            _onComplete = onComplete;
            ResultSet results = _context.ResultProvider.GetResults(_context.Path.Str, _context.Line, _context.Column, this);
            if (results == null)
                throw new System.Exception();

            _completionWindow = new CompletionWindow(_context.TextArea);
            foreach (IResult cd in results.Results)
            {
                _completionWindow.CompletionList.CompletionData.Add(cd);
            }

            _completionWindow.StartOffset = _context.Offset;
            _completionWindow.EndOffset = _completionWindow.StartOffset + _context.TriggerWord.Length;

            if (_context.TriggerWord.Length > 0)
            {
                _completionWindow.CompletionList.SelectItem(_context.TriggerWord);
                if(_completionWindow.CompletionList.SelectedItem == null) //nothing to display
                {
                    _completionWindow = null;
                    _onComplete();
                    ;return;
                }
            }

            _completionWindow.Show();
            
            _completionWindow.Closed += (o, args) =>
            {   
                _completionWindow = null;
                _onComplete();
            };
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <param name="triggerWord">Initial text to be selected in the completion window. line and col should point to the start of this word</param>
        /// <param name="line"></param>
        /// <param name="col"></param>
        public void BeginSelection(int offset)
        {
            if (_currentSelection != null) return;

            string triggerWord = ExtractTriggerWord(offset, out offset);

            int line, col;
            if (!_sourceDoc.GetLineAndColumnForOffset(offset, out line, out col))
                return;

            CompletionContext context = new CompletionContext
            {
                Line = line,
                Column = col,
                Offset = offset,
                Path = _sourceDoc.File.Path,
                ResultProvider = _resulsProvider,
                TextArea = _textArea,
                TriggerWord = triggerWord,
                Callback = delegate(LibClang.CodeCompletion.Result selection, ISegment completionSegment, EventArgs insertionRequestEventArgs) 
                    {
                        int caretLoc;
                        int startOffset = completionSegment.Offset;
                        string s = GetInsertionText(selection, insertionRequestEventArgs, out caretLoc);
                        _textArea.Document.Replace(completionSegment, s);
                        if (caretLoc != -1)
                        {
                            _textArea.Caret.Offset = startOffset + caretLoc;
                        }
                    }
            };
            _currentSelection = CompletionSelection.Create(context, delegate { _currentSelection = null; });
        }