Completed
Last Updated: 07 Jul 2020 08:22 by ADMIN
Release R3 2020 (LIB 2020.2.713)
Al
Created on: 20 Jun 2020 22:31
Category: SyntaxEditor
Type: Bug Report
1
RadSyntaxEditor: when you have RadSyntaxEditor in RadForm and AcceptButton Enter key does not result in new line instead the form gets closed

I'm trying to use the new RadSyntaxEditor in a popup editor and I'm having issues and questions. I'm using it in a component built in code that is used to edit a SQL Query from a grid cell double click. It seems to work except when I press enter to insert a new line it does not do that, instead the default form button is fired to close the form. Note that I can launch the form to either show a multi-line textbox or a RadSyntaxEditor depending on the input parameters. It works perfectly with the textbox. The issue is with the RadSyntaxEditor 

I also have the following questions:

I cannot find any documentation on loading text into the RadSyntaxEditor is my code correct for this?

I cannot find any documentation regarding the Document property - where do I find that?

I cannot find anything on how to get the text out of the RadSyntaxEditor when I'm done. Is my code correct on this?

Here are my code snippets:


        private void GvMrgLtr_CellDoubleClick(object sender, EventArgs e)
        {
            var m = MethodBase.GetCurrentMethod();
            try
            {
                if (sender is HostedTextBoxBase sndr)
                    sndr.Text = MemoDialog.ShowDialog(sndr.Text, "Edit", 0, false, false, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show($@"{m.Name} : {ex}");
                Log.Error(ex, m.Name);
            }
        }

 


using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinForms.Controls.SyntaxEditor.Taggers;
using Telerik.WinForms.SyntaxEditor.Core.Text;

namespace P3CMS.Components
{
    internal static class MemoDialog
    {
        public static string ShowDialog(string text, string caption, int maxLength = 0,
            bool ro = false, bool spellcheck = true, bool sqlSyntaxHighlight = false)
        {
            var originalText = text;

            var memoDialogForm = new RadForm
            {
                Width = 500,
                Height = 700,
                FormBorderStyle = FormBorderStyle.Sizable,
                Text = caption,
                StartPosition = FormStartPosition.CenterScreen
            };

            var textBox = new RadTextBox
            {
                Left = 50,
                Top = 40,
                Width = 400,
                Dock = DockStyle.Fill,
                Multiline = true,
                AcceptsReturn = true,
                Text = text,
                ScrollBars = ScrollBars.Both,
                MaxLength = maxLength,
                ReadOnly = ro
            };

            var textDocument = new TextDocument(text);
            var radSyntaxEditor = new RadSyntaxEditor
            {
                Left = 50,
                Top = 40,
                Width = 400,
                Dock = DockStyle.Fill, 
                Document = textDocument
            };

            var tagger = new SqlTagger(radSyntaxEditor.SyntaxEditorElement);
            radSyntaxEditor.TaggersRegistry.RegisterTagger(tagger);

            var checker = new RadSpellChecker { AutoSpellCheckControl = textBox };
            if (!spellcheck)
                checker.AutoSpellCheckControl = null;

            var bottomPanel = new RadPanel { Height = 60, Dock = DockStyle.Bottom };
            var confirmation = new RadButton
            { Text = @"Ok", Left = 50, Width = 100, Top = 8, DialogResult = DialogResult.OK };
            var cancel = new RadButton
            { Text = @"Cancel", Left = 200, Width = 100, Top = 8, DialogResult = DialogResult.Cancel };

            confirmation.Click += (sender, e) => { memoDialogForm.Close(); };

            if (sqlSyntaxHighlight)
                memoDialogForm.Controls.Add(radSyntaxEditor);
            else
                memoDialogForm.Controls.Add(textBox);
            memoDialogForm.Controls.Add(bottomPanel);
            bottomPanel.Controls.Add(confirmation);
            bottomPanel.Controls.Add(cancel);
            memoDialogForm.AcceptButton = confirmation;
            memoDialogForm.CancelButton = cancel;

            if (!sqlSyntaxHighlight)
                textBox.Select(0, 0);

            return memoDialogForm.ShowDialog() == DialogResult.OK
                ? sqlSyntaxHighlight ? textDocument.CurrentSnapshot.GetText() : textBox.Text
                : originalText;
        }
    }
}

3 comments
ADMIN
Nadya | Tech Support Engineer
Posted on: 24 Jun 2020 11:07

Hello Al,

We will do our best to introduce a fix in one of the upcoming Latest Internal Libs so the RadSyntaxEditor behaves the same as textbox when handling Enter key in this situation. Make sure that you subscribe to the item so that you get notified when there is a status change. Stay tuned!

Do not hesitate to contact us if you have other questions.

Regards,
Nadya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Al
Posted on: 23 Jun 2020 15:56
Thanks for the information and your work to confirm and provide a work around. My comment is if the multiline textbox does not have the same behavior why can't the RadSyntaxEditor mimic that same ability to consume the enter key?
ADMIN
Nadya | Tech Support Engineer
Posted on: 23 Jun 2020 08:43

Hello Al,

The provided code snippets are greatly appreciated.

After building them in my test project I was able to observe the same behavior - when pressing Enter key in RadSyntaxEditor the form gets closed instead of going to a new line. This is why I have logged it in our feedback portal by creating a public thread on your behalf. You can track its progress, subscribe for status changes, and add your comments on the following link - feedback item. I have also updated your TelerikPoints.

After investigating it further, I noticed that this behavior is observed when there is AcceptButton on the form. Since RadForm inherits the standard MS Form its base behavior is inherited as well. Currently, the possible solution that I can suggest is to override the ProcessCmdKey of the form and change the base behavior when the Enter key is pressed. Please refer to the following code snippet:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData== Keys.Enter)
    {
        RadSyntaxEditor syntaxEditor = this.ActiveControl as RadSyntaxEditor;
        if (syntaxEditor!=null)
        { 
            syntaxEditor.SyntaxEditorElement.InsertNewLine(); 
            return true;
        }
    }
    return base.ProcessCmdKey(ref msg, keyData);
}

According to the other questions:

You can find documentation about loading text in RadSyntaxEditor in the following Getting Started article. Yes, your code for loading text is absolutely correct. To load a text file in the RadSyntaxEditor you need to use its Document property.

We will consider adding more useful information in our documentation about Document property in order to make it more convenient for our clients to found out how it works. 

Regarding your last questions, yes your code about getting the text out of RadSyntaxEditor is ok. Using CurrentSnapshot.GetText method is the right way to achieve that. 

I hope this information is useful. Do not hesitate to contact me if you have any further questions.

Regards,
Nadya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Attached Files: