I have a TreeView connected to a model (a ListStore). The TreeView shows the data that is stored in the ListStore and the ListStore gets updated when the user enters data into a cell, so you could say it works fine.
Except in the following case: once the user is done editing, he presses a button in order to go to the next step. If the user is currently editing a cell, the changes in that cell will be lost.
If the user presses enter or clicks on another cell after editing, the changes will be saved. But it isn't natural to do this, he will just press "Next" and expect the data to be there.
So my problem is: how do you save changes from a editable cell when a button (unrelated to the cell) is pressed?
I've tried to get the focus out of the cell once "Next" is pressed by selecting a contiguous row, hoping that it has the same effect as the user clicking on another cell, but it doesn't work and the data is erased.
I've also tried calling the following:
treeView.get_column_cell_renderer(7)->stop_editing(false); // 7 is the index of the editable column
on the TreeView's focus-out-event, but the event doesn't get called when I press "Next".
There is a thread with a similar problem at http://www.gtkforums.com/about5015.html. There, it is recommended to catch the focus-out-event of GtkCellEditable, but I'm still navigating the api trying to find out how to do so.
So, how could I solve this problem? How can I catch the focus-out-event of GtkCellEditable? Are there any other signals that could be useful?
UPDATE:
So far, my approach to solving this problem has been to attach handlers to several signals in an attempt to "rescue" the data before it is erased. I have created handlers for the following signals:
For the TreeView:
- TreeView focus-out
- TreeView cursor-changed
- TreeView columns-changed
For the CellRenderer of the editable column:
- CellRenderer editing-started
- CellRenderer editing-canceled
For the CellEditable object I get when CellRenderer.editing-started is triggered
- CellEditable editing-done
For the "Next" Button
- Button pressed
- Button clicked
When I edit a cell and then press "Next", the following sequence of events is triggered:
- CellRenderer editing-started
- TreeView cursor-changed
- TreeView focus-out
... now I type in the cell, and press "Next"...
- CellRenderer editing-canceled
- CellEditable editing-done
- Button pressed
- Button clicked
I've been trying to find an event that is triggered before editing-canceled, so that I can call CellRenderer::stop_editing(bool canceled = false) hoping that this will prevent the data from being erased. But I don't know if such event exists and don't even know if calling stop_editing will work. Do you know of an event I could use to attempt a solution? Any other thoughts?