diff --git a/docs/dictionary/command/go.lcdoc b/docs/dictionary/command/go.lcdoc index d593c1aa2cc..ddb4bbf95dd 100644 --- a/docs/dictionary/command/go.lcdoc +++ b/docs/dictionary/command/go.lcdoc @@ -4,11 +4,11 @@ Synonyms: open Type: command -Syntax: go [invisible] [to] [of ] [{as |in [a] new window|in }] +Syntax: go [{visible | invisible}] [to] [of ] [{as |in [a] new window|in }] -Syntax: go [invisible] [to] {first | prev[ious]| next | last | any} [marked] [] +Syntax: go [{visible | invisible}] [to] {first | prev[ious]| next | last | any} [marked] [] -Syntax: go [invisible] [to] {recent | start | finish | home} +Syntax: go [{visible | invisible}] [to] {recent | start | finish | home} Syntax: go {forward | forth | back[ward]} [] @@ -36,6 +36,9 @@ go back 7 Example: go invisible stack "Preferences" +Example: +go visible stack "Script-only stack" + Example: local tStackFile, tStackFolder put the effective filename of me into tStackFile @@ -153,6 +156,11 @@ among the previously-visited cards: form moves forward in the recent cards list. "forward" and "forth" are synonyms. +If you use the visible form, the stack is made visible after being +opened. (When going to a stack, this form sets the stack's + to true.) Use this form of the command to display a +script-only stack without explicitly setting the +in the or handlers. If you use the invisible form, the window or card change does not show on the screen. (When going to a stack, this form sets the stack's @@ -160,6 +168,10 @@ show on the screen. (When going to a stack, this form sets the stack's a stack without displaying it on screen. To display the stack later, use the or set its to true. +Note that if a stack’s property is set in either the +or handlers, then this will override the expected behaviour +of the visible and invisible forms. + Any visual effects that have been queued with the visual effect command are displayed when the command is executed (unless the screen is locked). diff --git a/docs/notes/Bugfix-14721.md b/docs/notes/Bugfix-14721.md new file mode 100644 index 00000000000..61d83a5ced8 --- /dev/null +++ b/docs/notes/Bugfix-14721.md @@ -0,0 +1 @@ +# Implement 'go visible ' as an antonym to 'go invisible' diff --git a/engine/src/cmds.h b/engine/src/cmds.h index 52b304b6c1b..3724775b515 100644 --- a/engine/src/cmds.h +++ b/engine/src/cmds.h @@ -1737,7 +1737,7 @@ class MCGo : public MCStatement MCExpression *window; Window_mode mode; Boolean marked; - Boolean visible; + MCInterfaceExecGoVisibility visibility_type; Boolean thisstack; MCChunk *widget; @@ -1750,7 +1750,7 @@ class MCGo : public MCStatement window(nil), mode(WM_LAST), marked(False), - visible(True), + visibility_type(kMCInterfaceExecGoVisibilityImplicit), thisstack(False), widget(nil), direction(CT_BACKWARD) diff --git a/engine/src/cmdss.cpp b/engine/src/cmdss.cpp index 88396ccb7eb..7a0d26ff775 100644 --- a/engine/src/cmdss.cpp +++ b/engine/src/cmdss.cpp @@ -112,7 +112,9 @@ Parse_stat MCGo::parse(MCScriptPoint &sp) initpoint(sp); if (sp.skip_token(SP_FACTOR, TT_PROPERTY, P_INVISIBLE) == PS_NORMAL) - visible = False; + visibility_type = kMCInterfaceExecGoVisibilityExplicitInvisible; + if (sp.skip_token(SP_FACTOR, TT_PROPERTY, P_VISIBLE) == PS_NORMAL) + visibility_type = kMCInterfaceExecGoVisibilityExplicitVisible; while (True) { if (sp.next(type) != PS_NORMAL) @@ -744,9 +746,9 @@ void MCGo::exec_ctxt(MCExecContext &ctxt) } } else if (window != nil) - MCInterfaceExecGoCardInWindow(ctxt, cptr, *t_window, visible == True, thisstack == True); + MCInterfaceExecGoCardInWindow(ctxt, cptr, *t_window, visibility_type, thisstack == True); else - MCInterfaceExecGoCardAsMode(ctxt, cptr, mode, visible == True, thisstack == True); + MCInterfaceExecGoCardAsMode(ctxt, cptr, mode, visibility_type, thisstack == True); } MCHide::~MCHide() diff --git a/engine/src/exec-interface.cpp b/engine/src/exec-interface.cpp index f0f165d973b..f80b264678b 100644 --- a/engine/src/exec-interface.cpp +++ b/engine/src/exec-interface.cpp @@ -4329,8 +4329,9 @@ void MCInterfaceExecChooseTool(MCExecContext& ctxt, MCStringRef p_input, int p_t //////////////////////////////////////////////////////////////////////////////// -void MCInterfaceExecGo(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, int p_mode, bool p_this_stack, bool p_visible) +void MCInterfaceExecGo(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, int p_mode, bool p_this_stack, MCInterfaceExecGoVisibility p_visibility_type) { + if (p_card == nil) { if (MCresult -> isclear()) @@ -4452,11 +4453,14 @@ void MCInterfaceExecGo(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window MCtrace = False; // MW-2007-02-11: [[ Bug 4029 ]] - 'go invisible' fails to close stack window if window already open - if (!p_visible && t_stack -> getflag(F_VISIBLE)) + if (p_visibility_type != kMCInterfaceExecGoVisibilityImplicit) { if (t_stack -> getwindow() != NULL) MCscreen -> closewindow(t_stack -> getwindow()); - t_stack->setflag(False, F_VISIBLE); + if (p_visibility_type == kMCInterfaceExecGoVisibilityExplicitVisible) + t_stack->setflag(true, F_VISIBLE); + if (p_visibility_type == kMCInterfaceExecGoVisibilityExplicitInvisible) + t_stack->setflag(false, F_VISIBLE); } // 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 ctxt . Throw(); } -void MCInterfaceExecGoCardAsMode(MCExecContext& ctxt, MCCard *p_card, int p_mode, bool p_visible, bool p_this_stack) +void MCInterfaceExecGoCardAsMode(MCExecContext& ctxt, MCCard *p_card, int p_mode, MCInterfaceExecGoVisibility p_visibility_type, bool p_this_stack) { - MCInterfaceExecGo(ctxt, p_card, nil, p_mode, p_this_stack, p_visible); + MCInterfaceExecGo(ctxt, p_card, nil, p_mode, p_this_stack, p_visibility_type); } -void MCInterfaceExecGoCardInWindow(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, bool p_visible, bool p_this_stack) +void MCInterfaceExecGoCardInWindow(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, MCInterfaceExecGoVisibility p_visibility_type, bool p_this_stack) { - MCInterfaceExecGo(ctxt, p_card, p_window, WM_MODELESS, p_this_stack, p_visible); + MCInterfaceExecGo(ctxt, p_card, p_window, WM_MODELESS, p_this_stack, p_visibility_type); } void MCInterfaceExecGoRecentCard(MCExecContext& ctxt) @@ -4572,7 +4576,7 @@ void MCInterfaceExecGoHome(MCExecContext& ctxt, MCCard *p_card) MCdefaultstackptr->close(); MCdefaultstackptr->checkdestroy(); } - MCInterfaceExecGo(ctxt, p_card, nil, 0, false, true); + MCInterfaceExecGo(ctxt, p_card, nil, 0, false, kMCInterfaceExecGoVisibilityImplicit); } //////////////////////////////////////////////////////////////////////////////// diff --git a/engine/src/exec.h b/engine/src/exec.h index 81f22a8fe02..0e38c5e76a4 100644 --- a/engine/src/exec.h +++ b/engine/src/exec.h @@ -2449,8 +2449,14 @@ void MCInterfaceExecReplaceInField(MCExecContext& ctxt, MCStringRef p_pattern, M void MCInterfaceExecChooseTool(MCExecContext& ctxt, MCStringRef p_input, int p_tool); -void MCInterfaceExecGoCardAsMode(MCExecContext& ctxt, MCCard *p_card, int p_mode, bool p_visible, bool p_this_stack); -void MCInterfaceExecGoCardInWindow(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, bool p_visible, bool p_this_stack); +enum MCInterfaceExecGoVisibility +{ + kMCInterfaceExecGoVisibilityImplicit, + kMCInterfaceExecGoVisibilityExplicitVisible, + kMCInterfaceExecGoVisibilityExplicitInvisible +}; +void MCInterfaceExecGoCardAsMode(MCExecContext& ctxt, MCCard *p_card, int p_mode, MCInterfaceExecGoVisibility p_visibility_type, bool p_this_stack); +void MCInterfaceExecGoCardInWindow(MCExecContext& ctxt, MCCard *p_card, MCStringRef p_window, MCInterfaceExecGoVisibility p_visibility_type, bool p_this_stack); void MCInterfaceExecGoRecentCard(MCExecContext& ctxt); void MCInterfaceExecGoCardRelative(MCExecContext& ctxt, bool p_forward, real8 p_amount); void MCInterfaceExecGoCardEnd(MCExecContext& ctxt, bool p_is_start); diff --git a/tests/lcs/core/interface/go.livecodescript b/tests/lcs/core/interface/go.livecodescript index 009593777db..a8db125dfbe 100644 --- a/tests/lcs/core/interface/go.livecodescript +++ b/tests/lcs/core/interface/go.livecodescript @@ -55,14 +55,19 @@ on TestGoCardUnquotedName end TestGoCardUnquotedName local sStackFileName -command _TestCreateStack pBinary +command _TestCreateStack pBinary, pVisible local tStack put "stackToGo" into tStack if pBinary then create stack tStack + set the visible of stack tStack to pVisible else create script only stack tStack + if pVisible then + put "on preOpenStack" & return & "set the visible of me to" && pVisible & return & "end preOpenStack" into tScript + set the script of stack tStack to tScript + end if end if put the tempname into sStackFileName @@ -78,7 +83,7 @@ end _TestCleanupStack command _TestGoStackUrl pWhich TestSkipIfNot "write" local tStack - _TestCreateStack pWhich is "binary" + _TestCreateStack pWhich is "binary", true put it into tStack go url ("file:" & sStackFileName) TestDiagnostic the result @@ -117,3 +122,75 @@ on TestGoToCard TestAssert "openCard sent to opened card", the cOpened of card 1 TestAssert "closeCard sent to closed card", the cClosed of card 2 end TestGoToCard + +on _TestGoInvisibleVisibleStack pMode, pWhich, pVisible + TestSkipIfNot "write" + local tStack + _TestCreateStack pWhich is "binary", pVisible is "visible" + put it into tStack + do "go" && pMode && "stack sStackFilename" + TestDiagnostic the result + if pMode is empty then + put pVisible into pExpectedVisibility + else if pMode is "invisible" and pWhich is "script only" and pVisible is "visible" then + --a special case: + --a visible script only stack will be visible even if go invisible + --is used because the stack becomes visible by a "set the visible..." + --line in preOpenStack or openStack. So the setting of the visibility + --by the engine will be overridden when the stack is opened + put "visible" into pExpectedVisibility + else + put pMode into pExpectedVisibility + end if + TestAssert "go" && pMode && "on a" && pVisible && pWhich && "stack opened", there is a stack tStack + TestAssert "go" && pMode && "on a" && pVisible && pWhich && "stack is" && pExpectedVisibility, the visible of stack tStack is (pExpectedVisibility is "visible") + _TestCleanupStack +end _TestGoInvisibleVisibleStack + +on TestGoVisibleOnVisibleBinary + _TestGoInvisibleVisibleStack "visible", "binary", "visible" +end TestGoVisibleOnVisibleBinary + +on TestGoVisibleOnInvisibleBinary + _TestGoInvisibleVisibleStack "visible", "binary", "invisible" +end TestGoVisibleOnInvisibleBinary + +on TestGoVisibleOnVisibleScriptOnly + _TestGoInvisibleVisibleStack "visible", "script only", "visible" +end TestGoVisibleOnVisibleScriptOnly + +on TestGoVisibleOnInvisibleScriptOnly + _TestGoInvisibleVisibleStack "visible", "script only", "invisible" +end TestGoVisibleOnInvisibleScriptOnly + +on TestGoInvisibleOnVisibleBinary + _TestGoInvisibleVisibleStack "invisible", "binary", "visible" +end TestGoInvisibleOnVisibleBinary + +on TestGoInvisibleOnInvisibleBinary + _TestGoInvisibleVisibleStack "invisible", "binary", "invisible" +end TestGoInvisibleOnInvisibleBinary + +on TestGoInvisibleOnVisibleScriptOnly + _TestGoInvisibleVisibleStack "invisible", "script only", "visible" +end TestGoInvisibleOnVisibleScriptOnly + +on TestGoInvisibleOnInvisibleScriptOnly + _TestGoInvisibleVisibleStack "invisible", "script only", "invisible" +end TestGoInvisibleOnInvisibleScriptOnly + +on TestGoRegularOnVisibleBinary + _TestGoInvisibleVisibleStack "", "binary", "visible" +end TestGoRegularOnVisibleBinary + +on TestGoRegularOnInvisibleBinary + _TestGoInvisibleVisibleStack "", "binary", "invisible" +end TestGoRegularOnInvisibleBinary + +on TestGoRegularOnVisibleScriptOnly + _TestGoInvisibleVisibleStack "", "script only", "visible" +end TestGoRegularOnVisibleScriptOnly + +on TestGoRegularOnInvisibleScriptOnly + _TestGoInvisibleVisibleStack "", "script only", "invisible" +end TestGoRegularOnInvisibleScriptOnly diff --git a/tests/lcs/parser/go.parsertest b/tests/lcs/parser/go.parsertest new file mode 100644 index 00000000000..bc03de7ddc7 --- /dev/null +++ b/tests/lcs/parser/go.parsertest @@ -0,0 +1,39 @@ +%% Copyright (C) 2018 LiveCode Ltd. +%% +%% This file is part of LiveCode. +%% +%% LiveCode is free software; you can redistribute it and/or modify it under +%% the terms of the GNU General Public License v3 as published by the Free +%% Software Foundation. +%% +%% LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY +%% WARRANTY; without even the implied warranty of MERCHANTABILITY or +%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +%% for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with LiveCode. If not see . + +%TEST GoRegularStack +on parse_test + go stack "sample" +end parse_test +%EXPECT PASS +%SUCCESS +%ENDTEST + +%TEST GoVisibleStack +on parse_test + go visible stack "sample" +end parse_test +%EXPECT PASS +%SUCCESS +%ENDTEST + +%TEST GoVisibleStack +on parse_test + go invisible stack "sample" +end parse_test +%EXPECT PASS +%SUCCESS +%ENDTEST