Disable the Default Undo Behavior on the SwitchableSyntaxEditor

SyntaxEditor for WPF Forum

Posted 7 years ago by iyu - New York, NY
Version: 17.1.0652
Avatar

Dear Support,

Is there any way to disable the default undo behavior of the syntax editor? Currently, I'm using the SwitchableSyntaxEditor and use the Text property to bind a string variable in my view model. I have a custom undo command to handle the undo in the view model. However, when I use the ctrl-z shortcut to call my undo command on the Text property, my custom undo command is overridden by the Text property's default undo behavior and don't get called. The only way to enable my custom undo command is to click on other text fields and use ctrl-z. I can use my custom command if I click on the undo button directly on the view. Please help me to fix the problem.

Thanks,

This is the code in my view:

<dxlc:LayoutItem Label="{Binding SomeLabel, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding IsVisible, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource VisibleIfFalse}}">

    <views:SwitchableSyntaxEditor x:Name="ImplementsSyntaxEditor" IsTextDataBindingEnabled="True" Text="{Binding T.SomeText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsMultiLine="False" ScriptingLanguage="{Binding T.SomeLanguage, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" FontFamily="Segoe UI"/>

</dxlc:LayoutItem>

Comments (2)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

As the SyntaxEditor is being initialized, we set up these input bindings:

this.InputBindings.Add(new KeyBinding(EditorCommands.Redo, VKey.Y, ModifierKeys.Control));
this.InputBindings.Add(new KeyBinding(EditorCommands.Redo, VKey.Z, ModifierKeys.Control | ModifierKeys.Shift));
this.InputBindings.Add(new KeyBinding(EditorCommands.Undo, VKey.Z, ModifierKeys.Control));

If you scan through the InputBindings collection and remove any KeyBindings that use Redo/Undo commands, I think that will block our default undo logic from being key bound. 

You also will want to iterate the CommandBindings collection and remove any command bindings for the ApplicationCommands.Redo and ApplicationCommands.Undo commands to make sure those aren't handled by our control at all (if bound to a menu, etc.).


Actipro Software Support

Posted 7 years ago by iyu - New York, NY
Avatar

Thanks for your hint. I already figure out the solution.

 

            for (int i = 0; i < SyntaxEditor.InputBindings.Count; i++)
            {
                var inputBinding = SyntaxEditor.InputBindings[i] as KeyBinding;
                if (inputBinding != null)
                    if (((inputBinding.Modifiers == ModifierKeys.Control) && (inputBinding.Key == Key.Z)) || ((inputBinding.Modifiers == ModifierKeys.Control) && (inputBinding.Key == Key.Y)))
                        SyntaxEditor.InputBindings.RemoveAt(i);
            }
            for (int i = 0; i < SyntaxEditor.CommandBindings.Count; i++)
            {
                var commandBinding = SyntaxEditor.CommandBindings[i] as CommandBinding;
                if (commandBinding != null)
                    if (commandBinding.Command == ApplicationCommands.Undo || commandBinding.Command == ApplicationCommands.Redo)
                        SyntaxEditor.CommandBindings.RemoveAt(i);
            }

[Modified 7 years ago]

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.