From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!aioe.org!sk0Beg7Zrzno4hcHZ70Y5A.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: GtkAda's "On_Edited" Date: Mon, 30 May 2022 08:47:01 +0200 Organization: Aioe.org NNTP Server Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="24955"; posting-host="sk0Beg7Zrzno4hcHZ70Y5A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader02.eternal-september.org comp.lang.ada:63886 List-Id: On 2022-05-30 07:28, John Perry wrote: > 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: > > 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 Signature requires a TreeView, which I do not have. On_* procedures are useless most of the time. Instead, you have to instantiate Gtk.Handlers.User_Callback with a parameter indicating the widget: package Edited_Handlers is new Gtk.Handlers.User_Callback ( Gtk_Cell_Renderer_Text_Record, My_Widget_Where_The_Tree_View_Lives_Ptr ); The parameter could be Tree_Vuew as well, but having a widget is always a better design. Usually you derive your widget from some container like Gtk_Grid. The extension holds children and anything else you would need. E.g.: type My_Widget_Where_The_Tree_View_Lives is new Gtk_Grid_Record with View : Gtk_Tree_View; Store : Gtk_List_Store; Fancy_Button : Gtk_Button; ... end record; Define Gtk_New and override Initialize. In the Initialize after you called Gtk_Grid's Initialize you create all children and connect to the signal "editing-done" to the renderer: procedure Editing_Done ( Self : access Gtk_Cell_Renderer_Text_Record'Class; Path : UTF8_String; New_Text : UTF8_String; Widget : My_Widget_Where_The_Tree_View_Lives_Ptr ) Now when it is called you have the tree View and the list store (= the model) in the callback. Use Get_Iter_From_String in order to get the iterator from Path. Change the store at the iterator if you accept the edit. That's all. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de