Добавление заголовка в MultiColumnListModel
Я работаю с библиотекой Spec в Pharo 3, и я не нашел способа добавить заголовок в список из нескольких столбцов. Тем не менее, добавление заголовков возможно через TreeColumnModel и TreeModel, например:
| m col1 col2 |
m := TreeModel new.
m roots: #(#a #b #c #d).
m rootNodeHolder: [ :item |
TreeNodeModel new
content: item;
icon: Smalltalk ui icons smallConfigurationIcon ].
m openWithSpec.
col1 := TreeColumnModel new
displayBlock: [ :node | node content asString ];
headerLabel: 'Character'.
col2 := TreeColumnModel new
displayBlock: [ :node | (Character value: node content asString first asciiValue + 1) asString ];
headerLabel: 'Character +1';
headerIcon: Smalltalk ui icons smallBackIcon.
m
columns: {col1. col2};
acceptDropBlock: [ :transfer :event :source :receiver | self halt ].
col2
headerLabel: 'Character +2';
headerIcon: Smalltalk ui icons smallBackIcon;
displayBlock: [ :node | (Character value: node content asString first asciiValue + 2) asString ].
m rootNodeHolder: [ :item |
TreeNodeModel new
content: (Character value: (item asString first asciiValue + 5)) asSymbol;
icon: Smalltalk ui icons smallFullscreenIcon ].
Как я могу получить заголовок в следующем MultiColumnListModel?
MultiColumnListModel new
items: {$a. $b. $c. $d. $f.};
displayBlock: [:e | {e asString. e isVowel asString} ];
openWithSpec.
1 ответ
Будет ли это работать для вас?
model := MultiColumnListModel new
items: { {'Letter'. 'isVowel'.}. $a. $b. $c. $d. $f.};
displayBlock: [:e |
e isArray
ifTrue:[{e first asString. e last asString} ]
ifFalse:[
{e asString. e isVowel asString} ]].
model
whenSelectionChanged:[
model getIndex = 1 ifTrue:[
model setIndex:0].
];
openWithSpec.