Example #1
0
 void CodeBox_CharAdded(object sender, ScintillaNET.CharAddedEventArgs e)
 {
     if (Char.IsLetter(e.Ch))
     {
         codeBox.AutoComplete.Show();
     }
 }
Example #2
0
 private void EditControl_CharAdded(object sender, ScintillaNET.CharAddedEventArgs e)
 {
     if (e.Char == '\n')
     {
         this.Lines[this.CurrentLine].Indentation = this.Lines[this.CurrentLine - 1].Indentation;
         this.CurrentPosition = this.CurrentPosition + (this.Lines[this.CurrentLine].Indentation / this.TabWidth);
         this.SelectionStart  = this.CurrentPosition;
     }
 }
Example #3
0
 private void scintillaControl_CharAdded(object sender, CharAddedEventArgs e)
 {
     if (e.Char == '}')
     {
         int line = _scintillaControl.zGetCurrentLineNumber();
         int indent = _scintillaControl.zGetLineIndent(line);
         indent -= _tabWidth;
         if (indent < 0)
             indent = 0;
         _scintillaControl.zSetLineIndent(line, indent);
     }
 }
Example #4
0
        /// <summary>
        /// Wait for char add event to handle auto intent and auto complete.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="e"></param>
        private void HandleCharAdded(object s, CharAddedEventArgs e)
        {
            // auto indent
            if (e.Char == '}')
            {
                int curLine = LineFromPosition(CurrentPosition);
                // Check whether the bracket is the only non
                // whitespace in the line. For cases like "if() { }".
                if (Lines[curLine].Text.Trim() == "}")
                    SetIndent(curLine, GetIndent(curLine) - 4);
            }

            // auto complete
            if (char.IsLetter((char)e.Char))
                AutoCShow(CurrentPosition);
        }
Example #5
0
        //  Simple word autocompletion method
        private static void charAdded(object sender, SN.CharAddedEventArgs e)
        {
            //  Find the word start
            int currentPos   = languageEditor.CurrentPosition;
            int wordStartPos = languageEditor.WordStartPosition(currentPos, true);

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

            if (lenEntered > 0)
            {
                if (!languageEditor.AutoCActive)
                {
                    languageEditor.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 void Console System");
                }
            }
        }
Example #6
0
        private void Scintilla1_CharAdded(object sender, CharAddedEventArgs e)
        {
            var currentPos = scintilla1.CurrentPosition;
            var wordStartPos = scintilla1.WordStartPosition(currentPos, true);

            // Display the autocompletion list
            var lenEntered = currentPos - wordStartPos;
            if (e.Char == '.')
            {
                scintilla1.CallTipCancel();

                var leftPos = scintilla1.WordStartPosition(currentPos - 1, true);


                string word = scintilla1.GetWordFromPosition(leftPos);
                if (string.IsNullOrEmpty(word))
                    return;

                var type = Type.GetType("System.String");
                System.Reflection.MemberInfo[] memberInfos = type.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
                List<String> proposals = new List<string>();
                foreach (System.Reflection.MemberInfo mi in memberInfos)
                {
                    string member = mi.ToString();

                    proposals.Add(mi.ToString().Split(" ".ToCharArray(), 2)[1].Replace(" ", ""));
                }
                proposals.Sort();
                scintilla1.AutoCShow(lenEntered, string.Join(" ", proposals.ToArray()));


            }
            else if (e.Char == '(')
            {
                //scintilla1.CallTipShow(currentPos, "Your smart Tooltip functionality");
            }
            else
            {
                //scintilla1.CallTipCancel();
                //if (lenEntered > 0)
                //{
                //    //scintilla1.CallTipShow
                //    //scintilla1.AutoCComplete();
                //    scintilla1.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");
                //}
            }

            //ScintillaNET.Scintilla editor = sender as ScintillaNET.Scintilla;

            //if (e.Char == '.')
            //{
            //    Timer t = new Timer();

            //    t.Interval = 10;
            //    t.Tag = editor;
            //    t.Tick += new EventHandler((obj, ev) =>
            //    {
            //        // make a new autocomplete list if needed
            //        List<string> s = new List<string>();
            //        s.Add("test");
            //        s.Add("test2");
            //        s.Add("test3");
            //        s.Sort(); // don't forget to sort it

            //        editor.AutoComplete.ShowUserList(0, s);

            //        t.Stop();
            //        t.Enabled = false;
            //        t.Dispose();
            //    });
            //    t.Start();
            //}
        }
        protected override void OnCharAdded(CharAddedEventArgs e)
        {
            base.OnCharAdded(e);

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

            var lenEntered = currentPos - wordStartPos;
            if (lenEntered <= 0)
                return;

            // Display the autocompletion list
            var keywords = string.Join(" ", LexerService.Instance.AutoCompletionKeywords);
            this.AutoCShow(lenEntered, keywords);
        }
