I'm trying to edit a cell in a Tree_View with a List_Store, and saw in GtkAda's User Guide that it offers the On_Edited procedure. I set up a callback this way with the following procedure:Signature requires a TreeView, which I do not have.
procedure Editing_Done
( Self : access Gtk_Cell_Renderer_Text_Record'Class;
Path : Glib.UTF8_String; -- this is the row
New_Text : Glib.UTF8_String
) is
begin
Tio.Put_Line( Get_Property(Self, Gtk.Cell_Renderer_Text.Text_Property)'Image ); -- line 1
Tio.Put_Line(Path'Image); -- line 2
Tio.Put_Line(New_Text'Image); -- line 3
Set_Property(Self, Gtk.Cell_Renderer_Text.Text_Property, New_Text);
Self.Stop_Editing( False );
Tio.Put_Line( Get_Property(Self, Gtk.Cell_Renderer_Text.Text_Property)'Image ); -- line 4
end Editing_Done;
I didn't really expect this to work, and it doesn't, but here's what I have verified it does do, in order:
* prints the data that was in the cell before editing (line 1)
* prints the row that was edited (line 2)
* prints the new text (line 3)
* prints the data that is in the cell as the procedure ends (line 4)
Lines 3 and 4 agree, which is great! But what I see in the TreeView is that the cell reverts after editing to the value in Line 1.
My questions:
1) The documentation of On_Edited states that I am supposed to "update the model and store New_Text at the position indicated by Path." How do I get the model? I understand that "Path" indicates the row in the List_Store / TreeView, but Get_Model's
On_* procedures are useless most of the time.
On_* procedures are useless most of the time.
I guess you mean in GtkAda?
I've found them invaluable in other contexts. If so, that's disappointing. To be fair, in the hours of reading on this I did notice that Gtk+ itself makes this difficult; the On_* procedures seem to be a GtkAda enhancement.
In the end I made it work with an On_* design, but it was your suggestion that helped! I used the second form of On_Edited and passed a TreeView in the slot. To get the model:
Tree_View: Gtk_Tree_View := Gtk_Tree_View(Self);
Model: Gtk_Tree_Model := Get_Model( Tree_View );
Iter : Gtk_Tree_Iter := Get_Iter_From_String(Model, Path);
Store: Gtk_List_Store := Gtk_List_Store( To_Object(Model) );
Getting the rest wasn't too hard after I had that. What I hadn't understood at first was that the Model had to be converted from the Interface via the To_Object function.
PS If anyone knows how to make the first form of On_Edited work, I'd be delighted to know.
In the end I made it work with an On_* design...If that is OK to you, but in production code you need a lot of stuff to
do in a handler, most of it is unrelated to the tree view.
BTW, derived widgets is also a GtkAda feature, in GTK a derived widget require a lot of work. In GtkAda they are trivial.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 339 |
Nodes: | 16 (2 / 14) |
Uptime: | 00:30:23 |
Calls: | 7,466 |
Calls today: | 2 |
Files: | 12,691 |
Messages: | 5,627,864 |