selecting and grouping the label fields,rectangles, and such

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dochawk
Posts: 43
Joined: Wed Sep 02, 2009 9:29 pm

selecting and grouping the label fields,rectangles, and such

Post by dochawk » Tue Sep 15, 2009 7:02 pm

I have scripts to select all the Rectangles and Label fields, e.g.

Code: Select all

on selAllLabFlds
   -- to select all of the Label Fields
   
   --first make a list with the names of all the objects to select
   repeat with i = 1 to the number of fields in the target
      put the short name of field i of the target into y
      if the short name of field i of  the target = "Label Field" then
         put " and field " & i & " of the target " after theList
      end if
   end repeat
   delete the first word of theList
   do  "select " &  theList 
end selAllLabFlds
Once selected, I need to put them in a named group. I'm playing around with scripts like,

Code: Select all


on reGrp
   --regroup the background forms & Rectangles of the buttons
   --note:  if any other backgrounds are used, they need to be handled here
   
   --the label for the form graphics
   put the short name of the target & "BGStuff" into bgName
   put the short name of the target & "BGRects" into bgRects
   put the short name of the target & "BGLabFlds" into bgLabFlds
   
   --get rid of any existing group bgStuff, and it's parts 
   rmGroup bgName
   rmGroup bgRects
   rmGroup BGLabFlds
      
   --make a new rect group
   selAllRects
   create group bgRects
   #group
    #set the name of last group to bgRects
   
   --and for the labels
   selAllLabFlds
   create group bgLabFlds
   #group
   #set the name of last group to bgLabFlds
   
   --now combine them
   select group bgRects of the target and group bgLabFlds of the target
   #group
   #set the name of last group to bgName
   create group bgName
   set the cantSelect of group bgName to true
      
end reGrp
Upon return from the

Code: Select all

selAll
type funcitons, all of the correct objects are indeed selected.

When I use the

Code: Select all

create group bgName
type structure, currently uncommented, I usually get an empty group with the indicated name--and the individual fields or graphics still selected.

If I use the group command, grouping is always successful, but the group is not always the

Code: Select all

last group
, nor does it necessarily land in

Code: Select all

it
.

As I've read the userguide and dictionary, it appears that both of my methods should work, but neither do.

What am I doing wrong, or have I found a bug? (This is the linux alpha test version).

thanks,

hawk

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Sep 15, 2009 8:18 pm

Using the 'group' command after setting the selected of your controls to true, should do the trick - as long as you're not mixing selections from already grouped controls. Also important is the setting of the 'selectGroupedControls' global property.

Best of luck,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

dochawk
Posts: 43
Joined: Wed Sep 02, 2009 9:29 pm

Post by dochawk » Wed Sep 16, 2009 12:29 am

Thanks. But is there a reliable way to name the group I just created? I found "the last group" used in the dictionary examples, but this actually refers to the group with the highest number--and that isn't always the new group.

The

Code: Select all

group
command always works for me, and leaves the group selected; the problem is naming the new group so that I can find and delete it later. I just tried

Code: Select all

 set the name of the selection to bgRects
, that causes the script to bomb out with

Code: Select all

Message execution error:
Error description: Field: bad text attributes

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Sep 16, 2009 6:14 am

Try this instead

Code: Select all

set the name of the selectedObject to "Foobar"
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

dochawk
Posts: 43
Joined: Wed Sep 02, 2009 9:29 pm

Post by dochawk » Wed Sep 16, 2009 7:45 pm

Ah-hah! perfect; that's exactly what I've been bumbling after!

thanks

hawk

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Wed Sep 16, 2009 9:38 pm

Coincidentally, Wilhelm Sanke referred to the anomolies of the "group" object on the use- list today and with particular reference to the above, a workaround for the problem with "the last group" was given:
Here on the use- list, Wilhelm Sanke wrote:Workarounds:
To be on the safe side, I have rewritten my relevant scripts using the
"owner" property, like
"on mouseUp
select fld "one" and fld "two"
group
put the owner of fld "one" into tlastgroup
end mouseUp"
This may give an additional approach so that you can refer to the group in question if, for some reason, a deselection of the grouped objects occurs before renaming.

Post Reply