TextAreaUndo mod
BlitzMax Forums/MaxGUI Module/TextAreaUndo mod
| ||
| This was extremely difficult and time-consuming. It works just like it should, though: http://www.leadwerks.com/index.php?page=downloads.htm&subbar=blank.htm TextAreaUndo:Int(gadget:TGadget) TextAreaRedo:Int(gadget:TGadget) TextAreaCanUndo:Int(gadget:TGadget) TextAreaCanRedo:Int(gadget:TGadget) Function TextAreaFlushUndos:Int(gadget:TGadget) TextAreaCreateUndoState() If you manually alter the text area text with SetTextAreaText(), you must call TextAreaCreateUndoState() after the alterations, or your undos will be messed up. With this, TextAreas will only return a GADGETACTION event when they really have changed. EventData() will contain the length of the changed text, and may be a positive or negative number. This only alters the changed text, so it has low memory usage, and is compatible with syntax highlighting. Example program: Import leadwerks.textareaundo
Strict
Global window:TGadget
Global textarea:TGadget
Local menu:TGadget
window=CreateWindow("TextAreaUndo",200,200,640,480,,15|WINDOW_ACCEPTFILES)
textarea=CreateTextArea(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetLayout textarea,1,1,1,1
ActivateGadget textarea
menu=CreateMenu("Edit",0,WindowMenu(window))
Global menuundo:TGadget=CreateMenu("Undo",1,menu,KEY_Z,MODIFIER_COMMAND)
Global menuredo:TGadget=CreateMenu("Redo",2,menu,KEY_Z,MODIFIER_COMMAND|MODIFIER_OPTION)
UpdateWindowMenu window
While WaitEvent()
UpdateMenu()
Select EventID()
Case EVENT_MENUACTION
Select EventData()
Case 1
TextAreaUndo textarea
Case 2
TextAreaRedo textarea
EndSelect
Case EVENT_WINDOWCLOSE
End
Case EVENT_APPTERMINATE
End
End Select
Wend
Function UpdateMenu()
If TextAreaCanUndo(textarea)
EnableMenu menuundo
Else
DisableMenu menuundo
EndIf
If TextAreaCanRedo(textarea)
EnableMenu menuredo
Else
DisableMenu menuredo
EndIf
UpdateWindowMenu window
EndFunction |
| ||
| Just noticed this... many thanks Josh, a great piece of work. |
| ||
| Source: |