Page 1 of 1

Editorgadget undo?

Posted: Mon Apr 16, 2007 8:22 am
by omit59
Hello!

Does anyone know if editorgadget undo flag could temporary be suppressed, so that you could make some changes to text and then
unsuppress undo flag back again.
Reason for this is that I need a simple highlighter for editorgadget, but highlighting shouldn't be recorded to undo list...

Or is there some other way to do this?

Thanks
Timo

Posted: Mon Apr 16, 2007 12:14 pm
by milan1612
Hello omit59,

I'm not sure, but I think changes on a EditorGadget done per Code
are not recorded in the Undo-Buffer.
Please correct me if I am wrong

Regards, milan1612

EDIT: I tested it and I'm right...

Posted: Mon Apr 16, 2007 12:41 pm
by omit59
@milan1612,

great if that works, could you show the code for that test, please!!!

Timo

Posted: Mon Apr 16, 2007 1:35 pm
by milan1612

Code: Select all

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Editor_0
  #Button_0
  #Button_1
  #Button_2
EndEnumeration

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 408, 205, 413, 277, "Undo Test",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      EditorGadget(#Editor_0, 10, 10, 390, 220)
      ButtonGadget(#Button_0, 10, 240, 80, 30, "Undo")
      ButtonGadget(#Button_1, 100, 240, 80, 30, "Edit Text")
      ButtonGadget(#Button_2, 190, 240, 80, 30, "Edit Text 2")
    EndIf
  EndIf
EndProcedure
Open_Window_0()

Repeat
  Event = WaitWindowEvent()
  GadgetID = EventGadget()
  If Event = #PB_Event_Gadget
    If GadgetID = #Button_0
      SendMessage_(GadgetID(#Editor_0), #EM_UNDO, 0, 0)
    ElseIf GadgetID = #Button_1
      SetGadgetText(#Editor_0, "I love Purebasic")
    ElseIf GadgetID = #Button_2
      SetGadgetText(#Editor_0, GetGadgetText(#Editor_0) + Chr(13) + Chr(10) + "Another Test")
    EndIf
  EndIf
  
Until Event = #PB_Event_CloseWindow
End
Here you go... 8)

PS: Try edit some text manually and see...

Posted: Mon Apr 16, 2007 2:10 pm
by omit59
@milan1612,

try this:

Code: Select all

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Editor_0
  #Button_0
  #Button_1
  #Button_2
  #Text_1
EndEnumeration

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 408, 205, 413, 277, "Undo Test",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      EditorGadget(#Editor_0, 10, 10, 390, 220)
      ButtonGadget(#Button_0, 10, 240, 80, 30, "Undo")
      ButtonGadget(#Button_1, 100, 240, 80, 30, "Edit Text")
      ButtonGadget(#Button_2, 190, 240, 80, 30, "Edit Text 2")
      TextGadget(#Text_1, 280, 240, 100, 20, "")
    EndIf
  EndIf
EndProcedure
Open_Window_0()

SetGadgetText(#Editor_0, "")

Repeat
  Event = WaitWindowEvent()
  GadgetID = EventGadget()
  If Event = #PB_Event_Gadget
    If GadgetID = #Button_0
      SendMessage_(GadgetID(#Editor_0), #EM_UNDO, 0, 0)
    ElseIf GadgetID = #Button_1
      SetGadgetText(#Editor_0, "I love Purebasic")
    ElseIf GadgetID = #Button_2
      SetGadgetText(#Editor_0, GetGadgetText(#Editor_0) + Chr(13) + Chr(10) + "Another Test")
    EndIf
  EndIf
 
  If SendMessage_(GadgetID(#Editor_0),#EM_CANUNDO, 0, 0) = #True
    SetGadgetText(#Text_1, "CAN UNDO")
  Else
    SetGadgetText(#Text_1, "CAN'T UNDO")
  EndIf
  
Until Event = #PB_Event_CloseWindow
End
Using SetGadgetText() on EditorGadget, seems to empty undo-buffer, and thats the main problem here, or do I understand this wrong?

Timo

Posted: Mon Apr 16, 2007 2:15 pm
by freak

Posted: Mon Apr 16, 2007 2:20 pm
by milan1612
Yes that really looks interesting :!:
Could be a way for omit59...
Regards, milan1612

Posted: Mon Apr 16, 2007 2:34 pm
by omit59
@milan1612, thanks for trying :lol:

@Freak,

That's just what I was looking for!

And You gave that snippet already in 2006, can't understand why I didn't see that before :oops:

Thanks
Timo

Posted: Mon Apr 16, 2007 2:37 pm
by milan1612
Try 'n' Error :D

Posted: Tue Apr 17, 2007 4:59 pm
by milan1612
By the way, I tried SetWindowText_ and the Undo Buffer gets cleared, too.
The MSDN doesn't mention that behaviour, should be updated... :)

Posted: Tue Apr 17, 2007 5:31 pm
by Kaeru Gaman
> The MSDN doesn't mention that behaviour, should be updated...
go ahead and tell them... :lol: