renaming a group

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

renaming a group

Post by jalz » Mon Jun 16, 2014 12:03 am

Hi all,

How do I rename a group? I've got the following code which selects the fields on a layout, then groups them but I need to rename that group into something more meaningful. So far I have tried the following

---
//attempt 1
group "grp_card1"
---
//attempt 2
group
set the name of group to "grp_card1"
--
//attempt 3
group
set the name of last group to "grp_card1"
// This renames an group I pasted in before I selected objects to be in my new group
--
//attempt 4
group
set the name of it to "grp_card1"


I've run out of other ideas/concepts to try. I'm using the keyword group to group my objects, whats the next line of code I need to change the name of the newly created group into something more meaningful.

Many thanks
Jalz

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: renaming a group

Post by [-hh] » Mon Jun 16, 2014 12:28 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 2:21 pm, edited 1 time in total.
shiftLock happens

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

Re: renaming a group

Post by dunbarx » Mon Jun 16, 2014 4:54 am

Hi.

There is an anomaly (bug?) in LC that makes the "last" keyword unstable with groups. It works fine for all other objects. There are several threads about this, going back a year or three. Check the user notes in the dictionary under the "last" keyword. (they are mine).

So it is perfectly fine to say:

set the name of the last field to "myLastField"

where that field might have been created, say, under script control. But you cannot trust:

set the name of the last group to "myLastGroup"

The best way out of this is to name the templateGroup. The "last" group thus formed will take that property, and that is how you can isolate it and deal with it as you wish. Of course, you should change the name of that last group, so that any subsequently created groups will be able, in their turn, to be identified in the same way.

Write back if none of this makes sense.

Craig Newman

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: renaming a group

Post by jalz » Mon Jun 16, 2014 3:39 pm

Hi Craig,

Yes, I think I'm coming across that bug. I cant rely on the command
set the name of the last group to "myLastGroup" as that is renaming another group on my layout, and I have several grouped objects.

What I want to do in a script is select all objects and then simply group and then name that group. I've got everything apart from renaming the group.

I have not really looked into templateGroup, so didn't quite understand your solution - yet. I'll try and see if I can find some info in the forums. Pity LC has this anomaly, as the info I found, set the name of the last group to "myLastGroup" seemed to be the answer.

Thanks

Jalz

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: renaming a group

Post by FourthWorld » Mon Jun 16, 2014 3:46 pm

Craig, that sounds like a bug to me. Did you file a report?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: renaming a group

Post by jacque » Mon Jun 16, 2014 4:42 pm

It may not be a bug if there is a background group in place, where the last group would be the background one. If that's the case then asking for the "last card group" instead of just the "last group" should work.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: renaming a group

Post by bn » Mon Jun 16, 2014 7:25 pm

Craig,

if you file a bug report could you propose that Livecode returns the group involved in "group" in the it variable. Analoguous to "create".
Or is there something I am missing that prevents LC to put the long id of the group that groups into it?

Kind regards
Bernd

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: renaming a group

Post by jalz » Mon Jun 16, 2014 9:08 pm

Hi all,

Just thought I'd recreate a dummy card with objects and a script similar to the one I am working on so you guys can verify whether its a bug or me. I was trying to group all the objects and then put a v scrollbar around the group. Notice how it groups everything as it should, but renames a different group when I use the set name ..last... command.

Thanks
Jalz
Attachments
mygroup.livecode.zip
(1.39 KiB) Downloaded 176 times

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: renaming a group

Post by [-hh] » Mon Jun 16, 2014 9:26 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 2:20 pm, edited 1 time in total.
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: renaming a group

Post by bn » Mon Jun 16, 2014 9:36 pm

Hi Jalz,

either do as Hermann suggest with the highest group (did not try this) or do as I suggest look for the highest ID of all group and that should be the one just created to group your groups.

Code: Select all

on mouseUp
   repeat with x = 1 to the number of controls
      put "field,button,graphic,image" into tObjects
      put the long id of control x into tLong
      if tLong contains "group" AND  word 1 of tLong is among the items of tObjects then
         next repeat
      else
         set the selected of the long id of control x to true
      end if
      
   end repeat
   group
   
   -- get the highest id of groups, since "group" created a new group that is the one we are looking for
   repeat with i = 1 to the number of groups of this card
      put the short id of group i & comma after tCollect
   end repeat
   delete last char of tCollect -- a return
   put max (tCollect) into tHighestID -- here we extract the highest id
   set the name of  group id tHighestID to "grp_card1"
   set the vScrollbar of group "grp_card1" to true
end mouseUp
Kind regards
Bernd

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: renaming a group

Post by Simon » Mon Jun 16, 2014 9:53 pm

This is going on way too long:

Code: Select all

   set the name of the templateGroup to "Misery"
   group
   --set the name of the last group to "grp_card1"
   set the vScrollbar of group "Misery" to true
Sorry Craig.

Now in your stack that header is wide so you wont see the vertical scrollbar unless you increase the size of the stack.

Now from this is the "template object", just about everything has one and it is used when "create" or in this case "group" is used. New objects are created using their "template", so you just set it up before making the new object.

Easy yes?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: renaming a group

Post by [-hh] » Mon Jun 16, 2014 10:01 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 2:20 pm, edited 1 time in total.
shiftLock happens

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: renaming a group

Post by jalz » Mon Jun 16, 2014 10:03 pm

:oops: Sorry all! Its now working, with Simons latest addition - so embarrassed
Bernd, your code looking for the highest grouped number and then applying a scrollbar also seems to work
Last edited by jalz on Mon Jun 16, 2014 11:27 pm, edited 1 time in total.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: renaming a group

Post by Simon » Mon Jun 16, 2014 10:20 pm

Hi jalz,
No Worries, you've sparked an interesting conversation, without it I would never have seen Craig's post. Now it's stuck in my head for something to watch out for.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: renaming a group

Post by [-hh] » Mon Jun 16, 2014 10:43 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 2:20 pm, edited 1 time in total.
shiftLock happens

Post Reply