Skip to content

Commit fd3e9d9

Browse files
author
Monte Goulding
committed
[[ DocumentFilename ]] Add documentFilename property
1 parent b13d305 commit fd3e9d9

14 files changed

Lines changed: 184 additions & 6 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Name: documentFilename
2+
3+
Type: property
4+
5+
Syntax: set the documentFilename of <stack> to <filename>
6+
7+
Summary: Specifies the file path to the file that the stack is represents.
8+
9+
Associations: stack
10+
11+
Introduced: 8.0.0
12+
13+
OS: mac,windows,linux,ios,android
14+
15+
Platforms: desktop
16+
17+
Example:
18+
answer file "Open document"
19+
if it is not empty then
20+
put it into theFilename
21+
set the documentFilename of stack "Template Document Editor" to theFilename
22+
clone stack "Template Document Editor"
23+
end if
24+
25+
Example:
26+
put the documentFilename of this stack into theFilename
27+
if theFilename is not empty then
28+
# load data from file
29+
try
30+
put arrayDecode(url ("binfile:" & theFilename)) into theDataA
31+
# load the data into the UI
32+
UpdateWithData theDataA
33+
catch error
34+
# file corrupted
35+
end try
36+
end if
37+
38+
Parameters:
39+
Stack: The name or ID of the stack.
40+
Filename: The full or relative path to the document.
41+
42+
Description:
43+
Use the <documentFilename> property to associate a stack being presented to the
44+
user with a document on disk.
45+
46+
On mac setting the <documentFilename> property will set the represented filename
47+
of the window. The window will show an icon for the file next to the window
48+
title.
49+
50+
On other platforms there is no visual representation of the association between
51+
the stack and the document filename but the property may still be used to manage
52+
the association.
53+
54+
>*Note:* The <documentFilename> property is not persistent (not saved into the stackfile).
55+
56+
Tags: windowing
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# documentFilename property
2+
3+
A new property has been added to specify the file path to the file that a stack
4+
represents.
5+
6+
On mac setting the documentFilename property will set the represented filename
7+
of the window. The window will show an icon for the file next to the window
8+
title.
9+
10+
On other platforms there is no visual representation of the association between
11+
the stack and the document file but the property may still be used to manage
12+
the association.

engine/src/desktop-stack.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ void MCStack::realize(void)
215215

216216
// MW-2014-06-11: [[ Bug 12467 ]] Make sure we reset the cursor property of the window.
217217
resetcursor(True);
218+
219+
// MERG-2015-10-11: [[ DocumentFilename ]] update the window with the document filename property
220+
if (m_document_filename != nil)
221+
MCPlatformSetWindowProperty(t_window, kMCPlatformWindowPropertyDocumentFilename, kMCPlatformPropertyTypeMCString, &m_document_filename);
218222
}
219223

220224
start_externals();

engine/src/exec-interface-stack.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4646
#include "external.h"
4747

4848
#include "exec-interface.h"
49+
#include "osspec.h"
4950

5051
//////////
5152

@@ -2182,3 +2183,30 @@ void MCStack::SetScriptOnly(MCExecContext& ctxt, bool p_script_only)
21822183
{
21832184
m_is_script_only = p_script_only;
21842185
}
2186+
2187+
// MERG-2015-10-11: [[ DocumentFilename ]] Add stack documentFilename property
2188+
void MCStack::GetDocumentFilename(MCExecContext &ctxt, MCStringRef& r_document_filename)
2189+
{
2190+
if (m_document_filename == nil)
2191+
return;
2192+
2193+
r_document_filename = MCValueRetain(m_document_filename);
2194+
}
2195+
2196+
void MCStack::SetDocumentFilename(MCExecContext &ctxt, MCStringRef p_document_filename)
2197+
{
2198+
MCStringRef t_resolved_filename;
2199+
2200+
if (!MCS_resolvepath(p_document_filename, t_resolved_filename))
2201+
{
2202+
ctxt . LegacyThrow(EE_DOCUMENTFILENAME_BADFILENAME);
2203+
return;
2204+
}
2205+
2206+
MCValueAssign(m_document_filename, t_resolved_filename);
2207+
2208+
if (window != nil)
2209+
MCPlatformSetWindowProperty(window, kMCPlatformWindowPropertyDocumentFilename, kMCPlatformPropertyTypeMCString, &m_document_filename);
2210+
2211+
}
2212+

engine/src/executionerrors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,9 @@ enum Exec_errors
26652665

26662666
// {EE-0869} Import: not an object array
26672667
EE_IMPORT_NOTANOBJECTARRAY,
2668+
2669+
// {EE-0870} documentFilename: bad filename
2670+
EE_DOCUMENTFILENAME_BADFILENAME,
26682671
};
26692672

26702673
extern const char *MCexecutionerrors;

