| 
									
										
										
										
											2025-05-17 12:16:49 +00:00
										 |  |  | package cmdpacks | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2025-05-26 12:04:23 +00:00
										 |  |  | 	"lmika.dev/cmd/dynamo-browse/internal/common/ui/commandctrl" | 
					
						
							|  |  |  | 	"lmika.dev/cmd/dynamo-browse/internal/dynamo-browse/controllers" | 
					
						
							|  |  |  | 	"lmika.dev/cmd/dynamo-browse/internal/dynamo-browse/models" | 
					
						
							| 
									
										
										
										
											2025-05-17 12:16:49 +00:00
										 |  |  | 	"github.com/pkg/errors" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-18 03:42:44 +00:00
										 |  |  | type tablePVar struct { | 
					
						
							|  |  |  | 	state *controllers.State | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (rs tablePVar) Get(ctx context.Context) (any, error) { | 
					
						
							|  |  |  | 	return newTableProxy(rs.state.ResultSet().TableInfo), nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-17 12:16:49 +00:00
										 |  |  | type resultSetPVar struct { | 
					
						
							|  |  |  | 	state          *controllers.State | 
					
						
							|  |  |  | 	readController *controllers.TableReadController | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (rs resultSetPVar) Get(ctx context.Context) (any, error) { | 
					
						
							| 
									
										
										
										
											2025-05-18 03:42:44 +00:00
										 |  |  | 	return newResultSetProxy(rs.state.ResultSet()), nil | 
					
						
							| 
									
										
										
										
											2025-05-17 12:16:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (rs resultSetPVar) Set(ctx context.Context, value any) error { | 
					
						
							| 
									
										
										
										
											2025-05-19 12:14:22 +00:00
										 |  |  | 	rsVal, ok := value.(SimpleProxy[*models.ResultSet]) | 
					
						
							| 
									
										
										
										
											2025-05-17 12:16:49 +00:00
										 |  |  | 	if !ok { | 
					
						
							| 
									
										
										
										
											2025-05-19 12:14:22 +00:00
										 |  |  | 		return errors.New("new value to @resultset is nil or not a result set") | 
					
						
							| 
									
										
										
										
											2025-05-17 12:16:49 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-18 03:42:44 +00:00
										 |  |  | 	msg := rs.readController.SetResultSet(rsVal.value) | 
					
						
							| 
									
										
										
										
											2025-05-17 12:16:49 +00:00
										 |  |  | 	commandctrl.PostMsg(ctx, msg) | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-05-18 03:42:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | type itemPVar struct { | 
					
						
							|  |  |  | 	state *controllers.State | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (rs itemPVar) Get(ctx context.Context) (any, error) { | 
					
						
							|  |  |  | 	selItem, ok := commandctrl.SelectedItemIndex(ctx) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return nil, errors.New("no item selected") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return itemProxy{rs.state.ResultSet(), selItem, rs.state.ResultSet().Items()[selItem]}, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (rs itemPVar) Set(ctx context.Context, value any) error { | 
					
						
							|  |  |  | 	rsVal, ok := value.(itemProxy) | 
					
						
							|  |  |  | 	if !ok { | 
					
						
							|  |  |  | 		return errors.New("new value to @item is not an item") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if msg := commandctrl.SetSelectedItemIndex(ctx, rsVal.idx); msg != nil { | 
					
						
							|  |  |  | 		commandctrl.PostMsg(ctx, msg) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } |