# is there a Pending UNDO?

**URL:** <https://forum.xojo.com/t/is-there-a-pending-undo/41423>\
**Category:** General\
**Created:** [January 3, 2018, 6:56pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423 "2018-01-03T18:56:08Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 3, 2018, 6:56pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/1 "2018-01-03T18:56:08Z")

</div>

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

macOS only

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 3, 2018, 7:13pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/2 "2018-01-03T19:13:46Z")

</div>

it seems like something I stuck on for the listbox : you need to addhandler for the textedit you’re using ?

[https://forum.xojo.com/34073-listbox-activecell-contextual-menu](https://forum.xojo.com/34073-listbox-activecell-contextual-menu)

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 3, 2018, 7:26pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/3 "2018-01-03T19:26:20Z")

</div>

[quote=367284:@Jean-Yves Pochez]it seems like something I stuck on for the listbox : you need to addhandler for the textedit you’re using ?

[https://forum.xojo.com/34073-listbox-activecell-contextual-menu[/quote]](https://forum.xojo.com/34073-listbox-activecell-contextual-menu%5B/quote%5D)  
not an option, as some of the textarea/field controls are embeded in other custom controls…

So attempting to modifiy/subclass/replace those is beyond a reasonable scope

my EditUNDO consists of

```auto
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)

```auto
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
```

---

<div class="post-metadata">

**Author:** ![Asis\_Patisahusiwa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@Asis\_Patisahusiwa](https://forum.xojo.com/u/Asis_Patisahusiwa)\
**Post date:** [January 3, 2018, 8:22pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/4 "2018-01-03T20:22:09Z")

</div>

I don’t know about built-in undo manager. I think, it’s better to implement your own undo manager. In the undo menu handler, just call for example,

```auto
  mController.Undo()  
  Return True
```

Inside `mController.Undo`, you can implement Unit of Work.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 3, 2018, 8:30pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/5 "2018-01-03T20:30:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 3, 2018, 8:42pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/6 "2018-01-03T20:42:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Asis\_Patisahusiwa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@Asis\_Patisahusiwa](https://forum.xojo.com/u/Asis_Patisahusiwa)\
**Post date:** [January 3, 2018, 8:43pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/7 "2018-01-03T20:43:08Z")

</div>

[quote=367296:@Dave S]

- 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.

[https://forum.xojo.com/7726-textarea-undo/](https://forum.xojo.com/7726-textarea-undo/)  
[http://forums.realsoftware.com/viewtopic.php?f=10&t=44823](http://forums.realsoftware.com/viewtopic.php?f=10&t=44823)

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [January 3, 2018, 8:51pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/8 "2018-01-03T20:51:41Z")

</div>

> [@367299:@Asis Patisahusiwa](#):
>
> That’s the problem. TextArea and TextField don’t have the feature. You need to create one.

On Mac they do and Undo / Redo is handled automatically by the system (like Copy and Paste).

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 3, 2018, 8:52pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/9 "2018-01-03T20:52:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 3, 2018, 8:55pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/10 "2018-01-03T20:55:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 3, 2018, 9:06pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/11 "2018-01-03T21:06:04Z")

</div>

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 ,

---

<div class="post-metadata">

**Author:** ![Asis\_Patisahusiwa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@Asis\_Patisahusiwa](https://forum.xojo.com/u/Asis_Patisahusiwa)\
**Post date:** [January 3, 2018, 9:06pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/12 "2018-01-03T21:06:22Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 3, 2018, 9:24pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/13 "2018-01-03T21:24:25Z")

</div>

FYI… It took translating a Japanese website but there is the answer

place in the ENABLEMENUITEMS event

```auto
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
```

for more information  
[https://translate.google.com/translate?hl=en&sl=ja&u=http://greif.la.coocan.jp/rb\_tips93old.html&prev=search](https://translate.google.com/translate?hl=en&sl=ja&u=http://greif.la.coocan.jp/rb_tips93old.html&prev=search)

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:03pm UTC](https://forum.xojo.com/t/is-there-a-pending-undo/41423/14 "2020-10-29T19:03:21Z")

</div>