Example #8
0
 /// <summary>
 /// Triggered when a character is added to current document
 /// </summary>
 /// <param name="e"></param>
 protected override void OnCharAdded(CharAddedEventArgs e) {
     base.OnCharAdded(e);
     if (AutoIndent) AutoIndentCharAdded(e);
 }
Example #9
0
        private void scintilla_CharAdded(object sender, CharAddedEventArgs e)
        {
            int i = tabControl1.SelectedIndex;
            charcount[i]++;

            if (tabControl1.SelectedTab.Controls.ContainsKey("body"))
            {
                Scintilla body = (Scintilla)tabControl1.SelectedTab.Controls["body"];
                //Autocompletion. Will eventually make nicer.
                // Find the word start
                var currentPos = body.CurrentPosition;
                var wordStartPos = body.WordStartPosition(currentPos, true);

                // Display the autocompletion list
                var lenEntered = currentPos - wordStartPos;
                if (lenEntered > 0)
                {
                    body.AutoCShow(lenEntered, Keywords.Key0());
                }

                if (charcount[i] == 10)
                {
                    charcount[i] = 0;
                    body.EndUndoAction();
                    body.BeginUndoAction();
                }

                if (e.Char == (int)'}')
                {
                    int x = body.CurrentPosition - TabSize;
                    body.Text = body.Text.Remove(body.CurrentPosition - (TabSize + 1), TabSize);
                    body.SetEmptySelection(x);
                }
            }
        }
Example #10
0
        /// <summary>
        /// Handles the Char Added event of the <see cref="Scintilla"/> edit <see cref="Control"/>.
        /// </summary>
        private void ScintillaCharAdded(object sender, CharAddedEventArgs e)
        {
            if (scintilla.ReadOnly)
              {
            return;
              }

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

              // Display the autocompletion list.
              int lenEntered = currentPos - wordStartPos;

              if (lenEntered > 0)
              {
            scintilla.AutoCShow(
            lenEntered
              , LUA_AUTOCOMPLETE_KEYWORKDS);
              }
        }
Example #11
0
 /// <summary>
 /// Performs automatic decrase of indentation if brace is closed as the only non-whitespace character in line
 /// </summary>
 /// <param name="e"></param>
 private void AutoIndentCharAdded(CharAddedEventArgs e) {
     var c = e.Char;
     if (c == '}' || c == ']' || c == ')') {
         var line = Lines[CurrentLine];
         var lineNonWhitespace = line.Text.Trim();
         if (lineNonWhitespace.Length == 1) line.Indentation -= TabWidth;
     }
 }
