xbrowse problem with :bLClicked

xbrowse problem with :bLClicked

Postby Silvio.Falconi » Sun Apr 21, 2024 7:09 pm

i have a xbrowse with :SetMultiSelectCol()

with bRClicked I associated a menupopup

with :bLClicked I click on a row and select it I made the same with :bKeyChar ( space button)

Code: Select all  Expand view
 

 :bLClicked := { |r,c,f,oBrw| if( oBrw:Mousecolpos( c ) == 1, ;
                    ( if( ( f := AScan( oBrw:aSelected, oBrw:BookMark ) ) == 0, ;
                     ( AAdd( oBrw:aSelected, oBrw:BookMark ), ;
                       if( Len( oBrw:aSelected ) = 1, Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw), ) ), ;
                     ( ADel( oBrw:aSelected, f, .t. ), ;
                       if( LEN(oBrw:aSelected)==0, Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw), )) ), ;
                     Refresh_title(oBrw,oDlg,oDbf,cTitle),;
                     oBrw:RefreshCurrent() ), ) }

 




but if I use the mouse in the first column the system works, that is, if there are still records selected it does not change the buttonbar menu, if I use the space bar to deselect or select a record it puts the buttonbar buttons back on without checking if there are other records selected

yet I put this command for spacebar

Code: Select all  Expand view
 
:bKeyChar   := {| k | (If( k == VK_SPACE,(IIF( oBrw:IsSelectedRow(),;
                                          Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]), ;
                                         IIF(LEN(oBrw:aSelected)==0, Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]),) )), nil),;
                                          Refresh_title(oBrw,oDlg,oDbf,cSection))}
 


when I select a row the procedure change the options of buttonbar ( see samples\barchange.prg)

if I click twice it opens to edit the record

Code: Select all  Expand view

// from 2column
         FOR i := 2  TO Len( oBrw:aCols )
             oCol := oBrw:aCols[ i ]
             oCol:bLDClickData  := {|| Edit_Comuni(oBrw,2,oDlg,oDbf,aBtnBrow[4]) }
          NEXT


However, it happens that if I have selected two or more records and deselect only one, the procedure returns the buttonbar buttons to their initial state even if there are actually still two records selected


what happens is that if I click twice it selects the record and at the same time it goes to edit the record and it doesn't go well
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: xbrowse problem with :bLClicked

Postby Antonio Linares » Mon Apr 22, 2024 5:09 am

Dear Silvio,

Lets see if this can help you. Consulting Llama3-70B Harbour's code specialized https://hf.co/chat/assistant/66229318ae991ee8ad79a177

I see what's going on here. You're experiencing some issues with the selection and deselection of records in your xbrowse, specifically when using the spacebar to toggle selection. Let's break it down and see if we can fix this.

First, let's analyze the `:bLClicked` block:

Code: Select all  Expand view

:bLClicked := { |r,c,f,oBrw|
   if( oBrw:Mousecolpos( c ) == 1,
      ( if( ( f := AScan( oBrw:aSelected, oBrw:BookMark ) ) == 0,
         ( AAdd( oBrw:aSelected, oBrw:BookMark ),
           if( Len( oBrw:aSelected ) = 1, Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw), ) ),
         ( ADel( oBrw:aSelected, f,.t. ),
           if( LEN(oBrw:aSelected)==0, Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw), )) ),
      Refresh_title(oBrw,oDlg,oDbf,cTitle),
      oBrw:RefreshCurrent() ),
   )
}
 

This block seems to be working correctly. It toggles the selection of the record and updates the buttonbar accordingly.

Now, let's look at the `:bKeyChar` block:

Code: Select all  Expand view

:bKeyChar := {| k |
   (If( k == VK_SPACE,
      (IIF( oBrw:IsSelectedRow(),
         Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]),
         IIF(LEN(oBrw:aSelected)==0, Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]),) )),
      nil),
      Refresh_title(oBrw,oDlg,oDbf,cSection)
   )
}
 

Here's where the issue lies. When you press the spacebar, it checks if the current row is selected and updates the buttonbar accordingly. However, it doesn't take into account the overall selection state of the xbrowse. If you have multiple records selected and you deselect one using the spacebar, it will reset the buttonbar to its initial state, even if there are still other records selected.

To fix this, you need to modify the `:bKeyChar` block to check the overall selection state of the xbrowse, not just the current row. Here's a possible solution:

