コード例 #1
0
        public void ToggleBreakPoint(int line)
        {
            if (line >= 0 && line < this.Document.TotalNumberOfLines)
            {
                ICSharpCode.TextEditor.Document.LineSegment lineseg = this.Document.GetLineSegment(line);
                // walk through the line and make sure the first word is not a comment
                bool okToAdd = false;
                for (int i = 0; i < lineseg.Words.Count; i++)
                {
                    if (lineseg.Words[i].Type == ICSharpCode.TextEditor.Document.TextWordType.Word)
                    {
                        if (lineseg.Words[i].Color != System.Drawing.Color.Green)
                        {
                            okToAdd = true;
                        }
                        break;
                    }
                }
                if (!okToAdd)
                {
                    return;
                }

                ICSharpCode.TextEditor.Document.Bookmark existing_mark = null;
                foreach (ICSharpCode.TextEditor.Document.Bookmark mark in this.Document.BookmarkManager.Marks)
                {
                    if (mark.LineNumber == line)
                    {
                        existing_mark = mark;
                        break;
                    }
                }

                if (existing_mark != null)
                {
                    this.Document.BookmarkManager.RemoveMark(existing_mark);
                }
                else
                {
                    ICSharpCode.TextEditor.Document.Bookmark breakpoint = new BreakPoint(this.Document, new ICSharpCode.TextEditor.TextLocation(0, line));
                    this.Document.BookmarkManager.AddMark(breakpoint);
                }

                RepaintBookmarks();
            }
        }
コード例 #2
0
        //public override void IndentLines(ICSharpCode.TextEditor.TextArea textArea, int begin, int end)
        //{
        //}

        protected override int SmartIndentLine(ICSharpCode.TextEditor.TextArea area, int line)
        {
            ICSharpCode.TextEditor.Document.IDocument   document    = area.Document;
            ICSharpCode.TextEditor.Document.LineSegment lineSegment = document.GetLineSegment(line - 1);
            if (document.GetText(lineSegment).EndsWith(":"))
            {
                ICSharpCode.TextEditor.Document.LineSegment segment = document.GetLineSegment(line);
                string indent_str = "    ";// ICSharpCode.TextEditor.Actions.Tab.GetIndentationString(document);
                if (!area.TextEditorProperties.ConvertTabsToSpaces)
                {
                    indent_str = "\t";
                }
                string str = base.GetIndentation(area, line - 1) + indent_str;
                document.Replace(segment.Offset, segment.Length, str + document.GetText(segment));
                return(str.Length);
            }
            return(base.SmartIndentLine(area, line));
        }
コード例 #3
0
        /// <summary>
        /// Return true to handle the keypress, return false to let the text area handle the keypress
        /// </summary>
        bool TextAreaKeyEventHandler(char key)
        {
            if (m_code_complete != null)
            {
                // If completion window is open and wants to handle the key, don't let the text area
                // handle it
                if (m_code_complete.ProcessKeyEvent(key))
                {
                    return(true);
                }
            }

            ICSharpCode.TextEditor.Gui.CompletionWindow.ICompletionDataProvider completionDataProvider = CodeComplete.GetCompletionProvider(this, key);
            if (completionDataProvider == null && key == '(')
            {
                ICSharpCode.TextEditor.Document.LineSegment line = this.Document.GetLineSegment(ActiveTextAreaControl.Caret.Line);
                if (null == line)
                {
                    return(false);
                }

                List <ICSharpCode.TextEditor.Document.TextWord> words = line.Words;
                if (words == null || words.Count < 1)
                {
                    return(false);
                }

                ICSharpCode.TextEditor.Document.TextWord lastWord = words[words.Count - 1];
                if (lastWord.Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
                {
                    return(false);
                }
                // Todo: Remove hard coded colors
                if (lastWord.Color == System.Drawing.Color.Green || lastWord.Color == System.Drawing.Color.Red)
                {
                    return(false);
                }

                // make sure first real word on this line is not "def"
                for (int i = 0; i < words.Count; i++)
                {
                    if (words[i].Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
                    {
                        continue;
                    }
                    if (words[i].Word.Equals("def", StringComparison.Ordinal))
                    {
                        return(false);
                    }
                    break;
                }

                char c = lastWord.Word[0];
                if (char.IsLetter(c))
                {
                    // Build up a python script to execute
                    int           line_number = this.ActiveTextAreaControl.TextArea.Caret.Line;
                    StringBuilder script      = new StringBuilder();
                    for (int i = 0; i < line_number; i++)
                    {
                        line = this.ActiveTextAreaControl.TextArea.Document.GetLineSegment(i);
                        if (line != null && line.Words.Count > 2)
                        {
                            string firstword = line.Words[0].Word;
                            if (firstword.Equals("import", StringComparison.Ordinal) || firstword.Equals("from"))
                            {
                                script.AppendLine(this.ActiveTextAreaControl.TextArea.Document.GetText(line));
                            }
                        }
                    }

                    ICSharpCode.TextEditor.Document.LineSegment lastLine = this.ActiveTextAreaControl.TextArea.Document.GetLineSegment(line_number);
                    if (null == lastLine)
                    {
                        return(false);
                    }

                    //walk backward through the line until we hit something that is NOT a word or period
                    string evaluation = "";
                    for (int i = lastLine.Words.Count - 1; i >= 0; i--)
                    {
                        ICSharpCode.TextEditor.Document.TextWord word = lastLine.Words[i];
                        if (word.Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
                        {
                            break;
                        }
                        c = word.Word[0];
                        if (c != '.' && !char.IsLetter(c))
                        {
                            break;
                        }
                        evaluation = evaluation.Insert(0, word.Word);
                    }

                    if (evaluation != "if" && evaluation != "while")
                    {
                        RhinoDLR_Python.Intellisense isense = m_intellisense;
                        if (isense == null)
                        {
                            isense = CodeComplete.Intellisense;
                        }
                        string rc = isense.EvaluateHelp(script.ToString(), evaluation);
                        if (!string.IsNullOrEmpty(rc) && null != m_help_callback)
                        {
                            m_help_callback(rc);
                        }
                    }
                }
            }
            else if (completionDataProvider != null)
            {
                ScriptEditor.Model.ScriptDocument doc = ScriptEditor.Model.Documents.DocumentFromId(DocumentId);
                string path = "none";
                if (doc != null && !string.IsNullOrEmpty(doc.FullPath))
                {
                    path = doc.FullPath;
                }

                m_code_complete = ICSharpCode.TextEditor.Gui.CompletionWindow.CodeCompletionWindow.ShowCompletionWindow(
                    m_mainform,             // The parent window for the completion window
                    this,                   // The text editor to show the window for
                    path,                   // 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 (m_code_complete != null)
                {
                    // ShowCompletionWindow can return null when the provider returns an empty list
                    m_code_complete.Closed += new EventHandler(CloseCodeCompletionWindow);
                }
            }
            return(false);
        }
コード例 #4
0
 public LineLengthChangeEventArgs(IDocument document, ICSharpCode.TextEditor.Document.LineSegment lineSegment, int moved) : base(document, lineSegment)
 {
     this.lengthDelta = moved;
 }
コード例 #5
0
 public LineEventArgs(IDocument document, ICSharpCode.TextEditor.Document.LineSegment lineSegment)
 {
     this.document    = document;
     this.lineSegment = lineSegment;
 }