大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> Javascript实例教程(19) 使用HoTMetal(5)

Javascript实例教程(19) 使用HoTMetal(5)

时间: 2021-07-31 作者:daque

hotmetal中运用javascript 5.还好吗编写脚从来查看上回窜改的日子在本节教程中你将不妨学好还好吗编写一个宏来查看能否有任何的步调仍旧运用hotmetal中窜改过一个文献。这个宏囊括了以次几个查看的革新个性:on_document_open_complete、on_document_activate和 on_application_activate。在前方的教程中,那些宏的名字仍旧被预订义了,以是这边不许对它们举行窜改。那些名字指定了事变来触发宏。这个event-macro关系是隐含的,以是不许经过任何本领来对它举行改写。当咱们翻开一个文书档案的功夫,比方on_document_open_complete,它老是在实行文献翻开的功夫被挪用的。以次是简直的设置: <macro name="on_document_open_complete" lang="jscript"><![cdata[var name = activedocument.localfullname;if (application.readablefileexists(name)) { // if document has never been saved, do nothingapplication.run("on_document_save");}]]></macro>咱们开始索取暂时文献夹的文献名:name = activedocument.localfullname,而后查看可读的文献能否生存;接着咱们运转宏on_document_save,这个宏on_document_save演示了微软的filesystemobject动作activex控件的运用本领,这是一个在javascript中。这个宏的重要思维是革新文书档案的lastmod属性以反馈磁盘下文档的暂时事变:<macro name="on_document_save" lang="jscript"<>![cdata[var fso = new activexobject("scripting.filesystemobject");var f = fso.getfile(activedocument.localfullname);var mod = date.parse(f.datelastmodified);var props = activedocument.customdocumentproperties;if (props.count != 0) {props.add("lastmod", mod);}]]></macro>这个宏从filesystemobject创造了一个activex控件,它囊括了微软的剧本库: var fso = new activexobject("scripting.filesystemobject");咱们不妨经过以次的语句来从磁盘获得文献的属性:f = fso.getfile(name),而后索取出文献结果一次窜改的事变:mod = date.parse(f.datelastmodified)。咱们经过挪用activedocument的customdocumentproperties 属性来创造了一个用户设置的属性集:props。而后咱们运用mod属性来对这个集举行初始化,这时候它的数值为"lastmode"。

hotmetal中运用javascript 5.还好吗编写脚从来查看上回窜改的日子这个on_document_activate宏是查看磁盘上的文献能否有与运用hotmetal编纂的暂时文书档案沟通的上回窜改的日子。它提醒用户该做什么以防日子不配合。以次是这个宏的简直代码:<macro name="on_document_activate" lang="jscript" id="44" tooltip="hide_on_document_activate" desc="runs macro: hide_on_document_activate"><![cdata[// do this for local documents onlyif (activedocument.fullname == activedocument.localfullname) {var name = activedocument.localfullname;if (application.readablefileexists(name)) { // if document has never been saved, do nothingvar 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\n";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 showingapplication.run("on_document_open_complete");}}}}]]></macro>咱们再查看文献能否承载了: 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);hotmetal中运用javascript 5.还好吗编写脚从来查看上回窜改的日子接着,咱们挪用暂时文书档案的定制属性集:props = activedocument.customdocumentproperties 而且查看这个属性的数字能否不即是零。咱们仍旧在前方的on_document_open_complete 宏中仍旧生存了,并将它赋值给oldmod:oldmod = props.item("lastmod").value当咱们创造oldmod (来自翻开的文书档案) and newmod (来自磁盘)之间的冲突的功夫,咱们该当报告用户能否从磁盘上连载了这个文献: var yes = 6;var no = 7;var msg = "the disk version of this document has changed from the\n";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();}结果,咱们经过抄袭翻开的操纵来重置暂时文书档案的日子:application.run("on_document_open_complete");咱们想扩充这个革新个性的查看并触发它,而尽管在这个文书档案是暂时的仍旧当这个运用步调是暂时的。这时候咱们不妨设置on_application_activate宏,这个宏不过挪用上头的宏:<macro name="on_application_activate" lang="jscript"><![cdata[application.run("on_document_activate");]]></macro>此刻咱们须要复制on_document_save功效到on_document_saveas宏:<macro name="on_document_saveas" lang="jscript"<>![cdata[application.run("on_document_save");]]></macro>结果仍旧对它举行一下尝试吧。先在hotmetal pro 6.0中翻开一个文书档案。并在你爱好的编纂器中翻开沟通的文书档案。并在任何场合插入一个空格符再将它生存到磁盘中。当你切换到hotmetal运用步调,你将不妨获得如图1的消息。(图1)

javascript实例教程(19) 使用hotmetal(5)图1

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.