Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
24 changes: 21 additions & 3 deletions examples/ListBox-Sorted-StringList-model
Original file line number Diff line number Diff line change
@@ -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
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
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
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.

// Issues: list disply doesn't update correctly on delete.
// Issues: list display doesn't update correctly on delete.

// TODO: add a dialog window to allow adding rows.
// use plain gtk::Window for this per current practice.
Expand Down Expand Up @@ -106,8 +106,26 @@ fn build_ui(application: &gtk::Application) {
let selected = listbox.selected_row();

if let Some(selected) = selected {
let idx = selected.index();
model.remove(idx as u32);
let selected = selected.child()
.expect("Listrow child should be a widget");
let selected = selected.downcast_ref::<gtk::Inscription>()
.expect("The object should be of type `Inscription`.");
if let Some(selected) = selected.text() {
let mut selected_index = None;
for ind in 0..model.n_items() {
if let Some(item) = model.item(ind) {
let item = item.downcast_ref::<gtk::StringObject>()
.expect("Object should be a stringobject");
if item.string() == selected {
selected_index = Some(ind);
break;
}
}
}
if let Some(index) = selected_index {
model.remove(index);
}
}
}
}
));
Expand Down
Loading