Real Software Forums
http://forums.realsoftware.com/

How to disable built-in undo on TextArea?
http://forums.realsoftware.com/viewtopic.php?f=6&t=42790
Page 1 of 1

Author:  Flatline [ Mon Feb 20, 2012 4:47 pm ]
Post subject:  How to disable built-in undo on TextArea?

I wrote a simple undo/redo engine for TextArea. My subclass has menuhandlers for Undo, Redo and Paste. The Paste menuhandler stores the text from clipboard and insertion point, after that, it inserts the clipboard's content into control's text. The Undo menuhandler removes that stored text from control's text. The Redo menuhandler inserts stored text again.
Everything works fine, i can undo and redo. But if no undo available and Undo menu is disabled, when i press a shortcut for undo (Ctrl+Z), looks like the TextArea's built-in undo engine invoked.

Example: Empty textarea. I paste text from clipboard. Undoing it, my code works. Undo menuitem disabled. Pressing shortcut for undo. Previously pasted text appears again. Pressing again. The text disappears. Pressing again and nothing happens.

Looks like my undo engine's changes in text threated as simple text changes by TextArea's built-in undo, but i can't understand why built-in undo works when menuitem disabled...

How can i disable this built in undo???

Author:  MonkeybreadSoftware [ Tue Feb 21, 2012 6:11 am ]
Post subject:  Re: How to disable built-in undo on TextArea?

With MBS Plugins, simply do this in text area open event:

dim t as NSTextViewMBS = me.NSTextViewMBS
t.undoManager.disableUndoRegistration


Greetings
Christian

Author:  Flatline [ Tue Feb 21, 2012 2:24 pm ]
Post subject:  Re: How to disable built-in undo on TextArea?

Finally i've found a workaround. Maybe it's not as elegant as it would be, but for me it works. It resets the undo flag of an edit control.

Make a method with following code and call it at the end of TextChange eventhandler:

#if TargetWin32
Declare Function SendMessageA Lib "User32" Alias "SendMessageA" (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
Declare Function SendMessageW Lib "User32" Alias "SendMessageW" (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
// EM_EMPTYUNDOBUFFER = &hCD
If System.IsFunctionAvailable( "SendMessageW", "User32" ) Then
Call SendMessageW(Self.Handle, &hCD, 0, 0)
Else
Call SendMessageW(Self.Handle, &hCD, 0, 0)
End If
#endif

Author:  MonkeybreadSoftware [ Tue Feb 21, 2012 5:11 pm ]
Post subject:  Re: How to disable built-in undo on TextArea?

Oh, sorry. My idea was for Cocoa on Mac OS X.

For your code, well, please use SendMessageW in your else part.
But you can use SendMessageW only. It's always available.

Greetings
Christian

Author:  Flatline [ Wed Feb 22, 2012 5:24 am ]
Post subject:  Re: How to disable built-in undo on TextArea?

Thanks for the remark. The corrected code:

#if TargetWin32
Declare Function SendMessageA Lib "User32" Alias "SendMessageA" (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
Declare Function SendMessageW Lib "User32" Alias "SendMessageW" (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
// EM_EMPTYUNDOBUFFER = &hCD
If System.IsFunctionAvailable( "SendMessageW", "User32" ) Then
Call SendMessageW(Self.Handle, &hCD, 0, 0)
Else
Call SendMessageA(Self.Handle, &hCD, 0, 0)
End If
#endif

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/