Click, Pause, Click Again to Edit a Line in a Field?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Click, Pause, Click Again to Edit a Line in a Field?

Post by stephenmcnutt » Fri Aug 24, 2012 4:20 am

In a field with listBehavior = true, I'm trying to figure out how to make the field's lines behave the way items in Windows Explorer or Mac's Finder do: If I click a line, pause, and click again, the text in that line becomes editable and is selected.

Something Completely Different: The way this forum's search throws out words it deems too common makes trying to search for previous posts approximately impossible for me. Maybe I just don't understand how to search, but I kind of doubt it.

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by shaosean » Fri Aug 24, 2012 6:19 am

On the first click, set a flag to TRUE and do a send in time.. if the second click is before that handler runs, cancel the queued message and proceed with your editing.. if the click is fast, cancel the queued message in the mouseDoubleUp message.. The following code should get you started (just off the top of my head and not run through Rev/LC)

Code: Select all

local sAllowEditingFlag = "FALSE"  -- have to use the quotes, otherwise a script compile error
local sMessageID

on mouseUp
  if (sAllowEditingFlag = FALSE) then
    put TRUE into sAllowEditingFlag
    send "editingTimeout" to me in 2 seconds
    put the result into sMessageID
  else
    put FALSE into sAllowEditingFlag
    // do your editing
  end if
end mouseUp

on mouseDoubleUp
  if (sAllowEditingFlag = TRUE) then
    put FALSE into sAllowEditingFlag
    cancel sMessageID
  end if
end mouseDoubleUp

on editingTimeout
  put FALSE into sAllowEditingFlag
end editingTimeout

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by dunbarx » Fri Aug 24, 2012 2:58 pm

Hi.

A much more old fashioned way to to this, in the field script:

Code: Select all

on mouseup
   wait 15
   if the mouseClick then
      set the locktext of me to "false"
      set the listbehavior of me to "false"
   end if
end mouseup

on mouseLeave
    set the locktext of me to "true"
      set the listbehavior of me to "true"
end mouseLeave

stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by stephenmcnutt » Sat Aug 25, 2012 3:55 pm

Thanks. One of the things I'll have to take into account is guarding against deletion of the line or of multiple lines while listBehavior is temporarily suspended. I'm surprised LiveCode doesn't include a built-in behavior or property to mimic the way Windows Explorer and Finder lists work since I imagine wanting to do so would be a common thing.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by sturgis » Sat Aug 25, 2012 5:28 pm

If you don't mind using a datagrid (form not table) you can add the following to its behavior script.

Code: Select all

local sClicked -- can declare here or at top
on mouseup
   if not sClicked then
      put true into sClicked
      send "clearClick" to me in 35 -- adjust timing as you see fit
   else
      local theKey
      if the dgProps["allow editing"] of the dgControl of me then
         switch the short name of the target
            case "Label"
               put "Label 1" into theKey
               EditFieldText the long ID of the target, the dgIndex of me, theKey
               break                 
         end switch
       put false into sClicked
      end if
   end if
   pass mouseUp
end mouseup

command clearClick
   put false into sClicked
end clearClick
Then comment out the double click handler that is in there. 35 seems to work pretty well, and there may be other issues that haven't occured to me yet with this method but for the moment it seems to work pretty well.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by sturgis » Sat Aug 25, 2012 5:42 pm

EDITED: so that it might possibly work...

Actually, if you want doubleclick to still function for another purpose you can adjust like this:

Code: Select all

on mouseDoubleUp pMouseBtnNum
  ## Whatever you want to happen with doubleclick goes here. 
   
   pass mouseDoubleUp
end mouseDoubleUp


local sClickStarted --the milliseconds of the first click
on mouseup
   if not sClicked then
      put the milliseconds into sClickStarted -- store the milliseconds
      put true into sClicked --could probably drop this and just check of sClickStarted is empty /shrug
      send "clearClick" to me in 60 --if the double click interval is 500, then any interval longer than 1/2 sec, up to 1 full sec will enter edit mode
   else
      if the milliseconds - sClickStarted > the doubleclickinterval then -- do the interval check
         local theKey
         if the dgProps["allow editing"] of the dgControl of me then
            switch the short name of the target
               case "Label"
                  put "Label 1" into theKey
                  EditFieldText the long ID of the target, the dgIndex of me, theKey
                  break                 
            end switch

         end if
     put false into sClicked -- clear vars. Whether it was a double click or not, still clear here. 
      put empty into sClickStarted
      end if
 
   end if
   pass mouseUp
end mouseup

command clearClick
   put false into sClicked -- clears stray clicks longer than the max interval.  Should probably check pending messages and make sure these aren't stacked in queue
end clearClick



stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by stephenmcnutt » Fri Dec 07, 2012 4:16 pm

The solution I came up with is completely different, but it mimics what you see in the Mac Finder or Windows Explorer:

When the user clicks on a line in the list field, a heretofore invisible field appears, positioned exactly over the text on the underlying field. This newly visible field contains the same text as the clicked line, and that text is selected for immediate editing.

I temporarily delete the text from the underlying field's clicked line so that when the user begins typing, causing the size of the newly visible, overlaying field to initially shrink to a couple characters' width, the underlying text isn't visible, which would spoil the illusion.

I also put in safeguards so that if the user clicks out of the overlaying editable field while its contents are blank, the original text is restored to the underlying field.

Also, if you click the "Show Focus Border" checkbox for the overlaying field, it has a nice blue border around it just like when you're editing a line in the Mac Finder or Windows Explorer.

After coming up with this "work-around", I think this is may be more or less how the Finder and Windows Explorer handle editing entries.

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by Klaus » Fri Dec 07, 2012 4:44 pm

Hi Stephen,
stephenmcnutt wrote:...After coming up with this "work-around", I think this is may be more or less how the Finder and Windows Explorer handle editing entries.
yep, and the DataGrid :D


Best

Klaus

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by Simon Knight » Sun Jul 30, 2023 8:07 am

BUMP!!!!!!! :shock: :shock:

Just wanted to say thanks for the code snips - I have just used the simple old fashioned code presented by Dunbarx.
:D
best wishes
Skids

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by dunbarx » Sun Jul 30, 2023 1:24 pm

Simon.

That was a trick I made in HC about a million years ago. Looking at it again, maybe the 15 ticks wait period ought to be greater? Not everyone double-clicks as fast as I do.

Craig

stam
Posts: 3089
Joined: Sun Jun 04, 2006 9:39 pm

Re: Click, Pause, Click Again to Edit a Line in a Field?

Post by stam » Sun Jul 30, 2023 3:34 pm

I posted an alternative method in Simon's related thread that doesn't rely on time intervals (it tracks which line is already hilited and if same line clicked again it turns the field into an edit field) - I also find it cumbersome to have to trigger mouseLeave to change back to a listField so I use mouseLine instead (economy of movement!)

https://forums.livecode.com/viewtopic.p ... 32#p224835

Post Reply