Pharo 10及后续版本中GTInspector的替代方案咨询
关于Pharo 10中旧版GTInspector兼容包及替代方案的问题
我安装的一个旧Pharo包依赖GTInspector,该工具在Pharo 10之前是默认安装组件。但在Pharo 10中尝试安装GTInspector时,会自动安装大部分当前版本的Glamorous Toolkit包,因此我想知道是否有兼容Pharo 10的旧版GTInspector及相关工具,或者Pharo 10及以后版本是否提供了GTInspector的内置替代工具。
调用GTInspector的代码片段如下:
openInspector ifTrue: [ self bringToFront. GTInspector inspect: result ]. ^ { (#message -> result asString). (#status -> status) } asDictionary
以及
apiEvalBindings: req self bringToFront. GTInspector inspect: interactionModel bindings. ^ { (#status -> #success). (#message -> 'Inspector has been opened.') } asDictionary
一、兼容Pharo 10的旧版GTInspector包
可以安装GTInspectorCore独立包,它是旧版GTInspector的核心组件,不会连带安装完整的Glamorous Toolkit。在Pharo 10的Playground中执行以下代码即可安装:
Metacello new baseline: 'GTInspectorCore'; repository: 'github://pharo-ide/gt-inspector:pharo10'; load.
安装完成后,原代码中GTInspector inspect:的调用可直接正常使用,无需修改代码。
二、Pharo内置的替代方案
Pharo 10及以后版本默认提供StInspector(Spotlight Inspector)作为内置检查器,它是原GTInspector的替代工具,核心功能完全覆盖旧版GTInspector。
1. 直接替换类名
将原代码中的GTInspector inspect:替换为StInspector inspect:即可,修改后的代码如下:
第一个代码片段修改后:
openInspector ifTrue: [ self bringToFront. StInspector inspect: result ]. ^ { (#message -> result asString). (#status -> status) } asDictionary
第二个代码片段修改后:
apiEvalBindings: req self bringToFront. StInspector inspect: interactionModel bindings. ^ { (#status -> #success). (#message -> 'Inspector has been opened.') } asDictionary
2. 通用兼容写法
如果希望代码适配更多Pharo版本,可使用系统默认检查器的通用调用方式,无需硬编码具体类名:
Smalltalk tools inspector inspect: result
这种写法会自动调用当前系统的默认检查器,兼容性更强。
内容的提问来源于stack exchange,提问作者vfclists
相关产品推荐
相关产品推荐

