Disable Replace Function in RadSyntaxEditor

3 Answers 163 Views
SyntaxEditor
Luca
Top achievements
Rank 1
Iron
Luca asked on 21 Feb 2022, 09:39 AM | edited on 21 Feb 2022, 09:42 AM

Hi,

I need to use a RadSyntaxEditor in ReadOnly mode and i want to disable the replace functionality while letting the user to search for a specified string.

I've tried to find a way to hide or disable the replace part in the Find Dialog, but I've had no success.

Any suggestion on how can I achieve this ?

Thanks.

A suggestion: It would be nice to have a read only property at the RadSyntaxEditor level that disable everithing that implies a modification to the text (editor, commands, find dialog and so on).

3 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Feb 2022, 05:59 AM
Hello, Luca,

In order to make the syntax editor read-only, feel free to set the SyntaxEditorElement.IsReadOnly property to true:
this.radSyntaxEditor1.SyntaxEditorElement.IsReadOnly = true;

However, the Find and Replace dialog still allows you to change the text. 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 - feedbackitem.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to disabled the replace buttons and input box. I have prepared a sample code snippet for your reference:

            this.radSyntaxEditor1.SyntaxEditorElement.InputHandler = new MyInputBehavior(this.radSyntaxEditor1.SyntaxEditorElement);

        public class MyInputBehavior : SyntaxEditorInputBehavior
        {
            public MyInputBehavior(RadSyntaxEditorElement editor) : base(editor)
            {
                
            }

            protected override void PerformOpenFileDialog(KeyEventArgs e)
            {
                this.SyntaxEditor.SearchPanel.ReplaceAllButton.Enabled = false;
                this.SyntaxEditor.SearchPanel.ReplaceButton.Enabled = false;
                this.SyntaxEditor.SearchPanel.ReplaceTextBox.Enabled = false;
                base.PerformOpenFileDialog(e);
            }
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Luca
Top achievements
Rank 1
Iron
answered on 24 Feb 2022, 10:36 AM

Hi Dess,
thanks a lot for your answer.

It works fine but only if I open the find dialog using the keyboard command Ctrl-F.
In my application i have a commandBar with a Find button, and using this button the find dialog stil show up with all controls enabled.

To open the find dialog in the button OnClick event I have tried to use

rSyntEdit.Commands.OpenFindDialogCommand.Execute(null);

and

rSyntEdit.SyntaxEditorElement.OpenFindDialog(string.Empty);

but none seem to call the overload you have suggested.

The same problem exists with the Cut and Paste Commands that don't respect the read only flag when called programmatically.

Is there any way to make your workaround works in my scenario ?

Thanks a lot

Luca.

 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 25 Feb 2022, 08:45 AM

Hi, Luca,

Indeed, the SyntaxEditorInputBehavior is not used when the Find and Replace dialog is shown programmatically directly with executing the command. However, it is possible to disable the respective buttons before executing the command:

        private void radButton1_Click(object sender, EventArgs e)
        {
            this.radSyntaxEditor1.SyntaxEditorElement.SearchPanel.ReplaceAllButton.Enabled = false;
            this.radSyntaxEditor1.SyntaxEditorElement.SearchPanel.ReplaceButton.Enabled = false;
            this.radSyntaxEditor1.SyntaxEditorElement.SearchPanel.ReplaceTextBox.Enabled = false;
            this.radSyntaxEditor1.Commands.OpenFindDialogCommand.Execute(null);
        }

As to the question about the Cut and Paste commands, note that the IsReadOnly value is respected when the end user uses the keyboard combinations for Cut and Paste. However, when the developer executes the respective command, it is his/her responsibility to develop the code in such a way to determine under what conditions the command to be performed.

0
Luca
Top achievements
Rank 1
Iron
answered on 25 Feb 2022, 01:04 PM | edited on 25 Feb 2022, 01:23 PM

Hi Dess, thanks a lot for your answer.

In the meantime, I've developped my own workaround, it may be not fully orthodox, but it's a way to reuse Telerik implementation of readonly instead of creating mine.

I share it here in case someone find it useful.

        public class EditorCustomInputManager : SyntaxEditorInputBehavior {

            public EditorCustomInputManager(RadSyntaxEditorElement editor) : base(editor) {   }

            public void OpenFindDialog() => PerformOpenFileDialog(new KeyEventArgs(Keys.Control | Keys.F));
            public void Undo() => ProcessZKey(new KeyEventArgs(Keys.Control | Keys.Z));
            public void Redo() => ProcessYKey(new KeyEventArgs(Keys.Control | Keys.Y));
            public void Cut() => ProcessXKey(new KeyEventArgs(Keys.Control | Keys.X));
            public void Copy() => PerformCopyOperation(new KeyEventArgs(Keys.Control | Keys.C));
            public void Paste() => ProcessVKey(new KeyEventArgs(Keys.Control | Keys.V));

            protected override void PerformOpenFileDialog(KeyEventArgs e) {
                this.SyntaxEditor.SearchPanel.ReplaceAllButton.Enabled = !this.SyntaxEditor.IsReadOnly;
                this.SyntaxEditor.SearchPanel.ReplaceButton.Enabled = !this.SyntaxEditor.IsReadOnly;
                this.SyntaxEditor.SearchPanel.ReplaceTextBox.Enabled = !this.SyntaxEditor.IsReadOnly;
                base.PerformOpenFileDialog(e);
            }
        }

 and in the form :

public partial class XMLViewer : Telerik.WinControls.UI.RadForm {

        private EditorCustomInputManager EditorInputManager;

        private void XMLViewer_Load(object sender, EventArgs e) {
            EditorInputManager = new EditorCustomInputManager(rSyntEdit.SyntaxEditorElement);
            rSyntEdit.SyntaxEditorElement.InputHandler = EditorInputManager;
        }

        private void cbarBtnCut_Click(object sender, EventArgs e)  => EditorInputManager.Cut();
        private void cbarBtnCopy_Click(object sender, EventArgs e) => EditorInputManager.Copy();
        private void cbarBtnPaste_Click(object sender, EventArgs e)  => EditorInputManager.Paste();
        private void cmdBtnFind_Click(object sender, EventArgs e) => EditorInputManager.OpenFindDialog();           
        private void cmdBtnUndo_Click(object sender, EventArgs e) => EditorInputManager.Undo();
        private void cmdBtnRedo_Click(object sender, EventArgs e)  => EditorInputManager.Redo();
      
}

 

Thanks again for the support

Luca

Tags
SyntaxEditor
Asked by
Luca
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Luca
Top achievements
Rank 1
Iron
Share this question
or