public override void HandleTextEntered(CodeEditor control, string insertText)
    {
      switch (insertText)
      {
        case "\\":
          ShowCompletions(control);
          break;
        case "{":
        case "(":
        case "[":
          if (_currentInsight != null)
            _currentInsight.Hide();

          var overload = new OverloadInsightWindow(control.Editor.TextArea);
          if (insertText == "{")
            overload.Provider = _quantifiers;
          else if (insertText == "(")
            overload.Provider = _groups;
          else
            overload.Provider = _charClass;
          overload.Show();
          _currentInsight = overload;
          break;
        case "}":
        case ")":
        case "]":
          if (_currentInsight != null)
            _currentInsight.Hide();

          _currentInsight = null;
          break;
      }
    }
        public void EditorMouseHover(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner scanner, MouseEventArgs e)
        {
            TextViewPosition? pos = editor.GetPositionFromPoint(e.GetPosition(editor));
            if (pos != null)
            {
                try
                {
                    int line = pos.Value.Line;
                    int offset = editor.Document.GetOffset(pos.Value.Location);
                    Globals globs = GetGlobals();
                    if (globs != null)
                    {
                        bool isFunc = false;
                        string[] words = IntellisenseHelper.ExtractPath(editor.Document, offset, pos.Value.Location.Line, out isFunc);
                        if (words != null && words.Length > 0)
                        {
                            BaseTypeInfo info = null;
                            FunctionInfo func = null;
                            NameResolver reso = new NameResolver(globs, scanner);
                            if (words.Length > 1)
                            {
                                for (int i = 0; i < words.Length; ++i)
                                {
                                    if (i == words.Length - 1 && info != null && isFunc)
                                    {
                                        if (info is TypeInfo)
                                            func = ((TypeInfo)info).Functions.FirstOrDefault(f => f.Name.Equals(words[i]));
                                    }
                                    else
                                    {
                                        if (info == null)
                                        {
                                            info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                                        }
                                        else if (info != null && info is TypeInfo)
                                        {
                                            if (((TypeInfo)info).Properties.ContainsKey(words[i]))
                                                info = ((TypeInfo)info).Properties[words[i]];
                                        }
                                    }
                                }
                            }
                            else if (isFunc && words.Length == 1)
                            {
                                func = globs.GetFunction(words[0]);
                            }
                            else if (!isFunc && words.Length == 1)
                            {
                                info = reso.GetClassType(editor.Document, line, words[0]);
                                if (info == null)
                                {
                                    TypeInfo ty = globs.GetTypeInfo(words[0]);
                                    if (ty != null)
                                        info = ty;
                                }
                            }

                            string msg = "";
                            // Ask documentation for the information
                            if (info != null && func != null && info is TypeInfo)
                            { //member function
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name + "::" + func.Name + func.Inner);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }
                            else if (func != null)
                            { //global function
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(func.Name + func.Inner);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }
                            else if (info != null && info is TypeInfo)
                            { //global or member type
                                msg = ((TypeInfo)info).Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }

                            if (msg.Length > 0)
                            {
                                InsightWindow window = new InsightWindow(editor.TextArea);
                                window.Content = msg;
                                window.Show();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //deliberately swallow any exceptions here
                }
            }
        }
        void editor_MouseHover(object sender, MouseEventArgs e)
        {
            var pos = editor.GetPositionFromPoint(e.GetPosition(editor));
            if (pos != null) {
                string wordHovered = editor.Document.GetWordUnderMouse(pos.Value, true);
                if (Debugger.Debug.SessionData.inst().LocalData != null)
                {
                    Json.JWrapper wrapper = null;

                    // Try to find it in "this"
                    string[] words = wordHovered.Split('.');
                    if (Debugger.Debug.SessionData.inst().ThisData != null)
                        wrapper = Debugger.Debug.SessionData.inst().ThisData.ResolveDotPath(words);
                    if (wrapper != null && wrapper.Parent == null)
                        wrapper = null; //reset to null so other checks have an opportunity

                    // Check the Stack
                    if (wrapper == null)
                        wrapper = Debugger.Debug.SessionData.inst().LocalData.ResolveDotPath(words);
                    if (wrapper != null && wrapper.Parent == null)
                        wrapper = null; //reset to null so globals can have a chance

                    // Check the globals
                    if (wrapper == null && Debugger.Debug.SessionData.inst().GlobalData != null)
                        wrapper = Debugger.Debug.SessionData.inst().GlobalData.ResolveDotPath(words);

                    // If something has been found then show it in AvalonEdit's "Insight Window"
                    if (wrapper != null && wrapper.Parent != null) { //null check prevents display of all stack levels
                        InsightWindow window = new InsightWindow(editor.TextArea);
                        window.Background = new SolidColorBrush(Colors.Black);
                        if (wrapper is Json.JLeaf)
                            window.Content = new Label { Content = ((Json.JLeaf)wrapper).Value };
                        else
                            window.Content = new Controls.JWrapView() { DataContext = wrapper };
                        window.MaxHeight = 240;
                        window.SizeToContent = SizeToContent.WidthAndHeight;
                        window.Left = Mouse.GetPosition(this).X;
                        window.Top = Mouse.GetPosition(this).X;
                        window.Show();
                    }
                }
                e.Handled = true;
            }
        }
Exemple #4
0
        private void TextEntered(object sender, TextCompositionEventArgs e)
        {
            if (!IsReadOnly && e.Text.Length == 1)
            {
                var newChar = e.Text[0];
                if (UseCodeCompletion)
                {
                    Complete(newChar);
                }
            }
            if (CompletionWindow != null)
            {
                return;
            }

            var wordBeforeCaret = this.GetWordBeforeCaret(GetWordParts());

            if (SnippetManager.HasSnippetsFor(wordBeforeCaret, DocumentType))
            {
                insightWindow = new InsightWindow(TextArea)
                {
                    Content = "Press tab to enter snippet",
                    Background = Brushes.Linen
                };
                insightWindow.Show();
                return;
            }
            if (FileLanguage != null && !(FileLanguage is LanguageBase))
            {
                var text = FindWord();
                if (IsModified || IsModified)
                {
                    UpdateFolds();
                }
                if (text == null || !(string.IsNullOrEmpty(text) | text.Length < 3))
                {
                    ShowCompletionWindow(text);
                }
            }
        }