Пример #1
0
        private bool ShowNewCompletion(CodeEditorControl editor)
        {
            CSharpExpressionFinder ef = new CSharpExpressionFinder(editor.ActiveViewControl.FileName);
            int cursor = editor.ActiveViewControl.Caret.Offset;
            ExpressionContext context = ef.FindExpression(ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName).Substring(0, cursor) + " T.", cursor + 2).Context;

            if (context.IsObjectCreation)
            {
                editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(context), ' ');
                return(true);
            }
            return(false);
        }
Пример #2
0
        public override void InitializeNewComponent(System.Collections.IDictionary defaultValues)
        {
            base.InitializeNewComponent(defaultValues);
            if (DesignerHost != null)
            {
                DesignerTransaction trans = DesignerHost.CreateTransaction("Adding Syntaxdocument");
                SyntaxDocument      sd    = DesignerHost.CreateComponent(typeof(SyntaxDocument)) as SyntaxDocument;

                CodeEditorControl sb = this.Control as CodeEditorControl;
                sb.Document = sd;
                trans.Commit();
            }
        }
Пример #3
0
        protected IMember GetCurrentMember(CodeEditorControl editor)
        {
            Caret caret          = editor.ActiveViewControl.Caret;
            NRefactoryResolver r = new NRefactoryResolver(ScriptControl.Parser.ProjectParser.CurrentProjectContent, languageProperties);

            if (r.Initialize(editor.ActiveViewControl.FileName, caret.Position.Y + 1, caret.Position.X + 1))
            {
                return(r.CallingMember);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        protected bool ProvideContextCompletion(CodeEditorControl editor, IReturnType expected, char charTyped)
        {
            if (expected == null)
            {
                return(false);
            }
            IClass c = expected.GetUnderlyingClass();

            if (c == null)
            {
                return(false);
            }
            if (c.ClassType == ClassType.Enum)
            {
                CtrlSpaceCompletionDataProvider cdp = new CtrlSpaceCompletionDataProvider();
                cdp.ForceNewExpression = true;
                ContextCompletionDataProvider cache = new ContextCompletionDataProvider(cdp);
                cache.activationKey = charTyped;
                cache.GenerateCompletionData(editor.ActiveViewControl.FileName, editor.ActiveViewControl, charTyped);
                ICompletionData[] completionData = cache.CompletionData;
                Array.Sort(completionData);
                for (int i = 0; i < completionData.Length; i++)
                {
                    CodeCompletionData ccd = completionData[i] as CodeCompletionData;
                    if (ccd != null && ccd.Class != null)
                    {
                        if (ccd.Class.FullyQualifiedName == expected.FullyQualifiedName)
                        {
                            cache.DefaultIndex = i;
                            break;
                        }
                    }
                }

                if (cache.DefaultIndex >= 0)
                {
                    if (charTyped != ' ')
                    {
                        cdp.InsertSpace = true;
                    }
                    editor.ActiveViewControl.ShowCompletionWindow(cache, charTyped);
                    return(true);
                }
            }
            return(false);
        }
Пример #5
0
        private bool TryDeclarationTypeInference(CodeEditorControl editor, string curLine)
        {
            string lineText  = curLine;
            ILexer lexer     = ParserFactory.CreateLexer(SupportedLanguage.CSharp, new System.IO.StringReader(lineText));
            Token  typeToken = lexer.NextToken();

            if (typeToken.kind == CSTokens.Question)
            {
                if (lexer.NextToken().kind == CSTokens.Identifier)
                {
                    Token t = lexer.NextToken();
                    if (t.kind == CSTokens.Assign)
                    {
                        string expr = lineText.Substring(t.col);
                        //LoggingService.Debug("DeclarationTypeInference: >" + expr + "<");
                        ResolveResult rr = ScriptControl.Parser.ProjectParser.GetResolver().Resolve(new ExpressionResult(expr),
                                                                                                    editor.ActiveViewControl.Caret.Position.Y + 1,
                                                                                                    t.col, editor.ActiveViewControl.FileName,
                                                                                                    ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName));

                        if (rr != null && rr.ResolvedType != null)
                        {
                            ClassFinder context = new ClassFinder(editor.ActiveViewControl.FileName, editor.ActiveViewControl.Caret.Position.Y, t.col);
                            if (CodeGenerator.CanUseShortTypeName(rr.ResolvedType, context))
                            {
                                CSharpAmbience.Instance.ConversionFlags = ConversionFlags.None;
                            }
                            else
                            {
                                CSharpAmbience.Instance.ConversionFlags = ConversionFlags.UseFullyQualifiedNames;
                            }
                            string typeName = CSharpAmbience.Instance.Convert(rr.ResolvedType);

                            //editor.Document.Replace(curLine.Offset + typeToken.col - 1, 1, typeName);
                            int offset = editor.ActiveViewControl.Document.GetRange(new TextRange(0, 0, 0, editor.ActiveViewControl.Caret.Position.Y)).Length;

                            editor.ActiveViewControl.Document.InsertText(typeName, offset + typeToken.col - 1, editor.ActiveViewControl.Caret.Position.Y);
                            editor.ActiveViewControl.Caret.SetPos(new TextPoint(editor.ActiveViewControl.Caret.Position.X + typeName.Length - 1, editor.ActiveViewControl.Caret.Position.Y));
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Пример #6
0
        protected AbstractCompletionWindow(Form parentForm, CodeEditorControl control)
		{

            if(parentForm==null)
                workingScreen = Screen.GetWorkingArea(control);
            else
			    workingScreen = Screen.GetWorkingArea(parentForm);
//			SetStyle(ControlStyles.Selectable, false);
			this.parentForm = parentForm;
			this.control  = control;
			
			
			StartPosition   = FormStartPosition.Manual;
			FormBorderStyle = FormBorderStyle.None;
			ShowInTaskbar   = false;
			MinimumSize     = new Size(1, 1);
			Size            = new Size(1, 1);
            SetLocation();
		}
Пример #7
0
        void CodeEditor_CaretChange(object sender, EventArgs e)
        {
            CodeEditorControl control = (CodeEditorControl)sender;

            if (wordEnteredInfo != null && control.Caret.CurrentWord != null)
            {
                string row = wordEnteredInfo.Row.Text;

                int endWord = row.IndexOf(wordEnteredInfo.Text) + wordEnteredInfo.Text.Length - 1;

                int dotC = 1;


                int count = control.Caret.CurrentWord.Column;

                for (int i = endWord + 1; i < count; i++)
                {
                    string currentChar = row[i].ToString();

                    if (currentChar == ",")
                    {
                        dotC++;
                    }
                }
                if (dotC > control.InfoTipCount)
                {
                    control.InfoTipSelectedIndex = control.InfoTipCount;
                }
                else
                {
                    control.InfoTipSelectedIndex = dotC;
                }
            }
            //else if (wordEnteredInfo != null)
            //{
            //    if (wordEnteredInfo.Row != control.Caret.CurrentRow)
            //    {
            //        control.InfoTipVisible = false;
            //        wordEnteredInfo = null;
            //    }
            //}
        }
Пример #8
0
        void CodeEditor_InfoTipSelectedIndexChanged(object sender, EventArgs e)
        {
            CodeEditorControl editor = (CodeEditorControl)sender;

            string cleaned = currentTip.Substring(0, currentTip.IndexOf("-"));

            StringBuilder sb = new StringBuilder();

            sb.Append(cleaned.Substring(0, cleaned.IndexOf("(") + 1));

            string onlyArgs = cleaned.Substring(cleaned.IndexOf("(") + 1);

            onlyArgs = onlyArgs.Substring(0, onlyArgs.IndexOf(")") - 1);

            string[] args = onlyArgs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < args.Length; i++)
            {
                if (editor.InfoTipSelectedIndex - 1 == i)
                {
                    sb.Append("<b>");
                }
                sb.Append(args[i]);

                if (editor.InfoTipSelectedIndex - 1 == i)
                {
                    sb.Append("</b>");
                }

                if (i == args.Length - 1)
                {
                    sb.Append(",");
                }
            }

            sb.Append(")<br>");
            sb.Append("<font color=green>");
            sb.Append(currentTip.Substring(currentTip.IndexOf("-") + 1).Trim());
            sb.Append("</font>");

            editor.InfoTipText = sb.ToString();
        }
Пример #9
0
        protected IList <ResolveResult> ResolveCallParameters(CodeEditorControl editor, InspectedCall call)
        {
            List <ResolveResult> rr = new List <ResolveResult>();
            int offset = LocationToOffset(editor, call.start);

            string documentText = ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName);

            offset = documentText.LastIndexOf('(');
            int newOffset;

            foreach (Location loc in call.commas)
            {
                newOffset = LocationToOffset(editor, loc);
                if (newOffset < 0)
                {
                    break;
                }
                TextPoint start = editor.ActiveViewControl.Document.IntPosToPoint(offset);
                TextPoint end   = editor.ActiveViewControl.Document.IntPosToPoint(newOffset);

                TextRange tr   = new TextRange(start.X, start.Y, end.X, end.Y);
                string    text = editor.ActiveViewControl.Document.GetRange(tr);             //.GetText(offset+1,newOffset-(offset+1));
                rr.Add(ScriptControl.Parser.ProjectParser.GetResolver().Resolve(new ExpressionResult(text), loc.Line, loc.Column, editor.ActiveViewControl.FileName, documentText));
            }
            // the last argument is between the last comma and the caret position
            newOffset = editor.ActiveViewControl.Caret.Offset;
            if (offset < newOffset)
            {
                TextPoint start = editor.ActiveViewControl.Document.IntPosToPoint(offset);
                TextPoint end   = editor.ActiveViewControl.Document.IntPosToPoint(newOffset);

                TextRange tr = new TextRange(start.X, start.Y, end.X, end.Y);

                string text = editor.ActiveViewControl.Document.GetRange(tr);                //(offset+1,newOffset-(offset+1));
                rr.Add(ScriptControl.Parser.ProjectParser.GetResolver().Resolve(new ExpressionResult(text),
                                                                                editor.ActiveViewControl.Caret.Position.Y + 1,
                                                                                editor.ActiveViewControl.Caret.Position.X + 1,
                                                                                editor.ActiveViewControl.FileName, documentText));
            }
            return(rr);
        }
Пример #10
0
        public EditorTabItemOld()
        {
            InitializeComponent();

            _EditorControl = new CodeEditorControl();
            //_EditorControl.ShowGutterMargin = true;
            //_EditorControl.ShowTabGuides = true;

            _EditorControl.Dock = DockStyle.Fill;

            _EditorControl.ContextMenuStrip = EditorContextMenuStrip;

            _EditorControl.Name = "codeeditor";

            this.Controls.Add(_EditorControl);

            this.Text = "Document " + counter;
            counter++;

            _EditorControl.FileNameChanged += new EventHandler(_EditorControl_FileNameChanged);

            _EditorControl.FileSavedChanged += new EventHandler(_EditorControl_FileSaved);

            _EditorControl.FontName = "Courier New";

            _EditorControl.FontSize = 10;

            _EditorControl.LineNumberForeColor   = Color.SteelBlue;
            _EditorControl.LineNumberBorderColor = Color.SteelBlue;

            this.CodeEditor.Saved = true;

            this.Padding       = new Padding(1, 2, 1, 1);
            this.DockableAreas = DockAreas.Document;

            WindowMenuItem = new ToolStripMenuItem();

            //this.mnuGoToDeclarition.Visible = false;
            this.mnuFindUsage.Visible = false;
        }
Пример #11
0
        protected AbstractCompletionWindow(Form parentForm, CodeEditorControl control)
        {
            if (parentForm == null)
            {
                workingScreen = Screen.GetWorkingArea(control);
            }
            else
            {
                workingScreen = Screen.GetWorkingArea(parentForm);
            }
//			SetStyle(ControlStyles.Selectable, false);
            this.parentForm = parentForm;
            this.control    = control;


            StartPosition   = FormStartPosition.Manual;
            FormBorderStyle = FormBorderStyle.None;
            ShowInTaskbar   = false;
            MinimumSize     = new Size(1, 1);
            Size            = new Size(1, 1);
            SetLocation();
        }
Пример #12
0
        public override bool HandleKeyPress(CodeEditorControl editor, char ch)
        {
            CSharpExpressionFinder ef = new CSharpExpressionFinder(editor.ActiveViewControl.FileName);
            int cursor = editor.ActiveViewControl.Caret.Offset;
            ExpressionContext context = null;

            if (ch == '(')
            {
                if (CodeCompletionOptions.KeywordCompletionEnabled)
                {
                    switch (editor.ActiveViewControl.Caret.CurrentWord.Text.Trim())
                    {
                    case "for":
                    case "lock":
                        context = ExpressionContext.Default;
                        break;

                    case "using":
                        context = ExpressionContext.TypeDerivingFrom(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.IDisposable"), false);
                        break;

                    case "catch":
                        context = ExpressionContext.TypeDerivingFrom(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.Exception"), false);
                        break;

                    case "foreach":
                    case "typeof":
                    case "sizeof":
                    case "default":
                        context = ExpressionContext.Type;
                        break;
                    }
                }
                if (context != null)
                {
                    if (IsInComment(editor))
                    {
                        return(false);
                    }
                    editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(context), ch);
                    return(true);
                }
                else if (EnableMethodInsight)
                {
                    editor.ActiveViewControl.ShowInsightWindow(new MethodInsightDataProvider());
                    return(true);
                }
                return(false);
            }
            else if (ch == '[')
            {
                Word curWord = editor.ActiveViewControl.Caret.CurrentWord;
                //Word preWord =  curWord.Row.FormattedWords[curWord.Index-1];
                //int lineOffset = editor.ActiveViewControl.Document.Text.Substring(0, editor.ActiveViewControl.Caret.Offset - editor.ActiveViewControl.Caret.Position.X).Length;
                //TextPoint tp = editor.ActiveViewControl.Document.IntPosToPoint(lineOffset);
                if (curWord.Text.Length == 0)
                {
                    // [ is first character on the line
                    // -> Attribute completion
                    editor.ActiveViewControl.ShowCompletionWindow(new AttributesDataProvider(ScriptControl.Parser.ProjectParser.CurrentProjectContent), ch);
                    return(true);
                }
            }
            else if (ch == ',' && CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled)
            {
                if (InsightRefreshOnComma(editor, ch))
                {
                    return(true);
                }
            }
            else if (ch == '=')
            {
                string curLine      = editor.ActiveViewControl.Caret.CurrentRow.Text;
                string documentText = ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName);
                int    position     = editor.ActiveViewControl.Caret.Offset - 2;

                if (position > 0 && (documentText[position + 1] == '+'))
                {
                    ExpressionResult result = ef.FindFullExpression(documentText, position);

                    if (result.Expression != null)
                    {
                        ResolveResult resolveResult = ScriptControl.Parser.ProjectParser.GetResolver().Resolve(result, editor.ActiveViewControl.Caret.Position.Y + 1, editor.ActiveViewControl.Caret.Position.X + 1, editor.ActiveViewControl.FileName, documentText);
                        if (resolveResult != null && resolveResult.ResolvedType != null)
                        {
                            IClass underlyingClass = resolveResult.ResolvedType.GetUnderlyingClass();
                            if (underlyingClass == null && resolveResult.ResolvedType.FullyQualifiedName.Length > 0)
                            {
                                underlyingClass = ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass(resolveResult.ResolvedType.FullyQualifiedName);
                            }
                            //if (underlyingClass != null && underlyingClass.IsTypeInInheritanceTree(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.MulticastDelegate"))) {
                            if (underlyingClass != null && underlyingClass.IsTypeInInheritanceTree(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.Delegate")))
                            {
                                //EventHandlerCompletitionDataProvider eventHandlerProvider = new EventHandlerCompletitionDataProvider(result.Expression, resolveResult);
                                //eventHandlerProvider.InsertSpace = true;
                                //editor.ActiveViewControl.ShowCompletionWindow(eventHandlerProvider, ch);
                            }
                        }
                    }
                }
                else if (position > 0)
                {
                    ExpressionResult result = ef.FindFullExpression(documentText, position);
                    if (result.Expression != null)
                    {
                        ResolveResult resolveResult = ScriptControl.Parser.ProjectParser.GetResolver().Resolve(result, editor.ActiveViewControl.Caret.Position.Y + 1, editor.ActiveViewControl.Caret.Position.X + 1, editor.ActiveViewControl.FileName, documentText);
                        if (resolveResult != null && resolveResult.ResolvedType != null)
                        {
                            if (ProvideContextCompletion(editor, resolveResult.ResolvedType, ch))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            else if (ch == ';')
            {
                string curLine = editor.ActiveViewControl.Caret.CurrentRow.Text;
                // don't return true when inference succeeds, otherwise the ';' won't be added to the document.
                TryDeclarationTypeInference(editor, curLine);
            }

            return(base.HandleKeyPress(editor, ch));
        }
Пример #13
0
        public override bool HandleKeyword(CodeEditorControl editor, string word)
        {
            // TODO: Assistance writing Methods/Fields/Properties/Events:
            // use public/static/etc. as keywords to display a list with other modifiers
            // and possible return types.
            switch (word)
            {
            case "using":
                if (IsInComment(editor))
                {
                    return(false);
                }

                // TODO: check if we are inside class/namespace
                editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Namespace), ' ');
                return(true);

            case "as":
            case "is":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Type), ' ');
                return(true);

            case "override":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new OverrideCompletionDataProvider(), ' ');
                return(true);

            case "new":
                return(ShowNewCompletion(editor));

            case "case":
                if (IsInComment(editor))
                {
                    return(false);
                }
                return(DoCaseCompletion(editor));

            case "return":
                if (IsInComment(editor))
                {
                    return(false);
                }
                IMember m = GetCurrentMember(editor);
                if (m != null)
                {
                    return(ProvideContextCompletion(editor, m.ReturnType, ' '));
                }
                else
                {
                    goto default;
                }

            default:
                return(base.HandleKeyword(editor, word));
            }
        }
		/// <summary>
		/// Default constructor for the SyntaxBoxControl
		/// </summary>
		public EditViewControl(CodeEditorControl Parent) : base()
		{
			_CodeEditor = Parent;


            Painter = new Painter_GDI(this);
			_Selection = new Selection(this);
			_Caret = new Caret(this);

			_Caret.Change += new EventHandler(this.CaretChanged);
			_Selection.Change += new EventHandler(this.SelectionChanged);


			//	this.AttachDocument (_SyntaxBox.Document);


			InitializeComponent();


			CreateAutoList();
			//CreateFindForm ();
			CreateInfoTip();

            this.SetStyle(ControlStyles.AllPaintingInWmPaint, false);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
			this.SetStyle(ControlStyles.Selectable, true);
			this.SetStyle(ControlStyles.ResizeRedraw, true);
			this.SetStyle(ControlStyles.Opaque, true);
			this.SetStyle(ControlStyles.UserPaint, true);
           // this.SetStyle(ControlStyles.UserMouse, true);
		}
Пример #15
0
 public static void SetSyntax(CodeEditorControl editor, string filename)
 {
     editor.Document.Parser.Init(CodeEditorSyntaxLoader.LanguageList.GetLanguageFromFile(filename));
 }
Пример #16
0
        public static void SetSyntax(CodeEditorControl editor, SyntaxLanguage language)
        {
            Stream xml = GetSyntaxStream(GetSyntaxFileName(language));

            editor.Document.Parser.Init(Language.FromSyntaxFile(xml));
        }
Пример #17
0
        public virtual bool HandleKeyPress(CodeEditorControl editor, char ch)
        {
            switch (ch)
            {
            case '(':
                if (enableMethodInsight)
                {
                    editor.ActiveViewControl.ShowInsightWindow(new MethodInsightDataProvider());
                    return(true);
                }
                else
                {
                    return(false);
                }

            case '[':
                if (enableIndexerInsight)
                {
                    editor.ActiveViewControl.ShowInsightWindow(new IndexerInsightDataProvider());
                    return(true);
                }
                else
                {
                    return(false);
                }

            case '<':
                if (enableXmlCommentCompletion)
                {
                    editor.ActiveViewControl.ShowCompletionWindow(new CommentCompletionDataProvider(), ch);
                    return(true);
                }
                else
                {
                    return(false);
                }

            case '.':

                if (enableDotCompletion)
                {
                    editor.ActiveViewControl.ShowCompletionWindow(new CodeCompletionDataProvider(), ch);
                    return(true);
                }
                else
                {
                    return(false);
                }

            case ' ':

                string word = editor.ActiveViewControl.Caret.CurrentWord.Text;     //GetWordBeforeCaret();
                if (word != null)
                {
                    return(HandleKeyword(editor, word));
                }
                else
                {
                    return(false);
                }

            default:
                return(false);
            }
        }
Пример #18
0
		public InsightWindow(Form parentForm, CodeEditorControl control) : base(parentForm, control)
		{
			SetStyle(ControlStyles.UserPaint, true);
			SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
		}
Пример #19
0
 public static void SetSyntax(CodeEditorControl editor, SyntaxLanguage language)
 {
     Stream xml = GetSyntaxStream(GetSyntaxFileName(language));
     editor.Document.Parser.Init(Language.FromSyntaxFile(xml));
 }
Пример #20
0
        public override bool HandleKeyword(CodeEditorControl editor, string word)
        {
            // TODO: Assistance writing Methods/Fields/Properties/Events:
            // use public/static/etc. as keywords to display a list with other modifiers
            // and possible return types.
            switch (word.ToLowerInvariant())
            {
            case "imports":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new CodeCompletionDataProvider(new ExpressionResult("Global", ExpressionContext.Importable)), ' ');
                return(true);

            case "as":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Type), ' ');
                return(true);

            case "new":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.ObjectCreation), ' ');
                return(true);

            case "inherits":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Type), ' ');
                return(true);

            case "implements":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Interface), ' ');
                return(true);

            case "overrides":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new OverrideCompletionDataProvider(), ' ');
                return(true);

            case "return":
                if (IsInComment(editor))
                {
                    return(false);
                }
                IMember m = GetCurrentMember(editor);
                if (m != null)
                {
                    ProvideContextCompletion(editor, m.ReturnType, ' ');
                    return(true);
                }
                else
                {
                    goto default;
                }

            case "option":
                if (IsInComment(editor))
                {
                    return(false);
                }
                editor.ActiveViewControl.ShowCompletionWindow(new TextCompletionDataProvider("Explicit On",
                                                                                             "Explicit Off",
                                                                                             "Strict On",
                                                                                             "Strict Off",
                                                                                             "Compare Binary",
                                                                                             "Compare Text"), ' ');
                return(true);

            default:
                return(base.HandleKeyword(editor, word));
            }
        }
Пример #21
0
 public InsightWindow(Form parentForm, CodeEditorControl control) : base(parentForm, control)
 {
     SetStyle(ControlStyles.UserPaint, true);
     SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
 }
Пример #22
0
        void CodeEditor_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            CodeEditorControl editor = (CodeEditorControl)sender;

            if (e.KeyChar == ')')
            {
                wordEnteredInfo       = null;
                editor.InfoTipVisible = false;
            }
            else if (e.KeyChar == '(')
            {
                // Word word = editor.Caret.CurrentWord;
                editor.Caret.CurrentRow.Parse(true);
                Word word = editor.Caret.CurrentWord;

                if (word != null)
                {
                    if (word.Pattern == null || word.Pattern.Parent == null)

                    {
                        if (editor.Caret.CurrentWord.Index == 0)
                        {
                            return;
                        }
                        word = editor.Caret.CurrentRow[editor.Caret.CurrentWord.Index - 1];
                    }
                    if (word.Pattern == null || word.Pattern.Parent == null)
                    {
                        return;
                    }

                    if (word.Pattern.Parent.Style.Name == "PHP Functions")
                    {
                        if (word != wordEnteredInfo && _FunctionsHashTable.ContainsKey(word.Text))
                        {
                            if (editor.Caret.Position.X < word.Column)
                            {
                                return;
                            }

                            wordEnteredInfo = word;

                            currentTip             = _FunctionsHashTable[word.Text].ToString();
                            editor.InfoTipText     = currentTip;
                            editor.InfoTipVisible  = true;
                            editor.InfoTipPosition = editor.Caret.Position;
                            editor.InfoTipCount    = currentTip.Split(new char[] { ',' },
                                                                      StringSplitOptions.RemoveEmptyEntries).Length;
                            editor.InfoTipSelectedIndex = 1;
                        }
                    }
                }

                if (wordEnteredInfo != null)
                {
                    if (wordEnteredInfo.Row.Text.IndexOf(wordEnteredInfo.Text) == -1)
                    {
                        editor.InfoTipVisible = false;
                        wordEnteredInfo       = null;
                    }
                }
                else
                {
                    editor.InfoTipVisible = false;
                }
            }
            else if ((wordEnteredInfo != null && editor.Caret.CurrentWord == null) ||
                     (wordEnteredInfo != null && wordEnteredInfo.Column > editor.Caret.CurrentWord.Column))
            {
                editor.InfoTipVisible = false;//this is executed when you move before the ( or deleted it
            }
        }
