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

Commit 5d30677

Browse files
committed
Remove msgboxredirect and refactor msgChanged
1 parent 3506a1b commit 5d30677

File tree

19 files changed

+217
-265
lines changed

19 files changed

+217
-265
lines changed

docs/dictionary/keyword/message-box.lcdoc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: message box
22

3-
Synonyms: message window, message, msg box, msg window, msg
3+
Synonyms: message window, message, msg box, msg window
44

55
Type: keyword
66

@@ -11,6 +11,8 @@ Indicates the <message box>.
1111

1212
Introduced: 1.0
1313

14+
Deprecated: 9.0
15+
1416
OS: mac, windows, linux
1517

1618
Platforms: desktop, server
@@ -30,9 +32,12 @@ it.
3032

3133
The two-word synonyms message window and msg window can be used only to
3234
show and hide the message box. To put a value into the message box or
33-
read the value in the message box, use the forms message, msg, message
35+
read the value in the message box, use the forms message, message
3436
box, and msg box.
3537

36-
References: put (command), do (command), keyword (glossary),
37-
message box (keyword), blindTyping (property)
38+
From LiveCode 9.0 onwards use the <msg> global variable to refer to get
39+
and set the content of the message box as other legacy synonyms
40+
described here have been deprecated.
3841

42+
References: put (command), do (command), keyword (glossary),
43+
blindTyping (property), msg (keyword)

docs/dictionary/keyword/msg.lcdoc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Name: msg
2+
3+
Synonyms: msg
4+
5+
Type: keyword
6+
7+
Syntax: msg
8+
9+
Summary:
10+
A special <global> <variable> that is used with the <put> command when
11+
no other destination container is specified.
12+
13+
Introduced: 1.0
14+
15+
OS: mac, windows, linux, ios, android, HTML5
16+
17+
Platforms: desktop, mobile
18+
19+
Example:
20+
-- set msg to foobar
21+
put "foobar"
22+
23+
Example:
24+
put "baz" after msg
25+
26+
Description:
27+
When <msg> is modified by a command the <msgChanged> <message> is sent
28+
to the object that modified it. If the <msgChanged> <message> is
29+
unhandled or passed then the value of <msg> will be written to the
30+
system log or in no ui mode (command line) to <stdout>.
31+
32+
In LiveCode IDE <msg> and the <msgChanged> <message> are used to implement
33+
the message box.
34+
35+
References: put (command), msgChanged (message), keyword (glossary),
36+
global (keyword), variable (glossary), message (glossary),
37+
stdout <keyword>

docs/dictionary/message/msgChanged.lcdoc

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ Name: msgChanged
22

33
Type: message
44

5-
Syntax: msgChanged
5+
Syntax: msgChanged <handlerName>, <lineNumber>
66

77
Summary:
8-
Sent to the <messageBoxRedirect> object whenever the <message box> is
9-
changed.
8+
Sent to the object that altered the <msg> <global> <variable> using the
9+
<put> <command>.
1010

1111
Introduced: 9.0
1212

@@ -15,14 +15,24 @@ OS: mac, windows, linux, ios, android, html5
1515
Platforms: desktop, mobile
1616

1717
Example:
18-
on msgChanged
19-
set the text of field "Message" to msg
18+
on msgChanged pHandler, pLine
19+
set the text of field "Message" of stack "Message Box" to msg
2020
end msgChanged
2121

2222
Description:
23-
Use the msgChanged <message> to display or log the content of the
24-
<message box>.
23+
Use the <msgChanged> <message> to display or log the value of
24+
<msg> when it is changed by a script.
2525

26-
References: put (command), container (glossary), command (glossary),
27-
message (glossary), message box (glossary), property (glossary),
28-
messageBoxLastObject (property), messageBoxRedirect (property)
26+
If the <msgChanged> <message> is not handled the value of the
27+
<msg> will be logged to the system log unless the engine is
28+
running in no ui (command line) mode, in which case the value will be
29+
written to <stdout>.
30+
31+
Parameters:
32+
handlerName (string): The name of the handler that modified <msg>
33+
34+
lineNumber (integer): The line number within the script that modified
35+
<msg>
36+
37+
References: put (command), message (glossary), msg (keyword),
38+
stdout (keyword)

