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

Commit 535a1ba

Browse files
author
livecodeali
committed
[[ Revert Command ]] Add revert stack syntax
1 parent 6efa963 commit 535a1ba

File tree

7 files changed

+135
-37
lines changed

7 files changed

+135
-37
lines changed

docs/dictionary/command/revert.lcdoc

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ Name: revert
22

33
Type: command
44

5-
Syntax: revert
5+
Syntax: revert [<targetStack>]
66

7-
Summary: Restores the <current stack> to its state when last saved, deleting all changes made since the last save.
7+
Summary: Restores a stack to its state when last saved, deleting all
8+
changes made since the last save.
89

910
Introduced: 1.0
1011

@@ -16,13 +17,28 @@ Example:
1617
revert
1718

1819
Example:
19-
if it is "Don't Save" then revert
20+
revert stack "MyStack"
2021

21-
Description:
22-
Use the <revert> <command> to back out of any changes made to the <current stack> since the last save.
22+
Parameters:
2323

24-
The <revert> <command> also <undo|undoes> changes made to other <stacks> stored in the same <stack file>. That is, if you <revert> a <main stack>, all <substacks> of that <stack> also revert to the last save, and if you revert a <substack>, its <main stack> and any other <substacks> also revert.
24+
targetStack: An optional stack reference.
2525

26-
References: substacks (property), mainStack (property), revRollBackDatabase (command), reset paint (command), revdb_rollback (function), stacks (function), substack (glossary), stack file (glossary), current stack (glossary), command (glossary), undo (glossary), main stack (glossary), stack (object)
26+
Description:
27+
Use the <revert> <command> to back out of any changes made to a stack
28+
since the last save.
29+
30+
If no <targetStack> is specified, the <revert> command acts on the
31+
<current stack>.
32+
33+
The <revert> <command> also <undo|undoes> changes made to other <stacks>
34+
stored in the same <stack file>. That is, if you <revert> a <main stack>,
35+
all <substacks> of that <stack> also revert to the last save, and if you
36+
revert a <substack>, its <main stack> and any other <substacks> also
37+
revert.
38+
39+
References: substacks (property), mainStack (property),
40+
stacks (function), substack (glossary),
41+
stack file (glossary), current stack (glossary), command (glossary),
42+
undo (glossary), main stack (glossary), stack (object)
2743

2844
Tags: file system

engine/src/cmds.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,13 @@ class MCReplace : public MCStatement
871871

872872
class MCRevert : public MCStatement
873873
{
874+
MCChunk *stack;
874875
public:
875-
virtual void exec_ctxt(MCExecContext &);
876-
virtual void compile(MCSyntaxFactoryRef);
876+
MCRevert() : stack(NULL) {}
877+
virtual ~MCRevert();
878+
virtual Parse_stat parse(MCScriptPoint &);
879+
virtual void exec_ctxt(MCExecContext &ctxt);
880+
virtual void compile(MCSyntaxFactoryRef);
877881
};
878882

879883
class MCRotate : public MCStatement

engine/src/cmdsc.cpp

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,6 +3590,31 @@ void MCReplace::compile(MCSyntaxFactoryRef ctxt)
35903590
MCSyntaxFactoryEndStatement(ctxt);
35913591
}
35923592

3593+
MCRevert::~MCRevert()
3594+
{
3595+
delete stack;
3596+
}
3597+
3598+
Parse_stat MCRevert::parse(MCScriptPoint &sp)
3599+
{
3600+
initpoint(sp);
3601+
Symbol_type type;
3602+
if (sp.next(type) == PS_EOL)
3603+
return PS_NORMAL;
3604+
3605+
// Otherwise backup and parse a chunk
3606+
sp.backup();
3607+
stack = new MCChunk(False);
3608+
if (stack->parse(sp, False) != PS_NORMAL)
3609+
{
3610+
MCperror->add(PE_REVERT_BADSTACK, sp);
3611+
return PS_ERROR;
3612+
}
3613+
3614+
return PS_NORMAL;
3615+
}
3616+
3617+
35933618
void MCRevert::exec_ctxt(MCExecContext& ctxt)
35943619
{
35953620
#ifdef /* MCRevert */ LEGACY_EXEC
@@ -3621,15 +3646,36 @@ void MCRevert::exec_ctxt(MCExecContext& ctxt)
36213646
}
36223647
return ES_NORMAL;
36233648
#endif /* MCRevert */
3624-
3625-
MCInterfaceExecRevert(ctxt);
3649+
3650+
if (stack != nil)
3651+
{
3652+
MCObject *t_object;
3653+
uint4 parid;
3654+
3655+
if (!stack->getobj(ctxt, t_object, parid, True))
3656+
{
3657+
ctxt . LegacyThrow(EE_SAVE_NOTARGET);
3658+
return;
3659+
}
3660+
3661+
MCInterfaceExecRevertStack(ctxt, t_object);
3662+
}
3663+
else
3664+
MCInterfaceExecRevert(ctxt);
36263665
}
36273666

