예제 #1
0
        /// <summary>
        /// 确认完成或者丢弃
        /// </summary>
        private bool Complete(bool force)
        {
            if (_CurrentSession == null || !_CurrentSession.IsStarted)
            {
                return(false);
            }
            try
            {
                //如果用户没有选择并且主动丢弃
                if (!_CurrentSession.SelectedCompletionSet.SelectionStatus.IsSelected && !force)
                {
                    _CurrentSession.Dismiss();
                    return(false);
                }
                else
                {
                    ITextEdit     edit     = _CurrentSession.TextView.TextBuffer.CreateEdit();
                    ITextSnapshot snapshot = edit.Snapshot;


                    string inputtext = _CurrentSession.TextView.Caret.Position.BufferPosition.GetContainingLine().GetText();

                    var    inputlist = Core.UsuallyCommon.SearchExtensions.GetStringSingleColumn(inputtext);
                    var    starttext = inputlist.LastOrDefault();
                    string lastChar  = starttext.Substring(starttext.Length - 1, 1);
                    starttext = starttext.Replace(lastChar, "").Trim();

                    int position = (starttext.LastIndexOf(" ") > 0) ? (starttext.Length + 1 - starttext.LastIndexOf(" "))
                            : (starttext.LastIndexOf("\t") > 0 ? (starttext.Length + 1 - starttext.LastIndexOf("\t")) : starttext.Length + 1);


                    edit.Delete(_CurrentSession.TextView.Caret.Position.BufferPosition.Position - position, position);

                    string text = _CurrentSession.SelectedCompletionSet.SelectionStatus.Completion.InsertionText;

                    edit.Insert(_CurrentSession.TextView.Caret.Position.BufferPosition.Position - position, text);


                    edit.Apply();
                    if (_CurrentSession != null)
                    {
                        _CurrentSession.Dismiss();
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                DataServices.AddExexptionLogs(ex, "Complete 方法错误");
            }
            return(true);
        }
        void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (completionSets.Count != 0)
            {
                return;
            }
            try
            {
                string inputtext = session.TextView.Caret.Position.BufferPosition.GetContainingLine().GetText();
                var    alltext   = m_textBuffer.CurrentSnapshot.GetText();
                var    inputlist = Core.UsuallyCommon.SearchExtensions.GetStringSingleColumn(inputtext);


                var    starttext = inputlist.LastOrDefault();
                string lastChar  = starttext.Substring(starttext.Length - 1, 1);
                starttext = starttext.Replace(lastChar, "").Trim();


                var list      = DataServices.GetCompletionList(lastChar, starttext);
                var mCompList = new List <Completion>();
                foreach (var intellisences in list)
                {
                    mCompList.Add(new Completion(
                                      intellisences.DisplayText
                                      , intellisences.InsertionText
                                      , intellisences.Description
                                      , m_sourceProvider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupProperty, StandardGlyphItem.GlyphItemPublic)
                                      , "72"));
                }
                mCompList.Add(new Completion(
                                  "不吃肉的狮子"
                                  , "不吃肉的狮子"
                                  , "不吃肉的狮子"
                                  , m_sourceProvider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphExtensionMethod, StandardGlyphItem.GlyphItemPublic)
                                  , "72"));

                var set = new CompletionSet(
                    "moniker",  //"施政的智能提示",
                    "施政的智能提示",
                    FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer), session),
                    mCompList,
                    null);
                completionSets.Add(set);
            }
            catch (Exception ex)
            {
                DataServices.AddExexptionLogs(ex, "AugmentCompletionSession 方法错误");
            }
        }