Пример #23
0
 public static void SetSyntax(CodeEditorControl editor, string filename)
 {
     editor.Document.Parser.Init(CodeEditorSyntaxLoader.LanguageList.GetLanguageFromFile(filename));
 }
Пример #24
0
        protected void ShowInsight(CodeEditorControl editor, MethodInsightDataProvider dp, ICollection <ResolveResult> parameters, char charTyped)
        {
            int paramCount = parameters.Count;

            dp.SetupDataProvider(editor.ActiveViewControl.FileName, editor.ActiveViewControl);
            List <IMethodOrProperty> methods = dp.Methods;

            if (methods.Count == 0)
            {
                return;
            }
            bool overloadIsSure;

            if (methods.Count == 1)
            {
                overloadIsSure  = true;
                dp.DefaultIndex = 0;
            }
            else
            {
                IReturnType[] parameterTypes = new IReturnType[paramCount + 1];
                int           i = 0;
                foreach (ResolveResult rr in parameters)
                {
                    if (rr != null)
                    {
                        parameterTypes[i] = rr.ResolvedType;
                    }
                    i++;
                }
                IReturnType[][] tmp;
                int[]           ranking      = MemberLookupHelper.RankOverloads(methods, parameterTypes, true, out overloadIsSure, out tmp);
                bool            multipleBest = false;
                int             bestRanking  = -1;
                int             best         = 0;
                for (i = 0; i < ranking.Length; i++)
                {
                    if (ranking[i] > bestRanking)
                    {
                        bestRanking  = ranking[i];
                        best         = i;
                        multipleBest = false;
                    }
                    else if (ranking[i] == bestRanking)
                    {
                        multipleBest = true;
                    }
                }
                if (multipleBest)
                {
                    overloadIsSure = false;
                }
                dp.DefaultIndex = best;
            }
            editor.ActiveViewControl.ShowInsightWindow(dp);
            if (overloadIsSure)
            {
                IMethodOrProperty method = methods[dp.DefaultIndex];
                if (paramCount < method.Parameters.Count)
                {
                    IParameter param = method.Parameters[paramCount];
                    ProvideContextCompletion(editor, param.ReturnType, charTyped);
                }
            }
        }
