Page 1 of 1

Undo function (Ctrl+Z) in :TGet

Posted: Sun Oct 31, 2021 2:28 am
by dutch
Has it got UNDO function alike Ctrl+Z in :TGet? I cannot find it.

Thank you in advance for any suggestion and idea.
Dutch

Re: Undo function (Ctrl+Z) in :TGet

Posted: Sun Oct 31, 2021 3:28 am
by nageswaragunupudi
Please try

Code: Select all | Expand


oGet:Undo()
 

Re: Undo function (Ctrl+Z) in :TGet

Posted: Sun Oct 31, 2021 1:56 pm
by dutch
Dear Master,

It doesn't work. Nothing change, any editing still the same. It doesn't change back to original.
nageswaragunupudi wrote:Please try

Code: Select all | Expand


oGet:Undo()
 

Re: Undo function (Ctrl+Z) in :TGet

Posted: Sun Oct 31, 2021 2:00 pm
by karinha

Code: Select all | Expand



// By Marco Boschi

#Include "Fivewin.Ch"

#Define EM_SETSEL 177

FUNCTION main()

   LOCAL oDlg
   LOCAL oGet1, cGet1 := "Marco                "
   LOCAL oGet2, cGet2 := "Enrico               "
   LOCAL oGet3, cGet3 := "                     "

   DEFINE DIALOG oDlg

   @ 1,1 GET oGet1 VAR cGet1 OF oDlg UPDATE

   oGet1:bGotFocus := { || oGet1:PostMsg( EM_SETSEL, Len( RTrim( cGet1 ) ), 0 ) }

   oGet1:bRClicked := { || PopGet( oGet1 ) }

   @ 2,1 get oGet2 VAR cGet2 of oDlg UPDATE

   oGet2:bGotFocus := { || oGet2:PostMsg( EM_SETSEL, Len( RTrim( cGet2 ) ), 0 ) }

   oGet2:bRClicked := { || PopGet( oGet2 ) }

   @ 3,1 get oGet3 VAR cGet3 of oDlg UPDATE

   oGet3:bGotFocus := { || oGet3:PostMsg( EM_SETSEL, Len( RTrim( cGet3 ) ), 0 ) }

   oGet3:bRClicked := { || PopGet( oGet3 ) }

   ACTIVATE DIALOG oDlg CENTERED

RETURN NIL

FUNCTION POPGET( oGet )

   LOCAL oMenu

   MENU POPUP oMenu 2007

       MENUITEM "Cut"           ; // "Cortar"
          ACTION( oGet:Cut() )

       MENUITEM "Copy"          ; // "Copiar"
          ACTION( oGet:Copy() )

       MENUITEM "Paste"         ; // "Pegar"
          ACTION( cPaste( oGet ) )

       MENUITEM "Cancel"        ; // "Cancelar"
          ACTION( oGet:Undo() )

       MENUITEM "Empty"         ; // "Vacío"
          ACTION( sClear( oGet ) )

       MENUITEM "Select"        ; // "Seleccionar"
          ACTION oGet:PostMsg( EM_SETSEL, Len( RTrim( oGet:Varget() ) ), 0 )

       MENUITEM "Select all"    ; // "Seleccionar todo"
          ACTION( oGet:SelectAll() )

    ENDMENU

   oMenu:Activate( oGet:nBottom, oGet:nLeft, oGet )

RETURN NIL

FUNCTION sClear( oGet )

   M->xSvuotata := oGet:Varget()
   M->cGetCargo := oGet:Cargo

   oGet:VarPut( uValBlank( oGet:VarGet() ) )
   oGet:Refresh()

RETURN NIL

FUNCTION cPaste( oGet )

    LOCAL nLo, nHi

    oGet:GetSelPos( @nLo, @nHi )

    IF nHi != nLo

        oGet:GetDelSel( nLo, nHi )

    ENDIF

    oGet:EditUpdate()

    oGet:Paste()

RETURN NIL
 


Regards, saludos.

Re: Undo function (Ctrl+Z) in :TGet

Posted: Sun Oct 31, 2021 2:26 pm
by dutch
Dear karinha,

Your sample is working and I got it. TGet:undo() must still TGet in Focus.

Is it possible to add Ctrl+Z to TGet for :undo()?

I try as below at the main but ;
1. it works in case of typing more charactor.
2. it doesn't work in case delete some charactor.

Code: Select all | Expand

SETKEY( 26    , {|p, l, v| v:Undo() } )


karinha wrote:

Code: Select all | Expand



// By Marco Boschi

#Include "Fivewin.Ch"

#Define EM_SETSEL 177

FUNCTION main()

   LOCAL oDlg
   LOCAL oGet1, cGet1 := "Marco                "
   LOCAL oGet2, cGet2 := "Enrico               "
   LOCAL oGet3, cGet3 := "                     "

   DEFINE DIALOG oDlg

   @ 1,1 GET oGet1 VAR cGet1 OF oDlg UPDATE

   oGet1:bGotFocus := { || oGet1:PostMsg( EM_SETSEL, Len( RTrim( cGet1 ) ), 0 ) }

   oGet1:bRClicked := { || PopGet( oGet1 ) }

   @ 2,1 get oGet2 VAR cGet2 of oDlg UPDATE

   oGet2:bGotFocus := { || oGet2:PostMsg( EM_SETSEL, Len( RTrim( cGet2 ) ), 0 ) }

   oGet2:bRClicked := { || PopGet( oGet2 ) }

   @ 3,1 get oGet3 VAR cGet3 of oDlg UPDATE

   oGet3:bGotFocus := { || oGet3:PostMsg( EM_SETSEL, Len( RTrim( cGet3 ) ), 0 ) }

   oGet3:bRClicked := { || PopGet( oGet3 ) }

   ACTIVATE DIALOG oDlg CENTERED

