Skip to content

Commit 45aa692

Browse files
author
Deren Vural
committed
Quick MainWindow Refactor
Updated MainWindow class: - Refactor to use match instead of expect Signed-off-by: Deren Vural <[email protected]>
1 parent 09d8b58 commit 45aa692

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/mainwindow/imp.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,19 @@ impl MainWindow {
442442
// Add to list of pages
443443
let mut gpu_page_list: RefMut<Vec<GpuPage>> = self.gpu_pages.borrow_mut();
444444
gpu_page_list.push(new_page);
445-
let new_page_ref: &GpuPage = gpu_page_list.last().expect("COULD NOT FETCH GPU PAGE REF");
446-
447-
// Create scrollable container
448-
let scrolled_window: ScrolledWindow = ScrolledWindow::new();
449-
scrolled_window.set_hscrollbar_policy(PolicyType::Never);
450-
scrolled_window.set_vscrollbar_policy(PolicyType::Automatic);
451-
scrolled_window.set_child(Some(new_page_ref));
452-
453-
// Append new ListBoxRow object to GtkListBox
454-
self.gpu_stack.add_titled(&scrolled_window, Some(uuid), name);
445+
match gpu_page_list.last() {
446+
Some(new_page_ref) => {
447+
// Create scrollable container
448+
let scrolled_window: ScrolledWindow = ScrolledWindow::new();
449+
scrolled_window.set_hscrollbar_policy(PolicyType::Never);
450+
scrolled_window.set_vscrollbar_policy(PolicyType::Automatic);
451+
scrolled_window.set_child(Some(new_page_ref));
452+
453+
// Append new ListBoxRow object to GtkListBox
454+
self.gpu_stack.add_titled(&scrolled_window, Some(uuid), name);
455+
},
456+
None => panic!("COULD NOT FETCH GPU PAGE REF"),
457+
}
455458
}
456459

457460
/**
@@ -472,8 +475,7 @@ impl MainWindow {
472475
*/
473476
#[template_callback]
474477
fn refresh_cards(&self, _button: &Button) {
475-
//TEST
476-
println!("GPU Scan Button Pressed!");
478+
println!("GPU Scan Button Pressed!");//TEST
477479

478480
// Clear current ActionRow objects from GtkListBox
479481
let mut done: bool = false;

0 commit comments

Comments
 (0)