Example #12
0
        private void scintilla_CharAdded(object sender, CharAddedEventArgs e)
        {
            // Find the word start
            var currentPos = scintilla.CurrentPosition;
            var wordStartPos = scintilla.WordStartPosition(currentPos, true);

            if (e.Char == '\n')
            {
                if (scintilla.Lines.Count > 1)
                {
                    Line lastLine = scintilla.Lines[scintilla.CurrentLine - 1];
                    string lastIndent = lastLine.Text.Substring(0, lastLine.Indentation);
                    scintilla.AddText(lastIndent);
                }
            }

            // Display the autocompletion list
            var lenEntered = currentPos - wordStartPos;
            if (lenEntered > 0)
            {
                scintilla.AutoCShow(lenEntered, Target.NameExpressions);
            }
        }
Example #13
0
        private void scintilla1_CharAdded(object sender, CharAddedEventArgs e)
        {
            // Find the word start
            var currentPos = scintilla1.CurrentPosition;
            var wordStartPos = scintilla1.WordStartPosition(currentPos, true);

            // Display the autocompletion list
            var lenEntered = currentPos - wordStartPos;
            if (lenEntered > 0)
            {
                scintilla1.AutoCShow(lenEntered, Properties.Resources.JsKeywords);
            }
        }
Example #14
0
        private void scintilla1_CharAdded(object sender, ScintillaNET.CharAddedEventArgs e)
        {
            char newline = (scintilla1.EndOfLine.Mode == EndOfLineMode.CR) ? '\r' : '\n';

            if (e.Ch != '\r' && e.Ch != ' ' && e.Ch != ')' && e.Ch != '(' && e.Ch != ',' && EQ2LuaEditor.Settings.ShowAutoComplete)
            {
                // Get the current position of the carrot
                int pos = scintilla1.NativeInterface.GetCurrentPos();
                // Get the start of the current word based on carrot position and subtract from current position to get the length
                int length = pos - scintilla1.NativeInterface.WordStartPosition(pos, true);

                if (length > 2)
                {
                    scintilla1.AutoComplete.Show(length);
                }
            }

            #region Auto formating
            if (EQ2LuaEditor.Settings.EnableAutoFormat)
            {
                Line curLine  = scintilla1.Lines.Current;
                Line prevLine = scintilla1.Lines.Current.Previous;
                int  tabWidth = scintilla1.Indentation.TabWidth;

                if (e.Ch == newline)
                {
                    // Match previous line indentation
                    curLine.Indentation   = curLine.Previous.Indentation;
                    scintilla1.CurrentPos = curLine.IndentPosition;

                    if (prevLine.Text.Trim().StartsWith("function") && !prevLine.Text.Contains("end"))
                    {
                        curLine.Indentation  += tabWidth;
                        scintilla1.CurrentPos = scintilla1.Lines.Current.IndentPosition;
                    }
                    else if (prevLine.Text.Trim().StartsWith("if") && prevLine.Text.Contains("then") && !prevLine.Text.Contains("end"))
                    {
                        curLine.Indentation  += tabWidth;
                        scintilla1.CurrentPos = curLine.IndentPosition;
                    }
                    else if (prevLine.Text.Trim().StartsWith("else") && !prevLine.Text.Contains("end"))
                    {
                        curLine.Indentation  += tabWidth;
                        scintilla1.CurrentPos = curLine.IndentPosition;
                    }
                    else if (prevLine.Text.Trim().StartsWith("for") && prevLine.Text.Contains("do") && !prevLine.Text.Contains("end"))
                    {
                        curLine.Indentation  += tabWidth;
                        scintilla1.CurrentPos = curLine.IndentPosition;
                    }
                    else if (prevLine.Text.Trim().StartsWith("while") && prevLine.Text.Contains("do") && !prevLine.Text.Contains("end"))
                    {
                        curLine.Indentation  += tabWidth;
                        scintilla1.CurrentPos = curLine.IndentPosition;
                    }
                    else if (prevLine.Text.Trim().StartsWith("repeat") && !prevLine.Text.Contains("until"))
                    {
                        curLine.Indentation  += tabWidth;
                        scintilla1.CurrentPos = curLine.IndentPosition;
                    }
                }
                // end - remove 1 indent space
                if (e.Ch == 'd')
                {
                    if (curLine.Text.Trim().StartsWith("end") && curLine.Text.Trim().Length == 3)
                    {
                        int match = SafeBraceMatch(scintilla1.CurrentPos - 1);
                        if (match != -1)
                        {
                            curLine.Indentation = scintilla1.Lines.FromPosition(match).Indentation;
                        }

                        /*curLine.Indentation -= tabWidth;
                         * scintilla1.CurrentPos = curLine.EndPosition;*/
                    }
                }
                // else - remove 1 indent space
                if (e.Ch == 'e')
                {
                    if (curLine.Text.Trim().StartsWith("else") && curLine.Text.Trim().Length == 4)
                    {
                        int match = SafeBraceMatch(scintilla1.CurrentPos - 1);
                        if (match != -1)
                        {
                            curLine.Indentation = scintilla1.Lines.FromPosition(match).Indentation;
                        }


                        /*curLine.Indentation -= tabWidth;
                         * scintilla1.CurrentPos = curLine.EndPosition;*/
                    }
                }
                // until
                if (e.Ch == 'l')
                {
                    if (curLine.Text.Trim().StartsWith("until") && curLine.Text.Trim().Length == 5)
                    {
                        int match = SafeBraceMatch(scintilla1.CurrentPos - 1);
                        if (match != -1)
                        {
                            curLine.Indentation = scintilla1.Lines.FromPosition(match).Indentation;
                        }
                    }
                }
            }
            #endregion
        }
Example #15
0
        /// <summary>
        ///     Raises the <see cref="CharAdded"/> event.
        /// </summary>
        /// <param name="e">An <see cref="CharAddedEventArgs"/> that contains the event data.</param>
        protected virtual void OnCharAdded(CharAddedEventArgs e)
        {
            EventHandler<CharAddedEventArgs> handler = Events[_charAddedEventKey] as EventHandler<CharAddedEventArgs>;
            if (handler != null)
                handler(this, e);

            if (_indentation.SmartIndentType != SmartIndent.None)
                _indentation.CheckSmartIndent(e.Ch);
        }
Example #16
0
 private void OnCharAdded(object sender, ScintillaNET.CharAddedEventArgs e)
 {
     CharAdded?.Invoke(Widget, new CharAddedEventArgsWin());
 }
        private void scintilla_CharAdded(object sender, CharAddedEventArgs e)
        {
            Scintilla scintilla = txtScript;

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

            // Display the autocompletion list
            var lenEntered = currentPos - wordStartPos;
            if (lenEntered > 0)
            {
                scintilla.AutoCShow(lenEntered, AutoCompleteKeywords);
            }
        }
Example #18
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;
                }
            }
        }
Example #19
0
 /// <summary>
 /// Raises the <see cref="CharAdded" /> event.
 /// </summary>
 /// <param name="e">A <see cref="CharAddedEventArgs" /> that contains the event data.</param>
 protected virtual void OnCharAdded(CharAddedEventArgs e)
 {
     var handler = Events[charAddedEventKey] as EventHandler<CharAddedEventArgs>;
     if (handler != null)
         handler(this, e);
 }
Example #20
0
 void RubyScintilla_CharAdded(object sender, CharAddedEventArgs e)
 {
     if (e.Ch == '\n')
     {
         string lastline = this.Lines.Current.Previous.Text.Trim();
         if (lastline == "=begin" || lastline == "=end")
             this.Lines.Current.Previous.Indentation = 0;
         else
         {
             int num = this.GetLineIndent(Lines.Current.Previous);
             if (num != -1) { Lines.Current.Previous.Indentation = num * Indentation.TabWidth; }
         }
         int lineIndent = this.GetLineIndent(Lines.Current);
         if (lineIndent != -1)
             this.InsertText(new string(' ', lineIndent * Indentation.TabWidth));
     }
 }