FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Undo function (Ctrl+Z) in :TGet
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Undo function (Ctrl+Z) in :TGet
Posted: Sun Oct 31, 2021 02:28 AM

Has it got UNDO function alike Ctrl+Z in :TGet? I cannot find it.

Thank you in advance for any suggestion and idea.
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Sun Oct 31, 2021 03:28 AM
Please try
Code (fw): Select all Collapse
oGet:Undo()
Regards



G. N. Rao.

Hyderabad, India
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Sun Oct 31, 2021 01:56 PM
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 (fw): Select all Collapse
oGet:Undo()
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Sun Oct 31, 2021 02:00 PM
Code (fw): Select all Collapse
// 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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Sun Oct 31, 2021 02:26 PM
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 (fw): Select all Collapse
SETKEY( 26    , {|p, l, v| v:Undo() } )


karinha wrote:
Code (fw): Select all Collapse
// 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.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Sun Oct 31, 2021 03:16 PM
Maybe:

Code (fw): Select all Collapse
#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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Sun Oct 31, 2021 03:50 PM
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 (fw): Select all Collapse
oGet:Undo()


This is far better than oGet:Undo()

Code (fw): Select all Collapse
oGet:cText := oGet:uOriginalValue
Regards



G. N. Rao.

Hyderabad, India
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Mon Nov 01, 2021 02:14 AM
Dear Karinha,

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

Code (fw): Select all Collapse
#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.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Mon Nov 01, 2021 02:17 AM
Dear Master,

Code (fw): Select all Collapse
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 (fw): Select all Collapse
oGet:Undo()


This is far better than oGet:Undo()

Code (fw): Select all Collapse
oGet:cText := oGet:uOriginalValue
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Mon Nov 01, 2021 03:34 AM
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: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 (fw): Select all Collapse
oGet:bKeyChar := { |k,f,o| If( k == 26, ( o:cText := o:uOriginalValue, 0 ), nil ) }
Regards



G. N. Rao.

Hyderabad, India
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Thu Nov 04, 2021 03:51 PM
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 (fw): Select all Collapse
oGet:bKeyChar := { |k,f,o| If( k == 26, ( o:cText := o:uOriginalValue, 0 ), nil ) }
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Undo function (Ctrl+Z) in :TGet
Posted: Fri Nov 05, 2021 02:40 AM
Can it do in TGet classes?

Yes.
Posted after testing.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion