Editorgadget undo?

Just starting out? Need help? Post your questions and find answers here.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Editorgadget undo?

Post 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
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post 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...
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

@milan1612,

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

Timo
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post 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...
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

quidquid Latine dictum sit altum videtur
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Yes that really looks interesting :!:
Could be a way for omit59...
Regards, milan1612
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post 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
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Try 'n' Error :D
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post 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... :)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

> The MSDN doesn't mention that behaviour, should be updated...
go ahead and tell them... :lol:
oh... and have a nice day.
Post Reply