Skip to content

Conversation

@jimbrankelly
Copy link
Contributor

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.

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.
@jimbrankelly jimbrankelly marked this pull request as draft October 22, 2024 06:03
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.
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@jimbrankelly jimbrankelly marked this pull request as ready for review October 22, 2024 22:33
@jimbrankelly
Copy link
Contributor Author

I think its ready to go Bilel.

@bilelmoussaoui
Copy link
Member

Do you mind running the code with rustfmt? I will give it a review soonish

@jimbrankelly
Copy link
Contributor Author

sure. I'll run it with rustfmt.

listbox,
move |_| {
let selected = listbox.selected_row();
//let sorted_model = listbox.model();
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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");
Copy link
Member

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

Copy link
Contributor Author

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");
Copy link
Member

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.
Copy link
Member

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

@jimbrankelly
Copy link
Contributor Author

Much appreciate your review. I've implemented your suggestions, removing the add and delete buttons. Let me know if you have other suggestions. Thanks

@jimbrankelly
Copy link
Contributor Author

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.

@bilelmoussaoui
Copy link
Member

Sorry for the delay, but i finally took the time to clean up this example and merged it to main already https://github.com/gtk-rs/gtk4-rs/tree/main/examples/list_box_sort_stringlist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants