Last Click of a Multi-Hilited Text Field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Last Click of a Multi-Hilited Text Field

Post by townsend » Sat Jun 30, 2012 6:28 pm

If I want to grab a line single line in a text field set for:
ListBehavior, multipleHilite, nonContiquousHilite & toggleHilites.

This code returns a list of hilited line numbers.

Code: Select all

put the HilitedLines of fld "my.list" into my.variable
For instance, if 3 lines were hilited, I get something like this, "2,6,11".

Now here's my problem. I need to know when the user selects a new line.
I don't care when the user un-selects. Just when a new line is added.
But the above code only reports the entire list of lines.

So I wrote a little function where I pass the list before and after each click.
But now I'm thinking there might be a simpler way. This code works fine,
but I just can't resist asking, is there a better way to do this?

I pass in two values like: "2,6,11" and "2,6,8,11" and it returns 8.

Code: Select all

function last.click before.click, after.click
     local bigger, smaller, temp, the.answer
     if number of items in after.click > number of items in before.click then
          repeat with ii=1 to number of items in before.click
               put item ii of before.click into temp
               if temp is in after.click then
                    if temp & comma is in after.click then
                         replace temp & comma with empty in after.click
                    else
                         replace temp with empty in after.click
                    end if
               end if
          end repeat
          replace comma with empty in after.click
          return after.click
     else
          return empty
     end if
end last.click

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

Re: Last Click of a Multi-Hilited Text Field

Post by sturgis » Sat Jun 30, 2012 7:02 pm

Not sure exactly what direction you want to hit this from but heres a couple things.

The clickline returns the chunk description of the line that was just clicked. line 3 of field 1 for example. It sounds to me as though you don't want to know if a line is deselected, only when its hilited? Ok, so i'm not sure thats what you're going for but..

on mouseup (or mousedown) you can place word 2 of the clickline into a variable or property so that you know which line was clicked last.

If you want to keep track of the hilitedlines and the order in which they were hilited yourself. Here is a quicky script that will do this.

In the script of the field I put this:

Code: Select all

local myClickList
on mouseup
   if itemoffset(word 2 of the clickline,the hilitedlines of me) > 0 then -- see if it toggled on or off > 0 = hilited
    
       --add the number of the line clicked as the last item in myClickList.
       put word 2 of the clickline into item (the number of items in myClickList + 1) of myClickList 
   else
       -- if the line was unhilited remove the item from the tracking list. 
      delete item (itemoffset(word 2 of the clickline,myClickList)) of myClickList
   end if

-- this line just displays confirmation info in the msg box. 
   put "The hilitedlines: " & the hilitedlines of me & return & "Clickorder: " & myClickList & return & "The clickline: " & the clickline
end mouseup

Of course since all you probably need is to know the most recently clicked line, "the clickline" is the way.

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

Re: Last Click of a Multi-Hilited Text Field

Post by sturgis » Sat Jun 30, 2012 7:19 pm

hmm. The method I posted above doesn't account for a click and drag multiline select. Don't know if that would be a problem for you or not.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Last Click of a Multi-Hilited Text Field

Post by jmburnod » Sun Jul 01, 2012 1:55 pm

As said sturgis,
clickline is a good way
, but the itemoffset work only for a list have 9 lines max

Code: Select all

if itemoffset(word 2 of the clickline,the hilitedlines of me) > 0 then
itemoffset(1,"2,3,5,10,13" return 4
I tested an other way.Have a look at the cd script of this stack
Best regards

Jean-Marc
Attachments
LastClickInMultipleList.livecode.zip
(1.57 KiB) Downloaded 262 times
https://alternatic.ch

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Re: Last Click of a Multi-Hilited Text Field

Post by townsend » Mon Jul 02, 2012 3:06 pm

Thanks Sturgis-- that clickline is exactly what I needed.
I've deleted my original handler.

And Jean-Marc-- great little example stack there. That rounds out this thread.
If anybody every has a similar questions, this is where they'll find all the answers.

Post Reply