comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: GtkAda's "On_Edited"
Date: Mon, 30 May 2022 08:47:01 +0200	[thread overview]
Message-ID: <t71p94$obr$1@gioia.aioe.org> (raw)
In-Reply-To: fa06c2df-0b2b-4ddc-9534-b025df4d3f76n@googlegroups.com

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

  reply	other threads:[~2022-05-30  6:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30  5:28 GtkAda's "On_Edited" John Perry
2022-05-30  6:47 ` Dmitry A. Kazakov [this message]
2022-05-30  7:46   ` John Perry
2022-05-30 18:57     ` Dmitry A. Kazakov
2022-06-01  3:18       ` John Perry
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox