Skip to content

Commit

Permalink
chore: refactor some downcast
Browse files Browse the repository at this point in the history
Signed-off-by: tsukinaha <sakuovds@gmail.com>
  • Loading branch information
tsukinaha committed Nov 22, 2024
1 parent 791143e commit 7d8c7ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 40 deletions.
34 changes: 14 additions & 20 deletions src/ui/widgets/tu_list_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,29 +864,23 @@ impl TuListItem {
async move {
let parent = obj.parent().unwrap().parent().unwrap();
if let Some(list_view) = parent.downcast_ref::<gtk::ListView>() {
let selection = list_view
list_view
.model()
.unwrap()
.downcast::<gtk::SingleSelection>()
.unwrap();
let store = selection
.model()
.unwrap()
.downcast::<gio::ListStore>()
.unwrap();
store.remove(selection.selected());
.and_downcast::<gtk::SingleSelection>()
.map(|sel| {
sel.model()
.and_downcast::<gio::ListStore>()
.map(|store| store.remove(sel.selected()))
});
} else if let Some(grid_view) = parent.downcast_ref::<gtk::GridView>() {
let selection = grid_view
.model()
.unwrap()
.downcast::<gtk::SingleSelection>()
.unwrap();
let store = selection
grid_view
.model()
.unwrap()
.downcast::<gio::ListStore>()
.unwrap();
store.remove(selection.selected());
.and_downcast::<gtk::SingleSelection>()
.map(|sel| {
sel.model()
.and_downcast::<gio::ListStore>()
.map(|store| store.remove(sel.selected()))
});
}
}
));
Expand Down
34 changes: 14 additions & 20 deletions src/ui/widgets/tu_overview_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,29 +643,23 @@ impl TuOverviewItem {
async move {
let parent = obj.parent().unwrap().parent().unwrap();
if let Some(list_view) = parent.downcast_ref::<gtk::ListView>() {
let selection = list_view
list_view
.model()
.unwrap()
.downcast::<gtk::SingleSelection>()
.unwrap();
let store = selection
.model()
.unwrap()
.downcast::<gio::ListStore>()
.unwrap();
store.remove(selection.selected());
.and_downcast::<gtk::SingleSelection>()
.map(|sel| {
sel.model()
.and_downcast::<gio::ListStore>()
.map(|store| store.remove(sel.selected()))
});
} else if let Some(grid_view) = parent.downcast_ref::<gtk::GridView>() {
let selection = grid_view
.model()
.unwrap()
.downcast::<gtk::SingleSelection>()
.unwrap();
let store = selection
grid_view
.model()
.unwrap()
.downcast::<gio::ListStore>()
.unwrap();
store.remove(selection.selected());
.and_downcast::<gtk::SingleSelection>()
.map(|sel| {
sel.model()
.and_downcast::<gio::ListStore>()
.map(|store| store.remove(sel.selected()))
});
}
}
));
Expand Down

0 comments on commit 7d8c7ec

Please sign in to comment.