我有一个 SpTablePresenter
,我想编辑单元格内容。
在许多框架中,可以直接就地编辑表格的内容,而无需打开新组件(对话框或主从样式)。我怎样才能用 Spec 做到这一点?
最佳答案
Spec 中的表和树表实现了就地编辑字符串列的机制
在 Spec 中,只需将列声明为可编辑并发送 beEditable
消息并添加回调以通过发送 onAcceptEdition:
来处理编辑,即可编辑字符串列,它接收两个参数,正在编辑的对象和编辑后的字符串。
以下代码将展示如何完成此操作:
app := SpApplication new.
app useBackend: #Gtk.
presenter := SpPresenter new.
presenter application: app.
presenter layout: (SpBoxLayout newTopToBottom
add: (tablePresenter := presenter newTable);
yourself).
tablePresenter
addColumn: (SpStringTableColumn title: 'R/O' evaluated: #key);
addColumn: ((SpStringTableColumn
title: 'Editable'
evaluated: #value)
beEditable;
onAcceptEdition: [ :anAssociation :aString | anAssociation value: aString ];
yourself).
tablePresenter items: { 1 -> 'One'. 2 -> 'Two'. 3 -> 'Three' }.
presenter asWindow
title: 'Example editing cells';
open
这将产生(使用 Gtk3 后端)此输出:
关于smalltalk - 规范 - 如何就地编辑表格的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72257090/