-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create ListBox-Sorted-StringList-model #1879
base: main
Are you sure you want to change the base?
Conversation
Modified version of the ListBox-Model example using a StringList that is sorted. The StringSorter object uses a PropertyExpression to specify the sorted parameter. Delete button is functional but l suspect wrong entry is deleted. It is not needed for my use case, but it would be good to have it function correctly. Add button is not functional but might be a nice addition to the example.
Revised so that correct model entry is deleted when delete button is pressed.
@@ -1,5 +1,5 @@ | |||
// Variation on ListBox model example to show use of StringList and StringSorter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not enough, you should look at other examples. You need a folder containing a main.rs file, then the folder should be added to the README.md and Cargo.toml; like other examples https://github.com/gtk-rs/gtk4-rs/blob/master/examples/Cargo.toml#L163
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I create a folder? I'm afraid I'm not very familiar with actually doing stuff on github.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ping me by DM on Matrix and can guide through that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that tomorrow. Way past my bed time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have it figured out. I created a codespace where I can make the changes. Thanks for your help.
I think its ready to go Bilel. |
Do you mind running the code with rustfmt? I will give it a review soonish |
sure. I'll run it with rustfmt. |
listbox, | ||
move |_| { | ||
let selected = listbox.selected_row(); | ||
//let sorted_model = listbox.model(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused, remove it
let selected = listbox.selected_row(); | ||
//let sorted_model = listbox.model(); | ||
|
||
if let Some(selected) = selected { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Some(selected) = selected { | |
if let Some(row) = listbox.selected_row() { |
// Via the delete button we delete the item from the model that | ||
// is at the index of the selected row. Also deleting from the | ||
// model is immediately reflected in the listbox. | ||
let delete_button = gtk::Button::with_label("Delete"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this adds more complexity and it is not really the best way to achieve that. So I would just keep it for implementing a sort with stringlist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestions. I've removed the "add" and "delete" buttons to simplify the example.
// and only create it once the Ok button in the dialog is clicked, and only | ||
// then add it to the model. Once added to the model, it will immediately | ||
// appear in the listbox UI | ||
let add_button = gtk::Button::with_label("Add"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does nothing, i would also remove it and keep things pretty simple
@@ -0,0 +1,147 @@ | |||
// Variation on ListBox model example to show use of StringList and StringSorter. | |||
|
|||
// TODO: add a dialog window to allow adding rows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I mentioned below, just drop it
Co-authored-by: Bilal Elmoussaoui <[email protected]>
Co-authored-by: Bilal Elmoussaoui <[email protected]>
Much appreciate your review. I've implemented your suggestions, removing the add and delete buttons. Let me know if you have other suggestions. Thanks |
I've revised the delete button closure so that the Gobject to be deleted is found by indexing into the sort_model. This streamlines the code significantly. |
Modified version of the ListBox-Model example using a StringList that is sorted. The StringSorter object uses a PropertyExpression to specify the sorted parameter.
Delete button is functional but l suspect wrong entry is deleted. It is not needed for my use case, but it would be good to have it function correctly. Add button is not functional but might be a nice addition to the example.