36283667
void MCRevert::compile(MCSyntaxFactoryRef ctxt)
36293668
{
36303669
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
36313670

3632-
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecRevertMethodInfo);
3671+
if (stack != nil)
3672+
{
3673+
stack -> compile_object_ptr(ctxt);
3674+
3675+
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecRevertStackMethodInfo);
3676+
}
3677+
else
3678+
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecRevertMethodInfo);
36333679

36343680
MCSyntaxFactoryEndStatement(ctxt);
36353681
}

engine/src/exec-interface.cpp

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ MC_EXEC_DEFINE_EXEC_METHOD(Interface, RemoveGroupFromCard, 2)
162162
MC_EXEC_DEFINE_EXEC_METHOD(Interface, ResetCursors, 0)
163163
MC_EXEC_DEFINE_EXEC_METHOD(Interface, ResetTemplate, 1)
164164
MC_EXEC_DEFINE_EXEC_METHOD(Interface, Revert, 0)
165+
MC_EXEC_DEFINE_EXEC_METHOD(Interface, RevertStack, 1)
165166
MC_EXEC_DEFINE_EXEC_METHOD(Interface, SelectEmpty, 0)
166167
MC_EXEC_DEFINE_EXEC_METHOD(Interface, SelectAllTextOfField, 1)
167168
MC_EXEC_DEFINE_EXEC_METHOD(Interface, SelectAllTextOfButton, 1)
@@ -1930,32 +1931,55 @@ void MCInterfaceExecUndo(MCExecContext& ctxt)
19301931

19311932
////////////////////////////////////////////////////////////////////////////////
19321933

1934+
static void MCInterfaceRevertStack(MCExecContext& ctxt, MCStack *p_stack)
1935+
{
1936+
MCAssert(p_stack != nil);
1937+
1938+
Window_mode oldmode = p_stack->getmode();
1939+
MCRectangle oldrect = p_stack->getrect();
1940+
1941+
if (!MCdispatcher->ismainstack(p_stack))
1942+
p_stack = (MCStack *)p_stack->getparent();
1943+
if (p_stack == MCdispatcher->gethome())
1944+
{
1945+
ctxt . LegacyThrow(EE_REVERT_HOME);
1946+
return;
1947+
}
1948+
1949+
MCAutoStringRef t_filename;
1950+
p_stack -> getstringprop(ctxt, 0, P_FILE_NAME, False, &t_filename);
1951+
1952+
MCNewAutoNameRef t_name;
1953+
if (!MCNameCreate(*t_filename, &t_name))
1954+
return;
1955+
1956+
Boolean oldlock = MClockmessages;
1957+
MClockmessages = True;
1958+
MCerrorlock++;
1959+
if (p_stack->del())
1960+
p_stack -> scheduledelete();
1961+
MCerrorlock--;
1962+
MClockmessages = oldlock;
1963+
1964+
p_stack = MCdispatcher->findstackname(*t_name);
1965+
if (p_stack != NULL)
1966+
p_stack->openrect(oldrect, oldmode, NULL, WP_DEFAULT, OP_NONE);
1967+
}
1968+
19331969
void MCInterfaceExecRevert(MCExecContext& ctxt)
19341970
{
1935-
Window_mode oldmode = MCtopstackptr->getmode();
1936-
MCRectangle oldrect = MCtopstackptr->getrect();
1937-
MCStack *t_sptr = MCtopstackptr;
1938-
if (!MCdispatcher->ismainstack(t_sptr))
1939-
t_sptr = (MCStack *)t_sptr->getparent();
1940-
if (t_sptr == MCdispatcher->gethome())
1941-
{
1942-
ctxt . LegacyThrow(EE_REVERT_HOME);
1943-
return;
1944-
}
1945-
MCAutoStringRef t_filename;
1946-
t_sptr->getstringprop(ctxt, 0, P_FILE_NAME, False, &t_filename);
1947-
Boolean oldlock = MClockmessages;
1948-
MClockmessages = True;
1949-
MCerrorlock++;
1950-
if (t_sptr->del())
1951-
t_sptr -> scheduledelete();
1952-
MCerrorlock--;
1953-
MClockmessages = oldlock;
1954-
MCNewAutoNameRef t_name;
1955-
/* UNCHECKED */ MCNameCreate(*t_filename, &t_name);
1956-
t_sptr = MCdispatcher->findstackname(*t_name);
1957-
if (t_sptr != NULL)
1958-
t_sptr->openrect(oldrect, oldmode, NULL, WP_DEFAULT, OP_NONE);
1971+
MCInterfaceRevertStack(ctxt, MCtopstackptr);
1972+
}
1973+
1974+
void MCInterfaceExecRevertStack(MCExecContext& ctxt, MCObject *p_stack)
1975+
{
1976+
if (p_stack == nil || p_stack->gettype() != CT_STACK)
1977+
{
1978+
ctxt . LegacyThrow(EE_REVERT_NOSTACK);
1979+
return;
1980+
}
1981+
1982+
MCInterfaceRevertStack(ctxt, (MCStack *)p_stack);
19591983
}
19601984

19611985
////////////////////////////////////////////////////////////////////////////////

engine/src/exec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,7 @@ extern MCExecMethodInfo *kMCInterfaceExecRemoveGroupFromCardMethodInfo;
24942494
extern MCExecMethodInfo *kMCInterfaceExecResetCursorsMethodInfo;
24952495
extern MCExecMethodInfo *kMCInterfaceExecResetTemplateMethodInfo;
24962496
extern MCExecMethodInfo *kMCInterfaceExecRevertMethodInfo;
2497+
extern MCExecMethodInfo *kMCInterfaceExecRevertStackMethodInfo;
24972498
extern MCExecMethodInfo *kMCInterfaceExecSelectEmptyMethodInfo;
24982499
extern MCExecMethodInfo *kMCInterfaceExecSelectAllTextOfFieldMethodInfo;
24992500
extern MCExecMethodInfo *kMCInterfaceExecSelectAllTextOfButtonMethodInfo;
@@ -3008,6 +3009,7 @@ void MCInterfaceExecResetCursors(MCExecContext& ctxt);
30083009
void MCInterfaceExecResetTemplate(MCExecContext& ctxt, Reset_type type);
30093010

30103011
void MCInterfaceExecRevert(MCExecContext& ctxt);
3012+
void MCInterfaceExecRevertStack(MCExecContext& ctxt, MCObject *p_stack);
30113013

30123014
void MCInterfaceExecSelectEmpty(MCExecContext& ctxt);
30133015
void MCInterfaceExecSelectAllTextOfField(MCExecContext& ctxt, MCObjectPtr target);

engine/src/executionerrors.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,10 @@ enum Exec_errors
27092709
EE_INVOKE_TOOMANYARGS,
27102710

27112711
// {EE-0887} Stack: script only stacks can not be password protected
2712-
EE_SCRIPT_ONLY_STACK_NOPASSWORD
2712+
EE_SCRIPT_ONLY_STACK_NOPASSWORD,
2713+
2714+
// {EE-0888} revert: can't find stack
2715+
EE_REVERT_NOSTACK
27132716
};
27142717

27152718
extern const char *MCexecutionerrors;

engine/src/parseerrors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,9 @@ enum Parse_errors
17561756

17571757
// {PE-0569} replace: missing 'styles'
17581758
PE_REPLACE_NOSTYLES,
1759+
1760+
// {PE-0570} revert: bad stack expression
1761+
PE_REVERT_BADSTACK,
17591762

17601763
};
17611764

0 commit comments

Comments
 (0)