예제 #1
0
        private async Task ShowCompletion(bool controlSpace)
        {
            if (_completionWindow == null)
            {
                int offset         = _area.Caret.Offset;
                var completionChar = controlSpace ? (char?)null : _area.Document.GetCharAt(offset - 1);

                var codeLines         = _area.Document.GetCodeLinesBefore();
                var currentLineOffset = offset - _area.Document.GetCharactersBeforeCurrentLine();
                offset = codeLines.Sum(l => l.TotalLength - 1) + currentLineOffset - 1;

                var results = await _compProvider.GetCompletionData(offset, completionChar).ConfigureAwait(true);

                if (_insightWindow == null && results.OverloadProvider != null)
                {
                    _insightWindow = new MyOverloadInsightWindow(_area)
                    {
                        Provider = results.OverloadProvider
                    };
                    _insightWindow.Show();
                    _insightWindow.Closed += (o, args) => _insightWindow = null;
                    return;
                }

                if (_completionWindow == null && results.CompletionData.Any())
                {
                    // Open code completion after the user has pressed dot:
                    _completionWindow = new CompletionWindow(_area)
                    {
                        // CloseWhenCaretAtBeginning = controlSpace
                    };
                    if (completionChar != null && char.IsLetterOrDigit(completionChar.Value))
                    {
                        _completionWindow.StartOffset -= 1;
                    }

                    var data = _completionWindow.CompletionList.CompletionData;
                    ISelectedCompletionData selected = null;
                    foreach (var completion in results.CompletionData) //.OrderBy(item => item.SortText))
                    {
                        if (completion.IsSelected)
                        {
                            selected = completion;
                        }
                        data.Add(completion);
                    }

                    if (selected != null)
                    {
                        _completionWindow.CompletionList.SelectedItem = selected;
                    }
                    _completionWindow.Show();
                    _completionWindow.Closed += (o, args) =>
                    {
                        _completionWindow = null;
                    };
                }
            }
        }
예제 #2
0
 void CloseInsightWindow(object sender, EventArgs e)
 {
     if (insightWindow != null)
     {
         insightWindow.Closed -= new EventHandler(CloseInsightWindow);
         insightWindow.Dispose();
         insightWindow = null;
     }
 }
 void OnInsightWindowClosed(object sender, EventArgs e)
 {
     if (_insightWindow != null)
     {
         _insightWindow.Closed -= OnInsightWindowClosed;
         _insightWindow.Dispose();
         _insightWindow = null;
     }
 }
 private void CloseInsightWindow(object sender, EventArgs e)
 {
     if (_insightWindow != null)
     {
         _insightWindow.Closed -= CloseInsightWindow;
         _insightWindow.Dispose();
         _insightWindow = null;
     }
 }
예제 #5
0
 void CloseInsightWindow(object sender, EventArgs e)
 {
     if (FInsightWindow != null)
     {
         FInsightWindow.Closed -= CloseInsightWindow;
         FInsightWindow.Dispose();
         FInsightWindow = null;
     }
 }
예제 #6
0
 public void ShowInsightWindow(IInsightDataProvider insightDataProvider)
 {
     if (insightWindow == null || insightWindow.IsDisposed)
     {
         insightWindow         = new InsightWindow(OwnerForm, this);
         insightWindow.Closed += new EventHandler(CloseInsightWindow);
     }
     insightWindow.AddInsightDataProvider(insightDataProvider, FileName);
     insightWindow.ShowInsightWindow();
 }
 public void ShowInsightWindow(IInsightDataProvider insightDataProvider)
 {
     if (_insightWindow == null || _insightWindow.IsDisposed)
     {
         _insightWindow         = new InsightWindow(ParentForm, this);
         _insightWindow.Closed += CloseInsightWindow;
     }
     _insightWindow.AddInsightDataProvider(insightDataProvider, FileName);
     _insightWindow.ShowInsightWindow();
 }
 public void ShowInsightWindow(IInsightDataProvider insightDataProvider)
 {
     if (insightWindow == null || insightWindow.IsDisposed)
     {
         insightWindow         = new InsightWindow(WorkbenchSingleton.MainForm, this);
         insightWindow.Closed += new EventHandler(CloseInsightWindow);
     }
     insightWindow.AddInsightDataProvider(insightDataProvider, this.FileName);
     insightWindow.ShowInsightWindow();
 }
예제 #9
0
        public void ShowInsightWindow(IInsightDataProvider insightDataProvider)
        {
            if (insightWindow == null || insightWindow.IsDisposed)
            {
#if ModifiedForAltaxo
                insightWindow = new InsightWindow(Form.ActiveForm, this);
#else
                insightWindow = new InsightWindow(((Form)WorkbenchSingleton.Workbench), this);
#endif
                insightWindow.Closed += new EventHandler(CloseInsightWindow);
            }
            insightWindow.AddInsightDataProvider(insightDataProvider, this.FileName);
            insightWindow.ShowInsightWindow();
        }