docs/dictionary/property/messageBoxLastObject.lcdoc

Lines changed: 0 additions & 29 deletions
This file was deleted.

docs/dictionary/property/messageBoxRedirect.lcdoc

Lines changed: 0 additions & 26 deletions
This file was deleted.

docs/notes/bugfix-18245.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
# Message box properties aded to all engines
1+
# Message box refactor
22

3-
Previously global properties `revMessageBoxRedirect` and
4-
`revMessageBoxLastObject` were only availbe in the IDE engine. These
5-
properties have now been renamed to `messageBoxRedirect` and
6-
`messageBoxLastObject` and they are now available in all engines.
3+
The way the message box functions has been refactored:
74

8-
Set the `messageBoxRedirect` to the long id of the object that should
9-
receive `msgChanged` messages whenever the `msg` global is modified.
5+
- the IDE only global property `revMessageBoxRedirect` has been removed
6+
- the IDE only global property `revMessageBoxLastObject` has been removed
7+
- the legacy message box behavior setting the text of the first field
8+
of a stack named `Message Box` has been removed
9+
- the `msgChanged` message is now sent to the object that changed the
10+
message
11+
- IDE plugin developers should subscribe to `ideMsgChanged` for custom
12+
message box development.
13+
- If the `msgChanged` message is not handled the content of the
14+
`message box` will be logged to the system log unless the engine is
15+
running in no ui (command line) mode which will write the content to
16+
STDOUT.

engine/src/debug.cpp

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4141
#include "globals.h"
4242
#include "mode.h"
4343
#include "exec.h"
44+
#include "system.h"
4445

4546
////////////////////////////////////////////////////////////////////////////////
4647

@@ -129,58 +130,61 @@ void MCB_setvalue(MCExecContext &ctxt, MCExecValue p_value, MCNameRef name)
129130

130131
void MCB_setmsg(MCExecContext &ctxt, MCStringRef p_string)
131132
{
132-
if (!MCmessageboxredirect.IsValid())
133-
{
134-
MCAutoStringRefAsCString t_output;
135-
/* UNCHECKED */ t_output . Lock(p_string);
136-
MCS_write(*t_output, sizeof(char), strlen(*t_output), IO_stdout);
137-
uint4 length = MCStringGetLength(p_string);
138-
if (length && MCStringGetCharAtIndex(p_string, length - 1) != '\n')
139-
MCS_write("\n", sizeof(char), 1, IO_stdout);
140-
return;
141-
}
142-
else
143-
{
144-
MCObject *t_src_object = nil;
145-
if (ctxt.GetObject() != nil)
146-
t_src_object = ctxt.GetObject();
147-
148-
bool t_in_msg_box = false;
149-
150-
MCObject *t_obj_ptr = t_src_object;
151-
while (t_obj_ptr != nil)
152-
{
153-
if (t_obj_ptr == MCmessageboxredirect)
154-
{
155-
t_in_msg_box = true;
156-
break;
157-
}
158-
t_obj_ptr = t_obj_ptr->getparent();
159-
}
160-
161-
if (!t_in_msg_box)
162-
{
163-
MCmessageboxlastobject = t_src_object->GetHandle();
164-
165-
MCNameDelete(MCmessageboxlasthandler);
166-
MCmessageboxlasthandler = nil;
167-
MCNameClone(ctxt.GetHandler()->getname(), MCmessageboxlasthandler);
168-
169-
MCmessageboxlastline = ctxt . GetLine();
170-
}
171-
172-
bool t_added = false;
173-
if (MCnexecutioncontexts < MAX_CONTEXTS && ctxt.GetObject() != nil)
174-
{
175-
MCexecutioncontexts[MCnexecutioncontexts++] = &ctxt;
176-
t_added = true;
177-
}
178-
179-
MCmessageboxredirect -> message(MCM_msgchanged);
180-
181-
if (t_added)
182-
MCnexecutioncontexts--;
183-
}
133+
Exec_stat t_stat = ES_NOT_HANDLED;
134+
135+
MCObject *t_target = nil;
136+
if (ctxt.GetObject() != nil)
137+
t_target = ctxt.GetObject();
138+
else if (MCdefaultstackptr . IsValid())
139+
t_target = MCdefaultstackptr;
140+
141+
if (t_target != nil)
142+
{
143+
MCAutoStringRef t_handler;
144+
t_handler = MCNameGetString(ctxt.GetHandler()->getname());
145+
MCParameter *t_handler_parameter = new (nothrow) MCParameter;
146+
t_handler_parameter -> setvalueref_argument(*t_handler);
147+
148+
MCAutoNumberRef t_line;
149+
MCParameter *t_line_parameter;
150+
if (MCNumberCreateWithUnsignedInteger(ctxt.GetLine(), &t_line))
151+
{
152+
t_line_parameter = new (nothrow) MCParameter;
153+
t_line_parameter -> setvalueref_argument(*t_line);
154+
t_handler_parameter -> setnext(t_line_parameter);
155+
}
156+
157+
bool t_added = false;
158+
if (MCnexecutioncontexts < MAX_CONTEXTS && ctxt.GetObject() != nil)
159+
{
160+
MCexecutioncontexts[MCnexecutioncontexts++] = &ctxt;
161+
t_added = true;
162+
}
163+
164+
t_stat = t_target -> message(MCM_msgchanged, t_handler_parameter, True, True, False);
165+
166+
if (t_added)
167+
MCnexecutioncontexts--;
168+
}
169+
170+
if (t_stat == ES_NOT_HANDLED || t_stat == ES_PASS)
171+
{
172+
if (MCnoui)
173+
{
174+
MCAutoStringRefAsCString t_output;
175+
/* UNCHECKED */ t_output . Lock(p_string);
176+
MCS_write(*t_output, sizeof(char), strlen(*t_output), IO_stdout);
177+
uint4 length = MCStringGetLength(p_string);
178+
if (length && MCStringGetCharAtIndex(p_string, length - 1) != '\n')
179+
MCS_write("\n", sizeof(char), 1, IO_stdout);
180+
return;
181+
}
182+
else
183+
{
184+
MCsystem -> Debug(p_string);
185+
}
186+
}
187+
184188
}
185189

