Skip to content

Commit 54162ff

Browse files
authored
Merge pull request livecode#6641 from andrewferguson/bugfix-14721
[[Bugfix 14721]] Implement 'go visible <stack>' as an antonym to 'go invisible'
2 parents 1f3b3f3 + b875fbd commit 54162ff

8 files changed

Lines changed: 161 additions & 20 deletions

File tree

docs/dictionary/command/go.lcdoc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Synonyms: open
44

55
Type: command
66

7-
Syntax: go [invisible] [to] <card> [of <stack>] [{as <mode> |in [a] new window|in <window>}]
7+
Syntax: go [{visible | invisible}] [to] <card> [of <stack>] [{as <mode> |in [a] new window|in <window>}]
88

9-
Syntax: go [invisible] [to] {first | prev[ious]| next | last | any} [marked] [<card>]
9+
Syntax: go [{visible | invisible}] [to] {first | prev[ious]| next | last | any} [marked] [<card>]
1010

11-
Syntax: go [invisible] [to] {recent | start | finish | home} <card>
11+
Syntax: go [{visible | invisible}] [to] {recent | start | finish | home} <card>
1212

1313
Syntax: go {forward | forth | back[ward]} [<number>]
1414

@@ -36,6 +36,9 @@ go back 7
3636
Example:
3737
go invisible stack "Preferences"
3838

39+
Example:
40+
go visible stack "Script-only stack"
41+
3942
Example:
4043
local tStackFile, tStackFolder
4144
put the effective filename of me into tStackFile
@@ -153,13 +156,22 @@ among the previously-visited cards:
153156
form moves forward in the recent cards list. "forward" and "forth" are
154157
synonyms.
155158

159+
If you use the <go> visible form, the stack is made visible after being
160+
opened. (When going to a stack, this form sets the stack's <visible>
161+
<property> to true.) Use this form of the <go> command to display a
162+
script-only stack without explicitly setting the <visible (property)>
163+
in the <openStack> or <preOpenStack> handlers.
156164

157165
If you use the <go> invisible form, the window or card change does not
158166
show on the screen. (When going to a stack, this form sets the stack's
159167
<visible> <property> to false.) Use this form of the <go> command to open
160168
a stack without displaying it on screen. To display the stack later, use
161169
the <show> <command> or set its <visible (property)>to true.
162170

171+
Note that if a stack’s <visible> property is set in either the <openStack>
172+
or <preOpenStack> handlers, then this will override the expected behaviour
173+
of the <go> visible and <go> invisible forms.
174+
163175
Any visual effects that have been queued with the visual effect command
164176
are displayed when the <go> command is executed (unless the screen is
165177
locked).

docs/notes/Bugfix-14721.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Implement 'go visible <stack>' as an antonym to 'go invisible'

engine/src/cmds.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ class MCGo : public MCStatement
17441744
MCExpression *window;
17451745
Window_mode mode;
17461746
Boolean marked;
1747-
Boolean visible;
1747+
MCInterfaceExecGoVisibility visibility_type;
17481748
Boolean thisstack;
17491749

17501750
MCChunk *widget;
@@ -1757,7 +1757,7 @@ class MCGo : public MCStatement
17571757
window(nil),
17581758
mode(WM_LAST),
17591759
marked(False),
1760-
visible(True),
1760+
visibility_type(kMCInterfaceExecGoVisibilityImplicit),
17611761
thisstack(False),
17621762
widget(nil),
17631763
direction(CT_BACKWARD)

engine/src/cmdss.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ Parse_stat MCGo::parse(MCScriptPoint &sp)
112112

