Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
Undo/Redo in UltraFormattedTextEditor
posted

Hi,

I have two buttons to perform Undo and Redo operations in UltraFormattedTextEditor. I am trying to enable/disable these buttons using the CurrentState property. I have this logic in ValueChanged event handler.

Here is the problem scenario. I already have content in the text editor which I am loading from the database. Now, when I delete something in the text editor, the CurrentState is not getting changed to CanUndo.

Any suggestions on resolving this?

TIA.

Here is the code in ValueChanged event handler:

       private void ultraFormattedTextEditor1_ValueChanged(object sender, EventArgs e)
        {
            // Enable/Disable the "Undo" toolbar button based on the changes that can be undone
            if ((this.ultraFormattedTextEditor1.CurrentState & FormattedLinkEditorState.CanUndo) == FormattedLinkEditorState.CanUndo)
            {
                this.ultraToolbarsManagerMain.Toolbars["FormattingToolbar"].Tools["Undo"].SharedProps.Enabled = true;
            }
            else
            {
                this.ultraToolbarsManagerMain.Toolbars["FormattingToolbar"].Tools["Undo"].SharedProps.Enabled = false;
            }

            // Enable/Disable the "Redo" toolbar button based on the changes that can be redone
            if ((this.ultraFormattedTextEditor1.CurrentState & FormattedLinkEditorState.CanRedo) == FormattedLinkEditorState.CanRedo)
            {
                this.ultraToolbarsManagerMain.Toolbars["FormattingToolbar"].Tools["Redo"].SharedProps.Enabled = true;
            }
            else
            {
                this.ultraToolbarsManagerMain.Toolbars["FormattingToolbar"].Tools["Redo"].SharedProps.Enabled = false;
            }
        }
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    I tested this out and I get the same results. It looks like the State doesn't change until after the ValueChanged event fires. If I check the state after the event is complete, like in the Click event of the form, it correctly returns CanUndo.

    This may be a bug, and I will forward this thread over to Infragistics Developer Support so they can check it out.

    Howvever, even if this is a bug, changes to the order of events are dangerous and can often result in breaking backward compatibility. So it might not be fixable. It should still be looked into, though. :)

    In the mean time, you can get around this using a BeginInvoke. Take your existing code out of the ValueChanged event handler and move it to another method. Then, in the event handler, use BeginInvoke to call that method. This way the code doesn't get called until the method has already completed and the CurrentState will be updated by then.

    I tried this and the CurrentState was correct:


            private void ultraFormattedTextEditor1_ValueChanged(object sender, EventArgs e)
            {
                this.BeginInvoke(new MethodInvoker(this.UpdateUndoButtons));
               
            }

            private void UpdateUndoButtons()
            {
                UltraFormattedTextEditor ultraFormattedTextEditor = this.ultraFormattedTextEditor1;
                this.listBox1.Items.Add(DateTime.Now.ToShortTimeString() + " : " + ultraFormattedTextEditor.CurrentState.ToString());
            }