簡體   English   中英

規范 - 如何就地編輯表格的內容

[英]Spec - How to edit the contents of a table in place

我有一個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 后端)這個輸出:

示例就地編輯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM