Marcel Taeumel uploaded a new version of ToolBuilder-Morphic to project The Trunk: http://source.squeak.org/trunk/ToolBuilder-Morphic-mt.339.mcz
==================== Summary ====================
Name: ToolBuilder-Morphic-mt.339 Author: mt Time: 18 April 2023, 11:13:06.184406 am UUID: c2f8b605-4a98-b844-817d-b8479c2e6de2 Ancestors: ToolBuilder-Morphic-mt.338
In tree wigets, some code clean-up and a regression fix (subscript out of bounds).
=============== Diff against ToolBuilder-Morphic-mt.338 ===============
Item was changed: ----- Method: PluggableTreeMorph>>bottomVisibleRowIndex (in category 'geometry') ----- bottomVisibleRowIndex | itemAtBottom | itemAtBottom := self itemFromPoint: self bottomLeft + (3 @ -3). ^ itemAtBottom + ifNil: [ self items size ] - ifNil: [ scroller submorphs size ] ifNotNil: + [ : item | self items indexOf: item ]! - [ : item | scroller submorphs indexOf: item ]!
Item was changed: ----- Method: PluggableTreeMorph>>currentSelectionItem: (in category 'selection') ----- currentSelectionItem: itemOrNil "Variation of #selection: to ensure identity check for model data. See #updateSelection." | i | itemOrNil ifNil: [^ self selectionIndex: 0]. + i := self items findFirst: [:m | m complexContents item == itemOrNil]. - i := scroller submorphs findFirst: [:m | m complexContents item == itemOrNil]. self selectionIndex: i!
Item was changed: ----- Method: PluggableTreeMorph>>filterTreeNow (in category 'filtering') ----- filterTreeNow
self hasFilter ifFalse: [^ self removeFilter]. "Show all current items again before filtering them out." + self items do: [:item | item removeFilter]. - scroller submorphsDo: [:m | m removeFilter]. (self filterMode caseOf: { [#siblings] -> [self filterTreeNowSiblings "default"]. [#visible] -> [self filterTreeNowVisible]. [#all] -> [self filterTreeNowAll] }) ifFalse: [ "Remove the last character and try filtering again." lastKeystrokes := lastKeystrokes allButLast: 1. ^ self filterTreeNow].
self adjustSubmorphPositions.!
Item was added: + ----- Method: PluggableTreeMorph>>firstFilteredItem (in category 'filtering') ----- + firstFilteredItem + "Answer the first item that is visible and matches the current filter. That is, visible but not matching items could be a parent of a match." + + ^ self items + detect: [:item | item isFilterMatch] + ifNone: []!
Item was added: + ----- Method: PluggableTreeMorph>>firstFilteredItemAfterSelection (in category 'filtering') ----- + firstFilteredItemAfterSelection + + ^ self items + at: (self items + findFirst: [:m | m isFilterMatch] + startingAt: self getSelectionIndex) + ifAbsent: []!
Item was changed: ----- Method: PluggableTreeMorph>>removeFilter (in category 'filtering') ----- removeFilter "Remove the current filter. Keep the current selection stable unless it is expanded and needs more space for its children. Note that we must not check for #hasFilter here but in the sender if needed; see #filterTreeNow."
lastKeystrokes := String empty.
self filterMode = #all ifTrue: [ + self items do: [:item | item removeFilter]. - scroller submorphsDo: [:m | m removeFilter]. self collapseAllButSelection] ifFalse: [ self fixateSelectionDuring: [ + self items do: [:item | item removeFilter]. - scroller submorphsDo: [:m | m removeFilter]. self adjustSubmorphPositions]].
"Try to show all children again for the current selection." self scrollSelectionAndChildrenIntoView. self scrollSelectionAndExtraIntoView.!
Item was changed: ----- Method: PluggableTreeMorph>>selectPath: (in category 'selection') ----- selectPath: path "Select the given path. Do not tell the model. Just update the view."
| newSelection | path ifNil: [^ self]. path ifEmpty: [^ self selectedMorph: nil]. + self items ifEmpty: [^ self]. - scroller hasSubmorphs ifFalse: [^ self].
+ newSelection := self selectPath: path in: self items first. - newSelection := self selectPath: path in: scroller firstSubmorph. self adjustSubmorphPositions. "First adjust, then select to keep selection visible." self selectedMorph: newSelection.!
Item was changed: ----- Method: PluggableTreeMorph>>topVisibleRowIndex (in category 'geometry') ----- topVisibleRowIndex + ^ self items indexOf: (self itemFromPoint: self topLeft+(3@3))! - ^ scroller submorphs indexOf: (self itemFromPoint: self topLeft+(3@3))!
Item was changed: ----- Method: PluggableTreeMorph>>treeFilterSet: (in category 'filtering') ----- treeFilterSet: aString "Set the filter term and select the first match."
self filterTerm: aString. + self setSelectedMorph: self firstFilteredItem.! - self setSelectedMorph: self filteredItems first.!
Item was changed: ----- Method: PluggableTreeMorph>>update:with: (in category 'updating') ----- update: what with: anObject
super update: what with: anObject. what == #objectChanged ifTrue: [ ^ self updateFromChangedObject: anObject]. what == #expandAllNodesRequested ifTrue: [ "EX: model changed: #expandAllNodesRequested with: #classChildren:." "EX: model changed: #expandAllNodesRequested with: {#classChildren:. Morph}." | scope item | scope := anObject isArray ifTrue: [anObject first] ifFalse: [anObject]. item := anObject isArray ifTrue: [anObject second]. getChildrenSelector == scope ifTrue: [ item ifNil: [self roots do: [:ea | self expandAll: ea]] + ifNotNil: [self expandAll: (self items detect: [:ea | ea complexContents item == item])]. - ifNotNil: [self expandAll: (scroller submorphs detect: [:ea | ea complexContents item == item])]. self adjustSubmorphPositions. ^ self]]. what == #expandNodeRequested ifTrue: [ "EX: model changed: #expandNodeRequested with: {#classChildren:. Morph}." | scope item | scope := anObject first. item := anObject second. getChildrenSelector == scope ifTrue: [ + self items - scroller submorphs detect: [:ea | ea complexContents item == item] ifFound: [:morph | (morph canExpand and: [morph isExpanded not]) ifTrue: [self toggleExpandedState: morph]]. ^ self]].!
Item was changed: ----- Method: PluggableTreeMorph>>updateAllLabels (in category 'updating') ----- updateAllLabels
+ self items do: [:ea | ea contents: ea getLabel]. - scroller submorphs do: [:ea | ea contents: ea getLabel]. "self adjustSubmorphPositions. --- not required"!
Item was changed: ----- Method: PluggableTreeMorph>>updateFromChangedObject: (in category 'updating') ----- updateFromChangedObject: anObject
+ self items - scroller submorphs detect: [:morph | morph complexContents item == anObject] ifFound: [:morph | self updateMorph: morph] ifNone: ["Ignore the request. Object may not be visible anyway."].!
Item was changed: ----- Method: PluggableTreeMorph>>updateSelectionAfterFilter (in category 'updating') ----- updateSelectionAfterFilter "Filter has changed. The current selection might not be visible anymore. Update it accordingly."
| focus currentParent firstMatch | self hoveredMorph: nil. ((focus := self selectedMorph) notNil and: [focus isFilterMatch]) ifTrue: [^ self "no change, keep view stable"]. self filterMode = #siblings ifTrue: [ "Consider parent for local scope" firstMatch := (currentParent := self selectedParentMorph) + ifNil: [self firstFilteredItem "i.e., any visible root"] - ifNil: [self roots detect: [:ea | ea visible]] ifNotNil: [:pm | pm firstVisibleChild]] ifFalse: [ "#all, #visible -- any filter match will do" firstMatch := focus + ifNil: [self firstFilteredItem] + ifNotNil: [:fm | self firstFilteredItemAfterSelection + ifNil: [self firstFilteredItem]]]. - ifNil: [scroller submorphs detect: [:m | m isFilterMatch]] - ifNotNil: [:fm | - scroller submorphs at: (scroller submorphs - findFirst: [:m | m isFilterMatch] - startingAt: self getSelectionIndex)]].
"Select the first match only if current selection does not match anymore." self setSelectedMorph: firstMatch. "New parent for #all or #visible possible" self scrollSelectionAndExtraIntoView. "Keep parent visible to provide context information. Ensure visibility of current selection." self scrollSelectionParentIntoView: (currentParent ifNil: [self selectedParentMorph]).!
packages@lists.squeakfoundation.org