예제 #10
0
        private void InitPopups()
        {
            AvalonEditor.MouseHover += (sender, args) =>
            {
                if (CurrentCodeFile == null)
                {
                    return;     // Текущего файла нет совсем
                }
                TextViewPosition?pos = AvalonEditor.GetPositionFromPoint(Mouse.GetPosition(AvalonEditor.TextArea));
                if (!pos.HasValue)
                {
                    return;     // Не в области редактора
                }
                int          offset = AvalonEditor.Document.GetOffset(pos.Value.Location);
                CompileError error  = CurrentCodeFile.GetErrorByOffset(offset);

                if (error == null)
                {
                    return;     // Ошибки в этом месте нет
                }
                _errorPopup                    = new InsightWindow(AvalonEditor.TextArea);
                _errorPopup.StartOffset        = offset + 1;
                _errorPopup.EndOffset          = offset + 1;
                _errorPopup.Padding            = new Thickness(10, 0, 10, 0);
                _errorPopup.Content            = error.GetDiagnostic();
                _errorPopup.CloseAutomatically = false;

                _colorizeErrorForPopUp.Error = error;       // Выделить цветом ошибку, над которой аэростат
                Redraw();
                AvalonEditor.TextArea.Cursor             = Cursors.Hand;
                AvalonEditor.PreviewMouseLeftButtonDown += GoToMouseError;

                //_errorListView.SelectError(error, false);

                _errorPopup.Show();
            };

            AvalonEditor.MouseHoverStopped += (sender, args) =>
            {
                if (_errorPopup != null)
                {
                    AvalonEditor.PreviewMouseLeftButtonDown -= GoToMouseError;
                    _colorizeErrorForPopUp.Error             = null;
                    AvalonEditor.TextArea.Cursor             = null;
                    Redraw();

                    _errorPopup.Close();
                }
            };
        }
 private void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
 {
     if (isInString())
     {
         if (e.Text == "\"")
         {
             int p = txtScript.CaretOffset;
             if (p > 0 && txtScript.Text[p - 2] == '\\')
             {
                 return;
             }
             txtScript.Document.Insert(p, "\"");
             txtScript.CaretOffset = p;
         }
         return;
     }
     //
     if (e.Text == ".")
     {
         string[] prefix = getPrefix();
         if (prefix == null || prefix.Length == 0)
         {
             return;
         }
         setCompletionItems(prefix);
     }
     else if (e.Text == "(")
     {
         string[] prefix = getPrefix();
         if (prefix != null && prefix.Length > 0)
         {
             InsightWindow info = new InsightWindow(txtScript.TextArea);
             info.Content = findMethod(prefix);
             info.Show();
         }
         //
         int p = txtScript.CaretOffset;
         txtScript.Document.Insert(p, ")");
         txtScript.CaretOffset = p;
     }
     else if (e.Text == "{")
     {
         int p = txtScript.CaretOffset;
         txtScript.Document.Insert(p, "}");
         txtScript.CaretOffset = p;
     }
 }
예제 #12
0
 public void ShowInsightWindow(IInsightDataProvider insightDataProvider)
 {
     try
     {
         if (FInsightWindow == null || FInsightWindow.IsDisposed)
         {
             FInsightWindow         = new InsightWindow(FParentForm, this);
             FInsightWindow.Closed += new EventHandler(CloseInsightWindow);
         }
         FInsightWindow.AddInsightDataProvider(insightDataProvider, TextDocument.LocalPath);
         FInsightWindow.ShowInsightWindow();
     }
     catch (Exception e)
     {
         Logger.Log(e);
     }
 }
예제 #13
0
        private bool TextAreaKeyEventHandler(char key)
        {
            if (_codeCompletionWindow != null)
            {
                // If completion window is open and wants to handle the key, don't let the text area
                // handle it
                if (_codeCompletionWindow.ProcessKeyEvent(key))
                {
                    return(true);
                }
            }

            if (key == '.')
            {
                ICompletionDataProvider completionDataProvider = new CodeCompletionProvider(_iForm);

                _codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(
                    _iForm,                         // The parent window for the completion window
                    _editor,                        // The text editor to show the window for
                    IntellisenseForm.DummyFileName, // Filename - will be passed back to the provider
                    completionDataProvider,         // Provider to get the list of possible completions
                    key                             // Key pressed - will be passed to the provider
                    );
                if (_codeCompletionWindow != null)
                {
                    // ShowCompletionWindow can return null when the provider returns an empty list
                    _codeCompletionWindow.Closed += CloseCodeCompletionWindow;
                }
            }
            else if (key == '(')
            {
                if (_insightWindow != null && (!_insightWindow.IsDisposed))
                {
                    // provider returned an empty list, so the window never been opened
                    CloseInsightWindow(this, EventArgs.Empty);
                }

                IInsightDataProvider insightdataprovider = new MethodInsightDataProvider(_iForm);
                _insightWindow         = new InsightWindow(_iForm, _editor);
                _insightWindow.Closed += CloseInsightWindow;
                _insightWindow.AddInsightDataProvider(insightdataprovider, IntellisenseForm.DummyFileName);
                _insightWindow.ShowInsightWindow();
            }

            return(false);
        }
예제 #14
0
        public override void HandleTextEntered(EditorWinForm 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;
            }
        }
예제 #15
0
        public void Complete(TextArea textArea, ISegment completionSegment, EventArgs e)
        {
            int    offset = 0;
            string t      = this.Text;

            //if (Type == CompletionTypes.Method) {
            //    t += "()";
            //    offset = -1;
            //}
            textArea.Document.Replace(completionSegment, t);
            if (offset != 0)
            {
                textArea.Caret.Offset += offset;
            }
            //
            InsightWindow info = new InsightWindow(textArea);

            info.Content = ParamsDisplay;
            info.Show();
        }
        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;

                    //This -> Stack -> Globals
                    if (Debugger.Debug.SessionData.inst().ThisData != null)
                    {
                        wrapper = Debugger.Debug.SessionData.inst().ThisData.ContainsKey(wordHovered);
                    }
                    if (wrapper == null)
                    {
                        wrapper = Debugger.Debug.SessionData.inst().LocalData.ContainsKey(wordHovered);
                    }
                    if (wrapper == null && Debugger.Debug.SessionData.inst().GlobalData != null)
                    {
                        wrapper = Debugger.Debug.SessionData.inst().GlobalData.ContainsKey(wordHovered);
                    }

                    if (wrapper != null)
                    {
                        InsightWindow window = new InsightWindow(editor.TextArea);
                        window.Content = new Controls.JWrapView()
                        {
                            DataContext = wrapper
                        };
                        window.MinHeight     = 160;
                        window.MaxHeight     = 240;
                        window.SizeToContent = SizeToContent.Width;
                        window.Show();
                    }
                }
                e.Handled = true;
            }
        }
예제 #17
0
        void OnCodeInsight(object sender, ExecutedRoutedEventArgs e)
        {
            if (InsightWindow != null)
            {
                InsightWindow.Close();
            }

            // disable all code insight bindings when Insight is disabled
            if (!CodeCompletionOptions.InsightEnabled)
            {
                return;
            }

            CodeEditorView textEditor = GetTextEditorFromSender(sender);

            foreach (IInsightCodeCompletionBinding cc in CodeCompletionBindings.OfType <IInsightCodeCompletionBinding>())
            {
                if (cc.CtrlShiftSpace(textEditor.Adapter))
                {
                    e.Handled = true;
                    break;
                }
            }
        }
예제 #18
0
        void editor_MouseHover(object sender, 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  = IDEProject.inst().GlobalTypes;
                    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)
                        {
                            TypeInfo     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)
                                    {
                                        func = 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)
                                        {
                                            if (info.Properties.ContainsKey(words[i]))
                                            {
                                                info = info.Properties[words[i]];
                                            }
                                        }
                                    }
                                }
                            }
                            else if (isFunc && words.Length == 1)
                            {
                                func = globs.Functions.FirstOrDefault(f => f.Name.Equals(words[0]));
                            }
                            else if (!isFunc && words.Length == 1)
                            {
                                info = reso.GetClassType(editor.Document, line, words[0]);
                                if (info == null)
                                {
                                    KeyValuePair <string, TypeInfo> ty = globs.Classes.FirstOrDefault(p => p.Value.Equals(words[0]));
                                    if (ty.Value != null)
                                    {
                                        info = ty.Value;
                                    }
                                }
                            }

                            string msg = "";
                            // Ask documentation for the information
                            if (info != null && func != null)   //member function
                            {
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(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)     //global or member type
                            {
                                msg = info.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(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) { }
            }
        }
        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;
            }
        }

        void editor_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            {
                var newFontSize = editor.TextArea.FontSize + e.Delta / 50;
                editor.TextArea.FontSize = Math.Max(1, newFontSize);
                e.Handled = true;
            }
        }

        void aModelData_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("CurrentLine") || e.PropertyName.Equals("CurrentSection"))
            {
                bpMargin.InvalidateVisual();
            }
        }
예제 #20
0
        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
                }
            }
        }