Smalltalk 代码解析: moveBy: anOffset orTo: aPoint 方法详解
这段代码是一个方法定义,这个方法用于移动或删除一个标记。下面是代码的解释:
moveBy: anOffset orTo: aPoint: 这是方法的名称,表示可以通过给定的偏移量或给定的点来移动标记。| graphThing p |: 这是定义了两个局部变量graphThing和p。(p := aPoint) == nil ifTrue: [ p := self position + anOffset ]: 如果给定的点aPoint是空的,则将p设置为当前标记的位置加上给定的偏移量anOffset。graphThing := self graph nodeUnder: p: 将graphThing设置为位于点p下的图形节点。graphThing class == PCNMark ifTrue: [graphThing := graphThing container]: 如果graphThing的类是PCNMark,则将graphThing设置为其容器。graphThing class == PCNPlaceChart ifFalse: [ (Dialog confirm: 'Delete the mark?' initialAnswer: true) ifTrue: [self goAway]. ^self ]: 如果graphThing的类不是PCNPlaceChart,则弹出一个对话框询问是否删除标记。如果用户确认删除,则调用self goAway方法来删除标记,然后返回。否则,继续执行后面的代码。graphThing ~= self container ifTrue: [ self moveToNewContainer: graphThing at: p ] ifFalse: [ super moveBy: anOffset orTo: p ]: 如果graphThing不等于当前标记的容器,则调用self moveToNewContainer:at:方法将标记移动到新的容器graphThing中,并设置位置为p。否则,调用父类的moveBy:orTo:方法将标记移动到给定的偏移量anOffset或给定的点p。
原文地址: https://www.cveoy.top/t/topic/f3xz 著作权归作者所有。请勿转载和采集!