TextField and TextArea both have integrated UNDO manager…
but there is nothing exposed to indicate if there is a pending series of UNDO transactions available.
I have a custom menu handler for EditUNDO, but now cannot disable it when there is nothing to do
So attempting to modifiy/subclass/replace those is beyond a reasonable scope
my EditUNDO consists of
If Me.Focus IsA TextField Or Me.focus IsA TextArea Then Return False
call SpecialUNDO
Return True
where the first line lets Xojo process a Text Undo normally
the second gives me the ability to undo other actions as required (not text related)
so I was hoping for something in EnableMenuItems similar to this (NOT REAL CODE)
flag=false
If Me.Focus IsA TextField Or Me.focus IsA TextArea) then
flag=me.CANUNDO //<===========
else
flag=myUndoStack.ubound>=0
end if
menuitem.enabled=flag
Ok… guessing eveyone is missing my point
I need to know if ANY referenced TextField/Area has a pending UNDO
NOT controls I made, not controls I can make… I just have a reference to the control… nothing more
so let me state the problem in a different way.
GIVEN : a reference to a TEXTFIELD or TEXTAREA
PROBLEM : create a function where the TEXTAREA/FIELD reference is passed as an input argument, return a BOOLEAN value that indicates if the passed argument has a pending UNDO transaction available
SYNTAX : booleanVALUE=canUNDO(myTextField)
REQUIRMENTS : macOS, Declares acceptable, but no 3rd party plug-ins
you won’t get it.
only way is to intercept all textedit/area menus with an addhandler method, and deal with your own undo mecanism.
these undo for textedit must be apple system calls, not sure if xojo handle them…
I had the same problem trying to intercept the paste menu in my listbox example above.
you’re trying to intercept the undo menu.
PROBLEM : create a function where the TEXTAREA/FIELD reference is passed as an input argument, return a BOOLEAN value that indicates if the passed argument has a pending UNDO transaction available[/quote]
That’s the problem. TextArea and TextField don’t have the feature. You need to create one.
Which I realize… and I am not a novice with Xojo by any means.
I know how to subclass controls,
and if I had the luxury of doing this I would have, and this conversation would not have taken place.
but as stated, using custom subclassed Text controls IS NOT AN OPTION.
so of the controls in use are existing subclasses, some are embedded in other custom controls.
What I am looking for is a way interrogate an existing control
it’s easy to make a textedit subclass doing nothing but subclassing.
then make all your controls that have a textedit inside herit from this textedit subclass.
then do what you want in the subclass it will handle all of your texedits wherever they are.
in OOP, when you want to make a subclass, always make a subclass of the subclass and use the last one.
I understand subclassing… this is NOT what I want.
somewhere internally there is a canUNDO flag, and somewhere there is a declare to expose it.
this is all I need.
I do not need to “implement” an undo manager … that I have covered.
all I want to do is be able to disable the stupid menu item ,
[quote=367302:@Dave S]Which I realize… and I am not a novice with Xojo by any means.
I know how to subclass controls,
and if I had the luxury of doing this I would have, and this conversation would not have taken place.
but as stated, using custom subclassed Text controls IS NOT AN OPTION.
so of the controls in use are existing subclasses, some are embedded in other custom controls.
What I am looking for is a way interrogate an existing control[/quote]
Forget about my latest comment. You’re right.
I don’t have access to any Mac computer. On windows, TextArea is Rich Edit control, it has EM_CANPASTE and EM_CANREDO messages. Probably, there are similar APIs on Mac.
FYI… It took translating a Japanese website but there is the answer
place in the ENABLEMENUITEMS event
Declare Function undoManager Lib "Cocoa" selector "undoManager" (obj_id As Integer) As Ptr
Dim pnt1 As Ptr = undoManager(Self.Handle)
Declare Function canUndo Lib "Cocoa" selector "canUndo" (receiver As Ptr) As Boolean
flag=False
If (Me.Focus IsA TextField Or Me.focus IsA TextArea) Then
flag=canUndo(pnt1) // use status of Text control for menu item
Else
flag=(UNDO_STACK.ubound)>=0 // use status of custom undo stack for menu item
End If
EditUndo.Enabled=flag