HoTMetal中使用JavaScript
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/webkaifa/)5.怎样编写脚本来检查上次修改的日期
这个On_Document_Activate宏是检查磁盘上的文件是否有与利用HoTMetaL编辑的当前文档相同的上次修改的日期。它提示用户该做什么以防日期不匹配。以下是这个宏的具体代码:
desc="Runs Macro: Hide_On_Document_Activate"
// Do this for local documents only
if (ActiveDocument.FullName == ActiveDocument.LocalFullName) {
var name = ActiveDocument.LocalFullName;
if (Application.ReadableFileExists(name)) { // if document has never been saved, do nothing
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.GetFile(name);
var newMod = Date.parse(f.DateLastModified);
var props = ActiveDocument.CustomDocumentProperties;
if (props.count != 0) {
oldMod = props.Item("LastMod").value;
if (oldMod != newMod) {
var Yes = 6;
var No = 7;
var msg = "The disk version of this document has changed from the";
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/webkaifa/)msg += "version in memory. Do you want to re-open the document?";
var ret = Application.MessageBox(msg, 36, "Document Changed");
if (ret == Yes) {
ActiveDocument.Reload();
}
// Reset the timestamp regardless of the user's response
// This will prevent the dialog from always showing
Application.Run("On_Document_Open_Complete");
}
}
}
}
]]
我们再检查文件是否装载了: ActiveDocument.FullName == ActiveDocument.LocalFullName。然后我们验证一下文件是否被保存到磁盘中: Application.ReadableFileExists(name). 类似于前面的On_Document_Open_Complete 宏,我们创建一个ActiveX控件并且提取出文件的上次修改的日期,代码如下:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.GetFile(name);
var newMod = Date.parse(f.DateLastModified);