www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - GtkD: How to respond to cell edit's?

reply Johnson Jones <JJ Dynomite.com> writes:
Trying to setup a callback that will propagate changes from a 
cell(and editable GtkCellRendererText) to my model.

Can't seem to find any way to get the actual GtkCellRendererText

CellRendererText has an addOnEdited but I can't find a way to get 
the CellRendererTExt for a TreeViewColumn ;/

All the examples I've seen create the renderer programmatically, 
while I'm using glade.

https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/DemoMultiCellRenderer/DemoMultiCellRenderer.d

While I could ID the cell renderer in glade, I'd like to get it 
programmatically.

Any ideas?
Aug 17
parent reply Johnson Jones <JJ Dynomite.com> writes:
I should also mention that when I use an ID to do what I 
want(again, something I don't want to do), I also need to get the 
column that was edited. This is because I'm using one delegate 
for all the edits.


auto cb = delegate(string index, string text, CellRendererText r)
{
     // How to get the column of that we are editing? An index 
would be fine.
     writeln(index, " - ", text);
};

RT1.addOnEdited(cb);
RT2.addOnEdited(cb);
RT2.addOnEdited(cb);

Looks like I might have to use separate edit handlers ;/

I wonder if I can somehow template it so I can do something like


RT1.addOnEdited(cb!1);
RT2.addOnEdited(cb!2);
RT2.addOnEdited(cb!3);

without having to write a bunch of code to make it happen. Maybe 
there is a library function that can help?
Aug 17
parent reply Johnson Jones <JJ Dynomite.com> writes:
On Friday, 18 August 2017 at 00:27:05 UTC, Johnson Jones wrote:
 I should also mention that when I use an ID to do what I 
 want(again, something I don't want to do), I also need to get 
 the column that was edited. This is because I'm using one 
 delegate for all the edits.


 auto cb = delegate(string index, string text, CellRendererText 
 r)
 {
     // How to get the column of that we are editing? An index 
 would be fine.
     writeln(index, " - ", text);
 };

 RT1.addOnEdited(cb);
 RT2.addOnEdited(cb);
 RT2.addOnEdited(cb);

 Looks like I might have to use separate edit handlers ;/

 I wonder if I can somehow template it so I can do something like


 RT1.addOnEdited(cb!1);
 RT2.addOnEdited(cb!2);
 RT2.addOnEdited(cb!3);

 without having to write a bunch of code to make it happen. 
 Maybe there is a library function that can help?
Obvious it is easy when you have ID's, but this is meant for the original case where I'm not using ID's.
Aug 17
parent reply Mike Wey <mike-wey example.com> writes:
On 18-08-17 02:30, Johnson Jones wrote:
 On Friday, 18 August 2017 at 00:27:05 UTC, Johnson Jones wrote:
 I should also mention that when I use an ID to do what I want(again, 
 something I don't want to do), I also need to get the column that was 
 edited. This is because I'm using one delegate for all the edits.


 auto cb = delegate(string index, string text, CellRendererText r)
 {
     // How to get the column of that we are editing? An index would be 
 fine.
     writeln(index, " - ", text);
 };

 RT1.addOnEdited(cb);
 RT2.addOnEdited(cb);
 RT2.addOnEdited(cb);

 Looks like I might have to use separate edit handlers ;/

 I wonder if I can somehow template it so I can do something like


 RT1.addOnEdited(cb!1);
 RT2.addOnEdited(cb!2);
 RT2.addOnEdited(cb!3);

 without having to write a bunch of code to make it happen. Maybe there 
 is a library function that can help?
Obvious it is easy when you have ID's, but this is meant for the original case where I'm not using ID's.
A far as i can tell using id's is the only option. You can use a templated function as a delegate: ``` void cb(int column)(string index, string text, CellRendererText r) { writeln(column, " - ", index, " - ", text); } RT1.addOnEdited(&cb!1); RT2.addOnEdited(&cb!2); RT2.addOnEdited(&cb!3); ``` -- Mike Wey
Aug 18
parent Johnson <Johnson Johnson.com> writes:
On Friday, 18 August 2017 at 17:06:42 UTC, Mike Wey wrote:
 On 18-08-17 02:30, Johnson Jones wrote:
 On Friday, 18 August 2017 at 00:27:05 UTC, Johnson Jones wrote:
 [...]
Obvious it is easy when you have ID's, but this is meant for the original case where I'm not using ID's.
A far as i can tell using id's is the only option. You can use a templated function as a delegate: ``` void cb(int column)(string index, string text, CellRendererText r) { writeln(column, " - ", index, " - ", text); } RT1.addOnEdited(&cb!1); RT2.addOnEdited(&cb!2); RT2.addOnEdited(&cb!3); ```
Thanks! Hopefully that will help ease the pain and help avoid the large switch statement ;) It's strange one can't get the cellrenderers's from a column ;/
Aug 18