Exemplo n.º 1
0
        public void HandleCharAdded(ZeusScintillaControl scintilla, bool isTagged, char ch)
        {
            bool isCtrlPressed = (Control.ModifierKeys == (System.Windows.Forms.Keys.Control | Control.ModifierKeys));
            bool isAutoSeek    = IsAutoCompleteSeek(ch, isCtrlPressed);
            bool isAutoMember  = IsAutoCompleteMember(ch);
            bool isCallTip     = IsCallTip(ch);

            if (isAutoSeek || isAutoMember || isCallTip)
            {
                int                       pos = scintilla.CurrentPos - 1;
                char                      c   = scintilla.CharAt(--pos);
                Stack <string>            stk = new Stack <string>();
                List <string>             lst = new List <string>();
                System.Text.StringBuilder tmp = new System.Text.StringBuilder();

                int style = scintilla.StyleAt(pos);
                if (IsCodeStyle(isTagged, style))
                {
                    while (IsValidIdentifierChar(c) || (c == MemberSeperator))
                    {
                        if (c == MemberSeperator)
                        {
                            if (tmp.Length > 0)
                            {
                                lst.Insert(0, tmp.ToString());
                                stk.Push(tmp.ToString());
                                tmp.Remove(0, tmp.Length);
                            }
                        }
                        else
                        {
                            tmp.Insert(0, c);
                        }
                        c = scintilla.CharAt(--pos);
                    }
                    if (tmp.Length > 0)
                    {
                        lst.Insert(0, tmp.ToString());
                        stk.Push(tmp.ToString());
                        tmp.Remove(0, tmp.Length);
                    }

                    AutoCompleteNodeInfo n = null;
                    AutoCompleteNodeInfo nextToLastNode = null;
                    System.Collections.Generic.List <AutoCompleteNodeInfo> ns = null;
                    string lastmsg = null, firstmsg = null;
                    int    memberDepth = stk.Count;
                    if (stk.Count > 0)
                    {
                        lastmsg = stk.Pop();
                        if ((lastmsg.Equals(this.SelfQualifier, this.SelfQualifierStringComparisonRule)) && (stk.Count > 0))
                        {
                            lastmsg = stk.Pop();
                        }

                        if (AutoCompleteHelper.RootNodes.ContainsKey(lastmsg))
                        {
                            n = AutoCompleteHelper.RootNodes[lastmsg];
                        }
                        else
                        {
                            AutoCompleteNodeInfo newRootNode;
                            if (ScanCodeForVariable(scintilla, lastmsg, out newRootNode))
                            {
                                n = newRootNode;
                            }
                        }
                    }

                    while (n != null && stk.Count > 0)
                    {
                        nextToLastNode = n;
                        int stkCount = stk.Count;
                        lastmsg = stk.Pop();

                        ns = n[lastmsg];
                        if (ns.Count == 1)
                        {
                            n = ns[0];
                        }
                        else
                        {
                            n = null;
                            if (stk.Count != 0)
                            {
                                ns = null;
                            }
                        }
                    }

                    if (isAutoSeek)
                    {
                        scintilla.DeleteBack();

                        if (n != null)
                        {
                            if (scintilla.CharAt(scintilla.CurrentPos - 1) == MemberSeperator)
                            {
                                scintilla.AutoCShow(0, n.MembersString);
                            }
                            else
                            {
                                scintilla.AutoCShow(n.Name.Length, nextToLastNode.MembersString);
                            }
                        }
                        else if (stk.Count == 0 && nextToLastNode != null)
                        {
                            scintilla.AutoCShow(lastmsg.Length, nextToLastNode.MembersString);
                        }
                        else if (stk.Count == 0 && n == null && nextToLastNode == null)
                        {
                            if (lastmsg == null)
                            {
                                lastmsg = string.Empty;
                            }

                            scintilla.AutoCShow(lastmsg.Length, AutoCompleteHelper.RootNodesAutoCompleteString);
                        }
                    }
                    if (isAutoMember || isCallTip)
                    {
                        if (n != null)
                        {
                            if (isAutoMember)
                            {
                                scintilla.AutoCShow(0, n.MembersString);
                            }
                        }
                        else
                        {
                            if (isAutoMember &&
                                (lastmsg != null) &&
                                (lastmsg.Equals(this.SelfQualifier, this.SelfQualifierStringComparisonRule)) &&
                                (memberDepth == 1))
                            {
                                scintilla.AutoCShow(0, AutoCompleteHelper.RootNodesAutoCompleteString);
                            }
                        }

                        if (ns != null)
                        {
                            if (isCallTip)
                            {
                                string methodSigs = string.Empty;
                                int    i          = 0;
                                foreach (AutoCompleteNodeInfo ni in ns)
                                {
                                    if (ni.MemberType == System.Reflection.MemberTypes.Method)
                                    {
                                        i++;
                                        if (methodSigs.Length > 0)
                                        {
                                            methodSigs += "\n";
                                        }
                                        //methodSigs += '\u0001' + i.ToString() + " of " + ns.Count + '\u0002' + " " + ni.ParameterString;
                                        methodSigs += ni.ParameterString;
                                    }
                                }
                                if (methodSigs.Length > 0)
                                {
                                    scintilla.CallTipShow(scintilla.CurrentPos - 1, methodSigs);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void HandleCharAdded(ZeusScintillaControl scintilla, bool isTagged, char ch)
        {
            bool isCtrlPressed = (Control.ModifierKeys == (System.Windows.Forms.Keys.Control | Control.ModifierKeys));
            bool isAutoSeek = IsAutoCompleteSeek(ch, isCtrlPressed);
            bool isAutoMember = IsAutoCompleteMember(ch);
            bool isCallTip = IsCallTip(ch);

            if (isAutoSeek || isAutoMember || isCallTip)
            {
                int pos = scintilla.CurrentPos - 1;
                char c = scintilla.CharAt(--pos);
                Stack<string> stk = new Stack<string>();
                List<string> lst = new List<string>();
                System.Text.StringBuilder tmp = new System.Text.StringBuilder();

                int style = scintilla.StyleAt(pos);
                if (IsCodeStyle(isTagged, style))
                {
                    while (IsValidIdentifierChar(c) || (c == MemberSeperator))
                    {
                        if (c == MemberSeperator)
                        {
                            if (tmp.Length > 0)
                            {
                                lst.Insert(0, tmp.ToString());
                                stk.Push(tmp.ToString());
                                tmp.Remove(0, tmp.Length);
                            }
                        }
                        else
                        {
                            tmp.Insert(0, c);
                        }
                        c = scintilla.CharAt(--pos);
                    }
                    if (tmp.Length > 0)
                    {
                        lst.Insert(0, tmp.ToString());
                        stk.Push(tmp.ToString());
                        tmp.Remove(0, tmp.Length);
                    }

                    AutoCompleteNodeInfo n = null;
                    AutoCompleteNodeInfo nextToLastNode = null;
                    System.Collections.Generic.List<AutoCompleteNodeInfo> ns = null;
                    string lastmsg = null, firstmsg = null;
                    int memberDepth = stk.Count;
                    if (stk.Count > 0)
                    {
                        lastmsg = stk.Pop();
                        if ((lastmsg.Equals(this.SelfQualifier, this.SelfQualifierStringComparisonRule)) && (stk.Count > 0))
                        {
                            lastmsg = stk.Pop();
                        }

                        if (AutoCompleteHelper.RootNodes.ContainsKey(lastmsg))
                        {
                            n = AutoCompleteHelper.RootNodes[lastmsg];
                        }
                        else 
                        {
                            AutoCompleteNodeInfo newRootNode;
                            if (ScanCodeForVariable(scintilla, lastmsg, out newRootNode))
                            {
                                n = newRootNode;
                            }
                        }
                    }

                    while (n != null && stk.Count > 0)
                    {
                        nextToLastNode = n;
                        int stkCount = stk.Count;
                        lastmsg = stk.Pop();

                        ns = n[lastmsg];
                        if (ns.Count == 1)
                        {
                            n = ns[0];
                        }
                        else
                        {
                            n = null;
                            if (stk.Count != 0)
                            {
                                ns = null;
                            }
                        }
                    }

                    if (isAutoSeek)
                    {
                        scintilla.DeleteBack();

                        if (n != null)
                        {
                            if (scintilla.CharAt(scintilla.CurrentPos - 1) == MemberSeperator)
                            {
                                scintilla.AutoCShow(0, n.MembersString);
                            }
                            else
                            {
                                scintilla.AutoCShow(n.Name.Length, nextToLastNode.MembersString);
                            }
                        }
                        else if (stk.Count == 0 && nextToLastNode != null)
                        {
                            scintilla.AutoCShow(lastmsg.Length, nextToLastNode.MembersString);
                        }
                        else if (stk.Count == 0 && n == null && nextToLastNode == null)
                        {
                            if (lastmsg == null) lastmsg = string.Empty;

                            scintilla.AutoCShow(lastmsg.Length, AutoCompleteHelper.RootNodesAutoCompleteString);
                        }
                    }
                    if (isAutoMember || isCallTip)
                    {
                        if (n != null)
                        {
                            if (isAutoMember)
                            {
                                scintilla.AutoCShow(0, n.MembersString);
                            }
                        }
                        else
                        {
                            if (isAutoMember && 
                                (lastmsg != null) && 
                                (lastmsg.Equals(this.SelfQualifier, this.SelfQualifierStringComparisonRule)) && 
                                (memberDepth == 1))
                            {
                                scintilla.AutoCShow(0, AutoCompleteHelper.RootNodesAutoCompleteString);
                            }
                        }

                        if (ns != null)
                        {
                            if (isCallTip)
                            {
                                string methodSigs = string.Empty;
                                int i = 0;
                                foreach (AutoCompleteNodeInfo ni in ns)
                                {
                                    if (ni.MemberType == System.Reflection.MemberTypes.Method)
                                    {
                                        i++;
                                        if (methodSigs.Length > 0) methodSigs += "\n";
                                        //methodSigs += '\u0001' + i.ToString() + " of " + ns.Count + '\u0002' + " " + ni.ParameterString;
                                        methodSigs += ni.ParameterString;
                                    }
                                }
                                if (methodSigs.Length > 0)
                                {
                                    scintilla.CallTipShow(scintilla.CurrentPos - 1, methodSigs);
                                }
                            }
                        }
                    }
                }
            }
        }