Exemple #1
0
        public void scintilla_CharAdded(object sender, CharAddedEventArgs e)
        {
            // Find the word start
            var currentPos2  = t.CurrentPosition;
            var wordStartPos = t.WordStartPosition(currentPos2, true);

            // Display the autocompletion list
            var lenEntered = currentPos2 - wordStartPos;

            if (lenEntered > 0)
            {
                if (true || !t.AutoCActive)
                {
                    //"char double float int long static struct void unsigned"
                    string autokeywords = "abstract as base break case catch char checked continue default delegate do double else event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc static struct switch this throw true try typeof unchecked unsafe unsigned using virtual void while";
                    t.AutoCShow(lenEntered, autokeywords);
                }
            }
            if (e.Char == '}')
            {
                var currentPos = t.CurrentPosition;
                t.SearchFlags = SearchFlags.None;

                // Search back from the current position
                t.TargetStart = currentPos;
                t.TargetEnd   = 0;

                // Is the bracket following 4 spaces or a tab?
                if (t.SearchInTarget("    }") == (currentPos - 5))
                {
                    // Delete the leading 4 spaces
                    t.DeleteRange((currentPos - 5), 4);
                }
                else if (t.SearchInTarget("\t}") == (currentPos - 2))
                {
                    // Delete the leading tab
                    t.DeleteRange((currentPos - 2), 1);
                }
            }
        }
Exemple #2
0
        private void SetWord(string oldWord, string newWord)
        {
            //make sure the current word matches the old word we are replacing
            //(I guess somehow an async something could have changed the text while the menu was open)
            if (!string.Equals(GetCurrentWord(), oldWord))
            {
                return;
            }

            var pos       = _scintilla.CurrentPosition;
            var wordStart = _scintilla.WordStartPosition(pos, true);
            var wordEnd   = _scintilla.WordEndPosition(pos, true);

            _scintilla.DeleteRange(wordStart, wordEnd - wordStart);
            _scintilla.InsertText(wordStart, newWord);
        }
Exemple #3
0
        /// <summary>Scintilla Examples</summary>
        /// <param name="sci">Scintilla Control Name</param>
        public void Scintilla_TextModExamples(Scintilla sci)
        {
            sci.Text = "Hello";
            sci.AppendText(" World");     // 'Hello' -> 'Hello World'
            sci.DeleteRange(0, 5);        // 'Hello World' -> ' World'
            sci.InsertText(0, "Goodbye"); // ' World' -> 'Goodbye World'

            // Get the first 256 characters of the document
            var text = sci.GetTextRange(0, Math.Min(256, sci.TextLength));

            Console.WriteLine(text);

            sci.HideLines(3, 12);  // hide lines

            // find and replace plugin
            //https://github.com/Stumpii/ScintillaNET-FindReplaceDialog
        }
Exemple #4
0
        public void SetMenu()
        {
            ContextMenuStrip menu = new ContextMenuStrip();

            menu.Closed += new ToolStripDropDownClosedEventHandler(OnClosed);
            textArea.ContextMenuStrip = menu;

            menu.Items.Add(new ToolStripMenuItem("Undo Ctrl+Z", null, (s, ea) => textArea.Undo())
            {
                Enabled = textArea.CanUndo
            });
            menu.Items.Add(new ToolStripMenuItem("Redo Ctrl+Y", null, (s, ea) => textArea.Redo())
            {
                Enabled = textArea.CanRedo
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem("Cut Ctrl+X", null, (s, ea) => textArea.Cut())
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem("Copy Ctrl+C", null, (s, ea) => textArea.Copy())
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem("Paste Ctrl+V", null, (s, ea) => textArea.Paste())
            {
                Enabled = textArea.CanPaste
            });
            menu.Items.Add(new ToolStripMenuItem("Delete", null, (s, ea) => textArea.DeleteRange(textArea.SelectionStart, textArea.SelectionEnd - textArea.SelectionStart))
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem("Select All Ctrl+A", null, (s, ea) => textArea.SelectAll()));
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem("Find Ctrl+F", null, OpenFindDialog)
            {
                Enabled = null != sbDocument.Tab
            });
            menu.Items.Add(new ToolStripMenuItem("Find and Replace Ctrl+H", null, OpenReplaceDialog)
            {
                Enabled = null != sbDocument.Tab
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem("Comment Selected Lines", null, (s, ea) => sbDocument.Comment(true)));
            menu.Items.Add(new ToolStripMenuItem("Un-Comment Selected Lines", null, (s, ea) => sbDocument.Comment(false)));
            menu.Items.Add(new ToolStripMenuItem("Un-Comment File Commands", null, (s, ea) => sbDocument.UnCommentFile()));
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem("Collapse Folding", null, (s, ea) => sbDocument.FoldAll(FoldAction.Contract)));
            menu.Items.Add(new ToolStripMenuItem("Expand Folding", null, (s, ea) => sbDocument.FoldAll(FoldAction.Expand)));
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem("Navigate Back Ctrl+B", null, (s, ea) => sbDocument.GoBackwards())
            {
                Enabled = sbDocument.lineStack.backwards.Count > 1
            });
            menu.Items.Add(new ToolStripMenuItem("Navigate Forwards Ctrl+Shift+B", null, (s, ea) => sbDocument.GoForwards())
            {
                Enabled = sbDocument.lineStack.forwards.Count > 0
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(menuColors);
            menu.Items.Add(menuFonts);
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem("Copy Selection to Clipboard as HTML text", null, CopyToHtml)
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem("Copy Selection to Clipboard as HTML", null, (s, ea) => textArea.CopyAllowLine(CopyFormat.Html))
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem("Copy Selection to Clipboard as RTF", null, (s, ea) => textArea.CopyAllowLine(CopyFormat.Rtf))
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem("Open Containing Folder", null, OpenContainingFolder)
            {
                Enabled = null != sbDocument.Tab && File.Exists(((TabHeader)sbDocument.Tab.Header).FilePath)
            });
            menu.Items.Add(new ToolStripMenuItem("Add to Debug Watch Ctrl+Shift+W", null, (s, ea) => sbDocument.AddWatch())
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem("Display Flow Chart", null, OpenFlowChart)
            {
                Enabled = null != sbDocument.Tab
            });
            menu.Items.Add(new ToolStripMenuItem("Format Program", null, (s, ea) => sbDocument.Lexer.Format()));
        }
Exemple #5
0
 public void Delete()
 {
     textArea.DeleteRange(textArea.SelectionStart, textArea.SelectionEnd - textArea.SelectionStart);
 }
Exemple #6
0
        public void SetMenu()
        {
            ContextMenuStrip menu = new ContextMenuStrip();

            menu.Closed += new ToolStripDropDownClosedEventHandler(OnClosed);
            textArea.ContextMenuStrip = menu;

            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String89, null, (s, ea) => textArea.Undo())
            {
                Enabled = textArea.CanUndo
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String90, null, (s, ea) => textArea.Redo())
            {
                Enabled = textArea.CanRedo
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String91, null, (s, ea) => textArea.Cut())
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String92, null, (s, ea) => textArea.Copy())
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String93, null, (s, ea) => textArea.Paste())
            {
                Enabled = textArea.CanPaste
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String94, null, (s, ea) => textArea.DeleteRange(textArea.SelectionStart, textArea.SelectionEnd - textArea.SelectionStart))
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String95, null, (s, ea) => textArea.SelectAll()));
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String96, null, OpenFindDialog)
            {
                Enabled = null != sbDocument.Tab
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String97, null, OpenReplaceDialog)
            {
                Enabled = null != sbDocument.Tab
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String98, null, (s, ea) => sbDocument.Comment(true)));
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String99, null, (s, ea) => sbDocument.Comment(false)));
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String100, null, (s, ea) => sbDocument.UnCommentFile()));
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String101, null, (s, ea) => sbDocument.FoldAll(FoldAction.Contract)));
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String102, null, (s, ea) => sbDocument.FoldAll(FoldAction.Expand)));
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String103, null, (s, ea) => sbDocument.GoBackwards())
            {
                Enabled = sbDocument.lineStack.backwards.Count > 1
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String104, null, (s, ea) => sbDocument.GoForwards())
            {
                Enabled = sbDocument.lineStack.forwards.Count > 0
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(menuColors);
            menu.Items.Add(menuFonts);
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String105, null, CopyToHtml)
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String106, null, (s, ea) => textArea.CopyAllowLine(CopyFormat.Html))
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String107, null, (s, ea) => textArea.CopyAllowLine(CopyFormat.Rtf))
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String108, null, OpenContainingFolder)
            {
                Enabled = null != sbDocument.Tab && File.Exists(((TabHeader)sbDocument.Tab.Header).FilePath)
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String109, null, (s, ea) => sbDocument.AddWatch())
            {
                Enabled = textArea.SelectedText.Length > 0
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String110, null, OpenFlowChart)
            {
                Enabled = null != sbDocument.Tab
            });
            menu.Items.Add(new ToolStripMenuItem(Properties.Strings.String111, null, (s, ea) => sbDocument.Lexer.Format()));
        }
Exemple #7
0
        public bool TakeSelection()
        {
            bool       openAgain = false;
            Suggestion s         = theList.SelectedItem as Suggestion;

            if (s != null)
            {
                openAgain = s.openImmediatelyAfter;
                if (suggestionList.queryMode)
                {
                    if (s.dbColumn != null)
                    {
                        SqlBuilder b = new SqlBuilder(suggestionList.query);
                        b.AddColumn(suggestionList.keyword as Keyword, s.dbColumn, suggestionList.includeAliases);
                        string sql = b.Render();
                        editor.Text = sql;
                    }
                    else if (s.dbTable != null)
                    {
                        SqlBuilder b = new SqlBuilder(suggestionList.query);
                        b.AddTable(s.dbTable, suggestionList.includeAliases);
                        string sql = b.Render();
                        editor.Text = sql;
                    }
                }
                else
                {
                    string txt = s.expr;
                    if (txt != "")
                    {
                        txt = txt.Trim() + " ";

                        editor.Focus();
                        editor.DeleteRange(suggestionList.wordStartPosition, suggestionList.currentPos - suggestionList.wordStartPosition);
                        editor.InsertText(suggestionList.wordStartPosition, txt);
                        int pos = suggestionList.wordStartPosition + txt.Length;
                        while (editor.Text.Length > pos + 1 && editor.Text[pos - 1] == ' ' && editor.Text[pos] == ' ')
                        {
                            editor.DeleteRange(pos, 1);
                        }
                        if (s.dbColumn != null)
                        {
                            A.db.ColumnUsed(s.dbColumn);
                            A.db.TableUsed(s.dbColumn.table.name);
                            if (s.tableAlias != null && S.Get("RememberAliases", true))
                            {
                                A.db.AliasUsed(s.tableAlias, s.dbColumn.table.name);
                            }

                            if (S.Get("AutocompleteInsertTables", false))
                            {
                                AddTables(s.dbColumn);
                            }
                        }

                        editor.CurrentPosition = editor.SelectionStart = editor.SelectionEnd = pos;
                    }
                }
            }



            Hide();
            editor.Focus();
            return(openAgain);
        }
Exemple #8
0
        private void InsertMatchedChars(CharAddedEventArgs e)
        {
            var caretPos = Scintilla.CurrentPosition;
            var docStart = caretPos == 1;
            var docEnd   = caretPos == Scintilla.Text.Length;

            var charPrev = docStart ? Scintilla.GetCharAt(caretPos) : Scintilla.GetCharAt(caretPos - 2);
            var charNext = Scintilla.GetCharAt(caretPos);

            var isCharPrevBlank = charPrev == ' ' || charPrev == '\t' ||
                                  charPrev == '\n' || charPrev == '\r';

            var isCharNextBlank = charNext == ' ' || charNext == '\t' ||
                                  charNext == '\n' || charNext == '\r' ||
                                  docEnd;

            var isEnclosed = charPrev == '(' && charNext == ')' ||
                             charPrev == '{' && charNext == '}' ||
                             charPrev == '[' && charNext == ']';

            var isSpaceEnclosed = charPrev == '(' && isCharNextBlank || isCharPrevBlank && charNext == ')' ||
                                  charPrev == '{' && isCharNextBlank || isCharPrevBlank && charNext == '}' ||
                                  charPrev == '[' && isCharNextBlank || isCharPrevBlank && charNext == ']';

            var isCharOrString = isCharPrevBlank && isCharNextBlank || isEnclosed || isSpaceEnclosed;

            var charNextIsCharOrString = charNext == '"' || charNext == '\'';

            switch (e.Char)
            {
            case '(':
                if (charNextIsCharOrString)
                {
                    return;
                }

                Scintilla.InsertText(caretPos, ")");

                break;

            case '{':
                if (charNextIsCharOrString)
                {
                    return;
                }

                if (isEnclosed)
                {
                    Scintilla.GotoPosition(caretPos + 1);
                }
                else
                {
                    Scintilla.InsertText(caretPos, "}");
                }

                break;

            case '[':
                if (charNextIsCharOrString)
                {
                    return;
                }

                if (isEnclosed)
                {
                    Scintilla.GotoPosition(caretPos + 1);
                }
                else
                {
                    Scintilla.InsertText(caretPos, "]");
                }

                break;

            case '"':
                if (charPrev == '\"' && charNext == '\"')
                {
                    Scintilla.DeleteRange(caretPos, 1);
                    Scintilla.GotoPosition(caretPos);
                    return;
                }

                if (isCharOrString)
                {
                    Scintilla.InsertText(caretPos, "\"");
                }

                break;

            case '\'':
                if (charPrev == '\'' && charNext == '\'')
                {
                    Scintilla.DeleteRange(caretPos, 1);
                    Scintilla.GotoPosition(caretPos);

                    return;
                }

                if (isCharOrString)
                {
                    Scintilla.InsertText(caretPos, "'");
                }

                break;
            }
        }