@@ -109,6 +109,19 @@ func formatWidgetProps(w io.Writer, prefix string, header string, props []string
109109 fmt .Fprintf (w , "%s)%s" , prefix , suffix )
110110}
111111
112+ // outputDataContainerContext writes a comment showing available variables inside a data container.
113+ // isList indicates list containers (DataGrid2, ListView, Gallery) where a selection variable is available.
114+ func outputDataContainerContext (w io.Writer , prefix string , widgetName string , entityRef string , isList bool ) {
115+ if entityRef == "" {
116+ return
117+ }
118+ parts := []string {fmt .Sprintf ("$currentObject (%s)" , entityRef )}
119+ if isList && widgetName != "" {
120+ parts = append (parts , fmt .Sprintf ("$%s (selection)" , widgetName ))
121+ }
122+ fmt .Fprintf (w , "%s-- Context: %s\n " , prefix , strings .Join (parts , ", " ))
123+ }
124+
112125// outputWidgetMDLV3 outputs a widget in MDL V3 syntax.
113126// V3 syntax uses WIDGET Name (Props) { children } format.
114127func (e * Executor ) outputWidgetMDLV3 (w rawWidget , indent int ) {
@@ -255,6 +268,7 @@ func (e *Executor) outputWidgetMDLV3(w rawWidget, indent int) {
255268 }
256269 props = appendAppearanceProps (props , w )
257270 formatWidgetProps (e .output , prefix , header , props , " {\n " )
271+ outputDataContainerContext (e .output , prefix + " " , w .Name , w .EntityContext , false )
258272 for _ , child := range w .Children {
259273 e .outputWidgetMDLV3 (child , indent + 1 )
260274 }
@@ -377,6 +391,7 @@ func (e *Executor) outputWidgetMDLV3(w rawWidget, indent int) {
377391 hasContent := len (w .ControlBar ) > 0 || len (w .DataGridColumns ) > 0
378392 if hasContent {
379393 formatWidgetProps (e .output , prefix , header , props , " {\n " )
394+ outputDataContainerContext (e .output , prefix + " " , w .Name , w .EntityContext , true )
380395 // Output CONTROLBAR section if control bar widgets present
381396 if len (w .ControlBar ) > 0 {
382397 fmt .Fprintf (e .output , "%s CONTROLBAR controlBar1 {\n " , prefix )
@@ -441,6 +456,7 @@ func (e *Executor) outputWidgetMDLV3(w rawWidget, indent int) {
441456 hasContent := len (w .Children ) > 0 || len (w .FilterWidgets ) > 0
442457 if hasContent {
443458 formatWidgetProps (e .output , prefix , header , props , " {\n " )
459+ outputDataContainerContext (e .output , prefix + " " , w .Name , w .EntityContext , true )
444460 // Output FILTER section if filter widgets present
445461 if len (w .FilterWidgets ) > 0 {
446462 fmt .Fprintf (e .output , "%s FILTER filter1 {\n " , prefix )
@@ -598,6 +614,7 @@ func (e *Executor) outputWidgetMDLV3(w rawWidget, indent int) {
598614 props = appendAppearanceProps (props , w )
599615 if len (w .Children ) > 0 {
600616 formatWidgetProps (e .output , prefix , header , props , " {\n " )
617+ outputDataContainerContext (e .output , prefix + " " , w .Name , w .EntityContext , true )
601618 for _ , child := range w .Children {
602619 e .outputWidgetMDLV3 (child , indent + 1 )
603620 }
@@ -649,6 +666,7 @@ func (e *Executor) outputWidgetMDLV3(w rawWidget, indent int) {
649666 props = appendAppearanceProps (props , w )
650667 if len (w .Children ) > 0 {
651668 formatWidgetProps (e .output , prefix , header , props , " {\n " )
669+ outputDataContainerContext (e .output , prefix + " " , w .Name , w .EntityContext , true )
652670 for _ , child := range w .Children {
653671 e .outputWidgetMDLV3 (child , indent + 1 )
654672 }
0 commit comments