Example #1
0
        private void ShowIntellisense(bool force)
        {
            var pos = _editor.CurrentPosition - 1;

            if (pos == 0)
            {
                return;
            }

            var text = _editor.Text;

            EntityCache.TryGetEntities(_con.ServiceClient, out var entities);

            var suggestions = new Autocomplete(entities, Metadata).GetSuggestions(text, pos, out var currentLength).ToList();

            if (suggestions.Count == 0)
            {
                return;
            }

            if (force || currentLength > 0 || text[pos] == '.')
            {
                _editor.AutoCShow(currentLength, String.Join(_editor.AutoCSeparator.ToString(), suggestions));
            }
        }
Example #2
0
        private void codeBox_CharAdded(object sender, CharAddedEventArgs e)
        {
            if (char.IsLetter((char)e.Char) && _useAutoComplete && _codeBox.Lexer == Lexer.Cpp)
            {
                string word = _codeBox.GetWordFromPosition(_codeBox.CurrentPosition).ToLower();
                var    q    = from s in _main.Functions
                              where s.ToLower().Contains(word)
                              select s.Replace(";", "");

                string filter = string.Join(";", q);

                if (filter.Length > 0)
                {
                    _codeBox.AutoCShow(word.Length, filter);
                }
            }
            else if (e.Char == '}')
            {
                int curLine = _codeBox.LineFromPosition(_codeBox.CurrentPosition);

                if (_codeBox.Lines[curLine].Text.Trim() == "}")
                {
                    _codeBox.Lines[curLine].Indentation -= _codeBox.IndentWidth;
                }
            }
        }
        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);
                    });
                });
Example #4
0
        private void Scintilla_CharAdded(object sender, CharAddedEventArgs e)
        {
            var currentLineIndex = Scintilla.LineFromPosition(Scintilla.CurrentPosition);
            var currentLine      = Scintilla.Lines[currentLineIndex];

            switch (e.Char)
            {
            case '.':
            {
                var list = new List <string> {
                    "out", "in", "println", "currentTimeMillis"
                };
                list.Sort();
                Scintilla.AutoCShow(
                    Scintilla.CurrentPosition - Scintilla.WordStartPosition(Scintilla.CurrentPosition, true),
                    string.Join(" ", list));
                break;
            }

            case '}':
                if (Scintilla.Lines[currentLineIndex].Text.Trim() == "}")
                {
                    currentLine.Indentation -= Scintilla.TabWidth;
                }

                break;

            case '\n':
                var openingBraceLine = Scintilla.Lines[currentLineIndex - 2];
                var prevLine         = Scintilla.Lines[currentLineIndex - 1];

                if (Regex.IsMatch(openingBraceLine.Text, "{\\s*$"))
                {
                    Scintilla.InsertText(prevLine.EndPosition, "\n");
                    currentLine.Indentation = prevLine.Indentation + Scintilla.TabWidth;
                    Scintilla.GotoPosition(currentLine.Position + currentLine.Indentation);
                }

                break;

            default:
                InsertMatchedChars(e);
                break;
            }
        }
        static private void editor_CharAdded1(object sender, CharAddedEventArgs e)
        {
            Scintilla editor = (Scintilla)sender;

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

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

            if (lenEntered > 0)
            {
                if (!editor.AutoCActive)
                {
                    editor.AutoCShow(lenEntered,
                                     String.Join(" ", MatlabKeyWords));
                }
                // "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");
            }
        }
Example #6
0
        public void scintilla_CharAdded(object sender, CharAddedEventArgs e)
        {
            // Find the word start
            var currentPos2  = t.CurrentPosition;
            var wordStartPos = t.WordStartPosition(currentPos2, true);

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

            if (lenEntered > 0)
            {
                if (true || !t.AutoCActive)
                {
                    //"char double float int long static struct void unsigned"
                    string autokeywords = "abstract as base break case catch char checked continue default delegate do double else event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc static struct switch this throw true try typeof unchecked unsafe unsigned using virtual void while";
                    t.AutoCShow(lenEntered, autokeywords);
                }
            }
            if (e.Char == '}')
            {
                var currentPos = t.CurrentPosition;
                t.SearchFlags = SearchFlags.None;

                // Search back from the current position
                t.TargetStart = currentPos;
                t.TargetEnd   = 0;

                // Is the bracket following 4 spaces or a tab?
                if (t.SearchInTarget("    }") == (currentPos - 5))
                {
                    // Delete the leading 4 spaces
                    t.DeleteRange((currentPos - 5), 4);
                }
                else if (t.SearchInTarget("\t}") == (currentPos - 2))
                {
                    // Delete the leading tab
                    t.DeleteRange((currentPos - 2), 1);
                }
            }
        }
Example #7
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");
                }
            }
        }
        private void ShowAutocomplete(Scintilla scintilla, bool all)
        {
            // Find the word start
            string word = scintilla.GetWordFromPosition(scintilla.CurrentPosition)?.Trim();

            if (string.IsNullOrWhiteSpace(word) && !all)
            {
                scintilla.AutoCCancel();
                return;
            }

            var list = Items.Distinct()
                       .Where(s => !string.IsNullOrWhiteSpace(s) && s.Contains(word, StringComparison.CurrentCultureIgnoreCase))
                       .OrderBy(a => a);

            if (!list.Any())
            {
                scintilla.AutoCCancel();
                return;
            }

            // Display the autocompletion list
            scintilla.AutoCShow(word.Length, string.Join(Separator, list.Select(FormatForAutocomplete)));
        }
Example #9
0
        //mxd. Autocompletion handling (https://github.com/jacobslusser/ScintillaNET/wiki/Basic-Autocompletion)
        public virtual bool ShowAutoCompletionList()
        {
            int currentpos   = scriptedit.CurrentPosition;
            int wordstartpos = scriptedit.WordStartPosition(currentpos, true);

            if (wordstartpos >= currentpos)
            {
                // Hide the list
                scriptedit.AutoCCancel();
                return(false);
            }

            // Get entered text
            string start = scriptedit.GetTextRange(wordstartpos, currentpos - wordstartpos);

            if (string.IsNullOrEmpty(start))
            {
                // Hide the list
                scriptedit.AutoCCancel();
                return(false);
            }

            // Don't show Auto-completion list when editing comment, include or string
            switch (scriptcontrol.GetScriptStyle(scriptedit.GetStyleAt(currentpos)))
            {
            case ScriptStyleType.Comment:
            case ScriptStyleType.String:
                // Hide the list
                scriptedit.AutoCCancel();
                return(false);

            case ScriptStyleType.Include:
                // Hide the list unless current word is a keyword
                if (!start.StartsWith("#"))
                {
                    scriptedit.AutoCCancel();
                    return(false);
                }
                break;
            }

            // Filter the list
            List <string> filtered = new List <string>();

            foreach (string s in autocompletelist)
            {
                if (s.IndexOf(start, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    filtered.Add(s);
                }
            }

            // Any matches?
            if (filtered.Count > 0)
            {
                // Show the list
                scriptedit.AutoCShow(currentpos - wordstartpos, string.Join(" ", filtered.ToArray()));
                return(true);
            }

            // Hide the list
            scriptedit.AutoCCancel();
            return(false);
        }
Example #10
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;
            }
        }