单例和自动化桥

Singletons and the Automation bridge

改为 com.sun.star.frame.Desktop is deprecated, and it is recommended to use the com.sun.star.frame.theDesktop 单例类型。

其他语言绑定支持访问单例。在Java中,this thread表示以下作品:

com.sun.star.frame.theDesktop.get(componentContext)

但是,com.sun.star.frame 命名空间在自动化桥下不可用;服务管理器只有一个入口点:

var objServiceManager = new ActiveXObject('com.sun.star.ServiceManager');

如何访问这个(和其他)单例?

(最初发布于 ask.libreoffice

在脚本上下文中使用 getByName 方法访问单例,将字符串路径传递给单例:

'/singletons/com.sun.star.frame.theDesktop'

自动化桥在服务管理器的 DefaultContext 属性 公开脚本上下文:

var serviceManager = new ActiveXObject('com.sun.star.ServiceManager');
var desktop = serviceManager.defaultContext.getByName('/singletons/com.sun.star.frame.theDesktop');

(我被 this post 引导到解决方案,作者试图使用 Delphi 自动化 OpenOffice。)