Skip to content

Commit 88602b5

Browse files
committed
Deleted add and delete buttons
1 parent e0b01a5 commit 88602b5

File tree

1 file changed

+0
-59
lines changed
  • examples/listbox_sort_stringlist

1 file changed

+0
-59
lines changed

examples/listbox_sort_stringlist/main.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// Variation on ListBox model example to show use of StringList and StringSorter.
22

3-
// TODO: add a dialog window to allow adding rows.
4-
// use plain gtk::Window for this per current practice.
5-
63
use gtk::{
74
glib::{self, clone},
85
prelude::*,
@@ -79,62 +76,6 @@ fn build_ui(application: &gtk::Application) {
7976

8077
scrolled_window.set_child(Some(&listbox));
8178

82-
let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 5);
83-
84-
// The add button opens a new dialog which is basically the same as the edit
85-
// dialog, except that we don't have a corresponding item yet at that point
86-
// and only create it once the Ok button in the dialog is clicked, and only
87-
// then add it to the model. Once added to the model, it will immediately
88-
// appear in the listbox UI
89-
let add_button = gtk::Button::with_label("Add");
90-
add_button.set_sensitive(false);
91-
92-
hbox.append(&add_button);
93-
94-
// Via the delete button we delete the item from the model that
95-
// is at the index of the selected row. Also deleting from the
96-
// model is immediately reflected in the listbox.
97-
let delete_button = gtk::Button::with_label("Delete");
98-
delete_button.connect_clicked(clone!(
99-
#[weak]
100-
model,
101-
#[weak]
102-
listbox,
103-
move |_| {
104-
let selected = listbox.selected_row();
105-
//let sorted_model = listbox.model();
106-
107-
if let Some(selected) = selected {
108-
// Find the selected text.
109-
let selected = selected.child().expect("Listrow child should be a widget");
110-
let selected = selected
111-
.downcast_ref::<gtk::Inscription>()
112-
.expect("The object should be of type `Inscription`.");
113-
if let Some(selected) = selected.text() {
114-
let mut selected_index = None;
115-
// Find the position in the StringList model of the selected string
116-
for ind in 0..model.n_items() {
117-
if let Some(item) = model.item(ind) {
118-
let item = item
119-
.downcast_ref::<gtk::StringObject>()
120-
.expect("Object should be a stringobject");
121-
if item.string() == selected {
122-
selected_index = Some(ind);
123-
break;
124-
}
125-
}
126-
}
127-
// If the selected string is found in the stringlist model, delete it
128-
if let Some(index) = selected_index {
129-
model.remove(index);
130-
}
131-
}
132-
}
133-
}
134-
));
135-
hbox.append(&delete_button);
136-
137-
vbox.append(&hbox);
13879
vbox.append(&scrolled_window);
13980

14081
window.set_child(Some(&vbox));

0 commit comments

Comments
 (0)