engine/src/lextable.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,9 @@ LT factor_table[] =
823823
{"div", TT_BINOP, O_DIV},
824824
{"dnsservers", TT_FUNCTION, F_DNS_SERVERS},
825825
{"document", TT_CHUNK, CT_DOCUMENT},
826-
// MW-2011-11-24: [[ Nice Folders ]] The adjective for 'the documents folder'.
826+
// MERG-2015-10-11: [[ DocumentFilename ]] Property tag for documentFilename
827+
{"documentfilename", TT_PROPERTY, P_DOCUMENT_FILENAME},
828+
// MW-2011-11-24: [[ Nice Folders ]] The adjective for 'the documents folder'.
827829
{"documents", TT_PROPERTY, P_DOCUMENTS_FOLDER},
828830
{"dontdither", TT_PROPERTY, P_DONT_DITHER},
829831
{"dontrefresh", TT_PROPERTY, P_DONT_REFRESH},

engine/src/mac-internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,9 @@ class MCMacPlatformWindow: public MCPlatformWindow
521521
private:
522522
// Compute the Cocoa window style from the window's current properties.
523523
void ComputeCocoaStyle(NSUInteger& r_window_style);
524-
524+
// MERG-2015-10-11: [[ DocumentFilename ]] Set documentFilename.
525+
void UpdateDocumentFilename(void);
526+
525527
// The window delegate object.
526528
MCWindowDelegate *m_delegate;
527529

engine/src/mac-window.mm

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include "graphics_util.h"
3434

35+
#include "osspec.h"
36+
3537
///////////////////////////////////////////////////////////////////////////
3638

3739
static NSDragOperation s_drag_operation_result = NSDragOperationNone;
@@ -1894,6 +1896,10 @@ - (void)setFrameSize: (NSSize)size
18941896
// MW-2014-04-08: [[ Bug 12080 ]] Make sure we turn off automatic 'hiding on deactivate'.
18951897
// The engine handles this itself.
18961898
[m_window_handle setHidesOnDeactivate: m_hides_on_suspend];
1899+
1900+
// MERG-2015-10-11: [[ DocumentFilename ]] Set documentFilename.
1901+
if (m_document_filename != nil)
1902+
UpdateDocumentFilename();
18971903
}
18981904

18991905
void MCMacPlatformWindow::DoSynchronize(void)
@@ -1964,7 +1970,12 @@ - (void)setFrameSize: (NSSize)size
19641970
if (m_changes . ignore_mouse_events_changed)
19651971
[m_window_handle setIgnoresMouseEvents: m_ignore_mouse_events];
19661972

1967-
m_synchronizing = false;
1973+
if (m_changes . document_filename_changed)
1974+
{
1975+
UpdateDocumentFilename();
1976+
}
1977+
1978+
m_synchronizing = false;
19681979
}
19691980

19701981
bool MCMacPlatformWindow::DoSetProperty(MCPlatformWindowProperty p_property, MCPlatformPropertyType p_type, const void *value)
@@ -2191,6 +2202,22 @@ bool MCMacDoUpdateRegionCallback(void *p_context, const MCRectangle &p_rect)
21912202
r_cocoa_style = t_window_style;
21922203
}
21932204

2205+
// MERG-2015-10-11: [[ DocumentFilename ]] Set documentFilename.
2206+
void MCMacPlatformWindow::UpdateDocumentFilename(void)
2207+
{
2208+
MCStringRef t_native_filename;
2209+
2210+
NSString * t_represented_filename;
2211+
t_represented_filename = nil;
2212+
2213+
if (m_document_filename != nil && MCS_pathtonative(m_document_filename, t_native_filename))
2214+
{
2215+
t_represented_filename = [NSString stringWithMCStringRef: t_native_filename];
2216+
}
2217+
2218+
[m_window_handle setRepresentedFilename: t_represented_filename];
2219+
}
2220+
21942221
////////////////////////////////////////////////////////////////////////////////
21952222

21962223
static bool MCAlphaToCGImageNoCopy(const MCGRaster &p_alpha, CGImageRef &r_image)

engine/src/parsedef.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,10 @@ enum Properties {
16041604
// MW-2014-08-12: [[ EditionType ]] Returns whether the engine is commercial or community
16051605
P_EDITION_TYPE,
16061606

1607-
// ARRAY STYLE PROPERTIES
1607+
// MERG-2015-10-11: [[ DocumentFilename ]] Property tag for documentFilename
1608+
P_DOCUMENT_FILENAME,
1609+
1610+
// ARRAY STYLE PROPERTIES
16081611
P_FIRST_ARRAY_PROP,
16091612
P_CUSTOM_KEYS = P_FIRST_ARRAY_PROP,
16101613
P_CUSTOM_PROPERTIES,

engine/src/platform-internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ class MCPlatformWindow
188188

189189
// MERG-2014-06-02: [[ IgnoreMouseEvents ]] Changed flag for ignore mouse events.
190190
bool ignore_mouse_events_changed : 1;
191+
192+
// MERG-2015-10-11: [[ DocumentFilename ]] Changed flag for docuent filename
193+
bool document_filename_changed : 1;
191194
} m_changes;
192195
MCPlatformWindowStyle m_style;
193196
MCStringRef m_title;
@@ -221,6 +224,9 @@ class MCPlatformWindow
221224
bool m_use_text_input : 1;
222225
bool m_is_realized : 1;
223226
};
227+
228+
// MERG-2015-10-11: [[ DocumentFilename ]] documentFilename property
229+
MCStringRef m_document_filename;
224230
};
225231

226232
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)