Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 2dbd308

Browse files
committed
[[ Bug 6530 ]] Make 'group' return the long id of the new group
This patch changes the behavior of the 'group' command so that it returns the long id of the newly created group (or empty, if no group is created).
1 parent 6c7fd3b commit 2dbd308

File tree

6 files changed

+100
-8
lines changed

6 files changed

+100
-8
lines changed

docs/dictionary/command/group.lcdoc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Associations: group
1111

1212
Introduced: 1.0
1313

14+
Changed: 8.1
15+
1416
OS: mac, windows, linux, ios, android
1517

1618
Platforms: desktop, server, mobile
@@ -28,6 +30,10 @@ Parameters:
2830
objectList:
2931
A list of object references, separated by the word "and".
3032

33+
It:
34+
The <group> command places the ID property of the newly created
35+
object in the it variable.
36+
3137
Description:
3238
Use the <group> <command> after <select|selecting> <object|objects> to
3339
make a <group> out of them.
@@ -39,11 +45,12 @@ or <object|objects> are placed in the <group>.
3945
As with any group on a card, you can use the place <command> to make the
4046
newly-created <group> appear on other <card|cards>.
4147

42-
>*Tip:* To refer to the newly-created <group>, use the <last> <keyword>
43-
> :
48+
>*Tip:* To refer to the newly-created <group>, use the it variable immediately
49+
> after the 'group' command
50+
> :
4451

4552
group button "Yes" and button "No"
46-
set the name of last group to "Do It"
53+
set the name of it to "Do It"
4754

4855

4956
References: group (command), start editing (command),
@@ -53,4 +60,3 @@ card (object), selected (property), relayerGroupedControls (property),
5360
layer (property)
5461

5562
Tags: objects
56-

docs/notes/bugfix-6530.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Group command does not return new group id in it
2+
3+
The group command has been changed so that it returns the long id
4+
of the newly created group in the 'it' variable.
5+
6+
If no group is created (as a result of using 'group' with an empty
7+
selection) the 'it' variable will be set to empty.
8+

engine/src/exec-interface.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,12 +2080,32 @@ void MCInterfaceExecGroupControls(MCExecContext& ctxt, MCObjectPtr *p_controls,
20802080
gptr = (MCGroup *)MCtemplategroup->clone(False, OP_NONE, false);
20812081
else
20822082
gptr = (MCGroup *)MCsavegroupptr->remove(MCsavegroupptr);
2083-
gptr->makegroup(controls, t_card);
2083+
gptr->makegroup(controls, t_card);
2084+
2085+
MCAutoValueRef t_id;
2086+
gptr -> names(P_LONG_ID, &t_id);
2087+
ctxt . SetItToValue(*t_id);
20842088
}
20852089

20862090
void MCInterfaceExecGroupSelection(MCExecContext& ctxt)
20872091
{
2088-
MCselected->group();
2092+
MCGroup *t_group = nil;
2093+
if (MCselected->group(ctxt.GetLine(), ctxt.GetPos(), t_group) != ES_NORMAL)
2094+
{
2095+
ctxt.Throw();
2096+
return;
2097+
}
2098+
2099+
if (t_group != nil)
2100+
{
2101+
MCAutoValueRef t_id;
2102+
t_group -> names(P_LONG_ID, &t_id);
2103+
ctxt.SetItToValue(*t_id);
2104+
}
2105+
else
2106+
{
2107+
ctxt.SetItToEmpty();
2108+
}
20892109
}
20902110

20912111
////////////////////////////////////////////////////////////////////////////////

engine/src/sellst.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ MCControl *MCSellist::clone(MCObject *target)
272272
return t_result;
273273
}
274274

275-
Exec_stat MCSellist::group(uint2 line, uint2 pos)
275+
Exec_stat MCSellist::group(uint2 line, uint2 pos, MCGroup*& r_group_ptr)
276276
{
277277
MCresult->clear(False);
278278
if (objects != NULL && objects->ref->gettype() <= CT_LAST_CONTROL
@@ -330,7 +330,14 @@ Exec_stat MCSellist::group(uint2 line, uint2 pos)
330330
gptr->makegroup(controls, parent);
331331
objects = new MCSelnode(gptr);
332332
gptr->message(MCM_selected_object_changed);
333+
334+
r_group_ptr = gptr;
333335
}
336+
else
337+
{
338+
r_group_ptr = nil;
339+
}
340+
334341
return ES_NORMAL;
335342
}
336343

engine/src/sellst.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class MCSellist
8484
void sort();
8585
uint32_t count();
8686
MCControl *clone(MCObject *target);
87-
Exec_stat group(uint2 line = 0, uint2 pos = 0);
87+
Exec_stat group(uint2 line, uint2 pos, MCGroup*& r_group);
8888
Boolean copy();
8989
Boolean cut();
9090
Boolean del();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
script "CoreInterfaceGroup"
2+
/*
3+
Copyright (C) 2015 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
on TestGroupSelection
20+
create stack "Test"
21+
set the defaultStack to "Test"
22+
23+
select empty
24+
get "ThisIsNotEmpty"
25+
group
26+
TestAssert "Group empty selection sets it to empty", it is empty
27+
28+
create button "A"
29+
create button "B"
30+
select button "A" and button "B"
31+
set the name of the templateGroup to "NewGroup"
32+
get "ThisIsNotEmpty"
33+
group
34+
TestAssert "Group selection sets it to new group", the short name of it is "NewGroup"
35+
36+
delete stack "Test"
37+
end TestGroupSelection
38+
39+
on TestGroupByScript
40+
create stack "Test"
41+
set the defaultStack to "Test"
42+
43+
create button "A"
44+
create button "B"
45+
set the name of the templateGroup to "NewGroup"
46+
get "ThisIsNotEmpty"
47+
group button "A" and button "B"
48+
TestAssert "Group objects sets it to new group", the short name of it is "NewGroup"
49+
50+
delete stack "Test"
51+
end TestGroupByScript

0 commit comments

Comments
 (0)