Javascript实例教程(20-7)

好吧,现在让我们来测试一下这个宏。请在HotTMetaL中打开一个文档并将视图切换到源程序视图。你可以在ProgGuide目录中选择其中一段。并且通过使用Tools(工具)->Customization(定制)关闭Enable Source Layout按钮。接着将其中一行用加入空格往右移,再从工具菜单中调用宏对话框。这时会展现出定义在HotMetaL.mcr文件的宏的列表。然后运行Refresh Macros宏来装载你刚才编辑的新的宏。你将会看到Format Current Document (格式当前文档)宏。你可以运行它并且注意那个缩进的行回到它的原位置。接下来我们测试一下Alert()方法。现在将视图切换到TagsOn视图并再次运行宏,会弹出如图1的对话框:

(图1)

现在假设你想格式化文档中所选择的部分。这个请求的宏(称为Format Current Selection)跟上面所述的宏(Format Current Document)很类似。它们之间的不同只是在:Format Current Document中 Layout()方法是操作ActiveDocument 对象,而Format Current Selection中 Layout()方法是操作Selection对象:

 1<macro desc="Apply source layout to the current selection" id="53" lang="JScript" name="Format Current Selection">
 2<![CDATA[   
 3  
 4if (ActiveDocument.ViewType == viewSource) {   
 5  
 6Selection.Layout();   
 7  
 8} else{   
 9  
10Application.Alert("Applying source layout only works in source view.\nSwitch to source view and try again.");   
11  
12}   
13  
14]]></macro>
Published At
Categories with 网页设计
Tagged with
comments powered by Disqus