RETURN NIL

FUNCTION POPGET( oGet )

   LOCAL oMenu

   MENU POPUP oMenu 2007

       MENUITEM "Cut"           ; // "Cortar"
          ACTION( oGet:Cut() )

       MENUITEM "Copy"          ; // "Copiar"
          ACTION( oGet:Copy() )

       MENUITEM "Paste"         ; // "Pegar"
          ACTION( cPaste( oGet ) )

       MENUITEM "Cancel"        ; // "Cancelar"
          ACTION( oGet:Undo() )

       MENUITEM "Empty"         ; // "Vacío"
          ACTION( sClear( oGet ) )

       MENUITEM "Select"        ; // "Seleccionar"
          ACTION oGet:PostMsg( EM_SETSEL, Len( RTrim( oGet:Varget() ) ), 0 )

       MENUITEM "Select all"    ; // "Seleccionar todo"
          ACTION( oGet:SelectAll() )

    ENDMENU

   oMenu:Activate( oGet:nBottom, oGet:nLeft, oGet )

RETURN NIL

FUNCTION sClear( oGet )

   M->xSvuotata := oGet:Varget()
   M->cGetCargo := oGet:Cargo

   oGet:VarPut( uValBlank( oGet:VarGet() ) )
   oGet:Refresh()

RETURN NIL

FUNCTION cPaste( oGet )

    LOCAL nLo, nHi

    oGet:GetSelPos( @nLo, @nHi )

    IF nHi != nLo

        oGet:GetDelSel( nLo, nHi )

    ENDIF

    oGet:EditUpdate()

    oGet:Paste()

RETURN NIL
 


Regards, saludos.

Re: Undo function (Ctrl+Z) in :TGet

Posted: Sun Oct 31, 2021 3:16 pm
by karinha
Maybe:

Code: Select all | Expand


#Define VK_Z 26  // 538  ?

   SetKey( VK_Z, {|| IF( GetKeyState( VK_CONTROL ), MY_FUNCTION(), NIL ) } )
 


http://forums.fivetechsupport.com/viewtopic.php?f=6&t=8985

Regards, saludos.

Re: Undo function (Ctrl+Z) in :TGet

Posted: Sun Oct 31, 2021 3:50 pm
by nageswaragunupudi
dutch wrote:Dear Master,

It doesn't work. Nothing change, any editing still the same. It doesn't change back to original.
nageswaragunupudi wrote:Please try

Code: Select all | Expand


oGet:Undo()
 


This is far better than oGet:Undo()

Code: Select all | Expand


oGet:cText := oGet:uOriginalValue
 

Re: Undo function (Ctrl+Z) in :TGet

Posted: Mon Nov 01, 2021 2:14 am
by dutch
Dear Karinha,

SetKey() do not accept CTRL+Z. It doesn't go through My_Function().
karinha wrote:Maybe:

Code: Select all | Expand


#Define VK_Z 26  // 538  ?

   SetKey( VK_Z, {|| IF( GetKeyState( VK_CONTROL ), MY_FUNCTION(), NIL ) } )
 


http://forums.fivetechsupport.com/viewtopic.php?f=6&t=8985

Regards, saludos.

Re: Undo function (Ctrl+Z) in :TGet

Posted: Mon Nov 01, 2021 2:17 am
by dutch
Dear Master,

Code: Select all | Expand

oGet:undo() -> works
oGet:cText := v:oGet:Original -> works

// Do not response
SETKEY( 26    , {|p, l, v| GetUndo(v) } )  // or
SetKey( VK_Z, {|p, l, v| IF( GetKeyState( VK_CONTROL ), GetUndo(v), NIL ) } )
 

The problem is SetKey() do not accept CTRL+Z.

nageswaragunupudi wrote:
dutch wrote:Dear Master,

It doesn't work. Nothing change, any editing still the same. It doesn't change back to original.
nageswaragunupudi wrote:Please try

Code: Select all | Expand


oGet:Undo()
 


This is far better than oGet:Undo()

Code: Select all | Expand


oGet:cText := oGet:uOriginalValue
 

Re: Undo function (Ctrl+Z) in :TGet

Posted: Mon Nov 01, 2021 3:34 am
by nageswaragunupudi
oGet:undo() -> works

Works only when oGet has focus. By any chance/mistake if oGet:undo() is called when oGet is out of focus, unexpected and undesirable results can happen.

oGet:cText := v:oGet:Original -> works

This works always.

Actually, I am testing and considering changing Undo() method of TGet to implement the second logic.

Do not use SETKEY.
If you want to undo when the user presses Ctrl-Z while editing the Get, then

Code: Select all | Expand


oGet:bKeyChar := { |k,f,o| If( k == 26, ( o:cText := o:uOriginalValue, 0 ), nil ) }
 

Re: Undo function (Ctrl+Z) in :TGet

Posted: Thu Nov 04, 2021 3:51 pm
by dutch
Dear Master,

Can it do in TGet classes?
nageswaragunupudi wrote:Do not use SETKEY.
If you want to undo when the user presses Ctrl-Z while editing the Get, then

Code: Select all | Expand


oGet:bKeyChar := { |k,f,o| If( k == 26, ( o:cText := o:uOriginalValue, 0 ), nil ) }
 

Re: Undo function (Ctrl+Z) in :TGet

Posted: Fri Nov 05, 2021 2:40 am
by nageswaragunupudi
Can it do in TGet classes?

Yes.
Posted after testing.