public static Deferred <T> AutoComplete <T>(this Scintilla editor, int length, bool cancel, IDictionary <string, T> data, bool allItem = true)
        {
            _autoCompleteTimer?.Stop();

            var defer = new Deferred <T>();

            if (data.Count == 0)
            {
                editor.AutoCCancel();
                defer.Reject();
                return(defer);
            }

            _autoCompleteTimer = Redux.Timer.Timeout(100, () =>
            {
                editor.SafeInvoke(delegate
                {
                    var items = data.Keys.Take(MaxAutoCompleteItems).OrderBy(x => x.StartsWith("@") ? "\0" : x).ToArray();
                    var list  = (data.Count <= 20 && allItem && !cancel ? "<All>" + AutoCompleteSeprator : string.Empty) + string.Join(AutoCompleteSeprator.ToString(), items);

                    editor.AutoCShow(length, list);

                    _autoCompleteDeferred = new Deferred <string>();
                    _autoCompleteDeferred.Then(x =>
                    {
                        if (x == "<All>" && allItem && !cancel)
                        {
                            editor.AutoCCancel();
                            editor.AddText(string.Join(",", items.Take(20)));
                            return;
                        }

                        if (data.TryGetValue(x, out T d))
                        {
                            defer.Resolve(d);
                        }
                        if (cancel)
                        {
                            editor.AutoCCancel();
                        }
                    })
                    .Fail(x =>
                    {
                        defer.Reject(x);
                    });
                });
예제 #2
0
        private void OnCharAdded(object sender, CharAddedEventArgs e)
        {
            if (e.Char == 10) //created new line
            {
                string previousLine = TextArea.Lines[TextArea.CurrentLine - 1].Text;
                float  tabCount     = 0;
                foreach (var character in previousLine)
                {
                    if (character == ' ')
                    {
                        tabCount += 0.25f; //a tab is four spaces
                    }
                    else if (character == '\t')
                    {
                        tabCount++;
                    }
                    else
                    {
                        break;
                    }
                }
                TextArea.AddText(RepeatCharacter('\t', (int)tabCount));
            }

            // Find the word start
            var currentPos   = TextArea.CurrentPosition;
            var wordStartPos = TextArea.WordStartPosition(currentPos, true);

            // Display the autocompletion list
            var lenEntered = currentPos - wordStartPos;

            if (lenEntered > 0)
            {
                if (!TextArea.AutoCActive)
                {
                    TextArea.AutoCShow(lenEntered, "abstract as base break case catch checked continue default delegate do else event explicit extern false finally fixed for foreach goto if implicit in interface internal is lock namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc switch this throw true try typeof unchecked unsafe using virtual while");
                }
            }
        }
예제 #3
0
        private void OnCharAdded(object sender, CharAddedEventArgs e)
        {
            // Auto Indent
            if (e.Char == '\n')
            {
                int foldBase = textArea.Lines[0].FoldLevel;
                int lineCur  = textArea.CurrentLine;
                int foldCur  = textArea.Lines[lineCur].FoldLevel - foldBase;
                int foldPrev = textArea.Lines[lineCur - 1].FoldLevel - foldBase;

                string indents = "";
                for (int i = 0; i < foldCur; i++)
                {
                    indents += spaces;
                }
                textArea.AddText(indents);

                indents = "";
                for (int i = 0; i < foldPrev; i++)
                {
                    indents += spaces;
                }
                int    iStart   = textArea.Lines[lineCur - 1].Position;
                string linePrev = textArea.Lines[lineCur - 1].Text;
                int    iLen     = 0;
                while (iLen < linePrev.Length && char.IsWhiteSpace(linePrev[iLen]) && linePrev[iLen] != '\r' && linePrev[iLen] != '\n')
                {
                    iLen++;
                }
                textArea.SetTargetRange(iStart, iStart + iLen);
                textArea.ReplaceTarget(indents);
            }

            // Display the autocompletion list
            int    currentPos   = textArea.CurrentPosition;
            int    wordStartPos = textArea.WordStartPosition(currentPos, true);
            int    style        = textArea.GetStyleAt(currentPos - 2);
            string currentWord  = textArea.GetWordFromPosition(wordStartPos);
            int    lenEntered   = currentPos - wordStartPos;

            textArea.AutoCSetFillUps("");
            textArea.AutoCStops("");

            if (style == STYLE_COMMENT || style == STYLE_STRING)
            {
                return;
            }

            if (wordStartPos > 1 && textArea.GetCharAt(wordStartPos - 1) == '.') //method
            {
                textArea.AutoCSetFillUps("(");
                textArea.AutoCStops(" ");
                currentPos   = wordStartPos - 2;
                wordStartPos = textArea.WordStartPosition(currentPos, true);
                lastObject   = textArea.GetWordFromPosition(wordStartPos);
                AutoCData    = sbObjects.GetMembers(lastObject, currentWord).Trim();
                textArea.AutoCShow(lenEntered, AutoCData);
                AutoCMode          = 2;
                AutoCTimer.Enabled = true;
            }
            else if (lenEntered > 0)
            {
                textArea.AutoCSetFillUps(".");
                textArea.AutoCStops(" ");
                AutoCData = (sbObjects.GetKeywords(currentWord) + sbObjects.GetObjects(currentWord) + sbObjects.GetSubroutines(currentWord) + sbObjects.GetLabels(currentWord) + sbObjects.GetVariables(currentWord)).Trim();
                textArea.AutoCShow(lenEntered, AutoCData);
                lastObject         = "";
                AutoCMode          = 1;
                AutoCTimer.Enabled = true;
            }
        }