Пример #25
0
 public virtual bool HandleKeyword(CodeEditorControl editor, string word)
 {
     // DefaultCodeCompletionBinding does not support Keyword handling, but this
     // method can be overridden
     return(false);
 }
Пример #26
0
        private static void ReactToEventRename(object oldValue, EventResponseSave ers, IElement container)
        {
            string oldName = oldValue as string;
            string newName = ers.EventName;
            // The code
            // inside this
            // event handler
            // are saved in the
            // Element.Event.cs file
            // so that it can be edited
            // in Visual Studio.  If the
            // EventResponseSave changes then
            // it will use a new method.  We need
            // to take out the old method and move
            // the contents to the new method.

            // We'll "cheat" by setting the name to the old
            // one and getting the contents, then switching it
            // back to the new:
            string fullFileName = ers.GetSharedCodeFullFileName();

            if (!System.IO.File.Exists(fullFileName))
            {
                PluginManager.ReceiveError("Could not find the file " + fullFileName);
            }
            else if (CodeEditorControl.DetermineIfCodeFileIsValid(fullFileName) == false)
            {
                PluginManager.ReceiveError("Invalid code file " + fullFileName);
            }
            else
            {
                ers.EventName = oldName;
                string contents =
                    CodeEditorControl.RemoveWhiteSpaceForCodeWindow(ers.GetEventContents());

                ers.EventName = newName;
                // Now save the contents into the new method:

                if (string.IsNullOrEmpty(contents) || CodeEditorControl.HasMatchingBrackets(contents))
                {
                    EventCodeGenerator.InjectTextForEventAndSaveCustomFile(
                        container, ers, contents);
                    PluginManager.ReceiveOutput("Saved " + ers);
                    GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();

                    DialogResult result = MessageBox.Show("Would you like to delete the old method On" + oldName + "?", "Delete old function?", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        int startIndex;
                        int endIndex;

                        contents = FileManager.FromFileText(fullFileName);

                        EventCodeGenerator.GetStartAndEndIndexForMethod(contents,
                                                                        "On" + oldName, out startIndex, out endIndex);

                        contents = contents.Remove(startIndex, endIndex - startIndex);

                        FileManager.SaveText(contents, fullFileName);
                    }
                }
                else
                {
                    PluginManager.ReceiveError("Mismatch of } and { in event " + ers);
                }
            }
        }
Пример #27
0
        protected bool InsightRefreshOnComma(CodeEditorControl editor, char ch)
        {
            // Show MethodInsightWindow or IndexerInsightWindow
            NRefactoryResolver r = new NRefactoryResolver(ScriptControl.Parser.ProjectParser.CurrentProjectContent, languageProperties);
            Location           cursorLocation = new Location(editor.ActiveViewControl.Caret.Position.X + 1, editor.ActiveViewControl.Caret.Position.Y + 1);

            if (r.Initialize(editor.ActiveViewControl.FileName, cursorLocation.Y, cursorLocation.X))
            {
                TextReader currentMethod = r.ExtractCurrentMethod(ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName));
                if (currentMethod != null)
                {
                    ILexer        lexer = ParserFactory.CreateLexer(language, currentMethod);
                    Token         token;
                    InspectedCall call = new InspectedCall(Location.Empty, null);
                    call.parent = call;
                    while ((token = lexer.NextToken()) != null &&
                           token.kind != eofToken &&
                           token.Location < cursorLocation)
                    {
                        if (token.kind == commaToken)
                        {
                            call.commas.Add(token.Location);
                        }
                        else if (token.kind == openParensToken || token.kind == openBracketToken || token.kind == openBracesToken)
                        {
                            call = new InspectedCall(token.Location, call);
                        }
                        else if (token.kind == closeParensToken || token.kind == closeBracketToken || token.kind == closeBracesToken)
                        {
                            call = call.parent;
                        }
                    }
                    int    offset  = LocationToOffset(editor, call.start);
                    string docText = ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName);
                    offset = docText.LastIndexOf('(');
                    //int offset = editor.ActiveViewControl.Document.PointToIntPos(new TextPoint(call.start.X,call.start.Y));//, call.start);
                    if (offset >= 0 && offset < docText.Length)
                    {
                        char c = (char)docText.Substring(offset, 1).ToCharArray(0, 1)[0];
                        if (c == '(')
                        {
                            ShowInsight(editor,
                                        new MethodInsightDataProvider(offset, true),
                                        ResolveCallParameters(editor, call),
                                        ch);
                            return(true);
                        }
                        else if (c == '[')
                        {
                            ShowInsight(editor,
                                        new IndexerInsightDataProvider(offset, true),
                                        ResolveCallParameters(editor, call),
                                        ch);
                            return(true);
                        }
                        else
                        {
                            //LoggingService.Warn("Expected '(' or '[' at start position");
                        }
                    }
                }
            }
            return(false);
        }