186190
void MCB_message(MCExecContext &ctxt, MCNameRef mess, MCParameter *p)

engine/src/dsklnx.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
7171

7272
#include <gtk/gtk.h>
7373

74+
#include <syslog.h>
75+
7476
////////////////////////////////////////////////////////////////////////////////
7577

7678
// This is in here so we do not need GLIBC2.4
@@ -731,7 +733,9 @@ class MCLinuxDesktop: public MCSystemInterface
731733

732734
virtual void Debug(MCStringRef p_string)
733735
{
734-
// TODO implement?
736+
MCAutoStringRefAsSysString t_string;
737+
if (t_string.Lock(p_string))
738+
syslog(LOG_DEBUG, "%s", *t_string);
735739
}
736740

737741
virtual real64_t GetCurrentTime(void)

engine/src/dskmac.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ extern "C"
769769
#include <IOKit/IOKitLib.h>
770770
#include <IOKit/serial/IOSerialKeys.h>
771771
#include <IOKit/IOBSD.h>
772+
void NSLog(CFStringRef format, ...);
773+
void NSLogv(CFStringRef format, va_list args);
774+
772775
}
773776

774777
static kern_return_t FindSerialPortDevices(io_iterator_t *serialIterator, mach_port_t *masterPort)
@@ -2972,9 +2975,11 @@ struct MCMacDesktop: public MCSystemInterface, public MCMacSystemService
29722975

29732976
virtual void Debug(MCStringRef p_string)
29742977
{
2975-
2978+
CFStringRef t_string;
2979+
if (MCStringConvertToCFStringRef(p_string, t_string))
2980+
NSLog(CFSTR("%@"), t_string);
29762981
}
2977-
2982+
29782983
virtual real64_t GetCurrentTime(void)
29792984
{
29802985
struct timezone tz;

engine/src/dskw32.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,9 @@ struct MCWindowsDesktop: public MCSystemInterface, public MCWindowsSystemService
15741574

15751575
virtual void Debug(MCStringRef p_string)
15761576
{
1577+
MCAutoStringRefAsWString t_string;
1578+
if (t_string.Lock(p_string))
1579+
OutputDebugStringW(*t_string);
15771580
}
15781581

15791582
virtual real64_t GetCurrentTime()

0 commit comments

Comments
 (0)