예제 #1
0
        private void Replace_Menu_Click(object sender, EventArgs e)
        {
            if (CurrentTab != null)
            {
                string findText = "";

                NTDLS.Windows.Forms.CodeEditor.Selection selection = CurrentTab.CodeEditor.Selection;
                if (selection != null && selection.Text.Length > 0)
                {
                    findText = selection.Text;
                }
                else
                {
                    int caretX = CurrentTab.CodeEditor.Caret.Position.X;
                    int caretY = CurrentTab.CodeEditor.Caret.Position.Y;
                    if (caretX >= 0 && caretY >= 0)
                    {
                        NTDLS.Syntax.TextPoint currentWordPos = new NTDLS.Syntax.TextPoint(caretX, caretY);
                        NTDLS.Syntax.Word      currentWord    = CurrentTab.CodeEditor.Document.GetValidWordFromPos(currentWordPos);
                        if (currentWord != null && currentWord.Text.Length > 0)
                        {
                            findText = currentWord.Text.Trim();
                            if (findText.Substring(findText.Length - 1) == ",")
                            {
                                findText = findText.Substring(0, findText.Length - 1);
                            }
                        }
                    }
                }

                CurrentTab.CodeEditor.ShowReplace(findText);
            }
        }
예제 #2
0
        void TriggerImmediateAutoComplete(NTDLS.Windows.Forms.CodeEditorControl editor, KeyEventArgs e)
        {
            //We only auto-insert on tab and enter. This allows users to type words that are not in the list (aka variable names).

            if (e.Control || e.Alt || e.KeyCode == Keys.ShiftKey)
            {
                return; //Close on "control keys".
            }

            if (e.KeyCode == Keys.OemPeriod)
            {
                editor.AutoListClear(); //Reset the auto-list on period press.
            }

            if (!((e.KeyValue >= 'A' && e.KeyValue <= 'Z') || (e.KeyValue > '0' && e.KeyValue < '9') || e.KeyCode == Keys.OemPeriod))
            {
                if (e.KeyCode == Keys.Up || e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown || e.KeyCode == Keys.Down)
                {
                    return; //Allow user to scroll thorugh list.
                }

                editor.AutoListVisible = false; //Close on all invalid keys.
                return;
            }

            //If the auto-list has already been opened, then we will not repopulate it.
            if (editor.AutoListVisible && editor.AutoListItems.Count > 0)
            {
                return;
            }

            //Only open the auto-list if an alpha key (or period) were pressed.
            if (!((e.KeyValue >= 'A' && e.KeyValue <= 'Z') || e.KeyCode == Keys.OemPeriod))
            {
                return;
            }

            NTDLS.Syntax.Segment currentSegment = editor.Caret.CurrentSegment();
            if (currentSegment.BlockType.Name == "Text")
            {
                return; //We do not provide auto-completion within the text area.
            }

            //Save the caret positions.
            int caretX = editor.Caret.Position.X;
            int caretY = editor.Caret.Position.Y;

            if (caretX < 0 || caretY < 0)
            {
                return;
            }

            //Get the current word.
            NTDLS.Syntax.TextPoint currentWordPos = new NTDLS.Syntax.TextPoint(caretX - 1, caretY);
            NTDLS.Syntax.Word      currentWord    = editor.Document.GetValidWordFromPos(currentWordPos);
            if (currentWord == null || currentWord.Text.Length <= 0)
            {
                editor.AutoListVisible = false;
                return;
            }

            //We do not perform auto-listing within strings.
            if (currentWord.Style.Name == "Strings Style" || currentWord.Style.Name == "Comments Style")
            {
                editor.AutoListVisible = false;
                return; //We do not provide auto-completion within strings or comments.
            }

            //Subtract the current word length from the CaretX, this is so that
            //  the X position points to the beginning of the word on the document.
            caretX -= currentWord.Text.Length;
            if (caretX < 0 || caretY < 0)
            {
                return;
            }
            string currentWordText = ParseImmediateAutoCompleteWord(currentWord.Text);

            //If the current word is a period, then get the word before it.
            if (currentWordText == ".")
            {
                caretX--;

                //Get the current word.
                currentWordPos = new NTDLS.Syntax.TextPoint(caretX - 1, caretY);
                currentWord    = editor.Document.GetValidWordFromPos(currentWordPos);
                if (currentWord == null || currentWord.Text.Length <= 0)
                {
                    editor.AutoListVisible = false;
                    return;
                }

                caretX          = currentWord.Column;
                currentWordText = currentWord.Text + '.';
            }

            //string currentWord = editor.Caret.CurrentWord.Text;
            if (_RunningApplication.IsRunning)
            {
                if (_ImmediateText.Caret != null)
                {
                    if (currentWordText.Length > 0)
                    {
                        caretX = _ImmediateText.Caret.Position.X - currentWordText.Length;
                        caretY = _ImmediateText.Caret.Position.Y;

                        NTDLS.Syntax.TextPoint autoListPostion = new NTDLS.Syntax.TextPoint(caretX, caretY);

                        _ImmediateText.AutoListPosition = autoListPostion;
                        WriteToCmdPipe("::ImmediateAutoList~|" + currentWordText);
                    }
                }
            }
        }
