Page 1 of 1

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

Posted: Fri Aug 24, 2012 4:20 am
by stephenmcnutt
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.

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

Posted: Fri Aug 24, 2012 6:19 am
by shaosean
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

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

Posted: Fri Aug 24, 2012 2:58 pm
by dunbarx
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

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

Posted: Sat Aug 25, 2012 3:55 pm
by stephenmcnutt
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.

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

Posted: Sat Aug 25, 2012 5:28 pm
by sturgis
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.

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

Posted: Sat Aug 25, 2012 5:42 pm
by sturgis
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



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

Posted: Fri Dec 07, 2012 4:16 pm
by stephenmcnutt
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.

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

Posted: Fri Dec 07, 2012 4:44 pm
by Klaus
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

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

Posted: Sun Jul 30, 2023 8:07 am
by Simon Knight
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

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

Posted: Sun Jul 30, 2023 1:24 pm
by dunbarx
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

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

Posted: Sun Jul 30, 2023 3:34 pm
by stam
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