113113
initpoint(sp);
114114
if (sp.skip_token(SP_FACTOR, TT_PROPERTY, P_INVISIBLE) == PS_NORMAL)
115-
visible = False;
115+
visibility_type = kMCInterfaceExecGoVisibilityExplicitInvisible;
116+
if (sp.skip_token(SP_FACTOR, TT_PROPERTY, P_VISIBLE) == PS_NORMAL)
117+
visibility_type = kMCInterfaceExecGoVisibilityExplicitVisible;
116118
while (True)
117119
{
118120
if (sp.next(type) != PS_NORMAL)
@@ -744,9 +746,9 @@ void MCGo::exec_ctxt(MCExecContext &ctxt)
744746
}
745747
}
746748
else if (window != nil)
747-
MCInterfaceExecGoCardInWindow(ctxt, cptr, *t_window, visible == True, thisstack == True);
749+
MCInterfaceExecGoCardInWindow(ctxt, cptr, *t_window, visibility_type, thisstack == True);
748750
else
749-
MCInterfaceExecGoCardAsMode(ctxt, cptr, mode, visible == True, thisstack == True);
751+
MCInterfaceExecGoCardAsMode(ctxt, cptr, mode, visibility_type, thisstack == True);
750752
}
751753

752754
MCHide::~MCHide()

engine/src/exec-interface.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,8 +4329,9 @@ void MCInterfaceExecChooseTool(MCExecContext& ctxt, MCStringRef p_input, int p_t
43294329

43304330
////////////////////////////////////////////////////////////////////////////////
43314331

4332-
void MCInterfaceExecGo(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, int p_mode, bool p_this_stack, bool p_visible)
4332+
void MCInterfaceExecGo(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, int p_mode, bool p_this_stack, MCInterfaceExecGoVisibility p_visibility_type)
43334333
{
4334+
43344335
if (p_card == nil)
43354336
{
43364337
if (MCresult -> isclear())
@@ -4452,11 +4453,14 @@ void MCInterfaceExecGo(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window
44524453
MCtrace = False;
44534454

44544455
// MW-2007-02-11: [[ Bug 4029 ]] - 'go invisible' fails to close stack window if window already open
4455-
if (!p_visible && t_stack -> getflag(F_VISIBLE))
4456+
if (p_visibility_type != kMCInterfaceExecGoVisibilityImplicit)
44564457
{
44574458
if (t_stack -> getwindow() != NULL)
44584459
MCscreen -> closewindow(t_stack -> getwindow());
4459-
t_stack->setflag(False, F_VISIBLE);
4460+
if (p_visibility_type == kMCInterfaceExecGoVisibilityExplicitVisible)
4461+
t_stack->setflag(true, F_VISIBLE);
4462+
if (p_visibility_type == kMCInterfaceExecGoVisibilityExplicitInvisible)
4463+
t_stack->setflag(false, F_VISIBLE);
44604464
}
44614465

44624466
// MW-2011-02-27: [[ Bug ]] Make sure that if we open as a sheet, we have a parent pointer!
@@ -4539,14 +4543,14 @@ void MCInterfaceExecGo(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window
45394543
ctxt . Throw();
45404544
}
45414545

4542-
void MCInterfaceExecGoCardAsMode(MCExecContext& ctxt, MCCard *p_card, int p_mode, bool p_visible, bool p_this_stack)
4546+
void MCInterfaceExecGoCardAsMode(MCExecContext& ctxt, MCCard *p_card, int p_mode, MCInterfaceExecGoVisibility p_visibility_type, bool p_this_stack)
45434547
{
4544-
MCInterfaceExecGo(ctxt, p_card, nil, p_mode, p_this_stack, p_visible);
4548+
MCInterfaceExecGo(ctxt, p_card, nil, p_mode, p_this_stack, p_visibility_type);
45454549
}
45464550

4547-
void MCInterfaceExecGoCardInWindow(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, bool p_visible, bool p_this_stack)
4551+
void MCInterfaceExecGoCardInWindow(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, MCInterfaceExecGoVisibility p_visibility_type, bool p_this_stack)
45484552
{
4549-
MCInterfaceExecGo(ctxt, p_card, p_window, WM_MODELESS, p_this_stack, p_visible);
4553+
MCInterfaceExecGo(ctxt, p_card, p_window, WM_MODELESS, p_this_stack, p_visibility_type);
45504554
}
45514555

45524556
void MCInterfaceExecGoRecentCard(MCExecContext& ctxt)
@@ -4572,7 +4576,7 @@ void MCInterfaceExecGoHome(MCExecContext& ctxt, MCCard *p_card)
45724576
MCdefaultstackptr->close();
45734577
MCdefaultstackptr->checkdestroy();
45744578
}
4575-
MCInterfaceExecGo(ctxt, p_card, nil, 0, false, true);
4579+
MCInterfaceExecGo(ctxt, p_card, nil, 0, false, kMCInterfaceExecGoVisibilityImplicit);
45764580
}
45774581

45784582
////////////////////////////////////////////////////////////////////////////////

engine/src/exec.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,8 +2452,14 @@ void MCInterfaceExecReplaceInField(MCExecContext& ctxt, MCStringRef p_pattern, M
24522452

24532453
void MCInterfaceExecChooseTool(MCExecContext& ctxt, MCStringRef p_input, int p_tool);
24542454

2455-
void MCInterfaceExecGoCardAsMode(MCExecContext& ctxt, MCCard *p_card, int p_mode, bool p_visible, bool p_this_stack);
2456-
void MCInterfaceExecGoCardInWindow(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, bool p_visible, bool p_this_stack);
2455+
enum MCInterfaceExecGoVisibility
2456+
{
2457+
kMCInterfaceExecGoVisibilityImplicit,
2458+
kMCInterfaceExecGoVisibilityExplicitVisible,
2459+
kMCInterfaceExecGoVisibilityExplicitInvisible
2460+
};
2461+
void MCInterfaceExecGoCardAsMode(MCExecContext& ctxt, MCCard *p_card, int p_mode, MCInterfaceExecGoVisibility p_visibility_type, bool p_this_stack);
2462+
void MCInterfaceExecGoCardInWindow(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, MCInterfaceExecGoVisibility p_visibility_type, bool p_this_stack);
24572463
void MCInterfaceExecGoRecentCard(MCExecContext& ctxt);
24582464
void MCInterfaceExecGoCardRelative(MCExecContext& ctxt, bool p_forward, real8 p_amount);
24592465
void MCInterfaceExecGoCardEnd(MCExecContext& ctxt, bool p_is_start);

tests/lcs/core/interface/go.livecodescript

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ on TestGoCardUnquotedName
5555
end TestGoCardUnquotedName
5656

5757
local sStackFileName
58-
command _TestCreateStack pBinary
58+
command _TestCreateStack pBinary, pVisible
5959
local tStack
6060
put "stackToGo" into tStack
6161

6262
if pBinary then
6363
create stack tStack
64+
set the visible of stack tStack to pVisible
6465
else
6566
create script only stack tStack
67+
if pVisible then
68+
put "on preOpenStack" & return & "set the visible of me to" && pVisible & return & "end preOpenStack" into tScript
69+
set the script of stack tStack to tScript
70+
end if
6671
end if
6772

6873
put the tempname into sStackFileName
@@ -78,7 +83,7 @@ end _TestCleanupStack
7883
command _TestGoStackUrl pWhich
7984
TestSkipIfNot "write"
8085
local tStack
81-
_TestCreateStack pWhich is "binary"
86+
_TestCreateStack pWhich is "binary", true
8287
put it into tStack
8388
go url ("file:" & sStackFileName)
8489
TestDiagnostic the result
@@ -117,3 +122,75 @@ on TestGoToCard
117122
TestAssert "openCard sent to opened card", the cOpened of card 1
118123
TestAssert "closeCard sent to closed card", the cClosed of card 2
119124
end TestGoToCard
125+
126+
on _TestGoInvisibleVisibleStack pMode, pWhich, pVisible
127+
TestSkipIfNot "write"
128+
local tStack
129+
_TestCreateStack pWhich is "binary", pVisible is "visible"
130+
put it into tStack
131+
do "go" && pMode && "stack sStackFilename"
132+
TestDiagnostic the result
133+
if pMode is empty then
134+
put pVisible into pExpectedVisibility
135+
else if pMode is "invisible" and pWhich is "script only" and pVisible is "visible" then
136+
--a special case:
137+
--a visible script only stack will be visible even if go invisible
138+
--is used because the stack becomes visible by a "set the visible..."
139+
--line in preOpenStack or openStack. So the setting of the visibility
140+
--by the engine will be overridden when the stack is opened
141+
put "visible" into pExpectedVisibility
142+
else
143+
put pMode into pExpectedVisibility
144+
end if
145+
TestAssert "go" && pMode && "on a" && pVisible && pWhich && "stack opened", there is a stack tStack
146+
TestAssert "go" && pMode && "on a" && pVisible && pWhich && "stack is" && pExpectedVisibility, the visible of stack tStack is (pExpectedVisibility is "visible")
147+
_TestCleanupStack
148+
end _TestGoInvisibleVisibleStack
149+
150+
on TestGoVisibleOnVisibleBinary
151+
_TestGoInvisibleVisibleStack "visible", "binary", "visible"
152+
end TestGoVisibleOnVisibleBinary
153+
154+
on TestGoVisibleOnInvisibleBinary
155+
_TestGoInvisibleVisibleStack "visible", "binary", "invisible"
156+
end TestGoVisibleOnInvisibleBinary
157+
158+
on TestGoVisibleOnVisibleScriptOnly
159+
_TestGoInvisibleVisibleStack "visible", "script only", "visible"
160+
end TestGoVisibleOnVisibleScriptOnly
161+
162+
on TestGoVisibleOnInvisibleScriptOnly
163+
_TestGoInvisibleVisibleStack "visible", "script only", "invisible"
164+
end TestGoVisibleOnInvisibleScriptOnly
165+
166+
on TestGoInvisibleOnVisibleBinary
167+
_TestGoInvisibleVisibleStack "invisible", "binary", "visible"
168+
end TestGoInvisibleOnVisibleBinary
169+
170+
on TestGoInvisibleOnInvisibleBinary
171+
_TestGoInvisibleVisibleStack "invisible", "binary", "invisible"
172+
end TestGoInvisibleOnInvisibleBinary
173+
174+
on TestGoInvisibleOnVisibleScriptOnly
175+
_TestGoInvisibleVisibleStack "invisible", "script only", "visible"
176+
end TestGoInvisibleOnVisibleScriptOnly
177+
178+
on TestGoInvisibleOnInvisibleScriptOnly
179+
_TestGoInvisibleVisibleStack "invisible", "script only", "invisible"
180+
end TestGoInvisibleOnInvisibleScriptOnly
181+
182+
on TestGoRegularOnVisibleBinary
183+
_TestGoInvisibleVisibleStack "", "binary", "visible"
184+
end TestGoRegularOnVisibleBinary
185+
186+
on TestGoRegularOnInvisibleBinary
187+
_TestGoInvisibleVisibleStack "", "binary", "invisible"
188+
end TestGoRegularOnInvisibleBinary
189+
190+
on TestGoRegularOnVisibleScriptOnly
191+
_TestGoInvisibleVisibleStack "", "script only", "visible"
192+
end TestGoRegularOnVisibleScriptOnly
193+
194+
on TestGoRegularOnInvisibleScriptOnly
195+
_TestGoInvisibleVisibleStack "", "script only", "invisible"
196+
end TestGoRegularOnInvisibleScriptOnly

tests/lcs/parser/go.parsertest

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
%% Copyright (C) 2018 LiveCode Ltd.
2+
%%
3+
%% This file is part of LiveCode.
4+
%%
5+
%% LiveCode is free software; you can redistribute it and/or modify it under
6+
%% the terms of the GNU General Public License v3 as published by the Free
7+
%% Software Foundation.
8+
%%
9+
%% LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
%% WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
%% for more details.
13+
%%
14+
%% You should have received a copy of the GNU General Public License
15+
%% along with LiveCode. If not see <http://www.gnu.org/licenses/>.
16+
17+
%TEST GoRegularStack
18+
on parse_test
19+
go stack "sample"
20+
end parse_test
21+
%EXPECT PASS
22+
%SUCCESS
23+
%ENDTEST
24+
25+
%TEST GoVisibleStack
26+
on parse_test
27+
go visible stack "sample"
28+
end parse_test
29+
%EXPECT PASS
30+
%SUCCESS
31+
%ENDTEST
32+
33+
%TEST GoVisibleStack
34+
on parse_test
35+
go invisible stack "sample"
36+
end parse_test
37+
%EXPECT PASS
38+
%SUCCESS
39+
%ENDTEST

0 commit comments

Comments
 (0)