예제 #3
0
        void TriggerEditorAutoComplete(NTDLS.Windows.Forms.CodeEditorControl editor, KeyEventArgs e)
        {
            //We only auto-insert on tab and enter. This allows users to type words that are not in the list (aka variable names).

            if (e.Control || e.Alt || e.KeyCode == Keys.ShiftKey)
            {
                return; //Close on "control keys".
            }

            if (e.KeyCode == Keys.OemPeriod)
            {
                editor.AutoListClear(); //Reset the auto-list on period press.
            }

            if (!((e.KeyValue >= 'A' && e.KeyValue <= 'Z') || //A-Z
                  (e.KeyValue > '0' && e.KeyValue < '9') || //0-9
                  e.KeyCode == Keys.OemPeriod ||            //.
                  (e.KeyValue == '3' && e.Shift == true)    //# (for pre-processors)
                  ))
            {
                if (e.KeyCode == Keys.Up || e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown || e.KeyCode == Keys.Down)
                {
                    return; //Allow user to scroll thorugh list.
                }

                editor.AutoListVisible = false; //Close on all invalid keys.
                return;
            }

            //If the auto-list has already been opened, then we will not repopulate it.
            if (editor.AutoListVisible && editor.AutoListItems.Count > 0)
            {
                return;
            }

            //Only open the auto-list if an alpha key (or period) were pressed.
            if (!((e.KeyValue >= 'A' && e.KeyValue <= 'Z') || //A-Z
                  e.KeyCode == Keys.OemPeriod ||            //.
                  (e.KeyValue == '3' && e.Shift == true)    //# (for pre-processors)
                  ))
            {
                return;
            }

            NTDLS.Syntax.Segment currentSegment = editor.Caret.CurrentSegment();
            if (currentSegment.BlockType.Name == "Text")
            {
                return; //We do not provide auto-completion within the text area.
            }

            //Save the caret positions.
            int caretX = editor.Caret.Position.X;
            int caretY = editor.Caret.Position.Y;

            if (caretX < 0 || caretY < 0)
            {
                return;
            }

            //Get the current word.
            NTDLS.Syntax.TextPoint currentWordPos = new NTDLS.Syntax.TextPoint(caretX - 1, caretY);
            NTDLS.Syntax.Word      currentWord    = editor.Document.GetValidWordFromPos(currentWordPos);
            if (currentWord == null || currentWord.Text.Length <= 0)
            {
                editor.AutoListVisible = false;
                return;
            }

            //We do not perform auto-listing within strings.
            if (currentWord.Style.Name == "Strings Style" || currentWord.Style.Name == "Comments Style")
            {
                editor.AutoListVisible = false;
                return; //We do not provide auto-completion within strings or comments.
            }

            //Subtract the current word length from the CaretX, this is so that
            //  the X position points to the beginning of the word on the document.
            caretX -= currentWord.Text.Length;
            if (caretX < 0 || caretY < 0)
            {
                return;
            }
            string currentWordText = currentWord.Text;

            //If the current word is a period, then get the word before it.
            if (currentWordText == ".")
            {
                caretX--;

                //Get the current word.
                currentWordPos = new NTDLS.Syntax.TextPoint(caretX - 1, caretY);
                currentWord    = editor.Document.GetValidWordFromPos(currentWordPos);
                if (currentWord == null || currentWord.Text.Length <= 0)
                {
                    editor.AutoListVisible = false;
                    return;
                }

                caretX          = currentWord.Column;
                currentWordText = currentWord.Text + '.';
            }
            editor.AutoListClear();
            editor.AutoListBeginLoad();

            List <AutoCompleteWord> listWords = new List <AutoCompleteWord>();

            foreach (NTDLS.Syntax.PatternList patternList in currentSegment.BlockType.KeywordsList)
            {
                if (patternList.Name != "Numbers")
                {
                    int imageSegment    = 10;
                    int imageTerminator = 5;

                    if (patternList.Name == "Types")
                    {
                        imageSegment    = 10;
                        imageTerminator = 8;
                    }
                    else if (patternList.Name == "Constants")
                    {
                        imageSegment    = 10;
                        imageTerminator = 5;
                    }
                    else if (patternList.Name == "System")
                    {
                        imageSegment    = 10;
                        imageTerminator = 6;
                    }
                    else if (patternList.Name == "Keywords")
                    {
                        imageSegment    = 10;
                        imageTerminator = 6;
                    }
                    else if (patternList.Name == "Reserved")
                    {
                        imageSegment    = 10;
                        imageTerminator = 9;
                    }
                    else if (patternList.Name == "PreProcessors")
                    {
                        imageSegment    = 10;
                        imageTerminator = 11;
                    }

                    if (_IDEOptions.AutoCompleteSimpleExpressions)
                    {
                        foreach (System.Collections.DictionaryEntry pattern in patternList.SimplePatterns)
                        {
                            string patternText = pattern.Key.ToString();

                            if (_IDEOptions.AutoCompleteMatchOnBeginningOnly)
                            {
                                if (patternText.StartsWith(currentWordText, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    GetAutocompleteWords(listWords, patternText, imageSegment, imageTerminator);
                                }
                            }
                            else
                            {
                                if (patternText.ToLower().Contains(currentWordText.ToLower()))
                                {
                                    GetAutocompleteWords(listWords, patternText, imageSegment, imageTerminator);
                                }
                            }
                        }
                    }

                    if (_IDEOptions.AutoCompleteComplexExpressions)
                    {
                        foreach (NTDLS.Syntax.Pattern pattern in patternList.ComplexPatterns)
                        {
                            if (_IDEOptions.AutoCompleteMatchOnBeginningOnly)
                            {
                                if (pattern.StringPattern.StartsWith(currentWordText, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    GetAutocompleteWords(listWords, pattern.StringPattern, imageSegment, imageTerminator);
                                }
                            }
                            else
                            {
                                if (pattern.StringPattern.ToLower().Contains(currentWordText.ToLower()))
                                {
                                    GetAutocompleteWords(listWords, pattern.StringPattern, imageSegment, imageTerminator);
                                }
                            }
                        }
                    }
                }
            }

            //Add the words to the visual drop-down-list.
            foreach (AutoCompleteWord word in listWords)
            {
                string tipText = GetDocumentationText(word.Text);
                if (tipText == null)
                {
                    //tipText = "No documentation is available for [" + word.Text + "]";
                }

                editor.AutoListAdd(word.Text, word.Text, tipText, word.Image);
            }

            editor.AutoListEndLoad();

            if (editor.AutoListItems.Count > 0)
            {
                NTDLS.Syntax.TextPoint autoListPostion = new NTDLS.Syntax.TextPoint(caretX, caretY);

                editor.AutoListPosition   = autoListPostion;
                editor.AutoListAutoSelect = true;
                editor.AutoListVisible    = true;
            }
            else
            {
                editor.AutoListVisible = false;
            }
        }
예제 #4
0
        void CodeEditor_RowMouseUp(object sender, NTDLS.Windows.Forms.CodeEditor.RowMouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                ContextMenuStrip popupMenu = new ContextMenuStrip();
                popupMenu.ItemClicked += new ToolStripItemClickedEventHandler(CodeEditor_RowMouseUp_ItemClicked);

                PopupMenuInfo menuInfo = new PopupMenuInfo();

                menuInfo.Editor = (NTDLS.Windows.Forms.CodeEditorControl)sender;
                menuInfo.Row    = menuInfo.Editor.Caret.CurrentRow;

                Point xE = menuInfo.Editor.PointToClient(Cursor.Position);

                if (menuInfo.Editor.Selection.Text.Trim().Length > 0)
                {
                    string WatchText = menuInfo.Editor.Selection.Text.Trim();
                    if (WatchText.Length > 0 && WatchText.Length < 1028)
                    {
                        if (WatchText.Length > 50)
                        {
                            WatchText = WatchText.Substring(0, 47) + "...";
                        }

                        popupMenu.Items.Add("Watch: " + WatchText, TransparentImage(Properties.Resources.TabWatch)).Tag = menuInfo.Editor.Selection.Text.Trim();
                        popupMenu.Items.Add("-");
                    }

                    if (_RunningApplication.IsRunning)
                    {
                        _RunningApplication.TipMenuItem      = new ToolStripMenuItem();
                        _RunningApplication.TipMenuItem.Text = "Properties";
                        _RunningApplication.TipMenuItem.DropDownItems.Add("Name: " + menuInfo.Editor.Selection.Text.Trim());
                        _RunningApplication.TipMenuItem.DropDownOpening += new EventHandler(CodeEditor_RowMouseUp_DropDownOpening);
                        _RunningApplication.TipMenuItem.Tag              = menuInfo.Editor.Selection.Text.Trim();

                        popupMenu.Items.Add(_RunningApplication.TipMenuItem);
                    }

                    if (popupMenu.Items.Count > 0)
                    {
                        popupMenu.Items.Add("Cut", TransparentImage(Properties.Resources.ToolCut)).Enabled = !_RunningApplication.IsRunning;
                        popupMenu.Items.Add("Copy", TransparentImage(Properties.Resources.ToolCopy));
                        popupMenu.Items.Add("Paste", TransparentImage(Properties.Resources.ToolPaste)).Enabled = !_RunningApplication.IsRunning;
                    }
                }
                else
                {
                    NTDLS.Syntax.TextPoint textPoint = menuInfo.Editor.CharFromPixel(xE.X, xE.Y);
                    if (textPoint != null)
                    {
                        //If nothing is selected, then move the cursor.
                        menuInfo.Editor.Caret.Position = textPoint;
                        menuInfo.Editor.Refresh();
                        menuInfo.Row = menuInfo.Editor.Caret.CurrentRow;

                        NTDLS.Syntax.Word word = menuInfo.Editor.Document.GetValidWordFromPos(textPoint);
                        if (word != null && word.Text.Trim().Length > 0)
                        {
                            string wordText = word.Text.Trim();
                            if (wordText.Substring(wordText.Length - 1) == ",")
                            {
                                wordText = wordText.Substring(0, wordText.Length - 1);
                            }
                            if (wordText.Trim().Length > 0)
                            {
                                string sFriendly = wordText.Trim().Replace("\r", " ").Replace("\n", " ").Replace("\t", " ");
                                if (sFriendly.Length > 50)
                                {
                                    sFriendly = sFriendly.Substring(0, 50) + "...";
                                }

                                menuInfo.Text = wordText;

                                string WatchText = wordText;
                                if (WatchText.Length > 0 && WatchText.Length < 1028)
                                {
                                    if (WatchText.Length > 50)
                                    {
                                        WatchText = WatchText.Substring(0, 47) + "...";
                                    }

                                    popupMenu.Items.Add("Watch: " + WatchText, TransparentImage(Properties.Resources.TabWatch)).Tag = wordText;
                                }

                                if (_RunningApplication.IsRunning)
                                {
                                    ToolStripMenuItem quickWatch = new ToolStripMenuItem();
                                    quickWatch.Text = "Quick Watch";

                                    quickWatch.Click += new EventHandler(CodeEditor_QuickWatch_RowMouseUp_DropDownOpening);

                                    quickWatch.Tag = wordText.Trim();

                                    popupMenu.Items.Add(quickWatch);

                                    if (popupMenu.Items.Count > 0)
                                    {
                                        popupMenu.Items.Add("-");
                                    }
                                }

                                if (_RunningApplication.IsRunning)
                                {
                                    _RunningApplication.TipMenuItem      = new ToolStripMenuItem();
                                    _RunningApplication.TipMenuItem.Text = "Properties";

                                    _RunningApplication.TipMenuItem.DropDownItems.Add("Name: " + wordText.Trim());

                                    _RunningApplication.TipMenuItem.DropDownOpening += new EventHandler(CodeEditor_RowMouseUp_DropDownOpening);

                                    _RunningApplication.TipMenuItem.Tag = wordText.Trim();

                                    popupMenu.Items.Add(_RunningApplication.TipMenuItem);
                                }

                                if (popupMenu.Items.Count > 0)
                                {
                                    popupMenu.Items.Add("-");
                                }

                                popupMenu.Items.Add("Copy", TransparentImage(Properties.Resources.ToolCopy));
                                popupMenu.Items.Add("Paste", TransparentImage(Properties.Resources.ToolPaste)).Enabled = !_RunningApplication.IsRunning;
                            }
                        }
                    }
                }

                if (popupMenu.Items.Count == 0 && menuInfo.Row != null)
                {
                    menuInfo.Text = menuInfo.Row.Text;
                    if (menuInfo.Row.Text.Length > 0)
                    {
                        popupMenu.Items.Add("Cut", TransparentImage(Properties.Resources.ToolCut)).Enabled = !_RunningApplication.IsRunning;
                        popupMenu.Items.Add("Copy", TransparentImage(Properties.Resources.ToolCopy));
                    }
                    popupMenu.Items.Add("Paste", TransparentImage(Properties.Resources.ToolPaste)).Enabled = !_RunningApplication.IsRunning;
                }

                if (popupMenu.Items.Count > 0)
                {
                    popupMenu.Items.Add("-");
                    popupMenu.Items.Add("Toggle Breakpoint", TransparentImage(Properties.Resources.ToolBreakpoint));
                    popupMenu.Tag = menuInfo;
                    popupMenu.Show(menuInfo.Editor, xE);
                }
            }
        }