Code: Select all  Expand view
:bKeyChar := {| k |
   (If( k == VK_SPACE,
      (if( oBrw:IsSelectedRow(),
         ADel( oBrw:aSelected, oBrw:BookMark,.t. ),
         AAdd( oBrw:aSelected, oBrw:BookMark ) ),
      if( Len( oBrw:aSelected ) == 0, Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]),
         Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]) )),
      nil),
      Refresh_title(oBrw,oDlg,oDbf,cSection)
   )
}
 

In this modified block, when you press the spacebar, it toggles the selection of the current row and updates the buttonbar based on the overall selection state of the xbrowse.

As for the double-click issue, it's because the `:bLDClickData` block is being executed immediately after the selection is toggled. To fix this, you can add a small delay before executing the `Edit_Comuni` function. Here's an example:

Code: Select all  Expand view

oCol:bLDClickData := {|| SetKey( "KL", {|| Edit_Comuni(oBrw,2,oDlg,oDbf,aBtnBrow[4]) } ) }
 

This will set a keyboard shortcut "KL" to execute the `Edit_Comuni` function, which will be triggered after a short delay.

I hope this helps! Let me know if you have any further questions or issues.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: xbrowse problem with :bLClicked

Postby Antonio Linares » Mon Apr 22, 2024 5:25 am

> what is "KL" ?

In the code snippet I provided, "KL" is a keyboard shortcut that is set using the SetKey() function. It's a way to delay the execution of the Edit_Comuni() function.

When you set a keyboard shortcut using SetKey(), Harbour will wait for the user to release all keys and then execute the code block associated with that shortcut. In this case, "KL" is an arbitrary shortcut that is not likely to be pressed by the user, so it effectively creates a short delay before executing the Edit_Comuni() function.

By using SetKey() with a dummy shortcut like "KL", we can ensure that the Edit_Comuni() function is executed after the selection has been toggled, rather than immediately after the double-click event. This can help prevent issues with the selection state and the editing process.

If you want to avoid using a keyboard shortcut, you could also use a timer or a hb_idle() function to create a delay before executing the Edit_Comuni() function. However, using SetKey() with a dummy shortcut is a common idiom in Harbour programming to create a short delay.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: xbrowse problem with :bLClicked

Postby Silvio.Falconi » Mon Apr 22, 2024 7:22 am

Antonio Linares wrote:> what is "KL" ?

In the code snippet I provided, "KL" is a keyboard shortcut that is set using the SetKey() function. It's a way to delay the execution of the Edit_Comuni() function.

When you set a keyboard shortcut using SetKey(), Harbour will wait for the user to release all keys and then execute the code block associated with that shortcut. In this case, "KL" is an arbitrary shortcut that is not likely to be pressed by the user, so it effectively creates a short delay before executing the Edit_Comuni() function.

By using SetKey() with a dummy shortcut like "KL", we can ensure that the Edit_Comuni() function is executed after the selection has been toggled, rather than immediately after the double-click event. This can help prevent issues with the selection state and the editing process.

If you want to avoid using a keyboard shortcut, you could also use a timer or a hb_idle() function to create a delay before executing the Edit_Comuni() function. However, using SetKey() with a dummy shortcut is a common idiom in Harbour programming to create a short delay.



Sorry but with these lines

:
Code: Select all  Expand view
bKeyChar := {| k |
   (If( k == VK_SPACE,;
      (if( oBrw:IsSelectedRow(), ;
         ADel( oBrw:aSelected, oBrw:BookMark,.t. ), ;
         AAdd( oBrw:aSelected, oBrw:BookMark ) ),   ;
      if( Len( oBrw:aSelected ) == 0, Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]), ;
         Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]) )),  nil),;
         Refresh_title(oBrw,oDlg,oDbf,cSection))}



I have this errors

Compiling 'source\comuni\Pcomuni.prg'...
source\comuni\Pcomuni.prg(166) Error E0030 Syntax error "syntax error at '}'"
source\comuni\Pcomuni.prg(196) Error E0030 Syntax error "syntax error at '*'"
source\comuni\Pcomuni.prg(197) Error E0030 Syntax error "syntax error at '*'"
source\comuni\Pcomuni.prg(258) Error E0030 Syntax error "syntax error at '*'"
source\comuni\Pcomuni.prg(288) Error E0030 Syntax error "syntax error at '*'"
source\comuni\Pcomuni.prg(375) Error E0030 Syntax error "syntax error at '*'"
source\comuni\Pcomuni.prg(543) Error E0030 Syntax error "syntax error at '*'"
source\comuni\Pcomuni.prg(544) Error E0030 Syntax error "syntax error at '*'"
source\comuni\Pcomuni.prg(624) Error E0030 Syntax error "syntax error at '*'"
source\comuni\Pcomuni.prg(626) Error E0030 Syntax error "syntax error at '*'"
10 errors

AI doesn't know the real syntax and just wastes your time


Lines corrected in
Code: Select all  Expand view
:bKeyChar := {| k |  (If( k == VK_SPACE,;
                       (if( oBrw:IsSelectedRow(), ;
                             ADel( oBrw:aSelected, oBrw:BookMark,.t. ), ;
                             AAdd( oBrw:aSelected, oBrw:BookMark ) ),   ;
      if( Len( oBrw:aSelected ) == 0, ;
         Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]), ;
         Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4])   )  ),  nil),;
         Refresh_title(oBrw,oDlg,oDbf,cSection))}



Bu then not run good, now when I click spacebar the buttons on buttonbar are changed and the record is not selected
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: xbrowse problem with :bLClicked

Postby Antonio Linares » Mon Apr 22, 2024 7:45 am

You are right that AI still fails and make mistakes, but sometimes it offers you very useful hints :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: xbrowse problem with :bLClicked

Postby Silvio.Falconi » Mon Apr 22, 2024 7:49 am

Antonio Linares wrote:You are right that AI still fails and make mistakes, but sometimes it offers you very useful hints :-)

Ai not run his test never and make errors

Please run this test you can see the modifies not run ok

Code: Select all  Expand view



#include 'fivewin.ch'
#include 'xbrowse.ch'
#include "constant.ch"

request dbfcdx
request dbffpt



function Main()

   local oDlg, oBrw, oFont,obold
   local oSay:=array(2)
   local cSeek:=Space(100)
   local oGet
   local oBtn
   local aCooDlg := aParamDialog(1)
   local nWd  := aCooDlg[1]
   local nHt  := aCooDlg[2]
   local aBtnBrow:=array(4)
   local oDbf

     local  aCols    := { ;
                   { "FIRST",   "First"   ,,   120, },;
                   { "LAST",    "Last"    ,,   120, },;
                   { "STREET",  "Address" ,,   150, },;
                   { "CITY",    "City"    ,,   100, },;
                   { "STATE",   "State"   ,,    80, } }

   local cTitle :="Customers"
   local cPrefix:="Cli"
   local cSection:="Cli"

    RddSetDefault( "DBFCDX" )


       SetHandleCount( 100 )
       FWNumFormat( "E", .t. )


   oDbf :=TDatabase():Open( , "Customer", "DBFCDX", .T. )
       oDbf:setorder(1)
       oDbf:Gotop()

   oFont := TFont():New( "TAHOMA", 0, 14,, )
  oBold := TFont():New( "TAHOMA", 0, 14,,.t. )

   DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL TRUEPIXEL;
       FONT oFont   COLOR CLR_BLACK, CLR_WHITE  ;
       STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)

      DEFINE BUTTONBAR oBar OF oDlg  SIZE 80,70  TOP NOBORDER  2015


    @ 12,15 say oSay[1] Prompt "Cerca" SIZE 46,24 PIXEL OF oDlg FONT oBold TRANSPARENT
 @ 12,450 say oSay[2] Prompt "in" SIZE 20,24 PIXEL OF oDlg FONT oBold    TRANSPARENT


 @ 10, 165 GET oGet VAR cSeek SIZE 200,19 PIXEL OF oDlg PICTURE "@!"

    @ 103,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
          DATASOURCE oDbf COLUMNS aCols ;
          AUTOSORT FONT oFont;
          NOBORDER CELL LINES

      WITH OBJECT oBrw
              :SetMultiSelectCol()
              :bLClicked := { |r,c,f,oBrw| if( oBrw:Mousecolpos( c ) == 1, ;
                    ( if( ( f := AScan( oBrw:aSelected, oBrw:BookMark ) ) == 0, ;
                     ( AAdd( oBrw:aSelected, oBrw:BookMark ), ;
                       if( Len( oBrw:aSelected ) = 1, Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw), ) ), ;
                     ( ADel( oBrw:aSelected, f, .t. ), ;
                       if( LEN(oBrw:aSelected)==0, Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw), )) ), ;
                     Refresh_title(oBrw,oDlg,oDbf,cTitle),;
                     oBrw:RefreshCurrent() ), ) }

             :bKeyChar := {| k |  (If( k == VK_SPACE,;
                       (if( oBrw:IsSelectedRow(), ;
                             ADel( oBrw:aSelected, oBrw:BookMark,.t. ), ;
                             AAdd( oBrw:aSelected, oBrw:BookMark ) ),   ;
      if( Len( oBrw:aSelected ) == 0, ;
         Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]), ;
         Btnbar(2,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4])   )  ),  nil),;
         Refresh_title(oBrw,oDlg,oDbf,cSection))}

            :lHScroll  := .f.
            :lIncrFilter      := .t.
            :bOnSort          := { |b,oCol| oBrw:Seek( "" ), ;
                                   oBrw:cFilterFld := oCol:cExpr, ;
                                   oBrw:SetFocus() }
            :oSeek := oGet
            :CreateFromCode()
         END


  @ 10, 550 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder;
        SIZE 150,400 PIXEL OF oDlg HEIGHTGET 18 STYLE CBS_DROPDOWN


          oDlg:bResized  := <||
                  local oRect         := oDlg:GetCliRect()
                  oBrw:nHeight:= oRect:nBottom - 20
                  oSay[1]:setsize(90,   24.2)
                  oSay[1]:nTop        := oRect:ntop+78
                  oSay[1]:nLeft       := oRect:nLeft+10
                  oSay[2]:nTop        := oRect:ntop+78
                  oSay[2]:nLeft       := oRect:nLeft+270
                  oGet:nTop           := oRect:ntop+74
                  oGet:nLeft          := oRect:nLeft+60
                  oGet:setsize(200,   24.2)

                  oBrw:oSortCbx:nTop  := oRect:ntop+74.9
                  oBrw:oSortCbx:nLeft := oRect:nLeft+290
                    oBrw:refresh()
                   RETURN nil
                   >
                   ACTIVATE DIALOG oDlg CENTERED ;
                   ON INIT ( Btnbar(1,oDlg:oBar,oDlg,oDbf,oBrw,aBtnBrow[4]),;
                   oDlg:resize())

   RELEASE FONT oFont

   return nil


   Static Function Btnbar(nBar,oBar,oDlg,oDbf,oBrw,oCont)  // ,aBtnBar
   local aBtnBar
   local x


   if Valtype( oBar ) = "O"
      For x := Len( oBar:aControls ) to 1 step - 1
         oBar:Del( x,.f. )
      Next x
   endif

   Do case

   case nbar = 0
    * DEFINE BUTTONBAR oBar OF oDlg  SIZE 80,70  TOP NOBORDER  2015
