//========================================================================================= public CodeViewerTokenIndexTests() { this.Viewer = new CodeViewer(); this.Viewer.Language = PredefinedLanguage.MsSql; var oTestProvider = new TestDbInfoProvider(); var oSuggestionBuilder = new EditQueryRegExBuilder(this.Viewer, oTestProvider); this.Viewer.UseSuggestionRules(oSuggestionBuilder); }
//========================================================================================= public RendererTests() { this.Viewer = new CodeViewer(); this.Viewer.Language = PredefinedLanguage.MsSql; this.Viewer.Size = new Size(400, 400); Bitmap oBitmap = new Bitmap(1, 1); this.MyGraphics = Graphics.FromImage(oBitmap); }
public void Change_font() { CodeViewer oViewer = new CodeViewer(); oViewer.Language = PredefinedLanguage.MsSql; oViewer.Text = Script; Assert.AreEqual(oViewer.Font.Name, "Consolas"); oViewer.Body.Font = new Font("Arial", 12); Assert.AreEqual(oViewer.Font.Name, "Arial"); }
public void SetUp() { this.Viewer = new CodeViewer(); this.Viewer.Language = PredefinedLanguage.MsSql; var oTestProvider = new TestDbInfoProvider(); var oSuggestionBuilder = new EditQueryRegExBuilder(Viewer, oTestProvider); oSuggestionBuilder.DefaultSchema = "Schema_Second"; Viewer.UseSuggestionRules(oSuggestionBuilder); }
public void Getting_style_by_name() { CodeViewer oViewer = new CodeViewer(); oViewer.Language = PredefinedLanguage.MsSql; oViewer.Text = Script; SyntaxSettings oSettings = oViewer.SyntaxSettings; TextStyle oStyle = oSettings.GetStyleByName(SyntaxSettings.S_KEYWORDS_1); Assert.AreEqual(oStyle.ForeColor, Color.Blue); }
public void Linking() { CodeViewer oViewer = new CodeViewer(); Assert.IsNull(oViewer.CodeCompletor); oViewer.ReadOnly = false; Assert.IsNull(oViewer.CodeCompletor); TestDbInfoProvider oTestProvider = new TestDbInfoProvider(); var oSuggestionBuilder = new EditQueryRegExBuilder(oViewer, oTestProvider); oViewer.UseSuggestionRules(oSuggestionBuilder); Assert.IsNotNull(oViewer.CodeCompletor); Assert.IsNotNull(oViewer.CodeCompletor.Builder); Assert.AreEqual(oSuggestionBuilder, oViewer.CodeCompletor.Builder); }
//========================================================================================= public AutoCompleteTests() { this.Viewer = new CodeViewer(); this.Viewer.ReadOnly = false; this.Viewer.Language = PredefinedLanguage.MsSql; var oTestProvider = new TestDbInfoProvider(); var oSuggestionBuilder = new EditQueryRegExBuilder(Viewer, oTestProvider); oSuggestionBuilder.DefaultSchema = "Schema_Second"; //Create mock var oMock = new Mock<CodeCompletor>(MockBehavior.Default); //Mock variants list drawing oMock.Setup(x => x.ShowVariants(It.IsAny<Point>())).Callback(() => this.VariantsWereShown = true); oMock.Setup(x => x.HideVariants()).Callback(() => this.VariantsWereShown = false); oMock.Setup(x => x.IsVariantsVisible).Returns(() => this.VariantsWereShown); Viewer.CodeCompletor = oMock.Object; this.Viewer.UseSuggestionRules(oSuggestionBuilder); }
//========================================================================================= public DocumentViewRenderer(CodeViewer viewer) { this.Viewer = viewer; this.Body = this.Viewer.Body; this.Viewer.BackColorChanged += new EventHandler(Viewer_BackColorChanged); }
public void Text_caret_movements() { string sText = @"Create table T1(--xxxxxxx x int, y1 int )"; var oViewer = new CodeViewer(); oViewer.Text = sText; //To doc end oViewer.Body.Caret.MoveDocEnd(true); Assert.AreEqual("Ln:3, col:1, ch:1", oViewer.Body.Caret.Point.ToString()); ///Left oViewer.Body.Caret.MoveToPos(2, 13, true); Assert.AreEqual("Ln:2, col:13, ch:6", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveLeft(); Assert.AreEqual("Ln:2, col:12, ch:5", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveLeft(); Assert.AreEqual("Ln:2, col:8, ch:4", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveLeft(); Assert.AreEqual("Ln:2, col:6, ch:3", oViewer.Body.Caret.Point.ToString()); //Line home oViewer.Body.Caret.MoveLineHome(); Assert.AreEqual("Ln:2, col:4, ch:1", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveLineHome(); Assert.AreEqual("Ln:2, col:0, ch:0", oViewer.Body.Caret.Point.ToString()); //Right and word right oViewer.Body.Caret.MoveRight(); Assert.AreEqual("Ln:2, col:4, ch:1", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveRight(); Assert.AreEqual("Ln:2, col:5, ch:2", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveRight(); Assert.AreEqual("Ln:2, col:6, ch:3", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveRight(); Assert.AreEqual("Ln:2, col:8, ch:4", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveRight(); Assert.AreEqual("Ln:2, col:12, ch:5", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveToPos(2, 5, true); oViewer.Body.Caret.MoveWordRight(); Assert.AreEqual("Ln:2, col:12, ch:5", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveWordRight(); Assert.AreEqual("Ln:2, col:15, ch:8", oViewer.Body.Caret.Point.ToString()); //word left oViewer.Body.Caret.MoveLineEnd(true); Assert.AreEqual("Ln:2, col:15, ch:8", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveWordLeft(); Assert.AreEqual("Ln:2, col:12, ch:5", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveWordLeft(); Assert.AreEqual("Ln:2, col:4, ch:1", oViewer.Body.Caret.Point.ToString()); //Down oViewer.Body.Caret.MoveToPos(0, 100, true); oViewer.Body.Caret.MoveDown(1, true); Assert.AreEqual("Ln:1, col:16, ch:8", oViewer.Body.Caret.Point.ToString()); //Up oViewer.Body.Caret.MoveDown(1, true); oViewer.Body.Caret.MoveDown(1, true); oViewer.Body.Caret.MoveUp(1, true); Assert.AreEqual("Ln:2, col:15, ch:8", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveDocEnd(true); oViewer.Body.Caret.MoveUp(1, true); Assert.AreEqual("Ln:2, col:0, ch:0", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveRight(); oViewer.Body.Caret.MoveUp(1, true); Assert.AreEqual("Ln:1, col:4, ch:1", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveToPos(1, 9, true); Assert.AreEqual("Ln:1, col:8, ch:3", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveToPos(1, 10, true); Assert.AreEqual("Ln:1, col:8, ch:3", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveToPos(1, 11, true); Assert.AreEqual("Ln:1, col:12, ch:4", oViewer.Body.Caret.Point.ToString()); oViewer.Body.Caret.MoveToPos(1, 12, true); Assert.AreEqual("Ln:1, col:12, ch:4", oViewer.Body.Caret.Point.ToString()); }
public void Change_tab_size() { this.Viewer = new CodeViewer(); this.Viewer.Language = PredefinedLanguage.MsSql; this.Viewer.Text = "\tselect\r\n\t \t'a'"; this.AssertPoint(this.Viewer.Tokens[0].Start, 0, 1, 4); this.AssertPoint(this.Viewer.Tokens[1].Start, 1, 3, 8); //Change Tab Size and check token positions this.Viewer.TabSize = 7; this.AssertPoint(this.Viewer.Tokens[0].Start, 0, 1, 7); this.AssertPoint(this.Viewer.Tokens[1].Start, 1, 3, 14); }
public void Change_selection() { this.Viewer = new CodeViewer(); this.Viewer.Text = "\t \tselect\r\n'Привет!';"; //Select the whole document this.Viewer.Caret.MoveDocHome(true); this.Viewer.Caret.MoveDocEnd(false); this.AssertSelection(1, 10, 0, 0); }
public void Tabs_and_spaces() { { this.Viewer = new CodeViewer(); this.Viewer.Language = PredefinedLanguage.MsSql; this.Viewer.Text = "\t \tselect"; var oToken = this.Viewer.Tokens[0]; Assert.AreEqual(oToken.Start.Col, 8); Assert.AreEqual(oToken.Start.Char, 3); } }
public void CheckEvent_SelectionChanged() { int iCounter = 0, iHasSelectionCounter = 0; this.Viewer = new CodeViewer(); this.Viewer.Text = @"Create table [T 1](id int)"; this.Viewer.Caret.MoveDocHome(true); this.Viewer.SelectionChange += (sender, e) => { iCounter++; if (this.Viewer.SelectionExists) iHasSelectionCounter++; }; //Move caret left this.Viewer.Caret.MoveRight(false); Assert.AreEqual(1, iCounter); Assert.AreEqual(1, iHasSelectionCounter); //Go to the end of document this.Viewer.Caret.MoveDocEnd(true); Assert.AreEqual(2, iCounter); Assert.AreEqual(1, iHasSelectionCounter); //Go to the specified position this.Viewer.Caret.MoveToPos(0, 3, true); Assert.AreEqual(3, iCounter); Assert.AreEqual(1, iHasSelectionCounter); //Repeate previous movement. Event should not be generated. this.Viewer.Caret.MoveToPos(0, 3, false); Assert.AreEqual(3, iCounter); Assert.AreEqual(1, iHasSelectionCounter); //Go to the start of line this.Viewer.Caret.MoveLineHome(true); Assert.AreEqual(4, iCounter); Assert.AreEqual(1, iHasSelectionCounter); }
public void Select_the_whole_document() { this.Viewer = new CodeViewer(); this.Viewer.Text = @"Create table [T 1](--xxxxxxx x int, y1 int ) "; this.Viewer.Caret.MoveDocHome(true); this.Viewer.SelectAll(); this.AssertSelection(4, 0, 0, 0); this.Viewer.Caret.MoveToPos(2, 0, true); this.Viewer.SelectAll(); this.AssertSelection(4, 0, 0, 0); }
public void Caret_returns_and_empty_lines() { { //Single caret return at the end of document string sText = "create table t1 (id int)\r\n"; CodeViewer oViewer = new CodeViewer(); oViewer.Text = sText; Assert.AreEqual(oViewer.Document.Count, 2); } { //Two caret returns at the end of document string sText = "create table t1 (id int)\r\n\r\n"; CodeViewer oViewer = new CodeViewer(); oViewer.Text = sText; Assert.AreEqual(oViewer.Document.Count, 3); Assert.AreEqual(oViewer.Document[1].Text, string.Empty); Assert.AreEqual(oViewer.Document[2].Text, string.Empty); } { //Last line is empty but next to last contains tab string sText = "create table t1 (id int)\r\n\t\r\n"; CodeViewer oViewer = new CodeViewer(); oViewer.Text = sText; Assert.AreEqual(oViewer.Document.Count, 3); Assert.AreEqual(oViewer.Document[1].Text, "\t"); Assert.AreEqual(oViewer.Document[2].Text, string.Empty); } }
public void Spans_should_be_sorted_and_occupy_one_line() { string sText = @"Create table T1(--xxxxxxx x int ) GO CREATE T"; CodeViewer oViewer = new CodeViewer(); oViewer.Text = sText; oViewer.Spans.Add(Brushes.Red, 2, 0, 5); oViewer.Spans.Add(Brushes.Red, 0, 7, 4); oViewer.Spans.Add(Brushes.Red, 0, 1, 3); oViewer.Spans.Add(Brushes.Red, 1, 1, 4); Assert.AreEqual(oViewer.Spans.Count, 6); Assert.AreEqual(oViewer.Spans[0].Start.ToString(), "Ln:0, col:1, ch:1"); Assert.AreEqual(oViewer.Spans[1].Start.ToString(), "Ln:0, col:7, ch:7"); Assert.AreEqual(oViewer.Spans[2].End.ToString(), "Ln:1, col:13, ch:5"); Assert.AreEqual(oViewer.Spans[3].End.ToString(), "Ln:2, col:1, ch:1"); Assert.AreEqual(oViewer.Spans[4].End.ToString(), "Ln:3, col:2, ch:2"); }
//========================================================================================= public TextFinder(CodeViewer viewer) { this.Viewer = viewer; }
private void InitializeComponent() { this.checkLineNumbers = new System.Windows.Forms.CheckBox(); this.checkMargin = new System.Windows.Forms.CheckBox(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.codeViewer1 = new SA.CodeView.CodeViewer(); this.codeViewer2 = new SA.CodeView.CodeViewer(); this.textTabSize = new System.Windows.Forms.TextBox(); this.buttonApplyTabSize = new System.Windows.Forms.Button(); this.buttonChangeBackColor = new System.Windows.Forms.Button(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); this.SuspendLayout(); // // checkLineNumbers // this.checkLineNumbers.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.checkLineNumbers.AutoSize = true; this.checkLineNumbers.Location = new System.Drawing.Point(731, 12); this.checkLineNumbers.Name = "checkLineNumbers"; this.checkLineNumbers.Size = new System.Drawing.Size(119, 17); this.checkLineNumbers.TabIndex = 4; this.checkLineNumbers.Text = "Show Line Numbers"; this.checkLineNumbers.UseVisualStyleBackColor = true; // // checkMargin // this.checkMargin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.checkMargin.AutoSize = true; this.checkMargin.Location = new System.Drawing.Point(731, 35); this.checkMargin.Name = "checkMargin"; this.checkMargin.Size = new System.Drawing.Size(109, 17); this.checkMargin.TabIndex = 5; this.checkMargin.Text = "Show Left Margin"; this.checkMargin.UseVisualStyleBackColor = true; // // splitContainer1 // this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.splitContainer1.Location = new System.Drawing.Point(12, 12); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 // this.splitContainer1.Panel1.Controls.Add(this.codeViewer1); // // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.codeViewer2); this.splitContainer1.Size = new System.Drawing.Size(703, 457); this.splitContainer1.SplitterDistance = 351; this.splitContainer1.SplitterWidth = 5; this.splitContainer1.TabIndex = 0; // // codeViewer1 // this.codeViewer1.BackColor = System.Drawing.SystemColors.Control; this.codeViewer1.Dock = System.Windows.Forms.DockStyle.Fill; this.codeViewer1.Language = SA.CodeView.PredefinedLanguage.MsSql; this.codeViewer1.Location = new System.Drawing.Point(0, 0); this.codeViewer1.Margin = new System.Windows.Forms.Padding(4); this.codeViewer1.Name = "codeViewer1"; this.codeViewer1.Padding = new System.Windows.Forms.Padding(1); this.codeViewer1.ReadOnly = false; this.codeViewer1.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.codeViewer1.ShowLineNumbers = true; this.codeViewer1.Size = new System.Drawing.Size(351, 457); this.codeViewer1.TabIndex = 6; // // codeViewer2 // this.codeViewer2.BackColor = System.Drawing.SystemColors.Window; this.codeViewer2.Dock = System.Windows.Forms.DockStyle.Fill; this.codeViewer2.Language = SA.CodeView.PredefinedLanguage.MsSql; this.codeViewer2.Location = new System.Drawing.Point(0, 0); this.codeViewer2.Margin = new System.Windows.Forms.Padding(4); this.codeViewer2.Name = "codeViewer2"; this.codeViewer2.Padding = new System.Windows.Forms.Padding(1); this.codeViewer2.ReadOnly = false; this.codeViewer2.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.codeViewer2.ShowLineNumbers = true; this.codeViewer2.Size = new System.Drawing.Size(347, 457); this.codeViewer2.TabIndex = 0; // // textTabSize // this.textTabSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.textTabSize.Location = new System.Drawing.Point(731, 58); this.textTabSize.Name = "textTabSize"; this.textTabSize.Size = new System.Drawing.Size(45, 21); this.textTabSize.TabIndex = 10; this.textTabSize.Text = "4"; // // buttonApplyTabSize // this.buttonApplyTabSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonApplyTabSize.Location = new System.Drawing.Point(782, 56); this.buttonApplyTabSize.Name = "buttonApplyTabSize"; this.buttonApplyTabSize.Size = new System.Drawing.Size(87, 23); this.buttonApplyTabSize.TabIndex = 11; this.buttonApplyTabSize.Text = "Apply Tab Size"; this.buttonApplyTabSize.UseVisualStyleBackColor = true; this.buttonApplyTabSize.Click += new System.EventHandler(this.buttonApplyTabSize_Click); // // buttonChangeBackColor // this.buttonChangeBackColor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonChangeBackColor.Location = new System.Drawing.Point(731, 85); this.buttonChangeBackColor.Name = "buttonChangeBackColor"; this.buttonChangeBackColor.Size = new System.Drawing.Size(140, 23); this.buttonChangeBackColor.TabIndex = 13; this.buttonChangeBackColor.Text = "Change Back Color"; this.buttonChangeBackColor.UseVisualStyleBackColor = true; this.buttonChangeBackColor.Click += new System.EventHandler(this.buttonChangeBackColor_Click); // // StartForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(881, 518); this.Controls.Add(this.buttonChangeBackColor); this.Controls.Add(this.buttonApplyTabSize); this.Controls.Add(this.textTabSize); this.Controls.Add(this.splitContainer1); this.Controls.Add(this.checkMargin); this.Controls.Add(this.checkLineNumbers); this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.Name = "StartForm"; this.ShowIcon = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "CodeViewer Demo"; this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); this.splitContainer1.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); }
//========================================================================================= internal TextSpanCollection(CodeViewer viewer) { this.List = new List <TextSpan>(); this.Viewer = viewer; }
public void Setup() { this.Viewer = new CodeViewer(); this.Viewer.Language = PredefinedLanguage.MsSql; this.EditController = new EditingController(Viewer); }
//========================================================================================= internal void SetOwner(CodeViewer viewer) { this.Viewer = viewer; this.Caret = new TextCaret(this); this.Renderer = new DocumentViewRenderer(viewer); }