Exemple #1
0
        private static string GetPopupHintText(TextArea textArea, ToolTipRequestEventArgs e)
        {
            ICSharpCode.TextEditor.TextLocation logicPos = e.LogicalPosition;
            IDocument   doc      = textArea.Document;
            LineSegment seg      = doc.GetLineSegment(logicPos.Y);
            string      FileName = textArea.MotherTextEditorControl.FileName;

            PascalABCCompiler.Parsers.KeywordKind keyw = PascalABCCompiler.Parsers.KeywordKind.None;
            if (logicPos.X > seg.Length - 1)
            {
                return(null);
            }
            //string expr = FindFullExpression(doc.TextContent, seg.Offset + logicPos.X,e.LogicalPosition.Line,e.LogicalPosition.Column);
            string expr_without_brackets = null;
            string expr = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.FindExpressionFromAnyPosition(seg.Offset + logicPos.X, doc.TextContent, e.LogicalPosition.Line, e.LogicalPosition.Column, out keyw, out expr_without_brackets);

            if (expr == null)
            {
                expr = expr_without_brackets;
            }
            if (expr_without_brackets == null)
            {
                return(null);
            }
            List <PascalABCCompiler.Errors.Error> Errors = new List <PascalABCCompiler.Errors.Error>();

            PascalABCCompiler.SyntaxTree.expression tree = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
            bool header = false;

            if (tree == null || Errors.Count > 0)
            {
                Errors.Clear();
                tree   = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr_without_brackets, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
                header = true;
                if (tree == null || Errors.Count > 0)
                {
                    return(null);
                }
            }
            else
            {
                Errors.Clear();
                PascalABCCompiler.SyntaxTree.expression tree2 = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr_without_brackets, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
                //header = true;
                if (tree2 == null || Errors.Count > 0)
                {
                    return(null);
                }
                //if (tree is PascalABCCompiler.SyntaxTree.new_expr && (tree as PascalABCCompiler.SyntaxTree.new_expr).params_list == null)
                //	tree = tree2;
            }
            CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[FileName];
            if (dconv == null)
            {
                return(null);
            }
            return(dconv.GetDescription(tree, FileName, expr_without_brackets, WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController, e.LogicalPosition.Line, e.LogicalPosition.Column, keyw, header));
        }
Exemple #2
0
        public static PABCNETCodeCompletionWindow ShowCompletionWindowWithFirstChar(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, PascalABCCompiler.Parsers.KeywordKind keyw)
        {
            ICompletionData[] completionData = (completionDataProvider as VisualPascalABC.CodeCompletionProvider).GenerateCompletionDataByFirstChar(fileName, control.ActiveTextAreaControl.TextArea, firstChar, keyw);
            if (completionData == null || completionData.Length == 0)
            {
                return(null);
            }
            (completionDataProvider as VisualPascalABC.CodeCompletionProvider).preSelection = firstChar.ToString();
            PABCNETCodeCompletionWindow codeCompletionWindow = new PABCNETCodeCompletionWindow(completionDataProvider, completionData, parent, control, true, false);

            codeCompletionWindow.ShowCompletionWindow();
            return(codeCompletionWindow);
        }
Exemple #3
0
        public static PABCNETCodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, bool visibleKeyPressed, bool is_by_dot, PascalABCCompiler.Parsers.KeywordKind keyw)
        {
            ICompletionData[] completionData = (completionDataProvider as VisualPascalABC.CodeCompletionProvider).GenerateCompletionDataWithKeyword(fileName, control.ActiveTextAreaControl.TextArea, firstChar, keyw);
            if (completionData == null || completionData.Length == 0)
            {
                return(null);
            }
            PABCNETCodeCompletionWindow codeCompletionWindow = new PABCNETCodeCompletionWindow(completionDataProvider, completionData, parent, control, visibleKeyPressed, is_by_dot);

            codeCompletionWindow.ShowCompletionWindow();
            return(codeCompletionWindow);
        }
Exemple #4
0
        /// <summary>
        /// Return true to handle the keypress, return false to let the text area handle the keypress
        /// </summary>
        bool TextAreaKeyEventHandler(char key)
        {
            if (!WorkbenchServiceFactory.Workbench.UserOptions.AllowCodeCompletion || !VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.compilerLoaded)
            {
                return(false);
            }
            if (CodeCompletion.CodeCompletionController.CurrentParser == null)
            {
                return(false);
            }
            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);
                }
            }
            else
            {
                PABCNETCodeCompletionWindow ccw = CodeCompletionNamesOnlyInModuleAction.comp_windows[editor.ActiveTextAreaControl.TextArea] as PABCNETCodeCompletionWindow;

                if (ccw != null && CodeCompletionNamesOnlyInModuleAction.is_begin)
                {
                    CodeCompletionNamesOnlyInModuleAction.is_begin = false;
                    if (key != ' ')
                    {
                        ccw.ProcessKeyEvent(key);
                    }
                    else
                    {
                        ccw.ProcessKeyEvent('_');
                        ccw.Close();
                    }
                }
                else if (ccw != null && ccw.ProcessKeyEvent(key))
                {
                    return(true);
                }
            }
            if (key == '.')
            {
                if (CodeCompletion.CodeCompletionController.CurrentParser == null)
                {
                    return(false);
                }
                if (!string.IsNullOrEmpty(WorkbenchServiceFactory.DocumentService.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.SelectionManager.SelectedText))
                {
                    WorkbenchServiceFactory.DocumentService.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.Caret.Position = WorkbenchServiceFactory.DocumentService.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.SelectionManager.SelectionCollection[0].StartPosition;
                    WorkbenchServiceFactory.DocumentService.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.SelectionManager.RemoveSelectedText();
                }

                if (WorkbenchServiceFactory.Workbench.UserOptions.CodeCompletionDot)
                {
                    completionDataProvider = new CodeCompletionProvider();

                    codeCompletionWindow = PABCNETCodeCompletionWindow.ShowCompletionWindow(
                        VisualPABCSingleton.MainForm,   // The parent window for the completion window
                        editor,                         // The text editor to show the window for
                        editor.FileName,                // 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
                        true,
                        true,
                        PascalABCCompiler.Parsers.KeywordKind.None
                        );
                    CodeCompletionNamesOnlyInModuleAction.is_begin = true;
                    CodeCompletionNamesOnlyInModuleAction.comp_windows[editor.ActiveTextAreaControl.TextArea] = codeCompletionWindow;
                    if (codeCompletionWindow != null)
                    {
                        codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
                    }
                }
            }
            else if (key == '(' || key == '[' || key == ',')
            {
                if (CodeCompletion.CodeCompletionController.CurrentParser == null)
                {
                    return(false);
                }
                if (VisualPABCSingleton.MainForm.UserOptions.CodeCompletionParams)
                {
                    ICSharpCode.TextEditor.Gui.InsightWindow.IInsightDataProvider idp = new DefaultInsightDataProvider(-1, false, key);
                    if (insightWindow == null || insightWindow.InsightProviderStackLength == 0)
                    {
                        insightWindow         = new PABCNETInsightWindow(VisualPABCSingleton.MainForm, editor);
                        insightWindow.Font    = new Font(Constants.CompletionInsightWindowFontName, insightWindow.Font.Size);
                        insightWindow.Closed += new EventHandler(CloseInsightWindow);
                    }
                    else
                    {
                        (idp as DefaultInsightDataProvider).defaultIndex  = insightWindow.GetCurrentData();
                        (idp as DefaultInsightDataProvider).cur_param_num = (insightWindow.GetInsightProvider() as DefaultInsightDataProvider).param_count;
                    }
                    insightWindow.AddInsightDataProvider(idp, editor.FileName);
                    insightWindow.ShowInsightWindow();
                }
            }
            else if (key == ' ')
            {
                if (CodeCompletion.CodeCompletionController.CurrentParser == null)
                {
                    return(false);
                }
                if (VisualPABCSingleton.MainForm.UserOptions.CodeCompletionDot)
                {
                    PascalABCCompiler.Parsers.KeywordKind keyw = KeywordChecker.TestForKeyword(editor.Document.TextContent, editor.ActiveTextAreaControl.TextArea.Caret.Offset - 1);
                    if (keyw == PascalABCCompiler.Parsers.KeywordKind.New || keyw == PascalABCCompiler.Parsers.KeywordKind.Uses)
                    {
                        completionDataProvider = new CodeCompletionProvider();
                        codeCompletionWindow   = PABCNETCodeCompletionWindow.ShowCompletionWindow(
                            VisualPABCSingleton.MainForm, // The parent window for the completion window
                            editor,                       // The text editor to show the window for
                            editor.FileName,              // Filename - will be passed back to the provider
                            completionDataProvider,       // Provider to get the list of possible completions
                            ' ',                          // Key pressed - will be passed to the provider
                            true,
                            false,
                            keyw
                            );
                        CodeCompletionNamesOnlyInModuleAction.comp_windows[editor.ActiveTextAreaControl.TextArea] = codeCompletionWindow;
                        if (codeCompletionWindow != null)
                        {
                            codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
                        }
                        //return true;
                    }
                }
            }
            else if (key == '\n')
            {
                if (VisualPABCSingleton.MainForm.UserOptions.AllowCodeCompletion && CodeCompletion.CodeCompletionController.CurrentParser != null)
                {
                    try
                    {
                        CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[editor.FileName];
                        if (dconv != null)
                        {
                            CodeCompletion.SymScope ss = dconv.FindScopeByLocation(editor.ActiveTextAreaControl.TextArea.Caret.Line + 1, editor.ActiveTextAreaControl.TextArea.Caret.Column + 1);
                            ss.IncreaseEndLine();
                        }
                    }
                    catch
                    {
                    }
                }
            }
            else if (codeCompletionWindow == null && VisualPABCSingleton.MainForm.UserOptions.EnableSmartIntellisense && (char.IsLetter(key) || key == '_'))
            {
                if (VisualPABCSingleton.MainForm.UserOptions.CodeCompletionDot)
                {
                    if (CodeCompletion.CodeCompletionController.CurrentParser == null)
                    {
                        return(false);
                    }
                    PascalABCCompiler.Parsers.KeywordKind keyw = KeywordChecker.TestForKeyword(editor.Document.TextContent, editor.ActiveTextAreaControl.TextArea.Caret.Offset - 1);
                    if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsDefinitionIdentifierAfterKeyword(keyw))
                    {
                        return(false);
                    }

                    if (editor.ActiveTextAreaControl.TextArea.Caret.Offset > 0 && (char.IsLetterOrDigit(editor.Document.TextContent[editor.ActiveTextAreaControl.TextArea.Caret.Offset - 1]) || editor.Document.TextContent[editor.ActiveTextAreaControl.TextArea.Caret.Offset - 1] == '_'))
                    {
                        return(false);
                    }
                    completionDataProvider = new CodeCompletionProvider();
                    codeCompletionWindow   = PABCNETCodeCompletionWindow.ShowCompletionWindowWithFirstChar(
                        VisualPABCSingleton.MainForm,   // The parent window for the completion window
                        editor,                         // The text editor to show the window for
                        editor.FileName,                // 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
                        keyw
                        );
                    CodeCompletionNamesOnlyInModuleAction.comp_windows[editor.ActiveTextAreaControl.TextArea] = codeCompletionWindow;
                    if (codeCompletionWindow != null)
                    {
                        codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
                    }
                }
            }

            /*else if (codeCompletionWindow == null && key == '\n')
             * {
             *  if (mainForm.UserOptions.AllowCodeFormatting)
             *  {
             *          if (CodeCompletion.CodeCompletionController.currentParser == null) return false;
             *          string bracket = CodeCompletion.CodeCompletionController.currentParser.LanguageInformation.GetBodyStartBracket();
             *          string end_bracket = CodeCompletion.CodeCompletionController.currentParser.LanguageInformation.GetBodyEndBracket();
             *          if (bracket != null)
             *          {
             *                  int i = editor.ActiveTextAreaControl.TextArea.Caret.Offset-1;
             *                  int j = bracket.Length-1;
             *                  bool eq=true;
             *                  while (i >= 0 && j >= 0)
             *                  {
             *                          if (editor.Document.TextContent[i] != bracket[j])
             *                          {
             *                                  eq = false;
             *                                  break;
             *                          }
             *                          i--; j--;
             *                  }
             *                  if (eq && j<0)
             *                  {
             *                          TextArea textArea = editor.ActiveTextAreaControl.TextArea;
             *                          int col = textArea.Caret.Column-bracket.Length;
             *                                          textArea.InsertString("\n\n"+end_bracket);
             *                                          textArea.Caret.Column = 0;
             *                                          textArea.Caret.Line = textArea.Caret.Line-1;
             *                                          textArea.Caret.Column = VisualPABCSingleton.MainForm.UserOptions.CursorTabCount+col;
             *                                          return true;
             *                  }
             *          }
             *  }
             * }*/

            return(false);
        }