case nbar = 1
   aBtnBar := array(6)
   DEFINE BUTTON aBtnBar[1] OF oBar PROMPT "Nuovo" RESOURCE "NEW_REC"  ;
                 ACTION NIL
   DEFINE BUTTON aBtnBar[2] OF oBar PROMPT "Modifica" RESOURCE "MOD_REC" ;
                 ACTION NIL  GROUP
   DEFINE BUTTON aBtnBar[3] OF oBar PROMPT "Duplica" RESOURCE "DUP_REC" ;
                 ACTION NIL
   DEFINE BUTTON aBtnBar[4] OF oBar PROMPT "Cancella" RESOURCE "DEL_REC" ;
                 ACTION NIL
   DEFINE BUTTON aBtnBar[5] OF oBar PROMPT "Stampa" RESOURCE "PRN_REC" ;
                 ACTION NIL
   DEFINE BUTTON aBtnBar[6] OF oBar PROMPT "Aiuto" RESOURCE "HLP_DLG"  ;
                 ACTION NIL  BTNRIGHT


case nbar = 2
    aBtnBar := array(3)
    DEFINE BUTTON aBtnBar[1] OF oBar PROMPT "Cancella" RESOURCE "DEL_REC" ;
                  ACTION NIL
    DEFINE BUTTON aBtnBar[2] OF oBar PROMPT "Stampa" RESOURCE "PRN_REC"  ;
                  ACTION NIL
    DEFINE BUTTON aBtnBar[3] OF oBar PROMPT "Aiuto" RESOURCE "HLP_DLG"  ;
                   ACTION NIL  BTNRIGHT
endcase
return oBar
//--------------------------------------------------------------------------//
Function Refresh_title();RETURN NIL

Function aParamDialog(n)
     local  nBottom,nRight,nWd,nHt
     local aTmp :={0,0}

        Do Case
        Case n=1
           nBottom:= 32.4
           nRight := 95
         Endcase

        nHt       := nBottom * DLG_CHARPIX_H
        nWd       := Max( nRight * DLG_CHARPIX_W, 180 )
        aTmp[1]:=nWd
        aTmp[2]:=nHt
        return aTmp
//--------------------------------------------------------------------------//
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests