The icon widgets (EwIconList, EwFlowedIconList, EwIconArea, and EwIconTree) can be configured to allow dynamic editing of an item's label. The application must determine what user action is to trigger the editing of a label. After this action is detected, the application should request editing of a specific item.
When an edit action is requested, the widget fires the beginEditCallback to determine the specific editing policy (see "Edit policies"). When editing is complete, the widget activates the endEditCallback to allow the application to save the edited value as appropriate.
The following example enables label editing in an icon list. The defaultActionCallback is used to trigger editing of the label.
Object subclass: #IconListEditingExample instanceVariableNames: 'icon' classVariableNames: " poolDictionaries: 'CwConstants EwConstants'
open | iconList shell | shell := CwTopLevelShell createApplicationShell: 'shell' argBlock: [:w | w title: 'Icon List Example']. iconList := shell createScrolledIconList: 'iconList' argBlock: [ :w | w items: #('first item' 'second item' 'third item' 'fourth item') asOrderedCollection].
iconList addCallback: XmNvisualInfoCallback receiver: self selector: #visualInfo:clientData:callData: clientData: nil; addCallback: XmNdefaultActionCallback receiver: self selector: #defaultAction:clientData:callData: clientData: nil;
addCallback: XmNbeginEditCallback receiver: self selector: #beginEdit:clientData:callData: clientData: nil; addCallback: XmNendEditCallback receiver: self selector: #endEdit:clientData:callData: clientData: nil.
icon := shell screen getIcon: 'default_xm_information' foregroundColor: CgRGBColor black. shell addCallback: XmNdestroyCallback receiver: self selector: #destroy:clientData:callData: clientData: nil. iconList manageChild. shell realizeWidget.
defaultAction: widget clientData: clientData callData: callData "Request editing of the selected object." widget editItemAt: callData itemPosition
beginEdit: widget clientData: clientData callData: callData "Initiate the edit for the specified item." callData doit: true
endEdit: widget clientData: clientData callData: callData "End the edit for the specified item. Replace the old text with the new text." widget replaceItems: (Array with: callData item) newItems: (Array with: callData newValue)
visualInfo: widget clientData: clientData callData: callData "Provide the icon and label for the class contained in the callData." callData icon: icon; label: callData item.
destroy: shellWidget clientData: clientData callData: callData "Free the icon resource." shellWidget screen destroyIcon: icon